]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - kernel/patches/grsecurity-3.0-3.14.2-201404270907.patch
Merge remote-tracking branch 'ms/pdns'
[people/ms/ipfire-3.x.git] / kernel / patches / grsecurity-3.0-3.14.2-201404270907.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..e289b9b 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -92,32 +101,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -203,7 +227,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -213,8 +242,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -224,6 +257,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -235,13 +269,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -249,9 +287,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238 index 7116fda..d8ed6e8 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1084,6 +1084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246 + ignore grsecurity's /proc restrictions
247 +
248 +
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252 @@ -2080,6 +2084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256 + nopcid [X86-64]
257 + Disable PCID (Process-Context IDentifier) even if it
258 + is supported by the processor.
259 +
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263 @@ -2347,6 +2355,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268 + virtualization environments that don't cope well with the
269 + expand down segment used by UDEREF on X86-32 or the frequent
270 + page table updates on X86-64.
271 +
272 + pax_sanitize_slab=
273 + 0/1 to disable/enable slab object sanitization (enabled by
274 + default).
275 +
276 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277 +
278 + pax_extra_latent_entropy
279 + Enable a very simple form of latent entropy extraction
280 + from the first 4GB of memory as the bootmem allocator
281 + passes the memory pages to the buddy allocator.
282 +
283 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284 + when the processor supports PCID.
285 +
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289 diff --git a/Makefile b/Makefile
290 index b2f7de8..9e2b63f 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 -Wno-array-bounds
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305 @@ -423,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309 -PHONY += scripts_basic
310 -scripts_basic:
311 +PHONY += scripts_basic gcc-plugins
312 +scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316 @@ -585,6 +586,72 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320 +ifndef DISABLE_PAX_PLUGINS
321 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323 +else
324 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325 +endif
326 +ifneq ($(PLUGINCC),)
327 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329 +endif
330 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
331 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333 +endif
334 +ifdef CONFIG_KALLOCSTAT_PLUGIN
335 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336 +endif
337 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341 +endif
342 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346 +endif
347 +endif
348 +ifdef CONFIG_CHECKER_PLUGIN
349 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351 +endif
352 +endif
353 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354 +ifdef CONFIG_PAX_SIZE_OVERFLOW
355 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356 +endif
357 +ifdef CONFIG_PAX_LATENT_ENTROPY
358 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359 +endif
360 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362 +endif
363 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369 +ifeq ($(KBUILD_EXTMOD),)
370 +gcc-plugins:
371 + $(Q)$(MAKE) $(build)=tools/gcc
372 +else
373 +gcc-plugins: ;
374 +endif
375 +else
376 +gcc-plugins:
377 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
379 +else
380 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381 +endif
382 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383 +endif
384 +endif
385 +
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389 @@ -779,7 +846,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398 @@ -828,6 +895,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407 @@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411 -$(vmlinux-dirs): prepare scripts
412 +$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416 @@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430 @@ -991,6 +1063,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439 @@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443 -modules_prepare: prepare scripts
444 +modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448 @@ -1072,7 +1146,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452 - signing_key.x509.signer
453 + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
454 + tools/gcc/randomize_layout_seed.h
455
456 # clean - Delete most, but leave enough to build external modules
457 #
458 @@ -1112,6 +1187,7 @@ distclean: mrproper
459 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
460 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
461 -o -name '.*.rej' \
462 + -o -name '.*.rej' -o -name '*.so' \
463 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
464 -type f -print | xargs rm -f
465
466 @@ -1273,6 +1349,8 @@ PHONY += $(module-dirs) modules
467 $(module-dirs): crmodverdir $(objtree)/Module.symvers
468 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
469
470 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
471 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
472 modules: $(module-dirs)
473 @$(kecho) ' Building modules, stage 2.';
474 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
475 @@ -1412,17 +1490,21 @@ else
476 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
477 endif
478
479 -%.s: %.c prepare scripts FORCE
480 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
481 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
482 +%.s: %.c gcc-plugins prepare scripts FORCE
483 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
484 %.i: %.c prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486 -%.o: %.c prepare scripts FORCE
487 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
488 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
489 +%.o: %.c gcc-plugins prepare scripts FORCE
490 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
491 %.lst: %.c prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493 -%.s: %.S prepare scripts FORCE
494 +%.s: %.S gcc-plugins prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496 -%.o: %.S prepare scripts FORCE
497 +%.o: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 %.symtypes: %.c prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501 @@ -1432,11 +1514,15 @@ endif
502 $(cmd_crmodverdir)
503 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
504 $(build)=$(build-dir)
505 -%/: prepare scripts FORCE
506 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
507 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
508 +%/: gcc-plugins prepare scripts FORCE
509 $(cmd_crmodverdir)
510 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
511 $(build)=$(build-dir)
512 -%.ko: prepare scripts FORCE
513 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
514 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
515 +%.ko: gcc-plugins prepare scripts FORCE
516 $(cmd_crmodverdir)
517 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
518 $(build)=$(build-dir) $(@:.ko=.o)
519 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
520 index 78b03ef..da28a51 100644
521 --- a/arch/alpha/include/asm/atomic.h
522 +++ b/arch/alpha/include/asm/atomic.h
523 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
524 #define atomic_dec(v) atomic_sub(1,(v))
525 #define atomic64_dec(v) atomic64_sub(1,(v))
526
527 +#define atomic64_read_unchecked(v) atomic64_read(v)
528 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
529 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
530 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
531 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
532 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
533 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
534 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
535 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
536 +
537 #define smp_mb__before_atomic_dec() smp_mb()
538 #define smp_mb__after_atomic_dec() smp_mb()
539 #define smp_mb__before_atomic_inc() smp_mb()
540 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
541 index ad368a9..fbe0f25 100644
542 --- a/arch/alpha/include/asm/cache.h
543 +++ b/arch/alpha/include/asm/cache.h
544 @@ -4,19 +4,19 @@
545 #ifndef __ARCH_ALPHA_CACHE_H
546 #define __ARCH_ALPHA_CACHE_H
547
548 +#include <linux/const.h>
549
550 /* Bytes per L1 (data) cache line. */
551 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
552 -# define L1_CACHE_BYTES 64
553 # define L1_CACHE_SHIFT 6
554 #else
555 /* Both EV4 and EV5 are write-through, read-allocate,
556 direct-mapped, physical.
557 */
558 -# define L1_CACHE_BYTES 32
559 # define L1_CACHE_SHIFT 5
560 #endif
561
562 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
563 #define SMP_CACHE_BYTES L1_CACHE_BYTES
564
565 #endif
566 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
567 index 968d999..d36b2df 100644
568 --- a/arch/alpha/include/asm/elf.h
569 +++ b/arch/alpha/include/asm/elf.h
570 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
571
572 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
573
574 +#ifdef CONFIG_PAX_ASLR
575 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
576 +
577 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
578 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
579 +#endif
580 +
581 /* $0 is set by ld.so to a pointer to a function which might be
582 registered using atexit. This provides a mean for the dynamic
583 linker to call DT_FINI functions for shared libraries that have
584 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
585 index aab14a0..b4fa3e7 100644
586 --- a/arch/alpha/include/asm/pgalloc.h
587 +++ b/arch/alpha/include/asm/pgalloc.h
588 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
589 pgd_set(pgd, pmd);
590 }
591
592 +static inline void
593 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
594 +{
595 + pgd_populate(mm, pgd, pmd);
596 +}
597 +
598 extern pgd_t *pgd_alloc(struct mm_struct *mm);
599
600 static inline void
601 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
602 index d8f9b7e..f6222fa 100644
603 --- a/arch/alpha/include/asm/pgtable.h
604 +++ b/arch/alpha/include/asm/pgtable.h
605 @@ -102,6 +102,17 @@ struct vm_area_struct;
606 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
607 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
608 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
609 +
610 +#ifdef CONFIG_PAX_PAGEEXEC
611 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
612 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
613 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
614 +#else
615 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
616 +# define PAGE_COPY_NOEXEC PAGE_COPY
617 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
618 +#endif
619 +
620 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
621
622 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
623 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
624 index 2fd00b7..cfd5069 100644
625 --- a/arch/alpha/kernel/module.c
626 +++ b/arch/alpha/kernel/module.c
627 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
628
629 /* The small sections were sorted to the end of the segment.
630 The following should definitely cover them. */
631 - gp = (u64)me->module_core + me->core_size - 0x8000;
632 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
633 got = sechdrs[me->arch.gotsecindex].sh_addr;
634
635 for (i = 0; i < n; i++) {
636 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
637 index 1402fcc..0b1abd2 100644
638 --- a/arch/alpha/kernel/osf_sys.c
639 +++ b/arch/alpha/kernel/osf_sys.c
640 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
641 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
642
643 static unsigned long
644 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
645 - unsigned long limit)
646 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
647 + unsigned long limit, unsigned long flags)
648 {
649 struct vm_unmapped_area_info info;
650 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
651
652 info.flags = 0;
653 info.length = len;
654 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
655 info.high_limit = limit;
656 info.align_mask = 0;
657 info.align_offset = 0;
658 + info.threadstack_offset = offset;
659 return vm_unmapped_area(&info);
660 }
661
662 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
663 merely specific addresses, but regions of memory -- perhaps
664 this feature should be incorporated into all ports? */
665
666 +#ifdef CONFIG_PAX_RANDMMAP
667 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
668 +#endif
669 +
670 if (addr) {
671 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
672 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
673 if (addr != (unsigned long) -ENOMEM)
674 return addr;
675 }
676
677 /* Next, try allocating at TASK_UNMAPPED_BASE. */
678 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
679 - len, limit);
680 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
681 +
682 if (addr != (unsigned long) -ENOMEM)
683 return addr;
684
685 /* Finally, try allocating in low memory. */
686 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
687 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
688
689 return addr;
690 }
691 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
692 index 98838a0..b304fb4 100644
693 --- a/arch/alpha/mm/fault.c
694 +++ b/arch/alpha/mm/fault.c
695 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
696 __reload_thread(pcb);
697 }
698
699 +#ifdef CONFIG_PAX_PAGEEXEC
700 +/*
701 + * PaX: decide what to do with offenders (regs->pc = fault address)
702 + *
703 + * returns 1 when task should be killed
704 + * 2 when patched PLT trampoline was detected
705 + * 3 when unpatched PLT trampoline was detected
706 + */
707 +static int pax_handle_fetch_fault(struct pt_regs *regs)
708 +{
709 +
710 +#ifdef CONFIG_PAX_EMUPLT
711 + int err;
712 +
713 + do { /* PaX: patched PLT emulation #1 */
714 + unsigned int ldah, ldq, jmp;
715 +
716 + err = get_user(ldah, (unsigned int *)regs->pc);
717 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
718 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
719 +
720 + if (err)
721 + break;
722 +
723 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
724 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
725 + jmp == 0x6BFB0000U)
726 + {
727 + unsigned long r27, addr;
728 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
729 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
730 +
731 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
732 + err = get_user(r27, (unsigned long *)addr);
733 + if (err)
734 + break;
735 +
736 + regs->r27 = r27;
737 + regs->pc = r27;
738 + return 2;
739 + }
740 + } while (0);
741 +
742 + do { /* PaX: patched PLT emulation #2 */
743 + unsigned int ldah, lda, br;
744 +
745 + err = get_user(ldah, (unsigned int *)regs->pc);
746 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
747 + err |= get_user(br, (unsigned int *)(regs->pc+8));
748 +
749 + if (err)
750 + break;
751 +
752 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
753 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
754 + (br & 0xFFE00000U) == 0xC3E00000U)
755 + {
756 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
757 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
758 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
759 +
760 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
761 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
762 + return 2;
763 + }
764 + } while (0);
765 +
766 + do { /* PaX: unpatched PLT emulation */
767 + unsigned int br;
768 +
769 + err = get_user(br, (unsigned int *)regs->pc);
770 +
771 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
772 + unsigned int br2, ldq, nop, jmp;
773 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
774 +
775 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
776 + err = get_user(br2, (unsigned int *)addr);
777 + err |= get_user(ldq, (unsigned int *)(addr+4));
778 + err |= get_user(nop, (unsigned int *)(addr+8));
779 + err |= get_user(jmp, (unsigned int *)(addr+12));
780 + err |= get_user(resolver, (unsigned long *)(addr+16));
781 +
782 + if (err)
783 + break;
784 +
785 + if (br2 == 0xC3600000U &&
786 + ldq == 0xA77B000CU &&
787 + nop == 0x47FF041FU &&
788 + jmp == 0x6B7B0000U)
789 + {
790 + regs->r28 = regs->pc+4;
791 + regs->r27 = addr+16;
792 + regs->pc = resolver;
793 + return 3;
794 + }
795 + }
796 + } while (0);
797 +#endif
798 +
799 + return 1;
800 +}
801 +
802 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
803 +{
804 + unsigned long i;
805 +
806 + printk(KERN_ERR "PAX: bytes at PC: ");
807 + for (i = 0; i < 5; i++) {
808 + unsigned int c;
809 + if (get_user(c, (unsigned int *)pc+i))
810 + printk(KERN_CONT "???????? ");
811 + else
812 + printk(KERN_CONT "%08x ", c);
813 + }
814 + printk("\n");
815 +}
816 +#endif
817
818 /*
819 * This routine handles page faults. It determines the address,
820 @@ -133,8 +251,29 @@ retry:
821 good_area:
822 si_code = SEGV_ACCERR;
823 if (cause < 0) {
824 - if (!(vma->vm_flags & VM_EXEC))
825 + if (!(vma->vm_flags & VM_EXEC)) {
826 +
827 +#ifdef CONFIG_PAX_PAGEEXEC
828 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
829 + goto bad_area;
830 +
831 + up_read(&mm->mmap_sem);
832 + switch (pax_handle_fetch_fault(regs)) {
833 +
834 +#ifdef CONFIG_PAX_EMUPLT
835 + case 2:
836 + case 3:
837 + return;
838 +#endif
839 +
840 + }
841 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
842 + do_group_exit(SIGKILL);
843 +#else
844 goto bad_area;
845 +#endif
846 +
847 + }
848 } else if (!cause) {
849 /* Allow reads even for write-only mappings */
850 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
851 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
852 index 1594945..adf4001 100644
853 --- a/arch/arm/Kconfig
854 +++ b/arch/arm/Kconfig
855 @@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
856
857 config UACCESS_WITH_MEMCPY
858 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
859 - depends on MMU
860 + depends on MMU && !PAX_MEMORY_UDEREF
861 default y if CPU_FEROCEON
862 help
863 Implement faster copy_to_user and clear_user methods for CPU
864 @@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
865 config KEXEC
866 bool "Kexec system call (EXPERIMENTAL)"
867 depends on (!SMP || PM_SLEEP_SMP)
868 + depends on !GRKERNSEC_KMEM
869 help
870 kexec is a system call that implements the ability to shutdown your
871 current kernel, and to start another kernel. It is like a reboot
872 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
873 index 62d2cb5..09d45e3 100644
874 --- a/arch/arm/include/asm/atomic.h
875 +++ b/arch/arm/include/asm/atomic.h
876 @@ -18,17 +18,35 @@
877 #include <asm/barrier.h>
878 #include <asm/cmpxchg.h>
879
880 +#ifdef CONFIG_GENERIC_ATOMIC64
881 +#include <asm-generic/atomic64.h>
882 +#endif
883 +
884 #define ATOMIC_INIT(i) { (i) }
885
886 #ifdef __KERNEL__
887
888 +#define _ASM_EXTABLE(from, to) \
889 +" .pushsection __ex_table,\"a\"\n"\
890 +" .align 3\n" \
891 +" .long " #from ", " #to"\n" \
892 +" .popsection"
893 +
894 /*
895 * On ARM, ordinary assignment (str instruction) doesn't clear the local
896 * strex/ldrex monitor on some implementations. The reason we can use it for
897 * atomic_set() is the clrex or dummy strex done on every exception return.
898 */
899 #define atomic_read(v) (*(volatile int *)&(v)->counter)
900 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
901 +{
902 + return v->counter;
903 +}
904 #define atomic_set(v,i) (((v)->counter) = (i))
905 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
906 +{
907 + v->counter = i;
908 +}
909
910 #if __LINUX_ARM_ARCH__ >= 6
911
912 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
913
914 prefetchw(&v->counter);
915 __asm__ __volatile__("@ atomic_add\n"
916 +"1: ldrex %1, [%3]\n"
917 +" adds %0, %1, %4\n"
918 +
919 +#ifdef CONFIG_PAX_REFCOUNT
920 +" bvc 3f\n"
921 +"2: bkpt 0xf103\n"
922 +"3:\n"
923 +#endif
924 +
925 +" strex %1, %0, [%3]\n"
926 +" teq %1, #0\n"
927 +" bne 1b"
928 +
929 +#ifdef CONFIG_PAX_REFCOUNT
930 +"\n4:\n"
931 + _ASM_EXTABLE(2b, 4b)
932 +#endif
933 +
934 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
935 + : "r" (&v->counter), "Ir" (i)
936 + : "cc");
937 +}
938 +
939 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
940 +{
941 + unsigned long tmp;
942 + int result;
943 +
944 + prefetchw(&v->counter);
945 + __asm__ __volatile__("@ atomic_add_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_add_return\n"
953 +"1: ldrex %1, [%3]\n"
954 +" adds %0, %1, %4\n"
955 +
956 +#ifdef CONFIG_PAX_REFCOUNT
957 +" bvc 3f\n"
958 +" mov %0, %1\n"
959 +"2: bkpt 0xf103\n"
960 +"3:\n"
961 +#endif
962 +
963 +" strex %1, %0, [%3]\n"
964 +" teq %1, #0\n"
965 +" bne 1b"
966 +
967 +#ifdef CONFIG_PAX_REFCOUNT
968 +"\n4:\n"
969 + _ASM_EXTABLE(2b, 4b)
970 +#endif
971 +
972 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
973 + : "r" (&v->counter), "Ir" (i)
974 + : "cc");
975 +
976 + smp_mb();
977 +
978 + return result;
979 +}
980 +
981 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
982 +{
983 + unsigned long tmp;
984 + int result;
985 +
986 + smp_mb();
987 +
988 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
989 "1: ldrex %0, [%3]\n"
990 " add %0, %0, %4\n"
991 " strex %1, %0, [%3]\n"
992 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
993
994 prefetchw(&v->counter);
995 __asm__ __volatile__("@ atomic_sub\n"
996 +"1: ldrex %1, [%3]\n"
997 +" subs %0, %1, %4\n"
998 +
999 +#ifdef CONFIG_PAX_REFCOUNT
1000 +" bvc 3f\n"
1001 +"2: bkpt 0xf103\n"
1002 +"3:\n"
1003 +#endif
1004 +
1005 +" strex %1, %0, [%3]\n"
1006 +" teq %1, #0\n"
1007 +" bne 1b"
1008 +
1009 +#ifdef CONFIG_PAX_REFCOUNT
1010 +"\n4:\n"
1011 + _ASM_EXTABLE(2b, 4b)
1012 +#endif
1013 +
1014 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1015 + : "r" (&v->counter), "Ir" (i)
1016 + : "cc");
1017 +}
1018 +
1019 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1020 +{
1021 + unsigned long tmp;
1022 + int result;
1023 +
1024 + prefetchw(&v->counter);
1025 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1026 "1: ldrex %0, [%3]\n"
1027 " sub %0, %0, %4\n"
1028 " strex %1, %0, [%3]\n"
1029 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1030 smp_mb();
1031
1032 __asm__ __volatile__("@ atomic_sub_return\n"
1033 -"1: ldrex %0, [%3]\n"
1034 -" sub %0, %0, %4\n"
1035 +"1: ldrex %1, [%3]\n"
1036 +" subs %0, %1, %4\n"
1037 +
1038 +#ifdef CONFIG_PAX_REFCOUNT
1039 +" bvc 3f\n"
1040 +" mov %0, %1\n"
1041 +"2: bkpt 0xf103\n"
1042 +"3:\n"
1043 +#endif
1044 +
1045 " strex %1, %0, [%3]\n"
1046 " teq %1, #0\n"
1047 " bne 1b"
1048 +
1049 +#ifdef CONFIG_PAX_REFCOUNT
1050 +"\n4:\n"
1051 + _ASM_EXTABLE(2b, 4b)
1052 +#endif
1053 +
1054 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1055 : "r" (&v->counter), "Ir" (i)
1056 : "cc");
1057 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1058 return oldval;
1059 }
1060
1061 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1062 +{
1063 + unsigned long oldval, res;
1064 +
1065 + smp_mb();
1066 +
1067 + do {
1068 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1069 + "ldrex %1, [%3]\n"
1070 + "mov %0, #0\n"
1071 + "teq %1, %4\n"
1072 + "strexeq %0, %5, [%3]\n"
1073 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1074 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1075 + : "cc");
1076 + } while (res);
1077 +
1078 + smp_mb();
1079 +
1080 + return oldval;
1081 +}
1082 +
1083 #else /* ARM_ARCH_6 */
1084
1085 #ifdef CONFIG_SMP
1086 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1087
1088 return val;
1089 }
1090 +
1091 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1092 +{
1093 + return atomic_add_return(i, v);
1094 +}
1095 +
1096 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1097 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1098 +{
1099 + (void) atomic_add_return(i, v);
1100 +}
1101
1102 static inline int atomic_sub_return(int i, atomic_t *v)
1103 {
1104 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1105 return val;
1106 }
1107 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1108 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1109 +{
1110 + (void) atomic_sub_return(i, v);
1111 +}
1112
1113 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1114 {
1115 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 return ret;
1117 }
1118
1119 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1120 +{
1121 + return atomic_cmpxchg(v, old, new);
1122 +}
1123 +
1124 #endif /* __LINUX_ARM_ARCH__ */
1125
1126 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1127 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1128 +{
1129 + return xchg(&v->counter, new);
1130 +}
1131
1132 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1133 {
1134 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 }
1136
1137 #define atomic_inc(v) atomic_add(1, v)
1138 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1139 +{
1140 + atomic_add_unchecked(1, v);
1141 +}
1142 #define atomic_dec(v) atomic_sub(1, v)
1143 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1144 +{
1145 + atomic_sub_unchecked(1, v);
1146 +}
1147
1148 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1149 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1150 +{
1151 + return atomic_add_return_unchecked(1, v) == 0;
1152 +}
1153 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1154 #define atomic_inc_return(v) (atomic_add_return(1, v))
1155 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1156 +{
1157 + return atomic_add_return_unchecked(1, v);
1158 +}
1159 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1160 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1161
1162 @@ -221,6 +410,14 @@ typedef struct {
1163 long long counter;
1164 } atomic64_t;
1165
1166 +#ifdef CONFIG_PAX_REFCOUNT
1167 +typedef struct {
1168 + long long counter;
1169 +} atomic64_unchecked_t;
1170 +#else
1171 +typedef atomic64_t atomic64_unchecked_t;
1172 +#endif
1173 +
1174 #define ATOMIC64_INIT(i) { (i) }
1175
1176 #ifdef CONFIG_ARM_LPAE
1177 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1178 return result;
1179 }
1180
1181 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1182 +{
1183 + long long result;
1184 +
1185 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1186 +" ldrd %0, %H0, [%1]"
1187 + : "=&r" (result)
1188 + : "r" (&v->counter), "Qo" (v->counter)
1189 + );
1190 +
1191 + return result;
1192 +}
1193 +
1194 static inline void atomic64_set(atomic64_t *v, long long i)
1195 {
1196 __asm__ __volatile__("@ atomic64_set\n"
1197 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1198 : "r" (&v->counter), "r" (i)
1199 );
1200 }
1201 +
1202 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1203 +{
1204 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1205 +" strd %2, %H2, [%1]"
1206 + : "=Qo" (v->counter)
1207 + : "r" (&v->counter), "r" (i)
1208 + );
1209 +}
1210 #else
1211 static inline long long atomic64_read(const atomic64_t *v)
1212 {
1213 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1214 return result;
1215 }
1216
1217 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1218 +{
1219 + long long result;
1220 +
1221 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1222 +" ldrexd %0, %H0, [%1]"
1223 + : "=&r" (result)
1224 + : "r" (&v->counter), "Qo" (v->counter)
1225 + );
1226 +
1227 + return result;
1228 +}
1229 +
1230 static inline void atomic64_set(atomic64_t *v, long long i)
1231 {
1232 long long tmp;
1233 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1234 : "r" (&v->counter), "r" (i)
1235 : "cc");
1236 }
1237 +
1238 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1239 +{
1240 + long long tmp;
1241 +
1242 + prefetchw(&v->counter);
1243 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1244 +"1: ldrexd %0, %H0, [%2]\n"
1245 +" strexd %0, %3, %H3, [%2]\n"
1246 +" teq %0, #0\n"
1247 +" bne 1b"
1248 + : "=&r" (tmp), "=Qo" (v->counter)
1249 + : "r" (&v->counter), "r" (i)
1250 + : "cc");
1251 +}
1252 #endif
1253
1254 static inline void atomic64_add(long long i, atomic64_t *v)
1255 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1256 __asm__ __volatile__("@ atomic64_add\n"
1257 "1: ldrexd %0, %H0, [%3]\n"
1258 " adds %Q0, %Q0, %Q4\n"
1259 +" adcs %R0, %R0, %R4\n"
1260 +
1261 +#ifdef CONFIG_PAX_REFCOUNT
1262 +" bvc 3f\n"
1263 +"2: bkpt 0xf103\n"
1264 +"3:\n"
1265 +#endif
1266 +
1267 +" strexd %1, %0, %H0, [%3]\n"
1268 +" teq %1, #0\n"
1269 +" bne 1b"
1270 +
1271 +#ifdef CONFIG_PAX_REFCOUNT
1272 +"\n4:\n"
1273 + _ASM_EXTABLE(2b, 4b)
1274 +#endif
1275 +
1276 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1277 + : "r" (&v->counter), "r" (i)
1278 + : "cc");
1279 +}
1280 +
1281 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1282 +{
1283 + long long result;
1284 + unsigned long tmp;
1285 +
1286 + prefetchw(&v->counter);
1287 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1288 +"1: ldrexd %0, %H0, [%3]\n"
1289 +" adds %Q0, %Q0, %Q4\n"
1290 " adc %R0, %R0, %R4\n"
1291 " strexd %1, %0, %H0, [%3]\n"
1292 " teq %1, #0\n"
1293 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1294 __asm__ __volatile__("@ atomic64_add_return\n"
1295 "1: ldrexd %0, %H0, [%3]\n"
1296 " adds %Q0, %Q0, %Q4\n"
1297 +" adcs %R0, %R0, %R4\n"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +" bvc 3f\n"
1301 +" mov %0, %1\n"
1302 +" mov %H0, %H1\n"
1303 +"2: bkpt 0xf103\n"
1304 +"3:\n"
1305 +#endif
1306 +
1307 +" strexd %1, %0, %H0, [%3]\n"
1308 +" teq %1, #0\n"
1309 +" bne 1b"
1310 +
1311 +#ifdef CONFIG_PAX_REFCOUNT
1312 +"\n4:\n"
1313 + _ASM_EXTABLE(2b, 4b)
1314 +#endif
1315 +
1316 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1317 + : "r" (&v->counter), "r" (i)
1318 + : "cc");
1319 +
1320 + smp_mb();
1321 +
1322 + return result;
1323 +}
1324 +
1325 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1326 +{
1327 + long long result;
1328 + unsigned long tmp;
1329 +
1330 + smp_mb();
1331 +
1332 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1333 +"1: ldrexd %0, %H0, [%3]\n"
1334 +" adds %Q0, %Q0, %Q4\n"
1335 " adc %R0, %R0, %R4\n"
1336 " strexd %1, %0, %H0, [%3]\n"
1337 " teq %1, #0\n"
1338 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1339 __asm__ __volatile__("@ atomic64_sub\n"
1340 "1: ldrexd %0, %H0, [%3]\n"
1341 " subs %Q0, %Q0, %Q4\n"
1342 +" sbcs %R0, %R0, %R4\n"
1343 +
1344 +#ifdef CONFIG_PAX_REFCOUNT
1345 +" bvc 3f\n"
1346 +"2: bkpt 0xf103\n"
1347 +"3:\n"
1348 +#endif
1349 +
1350 +" strexd %1, %0, %H0, [%3]\n"
1351 +" teq %1, #0\n"
1352 +" bne 1b"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 +"\n4:\n"
1356 + _ASM_EXTABLE(2b, 4b)
1357 +#endif
1358 +
1359 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1360 + : "r" (&v->counter), "r" (i)
1361 + : "cc");
1362 +}
1363 +
1364 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1365 +{
1366 + long long result;
1367 + unsigned long tmp;
1368 +
1369 + prefetchw(&v->counter);
1370 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1371 +"1: ldrexd %0, %H0, [%3]\n"
1372 +" subs %Q0, %Q0, %Q4\n"
1373 " sbc %R0, %R0, %R4\n"
1374 " strexd %1, %0, %H0, [%3]\n"
1375 " teq %1, #0\n"
1376 @@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1377 __asm__ __volatile__("@ atomic64_sub_return\n"
1378 "1: ldrexd %0, %H0, [%3]\n"
1379 " subs %Q0, %Q0, %Q4\n"
1380 -" sbc %R0, %R0, %R4\n"
1381 +" sbcs %R0, %R0, %R4\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 +" bvc 3f\n"
1385 +" mov %0, %1\n"
1386 +" mov %H0, %H1\n"
1387 +"2: bkpt 0xf103\n"
1388 +"3:\n"
1389 +#endif
1390 +
1391 " strexd %1, %0, %H0, [%3]\n"
1392 " teq %1, #0\n"
1393 " bne 1b"
1394 +
1395 +#ifdef CONFIG_PAX_REFCOUNT
1396 +"\n4:\n"
1397 + _ASM_EXTABLE(2b, 4b)
1398 +#endif
1399 +
1400 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1401 : "r" (&v->counter), "r" (i)
1402 : "cc");
1403
1404 - smp_mb();
1405 -
1406 return result;
1407 }
1408
1409 @@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1410 return oldval;
1411 }
1412
1413 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1414 + long long new)
1415 +{
1416 + long long oldval;
1417 + unsigned long res;
1418 +
1419 + smp_mb();
1420 +
1421 + do {
1422 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1423 + "ldrexd %1, %H1, [%3]\n"
1424 + "mov %0, #0\n"
1425 + "teq %1, %4\n"
1426 + "teqeq %H1, %H4\n"
1427 + "strexdeq %0, %5, %H5, [%3]"
1428 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1429 + : "r" (&ptr->counter), "r" (old), "r" (new)
1430 + : "cc");
1431 + } while (res);
1432 +
1433 + smp_mb();
1434 +
1435 + return oldval;
1436 +}
1437 +
1438 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1439 {
1440 long long result;
1441 @@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1443 {
1444 long long result;
1445 - unsigned long tmp;
1446 + u64 tmp;
1447
1448 smp_mb();
1449
1450 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1451 -"1: ldrexd %0, %H0, [%3]\n"
1452 -" subs %Q0, %Q0, #1\n"
1453 -" sbc %R0, %R0, #0\n"
1454 +"1: ldrexd %1, %H1, [%3]\n"
1455 +" subs %Q0, %Q1, #1\n"
1456 +" sbcs %R0, %R1, #0\n"
1457 +
1458 +#ifdef CONFIG_PAX_REFCOUNT
1459 +" bvc 3f\n"
1460 +" mov %Q0, %Q1\n"
1461 +" mov %R0, %R1\n"
1462 +"2: bkpt 0xf103\n"
1463 +"3:\n"
1464 +#endif
1465 +
1466 " teq %R0, #0\n"
1467 -" bmi 2f\n"
1468 +" bmi 4f\n"
1469 " strexd %1, %0, %H0, [%3]\n"
1470 " teq %1, #0\n"
1471 " bne 1b\n"
1472 -"2:"
1473 +"4:\n"
1474 +
1475 +#ifdef CONFIG_PAX_REFCOUNT
1476 + _ASM_EXTABLE(2b, 4b)
1477 +#endif
1478 +
1479 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1480 : "r" (&v->counter)
1481 : "cc");
1482 @@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1483 " teq %0, %5\n"
1484 " teqeq %H0, %H5\n"
1485 " moveq %1, #0\n"
1486 -" beq 2f\n"
1487 +" beq 4f\n"
1488 " adds %Q0, %Q0, %Q6\n"
1489 -" adc %R0, %R0, %R6\n"
1490 +" adcs %R0, %R0, %R6\n"
1491 +
1492 +#ifdef CONFIG_PAX_REFCOUNT
1493 +" bvc 3f\n"
1494 +"2: bkpt 0xf103\n"
1495 +"3:\n"
1496 +#endif
1497 +
1498 " strexd %2, %0, %H0, [%4]\n"
1499 " teq %2, #0\n"
1500 " bne 1b\n"
1501 -"2:"
1502 +"4:\n"
1503 +
1504 +#ifdef CONFIG_PAX_REFCOUNT
1505 + _ASM_EXTABLE(2b, 4b)
1506 +#endif
1507 +
1508 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1509 : "r" (&v->counter), "r" (u), "r" (a)
1510 : "cc");
1511 @@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1512
1513 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1514 #define atomic64_inc(v) atomic64_add(1LL, (v))
1515 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1516 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1517 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1518 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1519 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1520 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1521 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1522 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1523 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1525 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1526 index 75fe66b..ba3dee4 100644
1527 --- a/arch/arm/include/asm/cache.h
1528 +++ b/arch/arm/include/asm/cache.h
1529 @@ -4,8 +4,10 @@
1530 #ifndef __ASMARM_CACHE_H
1531 #define __ASMARM_CACHE_H
1532
1533 +#include <linux/const.h>
1534 +
1535 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1536 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1537 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1538
1539 /*
1540 * Memory returned by kmalloc() may be used for DMA, so we must make
1541 @@ -24,5 +26,6 @@
1542 #endif
1543
1544 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1545 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1546
1547 #endif
1548 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1549 index 8b8b616..d973d24 100644
1550 --- a/arch/arm/include/asm/cacheflush.h
1551 +++ b/arch/arm/include/asm/cacheflush.h
1552 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1553 void (*dma_unmap_area)(const void *, size_t, int);
1554
1555 void (*dma_flush_range)(const void *, const void *);
1556 -};
1557 +} __no_const;
1558
1559 /*
1560 * Select the calling method
1561 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1562 index 5233151..87a71fa 100644
1563 --- a/arch/arm/include/asm/checksum.h
1564 +++ b/arch/arm/include/asm/checksum.h
1565 @@ -37,7 +37,19 @@ __wsum
1566 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1567
1568 __wsum
1569 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1570 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1571 +
1572 +static inline __wsum
1573 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1574 +{
1575 + __wsum ret;
1576 + pax_open_userland();
1577 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1578 + pax_close_userland();
1579 + return ret;
1580 +}
1581 +
1582 +
1583
1584 /*
1585 * Fold a partial checksum without adding pseudo headers
1586 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1587 index df2fbba..63fe3e1 100644
1588 --- a/arch/arm/include/asm/cmpxchg.h
1589 +++ b/arch/arm/include/asm/cmpxchg.h
1590 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1591
1592 #define xchg(ptr,x) \
1593 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1594 +#define xchg_unchecked(ptr,x) \
1595 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596
1597 #include <asm-generic/cmpxchg-local.h>
1598
1599 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1600 index 6ddbe44..b5e38b1 100644
1601 --- a/arch/arm/include/asm/domain.h
1602 +++ b/arch/arm/include/asm/domain.h
1603 @@ -48,18 +48,37 @@
1604 * Domain types
1605 */
1606 #define DOMAIN_NOACCESS 0
1607 -#define DOMAIN_CLIENT 1
1608 #ifdef CONFIG_CPU_USE_DOMAINS
1609 +#define DOMAIN_USERCLIENT 1
1610 +#define DOMAIN_KERNELCLIENT 1
1611 #define DOMAIN_MANAGER 3
1612 +#define DOMAIN_VECTORS DOMAIN_USER
1613 #else
1614 +
1615 +#ifdef CONFIG_PAX_KERNEXEC
1616 #define DOMAIN_MANAGER 1
1617 +#define DOMAIN_KERNEXEC 3
1618 +#else
1619 +#define DOMAIN_MANAGER 1
1620 +#endif
1621 +
1622 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1623 +#define DOMAIN_USERCLIENT 0
1624 +#define DOMAIN_UDEREF 1
1625 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1626 +#else
1627 +#define DOMAIN_USERCLIENT 1
1628 +#define DOMAIN_VECTORS DOMAIN_USER
1629 +#endif
1630 +#define DOMAIN_KERNELCLIENT 1
1631 +
1632 #endif
1633
1634 #define domain_val(dom,type) ((type) << (2*(dom)))
1635
1636 #ifndef __ASSEMBLY__
1637
1638 -#ifdef CONFIG_CPU_USE_DOMAINS
1639 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1640 static inline void set_domain(unsigned val)
1641 {
1642 asm volatile(
1643 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1644 isb();
1645 }
1646
1647 -#define modify_domain(dom,type) \
1648 - do { \
1649 - struct thread_info *thread = current_thread_info(); \
1650 - unsigned int domain = thread->cpu_domain; \
1651 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1652 - thread->cpu_domain = domain | domain_val(dom, type); \
1653 - set_domain(thread->cpu_domain); \
1654 - } while (0)
1655 -
1656 +extern void modify_domain(unsigned int dom, unsigned int type);
1657 #else
1658 static inline void set_domain(unsigned val) { }
1659 static inline void modify_domain(unsigned dom, unsigned type) { }
1660 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1661 index f4b46d3..abc9b2b 100644
1662 --- a/arch/arm/include/asm/elf.h
1663 +++ b/arch/arm/include/asm/elf.h
1664 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 the loader. We need to make sure that it is out of the way of the program
1666 that it will "exec", and that there is sufficient room for the brk. */
1667
1668 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1669 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1670 +
1671 +#ifdef CONFIG_PAX_ASLR
1672 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1673 +
1674 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1675 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1676 +#endif
1677
1678 /* When the program starts, a1 contains a pointer to a function to be
1679 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1680 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1681 extern void elf_set_personality(const struct elf32_hdr *);
1682 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1683
1684 -struct mm_struct;
1685 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1686 -#define arch_randomize_brk arch_randomize_brk
1687 -
1688 #ifdef CONFIG_MMU
1689 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1690 struct linux_binprm;
1691 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1692 index de53547..52b9a28 100644
1693 --- a/arch/arm/include/asm/fncpy.h
1694 +++ b/arch/arm/include/asm/fncpy.h
1695 @@ -81,7 +81,9 @@
1696 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1697 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1698 \
1699 + pax_open_kernel(); \
1700 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1701 + pax_close_kernel(); \
1702 flush_icache_range((unsigned long)(dest_buf), \
1703 (unsigned long)(dest_buf) + (size)); \
1704 \
1705 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1706 index e42cf59..7b94b8f 100644
1707 --- a/arch/arm/include/asm/futex.h
1708 +++ b/arch/arm/include/asm/futex.h
1709 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1710 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1711 return -EFAULT;
1712
1713 + pax_open_userland();
1714 +
1715 smp_mb();
1716 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1717 "1: ldrex %1, [%4]\n"
1718 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1719 : "cc", "memory");
1720 smp_mb();
1721
1722 + pax_close_userland();
1723 +
1724 *uval = val;
1725 return ret;
1726 }
1727 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1728 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1729 return -EFAULT;
1730
1731 + pax_open_userland();
1732 +
1733 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1734 "1: " TUSER(ldr) " %1, [%4]\n"
1735 " teq %1, %2\n"
1736 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1737 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1738 : "cc", "memory");
1739
1740 + pax_close_userland();
1741 +
1742 *uval = val;
1743 return ret;
1744 }
1745 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 return -EFAULT;
1747
1748 pagefault_disable(); /* implies preempt_disable() */
1749 + pax_open_userland();
1750
1751 switch (op) {
1752 case FUTEX_OP_SET:
1753 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1754 ret = -ENOSYS;
1755 }
1756
1757 + pax_close_userland();
1758 pagefault_enable(); /* subsumes preempt_enable() */
1759
1760 if (!ret) {
1761 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1762 index 83eb2f7..ed77159 100644
1763 --- a/arch/arm/include/asm/kmap_types.h
1764 +++ b/arch/arm/include/asm/kmap_types.h
1765 @@ -4,6 +4,6 @@
1766 /*
1767 * This is the "bare minimum". AIO seems to require this.
1768 */
1769 -#define KM_TYPE_NR 16
1770 +#define KM_TYPE_NR 17
1771
1772 #endif
1773 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1774 index 9e614a1..3302cca 100644
1775 --- a/arch/arm/include/asm/mach/dma.h
1776 +++ b/arch/arm/include/asm/mach/dma.h
1777 @@ -22,7 +22,7 @@ struct dma_ops {
1778 int (*residue)(unsigned int, dma_t *); /* optional */
1779 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1780 const char *type;
1781 -};
1782 +} __do_const;
1783
1784 struct dma_struct {
1785 void *addr; /* single DMA address */
1786 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1787 index f98c7f3..e5c626d 100644
1788 --- a/arch/arm/include/asm/mach/map.h
1789 +++ b/arch/arm/include/asm/mach/map.h
1790 @@ -23,17 +23,19 @@ struct map_desc {
1791
1792 /* types 0-3 are defined in asm/io.h */
1793 enum {
1794 - MT_UNCACHED = 4,
1795 - MT_CACHECLEAN,
1796 - MT_MINICLEAN,
1797 + MT_UNCACHED_RW = 4,
1798 + MT_CACHECLEAN_RO,
1799 + MT_MINICLEAN_RO,
1800 MT_LOW_VECTORS,
1801 MT_HIGH_VECTORS,
1802 - MT_MEMORY_RWX,
1803 + __MT_MEMORY_RWX,
1804 MT_MEMORY_RW,
1805 - MT_ROM,
1806 - MT_MEMORY_RWX_NONCACHED,
1807 + MT_MEMORY_RX,
1808 + MT_ROM_RX,
1809 + MT_MEMORY_RW_NONCACHED,
1810 + MT_MEMORY_RX_NONCACHED,
1811 MT_MEMORY_RW_DTCM,
1812 - MT_MEMORY_RWX_ITCM,
1813 + MT_MEMORY_RX_ITCM,
1814 MT_MEMORY_RW_SO,
1815 MT_MEMORY_DMA_READY,
1816 };
1817 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1818 index f94784f..9a09a4a 100644
1819 --- a/arch/arm/include/asm/outercache.h
1820 +++ b/arch/arm/include/asm/outercache.h
1821 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1822 #endif
1823 void (*set_debug)(unsigned long);
1824 void (*resume)(void);
1825 -};
1826 +} __no_const;
1827
1828 extern struct outer_cache_fns outer_cache;
1829
1830 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1831 index 4355f0e..cd9168e 100644
1832 --- a/arch/arm/include/asm/page.h
1833 +++ b/arch/arm/include/asm/page.h
1834 @@ -23,6 +23,7 @@
1835
1836 #else
1837
1838 +#include <linux/compiler.h>
1839 #include <asm/glue.h>
1840
1841 /*
1842 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1843 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1844 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1845 unsigned long vaddr, struct vm_area_struct *vma);
1846 -};
1847 +} __no_const;
1848
1849 #ifdef MULTI_USER
1850 extern struct cpu_user_fns cpu_user;
1851 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1852 index 78a7793..e3dc06c 100644
1853 --- a/arch/arm/include/asm/pgalloc.h
1854 +++ b/arch/arm/include/asm/pgalloc.h
1855 @@ -17,6 +17,7 @@
1856 #include <asm/processor.h>
1857 #include <asm/cacheflush.h>
1858 #include <asm/tlbflush.h>
1859 +#include <asm/system_info.h>
1860
1861 #define check_pgt_cache() do { } while (0)
1862
1863 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1864 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1865 }
1866
1867 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1868 +{
1869 + pud_populate(mm, pud, pmd);
1870 +}
1871 +
1872 #else /* !CONFIG_ARM_LPAE */
1873
1874 /*
1875 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1876 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1877 #define pmd_free(mm, pmd) do { } while (0)
1878 #define pud_populate(mm,pmd,pte) BUG()
1879 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1880
1881 #endif /* CONFIG_ARM_LPAE */
1882
1883 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1884 __free_page(pte);
1885 }
1886
1887 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1888 +{
1889 +#ifdef CONFIG_ARM_LPAE
1890 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1891 +#else
1892 + if (addr & SECTION_SIZE)
1893 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1894 + else
1895 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1896 +#endif
1897 + flush_pmd_entry(pmdp);
1898 +}
1899 +
1900 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1901 pmdval_t prot)
1902 {
1903 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1904 static inline void
1905 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1906 {
1907 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1908 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1909 }
1910 #define pmd_pgtable(pmd) pmd_page(pmd)
1911
1912 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1913 index 5cfba15..f415e1a 100644
1914 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1915 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1916 @@ -20,12 +20,15 @@
1917 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1918 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1919 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1920 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1921 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1922 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1923 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1924 +
1925 /*
1926 * - section
1927 */
1928 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1929 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1930 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1931 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1932 @@ -37,6 +40,7 @@
1933 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1934 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1935 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1936 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1937
1938 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1939 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1940 @@ -66,6 +70,7 @@
1941 * - extended small page/tiny page
1942 */
1943 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1944 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1945 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1946 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1947 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1948 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1949 index dfff709..ed4c4e7 100644
1950 --- a/arch/arm/include/asm/pgtable-2level.h
1951 +++ b/arch/arm/include/asm/pgtable-2level.h
1952 @@ -126,6 +126,9 @@
1953 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1954 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1955
1956 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1957 +#define L_PTE_PXN (_AT(pteval_t, 0))
1958 +
1959 /*
1960 * These are the memory types, defined to be compatible with
1961 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1962 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1963 index 626989f..9d67a33 100644
1964 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1965 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1966 @@ -75,6 +75,7 @@
1967 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1968 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1969 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1970 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1971 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1972
1973 /*
1974 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1975 index 85c60ad..b0bbd7e 100644
1976 --- a/arch/arm/include/asm/pgtable-3level.h
1977 +++ b/arch/arm/include/asm/pgtable-3level.h
1978 @@ -82,6 +82,7 @@
1979 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1980 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1981 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1982 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1983 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1984 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1985 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1986 @@ -95,6 +96,7 @@
1987 /*
1988 * To be used in assembly code with the upper page attributes.
1989 */
1990 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1991 #define L_PTE_XN_HIGH (1 << (54 - 32))
1992 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1993
1994 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1995 index 7d59b52..27a12f8 100644
1996 --- a/arch/arm/include/asm/pgtable.h
1997 +++ b/arch/arm/include/asm/pgtable.h
1998 @@ -33,6 +33,9 @@
1999 #include <asm/pgtable-2level.h>
2000 #endif
2001
2002 +#define ktla_ktva(addr) (addr)
2003 +#define ktva_ktla(addr) (addr)
2004 +
2005 /*
2006 * Just any arbitrary offset to the start of the vmalloc VM area: the
2007 * current 8MB value just means that there will be a 8MB "hole" after the
2008 @@ -48,6 +51,9 @@
2009 #define LIBRARY_TEXT_START 0x0c000000
2010
2011 #ifndef __ASSEMBLY__
2012 +extern pteval_t __supported_pte_mask;
2013 +extern pmdval_t __supported_pmd_mask;
2014 +
2015 extern void __pte_error(const char *file, int line, pte_t);
2016 extern void __pmd_error(const char *file, int line, pmd_t);
2017 extern void __pgd_error(const char *file, int line, pgd_t);
2018 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2019 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2020 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2021
2022 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2023 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2024 +
2025 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2026 +#include <asm/domain.h>
2027 +#include <linux/thread_info.h>
2028 +#include <linux/preempt.h>
2029 +
2030 +static inline int test_domain(int domain, int domaintype)
2031 +{
2032 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2033 +}
2034 +#endif
2035 +
2036 +#ifdef CONFIG_PAX_KERNEXEC
2037 +static inline unsigned long pax_open_kernel(void) {
2038 +#ifdef CONFIG_ARM_LPAE
2039 + /* TODO */
2040 +#else
2041 + preempt_disable();
2042 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2043 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2044 +#endif
2045 + return 0;
2046 +}
2047 +
2048 +static inline unsigned long pax_close_kernel(void) {
2049 +#ifdef CONFIG_ARM_LPAE
2050 + /* TODO */
2051 +#else
2052 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2053 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2054 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2055 + preempt_enable_no_resched();
2056 +#endif
2057 + return 0;
2058 +}
2059 +#else
2060 +static inline unsigned long pax_open_kernel(void) { return 0; }
2061 +static inline unsigned long pax_close_kernel(void) { return 0; }
2062 +#endif
2063 +
2064 /*
2065 * This is the lowest virtual address we can permit any user space
2066 * mapping to be mapped at. This is particularly important for
2067 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2068 /*
2069 * The pgprot_* and protection_map entries will be fixed up in runtime
2070 * to include the cachable and bufferable bits based on memory policy,
2071 - * as well as any architecture dependent bits like global/ASID and SMP
2072 - * shared mapping bits.
2073 + * as well as any architecture dependent bits like global/ASID, PXN,
2074 + * and SMP shared mapping bits.
2075 */
2076 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2077
2078 @@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2079 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2080 {
2081 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2082 - L_PTE_NONE | L_PTE_VALID;
2083 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2084 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2085 return pte;
2086 }
2087 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2088 index c4ae171..ea0c0c2 100644
2089 --- a/arch/arm/include/asm/psci.h
2090 +++ b/arch/arm/include/asm/psci.h
2091 @@ -29,7 +29,7 @@ struct psci_operations {
2092 int (*cpu_off)(struct psci_power_state state);
2093 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2094 int (*migrate)(unsigned long cpuid);
2095 -};
2096 +} __no_const;
2097
2098 extern struct psci_operations psci_ops;
2099 extern struct smp_operations psci_smp_ops;
2100 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2101 index 22a3b9b..7f214ee 100644
2102 --- a/arch/arm/include/asm/smp.h
2103 +++ b/arch/arm/include/asm/smp.h
2104 @@ -112,7 +112,7 @@ struct smp_operations {
2105 int (*cpu_disable)(unsigned int cpu);
2106 #endif
2107 #endif
2108 -};
2109 +} __no_const;
2110
2111 /*
2112 * set platform specific SMP operations
2113 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2114 index 71a06b2..8bb9ae1 100644
2115 --- a/arch/arm/include/asm/thread_info.h
2116 +++ b/arch/arm/include/asm/thread_info.h
2117 @@ -88,9 +88,9 @@ struct thread_info {
2118 .flags = 0, \
2119 .preempt_count = INIT_PREEMPT_COUNT, \
2120 .addr_limit = KERNEL_DS, \
2121 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2122 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2123 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2124 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2125 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2126 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2127 .restart_block = { \
2128 .fn = do_no_restart_syscall, \
2129 }, \
2130 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2131 #define TIF_SYSCALL_AUDIT 9
2132 #define TIF_SYSCALL_TRACEPOINT 10
2133 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2134 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2135 +/* within 8 bits of TIF_SYSCALL_TRACE
2136 + * to meet flexible second operand requirements
2137 + */
2138 +#define TIF_GRSEC_SETXID 12
2139 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2140 #define TIF_USING_IWMMXT 17
2141 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2142 #define TIF_RESTORE_SIGMASK 20
2143 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2144 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2145 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2146 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2147 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2148
2149 /* Checks for any syscall work in entry-common.S */
2150 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2151 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2152 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2153
2154 /*
2155 * Change these and you break ASM code in entry-common.S
2156 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2157 index 72abdc5..35acac1 100644
2158 --- a/arch/arm/include/asm/uaccess.h
2159 +++ b/arch/arm/include/asm/uaccess.h
2160 @@ -18,6 +18,7 @@
2161 #include <asm/domain.h>
2162 #include <asm/unified.h>
2163 #include <asm/compiler.h>
2164 +#include <asm/pgtable.h>
2165
2166 #if __LINUX_ARM_ARCH__ < 6
2167 #include <asm-generic/uaccess-unaligned.h>
2168 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2169 static inline void set_fs(mm_segment_t fs)
2170 {
2171 current_thread_info()->addr_limit = fs;
2172 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2173 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2174 }
2175
2176 #define segment_eq(a,b) ((a) == (b))
2177
2178 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2179 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2180 +
2181 +static inline void pax_open_userland(void)
2182 +{
2183 +
2184 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2185 + if (segment_eq(get_fs(), USER_DS)) {
2186 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2187 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2188 + }
2189 +#endif
2190 +
2191 +}
2192 +
2193 +static inline void pax_close_userland(void)
2194 +{
2195 +
2196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2197 + if (segment_eq(get_fs(), USER_DS)) {
2198 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2199 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2200 + }
2201 +#endif
2202 +
2203 +}
2204 +
2205 #define __addr_ok(addr) ({ \
2206 unsigned long flag; \
2207 __asm__("cmp %2, %0; movlo %0, #0" \
2208 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2209
2210 #define get_user(x,p) \
2211 ({ \
2212 + int __e; \
2213 might_fault(); \
2214 - __get_user_check(x,p); \
2215 + pax_open_userland(); \
2216 + __e = __get_user_check(x,p); \
2217 + pax_close_userland(); \
2218 + __e; \
2219 })
2220
2221 extern int __put_user_1(void *, unsigned int);
2222 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2223
2224 #define put_user(x,p) \
2225 ({ \
2226 + int __e; \
2227 might_fault(); \
2228 - __put_user_check(x,p); \
2229 + pax_open_userland(); \
2230 + __e = __put_user_check(x,p); \
2231 + pax_close_userland(); \
2232 + __e; \
2233 })
2234
2235 #else /* CONFIG_MMU */
2236 @@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2237
2238 #endif /* CONFIG_MMU */
2239
2240 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2241 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2242
2243 #define user_addr_max() \
2244 @@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2245 #define __get_user(x,ptr) \
2246 ({ \
2247 long __gu_err = 0; \
2248 + pax_open_userland(); \
2249 __get_user_err((x),(ptr),__gu_err); \
2250 + pax_close_userland(); \
2251 __gu_err; \
2252 })
2253
2254 #define __get_user_error(x,ptr,err) \
2255 ({ \
2256 + pax_open_userland(); \
2257 __get_user_err((x),(ptr),err); \
2258 + pax_close_userland(); \
2259 (void) 0; \
2260 })
2261
2262 @@ -319,13 +360,17 @@ do { \
2263 #define __put_user(x,ptr) \
2264 ({ \
2265 long __pu_err = 0; \
2266 + pax_open_userland(); \
2267 __put_user_err((x),(ptr),__pu_err); \
2268 + pax_close_userland(); \
2269 __pu_err; \
2270 })
2271
2272 #define __put_user_error(x,ptr,err) \
2273 ({ \
2274 + pax_open_userland(); \
2275 __put_user_err((x),(ptr),err); \
2276 + pax_close_userland(); \
2277 (void) 0; \
2278 })
2279
2280 @@ -425,11 +470,44 @@ do { \
2281
2282
2283 #ifdef CONFIG_MMU
2284 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2285 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2286 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2287 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2288 +
2289 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2290 +{
2291 + unsigned long ret;
2292 +
2293 + check_object_size(to, n, false);
2294 + pax_open_userland();
2295 + ret = ___copy_from_user(to, from, n);
2296 + pax_close_userland();
2297 + return ret;
2298 +}
2299 +
2300 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2301 +{
2302 + unsigned long ret;
2303 +
2304 + check_object_size(from, n, true);
2305 + pax_open_userland();
2306 + ret = ___copy_to_user(to, from, n);
2307 + pax_close_userland();
2308 + return ret;
2309 +}
2310 +
2311 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2312 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2313 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2314 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2315 +
2316 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2317 +{
2318 + unsigned long ret;
2319 + pax_open_userland();
2320 + ret = ___clear_user(addr, n);
2321 + pax_close_userland();
2322 + return ret;
2323 +}
2324 +
2325 #else
2326 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2327 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2328 @@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2329
2330 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2331 {
2332 + if ((long)n < 0)
2333 + return n;
2334 +
2335 if (access_ok(VERIFY_READ, from, n))
2336 n = __copy_from_user(to, from, n);
2337 else /* security hole - plug it */
2338 @@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2339
2340 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2341 {
2342 + if ((long)n < 0)
2343 + return n;
2344 +
2345 if (access_ok(VERIFY_WRITE, to, n))
2346 n = __copy_to_user(to, from, n);
2347 return n;
2348 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2349 index 5af0ed1..cea83883 100644
2350 --- a/arch/arm/include/uapi/asm/ptrace.h
2351 +++ b/arch/arm/include/uapi/asm/ptrace.h
2352 @@ -92,7 +92,7 @@
2353 * ARMv7 groups of PSR bits
2354 */
2355 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2356 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2357 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2358 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2359 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2360
2361 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2362 index 85e664b..419a1cd 100644
2363 --- a/arch/arm/kernel/armksyms.c
2364 +++ b/arch/arm/kernel/armksyms.c
2365 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2366
2367 /* networking */
2368 EXPORT_SYMBOL(csum_partial);
2369 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2370 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2371 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2372 EXPORT_SYMBOL(__csum_ipv6_magic);
2373
2374 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2375 #ifdef CONFIG_MMU
2376 EXPORT_SYMBOL(copy_page);
2377
2378 -EXPORT_SYMBOL(__copy_from_user);
2379 -EXPORT_SYMBOL(__copy_to_user);
2380 -EXPORT_SYMBOL(__clear_user);
2381 +EXPORT_SYMBOL(___copy_from_user);
2382 +EXPORT_SYMBOL(___copy_to_user);
2383 +EXPORT_SYMBOL(___clear_user);
2384
2385 EXPORT_SYMBOL(__get_user_1);
2386 EXPORT_SYMBOL(__get_user_2);
2387 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2388 index 1879e8d..b2207fc 100644
2389 --- a/arch/arm/kernel/entry-armv.S
2390 +++ b/arch/arm/kernel/entry-armv.S
2391 @@ -47,6 +47,87 @@
2392 9997:
2393 .endm
2394
2395 + .macro pax_enter_kernel
2396 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2397 + @ make aligned space for saved DACR
2398 + sub sp, sp, #8
2399 + @ save regs
2400 + stmdb sp!, {r1, r2}
2401 + @ read DACR from cpu_domain into r1
2402 + mov r2, sp
2403 + @ assume 8K pages, since we have to split the immediate in two
2404 + bic r2, r2, #(0x1fc0)
2405 + bic r2, r2, #(0x3f)
2406 + ldr r1, [r2, #TI_CPU_DOMAIN]
2407 + @ store old DACR on stack
2408 + str r1, [sp, #8]
2409 +#ifdef CONFIG_PAX_KERNEXEC
2410 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2411 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2412 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2413 +#endif
2414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2415 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2416 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2417 +#endif
2418 + @ write r1 to current_thread_info()->cpu_domain
2419 + str r1, [r2, #TI_CPU_DOMAIN]
2420 + @ write r1 to DACR
2421 + mcr p15, 0, r1, c3, c0, 0
2422 + @ instruction sync
2423 + instr_sync
2424 + @ restore regs
2425 + ldmia sp!, {r1, r2}
2426 +#endif
2427 + .endm
2428 +
2429 + .macro pax_open_userland
2430 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2431 + @ save regs
2432 + stmdb sp!, {r0, r1}
2433 + @ read DACR from cpu_domain into r1
2434 + mov r0, sp
2435 + @ assume 8K pages, since we have to split the immediate in two
2436 + bic r0, r0, #(0x1fc0)
2437 + bic r0, r0, #(0x3f)
2438 + ldr r1, [r0, #TI_CPU_DOMAIN]
2439 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2440 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2441 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2442 + @ write r1 to current_thread_info()->cpu_domain
2443 + str r1, [r0, #TI_CPU_DOMAIN]
2444 + @ write r1 to DACR
2445 + mcr p15, 0, r1, c3, c0, 0
2446 + @ instruction sync
2447 + instr_sync
2448 + @ restore regs
2449 + ldmia sp!, {r0, r1}
2450 +#endif
2451 + .endm
2452 +
2453 + .macro pax_close_userland
2454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2455 + @ save regs
2456 + stmdb sp!, {r0, r1}
2457 + @ read DACR from cpu_domain into r1
2458 + mov r0, sp
2459 + @ assume 8K pages, since we have to split the immediate in two
2460 + bic r0, r0, #(0x1fc0)
2461 + bic r0, r0, #(0x3f)
2462 + ldr r1, [r0, #TI_CPU_DOMAIN]
2463 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2464 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2465 + @ write r1 to current_thread_info()->cpu_domain
2466 + str r1, [r0, #TI_CPU_DOMAIN]
2467 + @ write r1 to DACR
2468 + mcr p15, 0, r1, c3, c0, 0
2469 + @ instruction sync
2470 + instr_sync
2471 + @ restore regs
2472 + ldmia sp!, {r0, r1}
2473 +#endif
2474 + .endm
2475 +
2476 .macro pabt_helper
2477 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2478 #ifdef MULTI_PABORT
2479 @@ -89,11 +170,15 @@
2480 * Invalid mode handlers
2481 */
2482 .macro inv_entry, reason
2483 +
2484 + pax_enter_kernel
2485 +
2486 sub sp, sp, #S_FRAME_SIZE
2487 ARM( stmib sp, {r1 - lr} )
2488 THUMB( stmia sp, {r0 - r12} )
2489 THUMB( str sp, [sp, #S_SP] )
2490 THUMB( str lr, [sp, #S_LR] )
2491 +
2492 mov r1, #\reason
2493 .endm
2494
2495 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2496 .macro svc_entry, stack_hole=0
2497 UNWIND(.fnstart )
2498 UNWIND(.save {r0 - pc} )
2499 +
2500 + pax_enter_kernel
2501 +
2502 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2503 +
2504 #ifdef CONFIG_THUMB2_KERNEL
2505 SPFIX( str r0, [sp] ) @ temporarily saved
2506 SPFIX( mov r0, sp )
2507 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2508 ldmia r0, {r3 - r5}
2509 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2510 mov r6, #-1 @ "" "" "" ""
2511 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2512 + @ offset sp by 8 as done in pax_enter_kernel
2513 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2514 +#else
2515 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2516 +#endif
2517 SPFIX( addeq r2, r2, #4 )
2518 str r3, [sp, #-4]! @ save the "real" r0 copied
2519 @ from the exception stack
2520 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2521 .macro usr_entry
2522 UNWIND(.fnstart )
2523 UNWIND(.cantunwind ) @ don't unwind the user space
2524 +
2525 + pax_enter_kernel_user
2526 +
2527 sub sp, sp, #S_FRAME_SIZE
2528 ARM( stmib sp, {r1 - r12} )
2529 THUMB( stmia sp, {r0 - r12} )
2530 @@ -416,7 +513,9 @@ __und_usr:
2531 tst r3, #PSR_T_BIT @ Thumb mode?
2532 bne __und_usr_thumb
2533 sub r4, r2, #4 @ ARM instr at LR - 4
2534 + pax_open_userland
2535 1: ldrt r0, [r4]
2536 + pax_close_userland
2537 ARM_BE8(rev r0, r0) @ little endian instruction
2538
2539 @ r0 = 32-bit ARM instruction which caused the exception
2540 @@ -450,11 +549,15 @@ __und_usr_thumb:
2541 */
2542 .arch armv6t2
2543 #endif
2544 + pax_open_userland
2545 2: ldrht r5, [r4]
2546 + pax_close_userland
2547 ARM_BE8(rev16 r5, r5) @ little endian instruction
2548 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2549 blo __und_usr_fault_16 @ 16bit undefined instruction
2550 + pax_open_userland
2551 3: ldrht r0, [r2]
2552 + pax_close_userland
2553 ARM_BE8(rev16 r0, r0) @ little endian instruction
2554 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2555 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2556 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2557 */
2558 .pushsection .fixup, "ax"
2559 .align 2
2560 -4: mov pc, r9
2561 +4: pax_close_userland
2562 + mov pc, r9
2563 .popsection
2564 .pushsection __ex_table,"a"
2565 .long 1b, 4b
2566 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2567 THUMB( str lr, [ip], #4 )
2568 ldr r4, [r2, #TI_TP_VALUE]
2569 ldr r5, [r2, #TI_TP_VALUE + 4]
2570 -#ifdef CONFIG_CPU_USE_DOMAINS
2571 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2572 ldr r6, [r2, #TI_CPU_DOMAIN]
2573 #endif
2574 switch_tls r1, r4, r5, r3, r7
2575 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2576 ldr r8, =__stack_chk_guard
2577 ldr r7, [r7, #TSK_STACK_CANARY]
2578 #endif
2579 -#ifdef CONFIG_CPU_USE_DOMAINS
2580 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2581 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2582 #endif
2583 mov r5, r0
2584 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2585 index a2dcafd..1048b5a 100644
2586 --- a/arch/arm/kernel/entry-common.S
2587 +++ b/arch/arm/kernel/entry-common.S
2588 @@ -10,18 +10,46 @@
2589
2590 #include <asm/unistd.h>
2591 #include <asm/ftrace.h>
2592 +#include <asm/domain.h>
2593 #include <asm/unwind.h>
2594
2595 +#include "entry-header.S"
2596 +
2597 #ifdef CONFIG_NEED_RET_TO_USER
2598 #include <mach/entry-macro.S>
2599 #else
2600 .macro arch_ret_to_user, tmp1, tmp2
2601 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2602 + @ save regs
2603 + stmdb sp!, {r1, r2}
2604 + @ read DACR from cpu_domain into r1
2605 + mov r2, sp
2606 + @ assume 8K pages, since we have to split the immediate in two
2607 + bic r2, r2, #(0x1fc0)
2608 + bic r2, r2, #(0x3f)
2609 + ldr r1, [r2, #TI_CPU_DOMAIN]
2610 +#ifdef CONFIG_PAX_KERNEXEC
2611 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2612 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2613 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2614 +#endif
2615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2616 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2617 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2618 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2619 +#endif
2620 + @ write r1 to current_thread_info()->cpu_domain
2621 + str r1, [r2, #TI_CPU_DOMAIN]
2622 + @ write r1 to DACR
2623 + mcr p15, 0, r1, c3, c0, 0
2624 + @ instruction sync
2625 + instr_sync
2626 + @ restore regs
2627 + ldmia sp!, {r1, r2}
2628 +#endif
2629 .endm
2630 #endif
2631
2632 -#include "entry-header.S"
2633 -
2634 -
2635 .align 5
2636 /*
2637 * This is the fast syscall return path. We do as little as
2638 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2639 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2640 #endif
2641
2642 + /*
2643 + * do this here to avoid a performance hit of wrapping the code above
2644 + * that directly dereferences userland to parse the SWI instruction
2645 + */
2646 + pax_enter_kernel_user
2647 +
2648 adr tbl, sys_call_table @ load syscall table pointer
2649
2650 #if defined(CONFIG_OABI_COMPAT)
2651 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2652 index 39f89fb..d612bd9 100644
2653 --- a/arch/arm/kernel/entry-header.S
2654 +++ b/arch/arm/kernel/entry-header.S
2655 @@ -184,6 +184,60 @@
2656 msr cpsr_c, \rtemp @ switch back to the SVC mode
2657 .endm
2658
2659 + .macro pax_enter_kernel_user
2660 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2661 + @ save regs
2662 + stmdb sp!, {r0, r1}
2663 + @ read DACR from cpu_domain into r1
2664 + mov r0, sp
2665 + @ assume 8K pages, since we have to split the immediate in two
2666 + bic r0, r0, #(0x1fc0)
2667 + bic r0, r0, #(0x3f)
2668 + ldr r1, [r0, #TI_CPU_DOMAIN]
2669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2670 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2671 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2672 +#endif
2673 +#ifdef CONFIG_PAX_KERNEXEC
2674 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2675 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2676 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2677 +#endif
2678 + @ write r1 to current_thread_info()->cpu_domain
2679 + str r1, [r0, #TI_CPU_DOMAIN]
2680 + @ write r1 to DACR
2681 + mcr p15, 0, r1, c3, c0, 0
2682 + @ instruction sync
2683 + instr_sync
2684 + @ restore regs
2685 + ldmia sp!, {r0, r1}
2686 +#endif
2687 + .endm
2688 +
2689 + .macro pax_exit_kernel
2690 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2691 + @ save regs
2692 + stmdb sp!, {r0, r1}
2693 + @ read old DACR from stack into r1
2694 + ldr r1, [sp, #(8 + S_SP)]
2695 + sub r1, r1, #8
2696 + ldr r1, [r1]
2697 +
2698 + @ write r1 to current_thread_info()->cpu_domain
2699 + mov r0, sp
2700 + @ assume 8K pages, since we have to split the immediate in two
2701 + bic r0, r0, #(0x1fc0)
2702 + bic r0, r0, #(0x3f)
2703 + str r1, [r0, #TI_CPU_DOMAIN]
2704 + @ write r1 to DACR
2705 + mcr p15, 0, r1, c3, c0, 0
2706 + @ instruction sync
2707 + instr_sync
2708 + @ restore regs
2709 + ldmia sp!, {r0, r1}
2710 +#endif
2711 + .endm
2712 +
2713 #ifndef CONFIG_THUMB2_KERNEL
2714 .macro svc_exit, rpsr, irq = 0
2715 .if \irq != 0
2716 @@ -203,6 +257,9 @@
2717 blne trace_hardirqs_off
2718 #endif
2719 .endif
2720 +
2721 + pax_exit_kernel
2722 +
2723 msr spsr_cxsf, \rpsr
2724 #if defined(CONFIG_CPU_V6)
2725 ldr r0, [sp]
2726 @@ -266,6 +323,9 @@
2727 blne trace_hardirqs_off
2728 #endif
2729 .endif
2730 +
2731 + pax_exit_kernel
2732 +
2733 ldr lr, [sp, #S_SP] @ top of the stack
2734 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2735 clrex @ clear the exclusive monitor
2736 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2737 index 918875d..cd5fa27 100644
2738 --- a/arch/arm/kernel/fiq.c
2739 +++ b/arch/arm/kernel/fiq.c
2740 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2741 void *base = vectors_page;
2742 unsigned offset = FIQ_OFFSET;
2743
2744 + pax_open_kernel();
2745 memcpy(base + offset, start, length);
2746 + pax_close_kernel();
2747 +
2748 if (!cache_is_vipt_nonaliasing())
2749 flush_icache_range((unsigned long)base + offset, offset +
2750 length);
2751 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2752 index f5f381d..a6f36a1 100644
2753 --- a/arch/arm/kernel/head.S
2754 +++ b/arch/arm/kernel/head.S
2755 @@ -437,7 +437,7 @@ __enable_mmu:
2756 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2757 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2758 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2759 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2760 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2761 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2762 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2763 #endif
2764 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2765 index 45e4781..8eac93d 100644
2766 --- a/arch/arm/kernel/module.c
2767 +++ b/arch/arm/kernel/module.c
2768 @@ -38,12 +38,39 @@
2769 #endif
2770
2771 #ifdef CONFIG_MMU
2772 -void *module_alloc(unsigned long size)
2773 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2774 {
2775 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2776 + return NULL;
2777 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2778 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2779 + GFP_KERNEL, prot, NUMA_NO_NODE,
2780 __builtin_return_address(0));
2781 }
2782 +
2783 +void *module_alloc(unsigned long size)
2784 +{
2785 +
2786 +#ifdef CONFIG_PAX_KERNEXEC
2787 + return __module_alloc(size, PAGE_KERNEL);
2788 +#else
2789 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2790 +#endif
2791 +
2792 +}
2793 +
2794 +#ifdef CONFIG_PAX_KERNEXEC
2795 +void module_free_exec(struct module *mod, void *module_region)
2796 +{
2797 + module_free(mod, module_region);
2798 +}
2799 +EXPORT_SYMBOL(module_free_exec);
2800 +
2801 +void *module_alloc_exec(unsigned long size)
2802 +{
2803 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2804 +}
2805 +EXPORT_SYMBOL(module_alloc_exec);
2806 +#endif
2807 #endif
2808
2809 int
2810 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2811 index 07314af..c46655c 100644
2812 --- a/arch/arm/kernel/patch.c
2813 +++ b/arch/arm/kernel/patch.c
2814 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2816 int size;
2817
2818 + pax_open_kernel();
2819 if (thumb2 && __opcode_is_thumb16(insn)) {
2820 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2821 size = sizeof(u16);
2822 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2823 *(u32 *)addr = insn;
2824 size = sizeof(u32);
2825 }
2826 + pax_close_kernel();
2827
2828 flush_icache_range((uintptr_t)(addr),
2829 (uintptr_t)(addr) + size);
2830 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2831 index 92f7b15..7048500 100644
2832 --- a/arch/arm/kernel/process.c
2833 +++ b/arch/arm/kernel/process.c
2834 @@ -217,6 +217,7 @@ void machine_power_off(void)
2835
2836 if (pm_power_off)
2837 pm_power_off();
2838 + BUG();
2839 }
2840
2841 /*
2842 @@ -230,7 +231,7 @@ void machine_power_off(void)
2843 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2844 * to use. Implementing such co-ordination would be essentially impossible.
2845 */
2846 -void machine_restart(char *cmd)
2847 +__noreturn void machine_restart(char *cmd)
2848 {
2849 local_irq_disable();
2850 smp_send_stop();
2851 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2852
2853 show_regs_print_info(KERN_DEFAULT);
2854
2855 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2856 - print_symbol("LR is at %s\n", regs->ARM_lr);
2857 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2858 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2859 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2860 "sp : %08lx ip : %08lx fp : %08lx\n",
2861 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2862 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2863 return 0;
2864 }
2865
2866 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2867 -{
2868 - unsigned long range_end = mm->brk + 0x02000000;
2869 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2870 -}
2871 -
2872 #ifdef CONFIG_MMU
2873 #ifdef CONFIG_KUSER_HELPERS
2874 /*
2875 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2876
2877 static int __init gate_vma_init(void)
2878 {
2879 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2880 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2881 return 0;
2882 }
2883 arch_initcall(gate_vma_init);
2884 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2885
2886 const char *arch_vma_name(struct vm_area_struct *vma)
2887 {
2888 - return is_gate_vma(vma) ? "[vectors]" :
2889 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2890 - "[sigpage]" : NULL;
2891 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2892 }
2893
2894 -static struct page *signal_page;
2895 -extern struct page *get_signal_page(void);
2896 -
2897 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2898 {
2899 struct mm_struct *mm = current->mm;
2900 - unsigned long addr;
2901 - int ret;
2902 -
2903 - if (!signal_page)
2904 - signal_page = get_signal_page();
2905 - if (!signal_page)
2906 - return -ENOMEM;
2907
2908 down_write(&mm->mmap_sem);
2909 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2910 - if (IS_ERR_VALUE(addr)) {
2911 - ret = addr;
2912 - goto up_fail;
2913 - }
2914 -
2915 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2916 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2917 - &signal_page);
2918 -
2919 - if (ret == 0)
2920 - mm->context.sigpage = addr;
2921 -
2922 - up_fail:
2923 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2924 up_write(&mm->mmap_sem);
2925 - return ret;
2926 + return 0;
2927 }
2928 #endif
2929 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2930 index 4693188..4596c5e 100644
2931 --- a/arch/arm/kernel/psci.c
2932 +++ b/arch/arm/kernel/psci.c
2933 @@ -24,7 +24,7 @@
2934 #include <asm/opcodes-virt.h>
2935 #include <asm/psci.h>
2936
2937 -struct psci_operations psci_ops;
2938 +struct psci_operations psci_ops __read_only;
2939
2940 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2941
2942 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2943 index 0dd3b79..e018f64 100644
2944 --- a/arch/arm/kernel/ptrace.c
2945 +++ b/arch/arm/kernel/ptrace.c
2946 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2947 return current_thread_info()->syscall;
2948 }
2949
2950 +#ifdef CONFIG_GRKERNSEC_SETXID
2951 +extern void gr_delayed_cred_worker(void);
2952 +#endif
2953 +
2954 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2955 {
2956 current_thread_info()->syscall = scno;
2957
2958 +#ifdef CONFIG_GRKERNSEC_SETXID
2959 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2960 + gr_delayed_cred_worker();
2961 +#endif
2962 +
2963 /* Do the secure computing check first; failures should be fast. */
2964 if (secure_computing(scno) == -1)
2965 return -1;
2966 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2967 index 1e8b030..37c3022 100644
2968 --- a/arch/arm/kernel/setup.c
2969 +++ b/arch/arm/kernel/setup.c
2970 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2971 unsigned int elf_hwcap __read_mostly;
2972 EXPORT_SYMBOL(elf_hwcap);
2973
2974 +pteval_t __supported_pte_mask __read_only;
2975 +pmdval_t __supported_pmd_mask __read_only;
2976
2977 #ifdef MULTI_CPU
2978 -struct processor processor __read_mostly;
2979 +struct processor processor __read_only;
2980 #endif
2981 #ifdef MULTI_TLB
2982 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2983 +struct cpu_tlb_fns cpu_tlb __read_only;
2984 #endif
2985 #ifdef MULTI_USER
2986 -struct cpu_user_fns cpu_user __read_mostly;
2987 +struct cpu_user_fns cpu_user __read_only;
2988 #endif
2989 #ifdef MULTI_CACHE
2990 -struct cpu_cache_fns cpu_cache __read_mostly;
2991 +struct cpu_cache_fns cpu_cache __read_only;
2992 #endif
2993 #ifdef CONFIG_OUTER_CACHE
2994 -struct outer_cache_fns outer_cache __read_mostly;
2995 +struct outer_cache_fns outer_cache __read_only;
2996 EXPORT_SYMBOL(outer_cache);
2997 #endif
2998
2999 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3000 asm("mrc p15, 0, %0, c0, c1, 4"
3001 : "=r" (mmfr0));
3002 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3003 - (mmfr0 & 0x000000f0) >= 0x00000030)
3004 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3005 cpu_arch = CPU_ARCH_ARMv7;
3006 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3007 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3008 + __supported_pte_mask |= L_PTE_PXN;
3009 + __supported_pmd_mask |= PMD_PXNTABLE;
3010 + }
3011 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3012 (mmfr0 & 0x000000f0) == 0x00000020)
3013 cpu_arch = CPU_ARCH_ARMv6;
3014 else
3015 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016 index 04d6388..5115238 100644
3017 --- a/arch/arm/kernel/signal.c
3018 +++ b/arch/arm/kernel/signal.c
3019 @@ -23,8 +23,6 @@
3020
3021 extern const unsigned long sigreturn_codes[7];
3022
3023 -static unsigned long signal_return_offset;
3024 -
3025 #ifdef CONFIG_CRUNCH
3026 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3027 {
3028 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3029 * except when the MPU has protected the vectors
3030 * page from PL0
3031 */
3032 - retcode = mm->context.sigpage + signal_return_offset +
3033 - (idx << 2) + thumb;
3034 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3035 } else
3036 #endif
3037 {
3038 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3039 } while (thread_flags & _TIF_WORK_MASK);
3040 return 0;
3041 }
3042 -
3043 -struct page *get_signal_page(void)
3044 -{
3045 - unsigned long ptr;
3046 - unsigned offset;
3047 - struct page *page;
3048 - void *addr;
3049 -
3050 - page = alloc_pages(GFP_KERNEL, 0);
3051 -
3052 - if (!page)
3053 - return NULL;
3054 -
3055 - addr = page_address(page);
3056 -
3057 - /* Give the signal return code some randomness */
3058 - offset = 0x200 + (get_random_int() & 0x7fc);
3059 - signal_return_offset = offset;
3060 -
3061 - /*
3062 - * Copy signal return handlers into the vector page, and
3063 - * set sigreturn to be a pointer to these.
3064 - */
3065 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3066 -
3067 - ptr = (unsigned long)addr + offset;
3068 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3069 -
3070 - return page;
3071 -}
3072 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3073 index b7b4c86..47c4f77 100644
3074 --- a/arch/arm/kernel/smp.c
3075 +++ b/arch/arm/kernel/smp.c
3076 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3077
3078 static DECLARE_COMPLETION(cpu_running);
3079
3080 -static struct smp_operations smp_ops;
3081 +static struct smp_operations smp_ops __read_only;
3082
3083 void __init smp_set_ops(struct smp_operations *ops)
3084 {
3085 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3086 index 7a3be1d..b00c7de 100644
3087 --- a/arch/arm/kernel/tcm.c
3088 +++ b/arch/arm/kernel/tcm.c
3089 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3090 .virtual = ITCM_OFFSET,
3091 .pfn = __phys_to_pfn(ITCM_OFFSET),
3092 .length = 0,
3093 - .type = MT_MEMORY_RWX_ITCM,
3094 + .type = MT_MEMORY_RX_ITCM,
3095 }
3096 };
3097
3098 @@ -267,7 +267,9 @@ no_dtcm:
3099 start = &__sitcm_text;
3100 end = &__eitcm_text;
3101 ram = &__itcm_start;
3102 + pax_open_kernel();
3103 memcpy(start, ram, itcm_code_sz);
3104 + pax_close_kernel();
3105 pr_debug("CPU ITCM: copied code from %p - %p\n",
3106 start, end);
3107 itcm_present = true;
3108 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3109 index 172ee18..ce4ec3d 100644
3110 --- a/arch/arm/kernel/traps.c
3111 +++ b/arch/arm/kernel/traps.c
3112 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3113 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3114 {
3115 #ifdef CONFIG_KALLSYMS
3116 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3117 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3118 #else
3119 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3120 #endif
3121 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3122 static int die_owner = -1;
3123 static unsigned int die_nest_count;
3124
3125 +extern void gr_handle_kernel_exploit(void);
3126 +
3127 static unsigned long oops_begin(void)
3128 {
3129 int cpu;
3130 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3131 panic("Fatal exception in interrupt");
3132 if (panic_on_oops)
3133 panic("Fatal exception");
3134 +
3135 + gr_handle_kernel_exploit();
3136 +
3137 if (signr)
3138 do_exit(signr);
3139 }
3140 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3141 * The user helper at 0xffff0fe0 must be used instead.
3142 * (see entry-armv.S for details)
3143 */
3144 + pax_open_kernel();
3145 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3146 + pax_close_kernel();
3147 }
3148 return 0;
3149
3150 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3151 kuser_init(vectors_base);
3152
3153 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3154 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3155 +
3156 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3157 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3158 +#endif
3159 +
3160 #else /* ifndef CONFIG_CPU_V7M */
3161 /*
3162 * on V7-M there is no need to copy the vector table to a dedicated
3163 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3164 index 7bcee5c..e2f3249 100644
3165 --- a/arch/arm/kernel/vmlinux.lds.S
3166 +++ b/arch/arm/kernel/vmlinux.lds.S
3167 @@ -8,7 +8,11 @@
3168 #include <asm/thread_info.h>
3169 #include <asm/memory.h>
3170 #include <asm/page.h>
3171 -
3172 +
3173 +#ifdef CONFIG_PAX_KERNEXEC
3174 +#include <asm/pgtable.h>
3175 +#endif
3176 +
3177 #define PROC_INFO \
3178 . = ALIGN(4); \
3179 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3180 @@ -34,7 +38,7 @@
3181 #endif
3182
3183 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3184 - defined(CONFIG_GENERIC_BUG)
3185 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3186 #define ARM_EXIT_KEEP(x) x
3187 #define ARM_EXIT_DISCARD(x)
3188 #else
3189 @@ -90,6 +94,11 @@ SECTIONS
3190 _text = .;
3191 HEAD_TEXT
3192 }
3193 +
3194 +#ifdef CONFIG_PAX_KERNEXEC
3195 + . = ALIGN(1<<SECTION_SHIFT);
3196 +#endif
3197 +
3198 .text : { /* Real text segment */
3199 _stext = .; /* Text and read-only data */
3200 __exception_text_start = .;
3201 @@ -112,6 +121,8 @@ SECTIONS
3202 ARM_CPU_KEEP(PROC_INFO)
3203 }
3204
3205 + _etext = .; /* End of text section */
3206 +
3207 RO_DATA(PAGE_SIZE)
3208
3209 . = ALIGN(4);
3210 @@ -142,7 +153,9 @@ SECTIONS
3211
3212 NOTES
3213
3214 - _etext = .; /* End of text and rodata section */
3215 +#ifdef CONFIG_PAX_KERNEXEC
3216 + . = ALIGN(1<<SECTION_SHIFT);
3217 +#endif
3218
3219 #ifndef CONFIG_XIP_KERNEL
3220 . = ALIGN(PAGE_SIZE);
3221 @@ -220,6 +233,11 @@ SECTIONS
3222 . = PAGE_OFFSET + TEXT_OFFSET;
3223 #else
3224 __init_end = .;
3225 +
3226 +#ifdef CONFIG_PAX_KERNEXEC
3227 + . = ALIGN(1<<SECTION_SHIFT);
3228 +#endif
3229 +
3230 . = ALIGN(THREAD_SIZE);
3231 __data_loc = .;
3232 #endif
3233 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3234 index bd18bb8..87ede26 100644
3235 --- a/arch/arm/kvm/arm.c
3236 +++ b/arch/arm/kvm/arm.c
3237 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3238 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3239
3240 /* The VMID used in the VTTBR */
3241 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3242 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3243 static u8 kvm_next_vmid;
3244 static DEFINE_SPINLOCK(kvm_vmid_lock);
3245
3246 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3247 */
3248 static bool need_new_vmid_gen(struct kvm *kvm)
3249 {
3250 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3251 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3252 }
3253
3254 /**
3255 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3256
3257 /* First user of a new VMID generation? */
3258 if (unlikely(kvm_next_vmid == 0)) {
3259 - atomic64_inc(&kvm_vmid_gen);
3260 + atomic64_inc_unchecked(&kvm_vmid_gen);
3261 kvm_next_vmid = 1;
3262
3263 /*
3264 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3265 kvm_call_hyp(__kvm_flush_vm_context);
3266 }
3267
3268 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3269 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3270 kvm->arch.vmid = kvm_next_vmid;
3271 kvm_next_vmid++;
3272
3273 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3274 index 14a0d98..7771a7d 100644
3275 --- a/arch/arm/lib/clear_user.S
3276 +++ b/arch/arm/lib/clear_user.S
3277 @@ -12,14 +12,14 @@
3278
3279 .text
3280
3281 -/* Prototype: int __clear_user(void *addr, size_t sz)
3282 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3283 * Purpose : clear some user memory
3284 * Params : addr - user memory address to clear
3285 * : sz - number of bytes to clear
3286 * Returns : number of bytes NOT cleared
3287 */
3288 ENTRY(__clear_user_std)
3289 -WEAK(__clear_user)
3290 +WEAK(___clear_user)
3291 stmfd sp!, {r1, lr}
3292 mov r2, #0
3293 cmp r1, #4
3294 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3295 USER( strnebt r2, [r0])
3296 mov r0, #0
3297 ldmfd sp!, {r1, pc}
3298 -ENDPROC(__clear_user)
3299 +ENDPROC(___clear_user)
3300 ENDPROC(__clear_user_std)
3301
3302 .pushsection .fixup,"ax"
3303 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3304 index 66a477a..bee61d3 100644
3305 --- a/arch/arm/lib/copy_from_user.S
3306 +++ b/arch/arm/lib/copy_from_user.S
3307 @@ -16,7 +16,7 @@
3308 /*
3309 * Prototype:
3310 *
3311 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3312 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3313 *
3314 * Purpose:
3315 *
3316 @@ -84,11 +84,11 @@
3317
3318 .text
3319
3320 -ENTRY(__copy_from_user)
3321 +ENTRY(___copy_from_user)
3322
3323 #include "copy_template.S"
3324
3325 -ENDPROC(__copy_from_user)
3326 +ENDPROC(___copy_from_user)
3327
3328 .pushsection .fixup,"ax"
3329 .align 0
3330 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3331 index 6ee2f67..d1cce76 100644
3332 --- a/arch/arm/lib/copy_page.S
3333 +++ b/arch/arm/lib/copy_page.S
3334 @@ -10,6 +10,7 @@
3335 * ASM optimised string functions
3336 */
3337 #include <linux/linkage.h>
3338 +#include <linux/const.h>
3339 #include <asm/assembler.h>
3340 #include <asm/asm-offsets.h>
3341 #include <asm/cache.h>
3342 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3343 index d066df6..df28194 100644
3344 --- a/arch/arm/lib/copy_to_user.S
3345 +++ b/arch/arm/lib/copy_to_user.S
3346 @@ -16,7 +16,7 @@
3347 /*
3348 * Prototype:
3349 *
3350 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3351 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3352 *
3353 * Purpose:
3354 *
3355 @@ -88,11 +88,11 @@
3356 .text
3357
3358 ENTRY(__copy_to_user_std)
3359 -WEAK(__copy_to_user)
3360 +WEAK(___copy_to_user)
3361
3362 #include "copy_template.S"
3363
3364 -ENDPROC(__copy_to_user)
3365 +ENDPROC(___copy_to_user)
3366 ENDPROC(__copy_to_user_std)
3367
3368 .pushsection .fixup,"ax"
3369 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3370 index 7d08b43..f7ca7ea 100644
3371 --- a/arch/arm/lib/csumpartialcopyuser.S
3372 +++ b/arch/arm/lib/csumpartialcopyuser.S
3373 @@ -57,8 +57,8 @@
3374 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3375 */
3376
3377 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3378 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3379 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3380 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3381
3382 #include "csumpartialcopygeneric.S"
3383
3384 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3385 index 5306de3..aed6d03 100644
3386 --- a/arch/arm/lib/delay.c
3387 +++ b/arch/arm/lib/delay.c
3388 @@ -28,7 +28,7 @@
3389 /*
3390 * Default to the loop-based delay implementation.
3391 */
3392 -struct arm_delay_ops arm_delay_ops = {
3393 +struct arm_delay_ops arm_delay_ops __read_only = {
3394 .delay = __loop_delay,
3395 .const_udelay = __loop_const_udelay,
3396 .udelay = __loop_udelay,
3397 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3398 index 3e58d71..029817c 100644
3399 --- a/arch/arm/lib/uaccess_with_memcpy.c
3400 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3401 @@ -136,7 +136,7 @@ out:
3402 }
3403
3404 unsigned long
3405 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3406 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3407 {
3408 /*
3409 * This test is stubbed out of the main function above to keep
3410 @@ -190,7 +190,7 @@ out:
3411 return n;
3412 }
3413
3414 -unsigned long __clear_user(void __user *addr, unsigned long n)
3415 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3416 {
3417 /* See rational for this in __copy_to_user() above. */
3418 if (n < 64)
3419 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3420 index f7ca97b..3d7e719 100644
3421 --- a/arch/arm/mach-at91/setup.c
3422 +++ b/arch/arm/mach-at91/setup.c
3423 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3424
3425 desc->pfn = __phys_to_pfn(base);
3426 desc->length = length;
3427 - desc->type = MT_MEMORY_RWX_NONCACHED;
3428 + desc->type = MT_MEMORY_RW_NONCACHED;
3429
3430 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3431 base, length, desc->virtual);
3432 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3433 index f3407a5..bd4256f 100644
3434 --- a/arch/arm/mach-kirkwood/common.c
3435 +++ b/arch/arm/mach-kirkwood/common.c
3436 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3437 clk_gate_ops.disable(hw);
3438 }
3439
3440 -static struct clk_ops clk_gate_fn_ops;
3441 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3442 +{
3443 + return clk_gate_ops.is_enabled(hw);
3444 +}
3445 +
3446 +static struct clk_ops clk_gate_fn_ops = {
3447 + .enable = clk_gate_fn_enable,
3448 + .disable = clk_gate_fn_disable,
3449 + .is_enabled = clk_gate_fn_is_enabled,
3450 +};
3451
3452 static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 const char *name,
3454 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3455 gate_fn->fn_en = fn_en;
3456 gate_fn->fn_dis = fn_dis;
3457
3458 - /* ops is the gate ops, but with our enable/disable functions */
3459 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3460 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3461 - clk_gate_fn_ops = clk_gate_ops;
3462 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3463 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3464 - }
3465 -
3466 clk = clk_register(dev, &gate_fn->gate.hw);
3467
3468 if (IS_ERR(clk))
3469 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3470 index aead77a..a2253fa 100644
3471 --- a/arch/arm/mach-omap2/board-n8x0.c
3472 +++ b/arch/arm/mach-omap2/board-n8x0.c
3473 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3474 }
3475 #endif
3476
3477 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3478 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3479 .late_init = n8x0_menelaus_late_init,
3480 };
3481
3482 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3483 index ab43755..ccfa231 100644
3484 --- a/arch/arm/mach-omap2/gpmc.c
3485 +++ b/arch/arm/mach-omap2/gpmc.c
3486 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3487 };
3488
3489 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3490 -static struct irq_chip gpmc_irq_chip;
3491 static int gpmc_irq_start;
3492
3493 static struct resource gpmc_mem_root;
3494 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3495
3496 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3497
3498 +static struct irq_chip gpmc_irq_chip = {
3499 + .name = "gpmc",
3500 + .irq_startup = gpmc_irq_noop_ret,
3501 + .irq_enable = gpmc_irq_enable,
3502 + .irq_disable = gpmc_irq_disable,
3503 + .irq_shutdown = gpmc_irq_noop,
3504 + .irq_ack = gpmc_irq_noop,
3505 + .irq_mask = gpmc_irq_noop,
3506 + .irq_unmask = gpmc_irq_noop,
3507 +
3508 +};
3509 +
3510 static int gpmc_setup_irq(void)
3511 {
3512 int i;
3513 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3514 return gpmc_irq_start;
3515 }
3516
3517 - gpmc_irq_chip.name = "gpmc";
3518 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3519 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3520 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3521 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3522 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3523 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3524 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3525 -
3526 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3527 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3528
3529 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530 index 667915d..2ee1219 100644
3531 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3532 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3533 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3534 int (*finish_suspend)(unsigned long cpu_state);
3535 void (*resume)(void);
3536 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3537 -};
3538 +} __no_const;
3539
3540 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3541 static struct powerdomain *mpuss_pd;
3542 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3543 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3544 {}
3545
3546 -struct cpu_pm_ops omap_pm_ops = {
3547 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3548 .finish_suspend = default_finish_suspend,
3549 .resume = dummy_cpu_resume,
3550 .scu_prepare = dummy_scu_prepare,
3551 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3552 index 3664562..72f85c6 100644
3553 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3554 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3555 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3556 return NOTIFY_OK;
3557 }
3558
3559 -static struct notifier_block __refdata irq_hotplug_notifier = {
3560 +static struct notifier_block irq_hotplug_notifier = {
3561 .notifier_call = irq_cpu_hotplug_notify,
3562 };
3563
3564 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3565 index 01ef59d..32ae28a8 100644
3566 --- a/arch/arm/mach-omap2/omap_device.c
3567 +++ b/arch/arm/mach-omap2/omap_device.c
3568 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3569 struct platform_device __init *omap_device_build(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod *oh,
3572 - void *pdata, int pdata_len)
3573 + const void *pdata, int pdata_len)
3574 {
3575 struct omap_hwmod *ohs[] = { oh };
3576
3577 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3578 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3579 int pdev_id,
3580 struct omap_hwmod **ohs,
3581 - int oh_cnt, void *pdata,
3582 + int oh_cnt, const void *pdata,
3583 int pdata_len)
3584 {
3585 int ret = -ENOMEM;
3586 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3587 index 78c02b3..c94109a 100644
3588 --- a/arch/arm/mach-omap2/omap_device.h
3589 +++ b/arch/arm/mach-omap2/omap_device.h
3590 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3591 /* Core code interface */
3592
3593 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3594 - struct omap_hwmod *oh, void *pdata,
3595 + struct omap_hwmod *oh, const void *pdata,
3596 int pdata_len);
3597
3598 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3599 struct omap_hwmod **oh, int oh_cnt,
3600 - void *pdata, int pdata_len);
3601 + const void *pdata, int pdata_len);
3602
3603 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3604 struct omap_hwmod **ohs, int oh_cnt);
3605 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3606 index 1f33f5d..b29fa75 100644
3607 --- a/arch/arm/mach-omap2/omap_hwmod.c
3608 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3609 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3610 int (*init_clkdm)(struct omap_hwmod *oh);
3611 void (*update_context_lost)(struct omap_hwmod *oh);
3612 int (*get_context_lost)(struct omap_hwmod *oh);
3613 -};
3614 +} __no_const;
3615
3616 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3617 -static struct omap_hwmod_soc_ops soc_ops;
3618 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3619
3620 /* omap_hwmod_list contains all registered struct omap_hwmods */
3621 static LIST_HEAD(omap_hwmod_list);
3622 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3623 index 95fee54..cfa9cf1 100644
3624 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3625 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3626 @@ -10,6 +10,7 @@
3627
3628 #include <linux/kernel.h>
3629 #include <linux/init.h>
3630 +#include <asm/pgtable.h>
3631
3632 #include "powerdomain.h"
3633
3634 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3635
3636 void __init am43xx_powerdomains_init(void)
3637 {
3638 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639 + pax_open_kernel();
3640 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3641 + pax_close_kernel();
3642 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3643 pwrdm_register_pwrdms(powerdomains_am43xx);
3644 pwrdm_complete_init();
3645 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3646 index d15c7bb..b2d1f0c 100644
3647 --- a/arch/arm/mach-omap2/wd_timer.c
3648 +++ b/arch/arm/mach-omap2/wd_timer.c
3649 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3650 struct omap_hwmod *oh;
3651 char *oh_name = "wd_timer2";
3652 char *dev_name = "omap_wdt";
3653 - struct omap_wd_timer_platform_data pdata;
3654 + static struct omap_wd_timer_platform_data pdata = {
3655 + .read_reset_sources = prm_read_reset_sources
3656 + };
3657
3658 if (!cpu_class_is_omap2() || of_have_populated_dt())
3659 return 0;
3660 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3661 return -EINVAL;
3662 }
3663
3664 - pdata.read_reset_sources = prm_read_reset_sources;
3665 -
3666 pdev = omap_device_build(dev_name, id, oh, &pdata,
3667 sizeof(struct omap_wd_timer_platform_data));
3668 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3669 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3670 index b82dcae..44ee5b6 100644
3671 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3672 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3673 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3674 bool entered_lp2 = false;
3675
3676 if (tegra_pending_sgi())
3677 - ACCESS_ONCE(abort_flag) = true;
3678 + ACCESS_ONCE_RW(abort_flag) = true;
3679
3680 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3681
3682 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3683 index 2dea8b5..6499da2 100644
3684 --- a/arch/arm/mach-ux500/setup.h
3685 +++ b/arch/arm/mach-ux500/setup.h
3686 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3687 .type = MT_DEVICE, \
3688 }
3689
3690 -#define __MEM_DEV_DESC(x, sz) { \
3691 - .virtual = IO_ADDRESS(x), \
3692 - .pfn = __phys_to_pfn(x), \
3693 - .length = sz, \
3694 - .type = MT_MEMORY_RWX, \
3695 -}
3696 -
3697 extern struct smp_operations ux500_smp_ops;
3698 extern void ux500_cpu_die(unsigned int cpu);
3699
3700 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3701 index 1f8fed9..14d7823 100644
3702 --- a/arch/arm/mm/Kconfig
3703 +++ b/arch/arm/mm/Kconfig
3704 @@ -446,7 +446,7 @@ config CPU_32v5
3705
3706 config CPU_32v6
3707 bool
3708 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3709 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3710 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3711
3712 config CPU_32v6K
3713 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3714
3715 config CPU_USE_DOMAINS
3716 bool
3717 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3718 help
3719 This option enables or disables the use of domain switching
3720 via the set_fs() function.
3721 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3722 config KUSER_HELPERS
3723 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3724 default y
3725 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3726 help
3727 Warning: disabling this option may break user programs.
3728
3729 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3730 See Documentation/arm/kernel_user_helpers.txt for details.
3731
3732 However, the fixed address nature of these helpers can be used
3733 - by ROP (return orientated programming) authors when creating
3734 + by ROP (Return Oriented Programming) authors when creating
3735 exploits.
3736
3737 If all of the binaries and libraries which run on your platform
3738 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3739 index 9240364..a2b8cf3 100644
3740 --- a/arch/arm/mm/alignment.c
3741 +++ b/arch/arm/mm/alignment.c
3742 @@ -212,10 +212,12 @@ union offset_union {
3743 #define __get16_unaligned_check(ins,val,addr) \
3744 do { \
3745 unsigned int err = 0, v, a = addr; \
3746 + pax_open_userland(); \
3747 __get8_unaligned_check(ins,v,a,err); \
3748 val = v << ((BE) ? 8 : 0); \
3749 __get8_unaligned_check(ins,v,a,err); \
3750 val |= v << ((BE) ? 0 : 8); \
3751 + pax_close_userland(); \
3752 if (err) \
3753 goto fault; \
3754 } while (0)
3755 @@ -229,6 +231,7 @@ union offset_union {
3756 #define __get32_unaligned_check(ins,val,addr) \
3757 do { \
3758 unsigned int err = 0, v, a = addr; \
3759 + pax_open_userland(); \
3760 __get8_unaligned_check(ins,v,a,err); \
3761 val = v << ((BE) ? 24 : 0); \
3762 __get8_unaligned_check(ins,v,a,err); \
3763 @@ -237,6 +240,7 @@ union offset_union {
3764 val |= v << ((BE) ? 8 : 16); \
3765 __get8_unaligned_check(ins,v,a,err); \
3766 val |= v << ((BE) ? 0 : 24); \
3767 + pax_close_userland(); \
3768 if (err) \
3769 goto fault; \
3770 } while (0)
3771 @@ -250,6 +254,7 @@ union offset_union {
3772 #define __put16_unaligned_check(ins,val,addr) \
3773 do { \
3774 unsigned int err = 0, v = val, a = addr; \
3775 + pax_open_userland(); \
3776 __asm__( FIRST_BYTE_16 \
3777 ARM( "1: "ins" %1, [%2], #1\n" ) \
3778 THUMB( "1: "ins" %1, [%2]\n" ) \
3779 @@ -269,6 +274,7 @@ union offset_union {
3780 " .popsection\n" \
3781 : "=r" (err), "=&r" (v), "=&r" (a) \
3782 : "0" (err), "1" (v), "2" (a)); \
3783 + pax_close_userland(); \
3784 if (err) \
3785 goto fault; \
3786 } while (0)
3787 @@ -282,6 +288,7 @@ union offset_union {
3788 #define __put32_unaligned_check(ins,val,addr) \
3789 do { \
3790 unsigned int err = 0, v = val, a = addr; \
3791 + pax_open_userland(); \
3792 __asm__( FIRST_BYTE_32 \
3793 ARM( "1: "ins" %1, [%2], #1\n" ) \
3794 THUMB( "1: "ins" %1, [%2]\n" ) \
3795 @@ -311,6 +318,7 @@ union offset_union {
3796 " .popsection\n" \
3797 : "=r" (err), "=&r" (v), "=&r" (a) \
3798 : "0" (err), "1" (v), "2" (a)); \
3799 + pax_close_userland(); \
3800 if (err) \
3801 goto fault; \
3802 } while (0)
3803 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3804 index 7abde2c..9df495f 100644
3805 --- a/arch/arm/mm/cache-l2x0.c
3806 +++ b/arch/arm/mm/cache-l2x0.c
3807 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3808 void (*setup)(const struct device_node *, u32 *, u32 *);
3809 void (*save)(void);
3810 struct outer_cache_fns outer_cache;
3811 -};
3812 +} __do_const;
3813
3814 static bool of_init = false;
3815
3816 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3817 index 6eb97b3..ac509f6 100644
3818 --- a/arch/arm/mm/context.c
3819 +++ b/arch/arm/mm/context.c
3820 @@ -43,7 +43,7 @@
3821 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3822
3823 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3824 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3825 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3826 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3827
3828 static DEFINE_PER_CPU(atomic64_t, active_asids);
3829 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3830 {
3831 static u32 cur_idx = 1;
3832 u64 asid = atomic64_read(&mm->context.id);
3833 - u64 generation = atomic64_read(&asid_generation);
3834 + u64 generation = atomic64_read_unchecked(&asid_generation);
3835
3836 if (asid != 0 && is_reserved_asid(asid)) {
3837 /*
3838 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3839 */
3840 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3841 if (asid == NUM_USER_ASIDS) {
3842 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3843 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3844 &asid_generation);
3845 flush_context(cpu);
3846 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3847 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3848 cpu_set_reserved_ttbr0();
3849
3850 asid = atomic64_read(&mm->context.id);
3851 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3852 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3853 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3854 goto switch_mm_fastpath;
3855
3856 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3857 /* Check that our ASID belongs to the current generation. */
3858 asid = atomic64_read(&mm->context.id);
3859 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3860 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3861 asid = new_context(mm, cpu);
3862 atomic64_set(&mm->context.id, asid);
3863 }
3864 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3865 index eb8830a..5360ce7 100644
3866 --- a/arch/arm/mm/fault.c
3867 +++ b/arch/arm/mm/fault.c
3868 @@ -25,6 +25,7 @@
3869 #include <asm/system_misc.h>
3870 #include <asm/system_info.h>
3871 #include <asm/tlbflush.h>
3872 +#include <asm/sections.h>
3873
3874 #include "fault.h"
3875
3876 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3877 if (fixup_exception(regs))
3878 return;
3879
3880 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3881 + if (addr < TASK_SIZE) {
3882 + if (current->signal->curr_ip)
3883 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3884 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3885 + else
3886 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3887 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3888 + }
3889 +#endif
3890 +
3891 +#ifdef CONFIG_PAX_KERNEXEC
3892 + if ((fsr & FSR_WRITE) &&
3893 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3894 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3895 + {
3896 + if (current->signal->curr_ip)
3897 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3898 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3899 + else
3900 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3901 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3902 + }
3903 +#endif
3904 +
3905 /*
3906 * No handler, we'll have to terminate things with extreme prejudice.
3907 */
3908 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3909 }
3910 #endif
3911
3912 +#ifdef CONFIG_PAX_PAGEEXEC
3913 + if (fsr & FSR_LNX_PF) {
3914 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3915 + do_group_exit(SIGKILL);
3916 + }
3917 +#endif
3918 +
3919 tsk->thread.address = addr;
3920 tsk->thread.error_code = fsr;
3921 tsk->thread.trap_no = 14;
3922 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3923 }
3924 #endif /* CONFIG_MMU */
3925
3926 +#ifdef CONFIG_PAX_PAGEEXEC
3927 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3928 +{
3929 + long i;
3930 +
3931 + printk(KERN_ERR "PAX: bytes at PC: ");
3932 + for (i = 0; i < 20; i++) {
3933 + unsigned char c;
3934 + if (get_user(c, (__force unsigned char __user *)pc+i))
3935 + printk(KERN_CONT "?? ");
3936 + else
3937 + printk(KERN_CONT "%02x ", c);
3938 + }
3939 + printk("\n");
3940 +
3941 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3942 + for (i = -1; i < 20; i++) {
3943 + unsigned long c;
3944 + if (get_user(c, (__force unsigned long __user *)sp+i))
3945 + printk(KERN_CONT "???????? ");
3946 + else
3947 + printk(KERN_CONT "%08lx ", c);
3948 + }
3949 + printk("\n");
3950 +}
3951 +#endif
3952 +
3953 /*
3954 * First Level Translation Fault Handler
3955 *
3956 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3957 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3958 struct siginfo info;
3959
3960 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3961 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3962 + if (current->signal->curr_ip)
3963 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3964 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965 + else
3966 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3967 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3968 + goto die;
3969 + }
3970 +#endif
3971 +
3972 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3973 return;
3974
3975 +die:
3976 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3977 inf->name, fsr, addr);
3978
3979 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3980 ifsr_info[nr].name = name;
3981 }
3982
3983 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3984 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3985 +
3986 asmlinkage void __exception
3987 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3988 {
3989 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3990 struct siginfo info;
3991 + unsigned long pc = instruction_pointer(regs);
3992 +
3993 + if (user_mode(regs)) {
3994 + unsigned long sigpage = current->mm->context.sigpage;
3995 +
3996 + if (sigpage <= pc && pc < sigpage + 7*4) {
3997 + if (pc < sigpage + 3*4)
3998 + sys_sigreturn(regs);
3999 + else
4000 + sys_rt_sigreturn(regs);
4001 + return;
4002 + }
4003 + if (pc == 0xffff0f60UL) {
4004 + /*
4005 + * PaX: __kuser_cmpxchg64 emulation
4006 + */
4007 + // TODO
4008 + //regs->ARM_pc = regs->ARM_lr;
4009 + //return;
4010 + }
4011 + if (pc == 0xffff0fa0UL) {
4012 + /*
4013 + * PaX: __kuser_memory_barrier emulation
4014 + */
4015 + // dmb(); implied by the exception
4016 + regs->ARM_pc = regs->ARM_lr;
4017 + return;
4018 + }
4019 + if (pc == 0xffff0fc0UL) {
4020 + /*
4021 + * PaX: __kuser_cmpxchg emulation
4022 + */
4023 + // TODO
4024 + //long new;
4025 + //int op;
4026 +
4027 + //op = FUTEX_OP_SET << 28;
4028 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4029 + //regs->ARM_r0 = old != new;
4030 + //regs->ARM_pc = regs->ARM_lr;
4031 + //return;
4032 + }
4033 + if (pc == 0xffff0fe0UL) {
4034 + /*
4035 + * PaX: __kuser_get_tls emulation
4036 + */
4037 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4038 + regs->ARM_pc = regs->ARM_lr;
4039 + return;
4040 + }
4041 + }
4042 +
4043 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4044 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4045 + if (current->signal->curr_ip)
4046 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4047 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4048 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4049 + else
4050 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4051 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4052 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4053 + goto die;
4054 + }
4055 +#endif
4056 +
4057 +#ifdef CONFIG_PAX_REFCOUNT
4058 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4059 + unsigned int bkpt;
4060 +
4061 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4062 + current->thread.error_code = ifsr;
4063 + current->thread.trap_no = 0;
4064 + pax_report_refcount_overflow(regs);
4065 + fixup_exception(regs);
4066 + return;
4067 + }
4068 + }
4069 +#endif
4070
4071 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4072 return;
4073
4074 +die:
4075 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4076 inf->name, ifsr, addr);
4077
4078 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4079 index cf08bdf..772656c 100644
4080 --- a/arch/arm/mm/fault.h
4081 +++ b/arch/arm/mm/fault.h
4082 @@ -3,6 +3,7 @@
4083
4084 /*
4085 * Fault status register encodings. We steal bit 31 for our own purposes.
4086 + * Set when the FSR value is from an instruction fault.
4087 */
4088 #define FSR_LNX_PF (1 << 31)
4089 #define FSR_WRITE (1 << 11)
4090 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4091 }
4092 #endif
4093
4094 +/* valid for LPAE and !LPAE */
4095 +static inline int is_xn_fault(unsigned int fsr)
4096 +{
4097 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4098 +}
4099 +
4100 +static inline int is_domain_fault(unsigned int fsr)
4101 +{
4102 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4103 +}
4104 +
4105 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4106 unsigned long search_exception_table(unsigned long addr);
4107
4108 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4109 index 804d615..fcec50a 100644
4110 --- a/arch/arm/mm/init.c
4111 +++ b/arch/arm/mm/init.c
4112 @@ -30,6 +30,8 @@
4113 #include <asm/setup.h>
4114 #include <asm/tlb.h>
4115 #include <asm/fixmap.h>
4116 +#include <asm/system_info.h>
4117 +#include <asm/cp15.h>
4118
4119 #include <asm/mach/arch.h>
4120 #include <asm/mach/map.h>
4121 @@ -625,7 +627,46 @@ void free_initmem(void)
4122 {
4123 #ifdef CONFIG_HAVE_TCM
4124 extern char __tcm_start, __tcm_end;
4125 +#endif
4126
4127 +#ifdef CONFIG_PAX_KERNEXEC
4128 + unsigned long addr;
4129 + pgd_t *pgd;
4130 + pud_t *pud;
4131 + pmd_t *pmd;
4132 + int cpu_arch = cpu_architecture();
4133 + unsigned int cr = get_cr();
4134 +
4135 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4136 + /* make pages tables, etc before .text NX */
4137 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4138 + pgd = pgd_offset_k(addr);
4139 + pud = pud_offset(pgd, addr);
4140 + pmd = pmd_offset(pud, addr);
4141 + __section_update(pmd, addr, PMD_SECT_XN);
4142 + }
4143 + /* make init NX */
4144 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4145 + pgd = pgd_offset_k(addr);
4146 + pud = pud_offset(pgd, addr);
4147 + pmd = pmd_offset(pud, addr);
4148 + __section_update(pmd, addr, PMD_SECT_XN);
4149 + }
4150 + /* make kernel code/rodata RX */
4151 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4152 + pgd = pgd_offset_k(addr);
4153 + pud = pud_offset(pgd, addr);
4154 + pmd = pmd_offset(pud, addr);
4155 +#ifdef CONFIG_ARM_LPAE
4156 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4157 +#else
4158 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4159 +#endif
4160 + }
4161 + }
4162 +#endif
4163 +
4164 +#ifdef CONFIG_HAVE_TCM
4165 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4166 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4167 #endif
4168 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4169 index f9c32ba..8540068 100644
4170 --- a/arch/arm/mm/ioremap.c
4171 +++ b/arch/arm/mm/ioremap.c
4172 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4173 unsigned int mtype;
4174
4175 if (cached)
4176 - mtype = MT_MEMORY_RWX;
4177 + mtype = MT_MEMORY_RX;
4178 else
4179 - mtype = MT_MEMORY_RWX_NONCACHED;
4180 + mtype = MT_MEMORY_RX_NONCACHED;
4181
4182 return __arm_ioremap_caller(phys_addr, size, mtype,
4183 __builtin_return_address(0));
4184 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4185 index 5e85ed3..b10a7ed 100644
4186 --- a/arch/arm/mm/mmap.c
4187 +++ b/arch/arm/mm/mmap.c
4188 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4189 struct vm_area_struct *vma;
4190 int do_align = 0;
4191 int aliasing = cache_is_vipt_aliasing();
4192 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4193 struct vm_unmapped_area_info info;
4194
4195 /*
4196 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4197 if (len > TASK_SIZE)
4198 return -ENOMEM;
4199
4200 +#ifdef CONFIG_PAX_RANDMMAP
4201 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4202 +#endif
4203 +
4204 if (addr) {
4205 if (do_align)
4206 addr = COLOUR_ALIGN(addr, pgoff);
4207 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4208 addr = PAGE_ALIGN(addr);
4209
4210 vma = find_vma(mm, addr);
4211 - if (TASK_SIZE - len >= addr &&
4212 - (!vma || addr + len <= vma->vm_start))
4213 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4214 return addr;
4215 }
4216
4217 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4218 info.high_limit = TASK_SIZE;
4219 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4220 info.align_offset = pgoff << PAGE_SHIFT;
4221 + info.threadstack_offset = offset;
4222 return vm_unmapped_area(&info);
4223 }
4224
4225 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4226 unsigned long addr = addr0;
4227 int do_align = 0;
4228 int aliasing = cache_is_vipt_aliasing();
4229 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4230 struct vm_unmapped_area_info info;
4231
4232 /*
4233 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4234 return addr;
4235 }
4236
4237 +#ifdef CONFIG_PAX_RANDMMAP
4238 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4239 +#endif
4240 +
4241 /* requesting a specific address */
4242 if (addr) {
4243 if (do_align)
4244 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4245 else
4246 addr = PAGE_ALIGN(addr);
4247 vma = find_vma(mm, addr);
4248 - if (TASK_SIZE - len >= addr &&
4249 - (!vma || addr + len <= vma->vm_start))
4250 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4251 return addr;
4252 }
4253
4254 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4255 info.high_limit = mm->mmap_base;
4256 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4257 info.align_offset = pgoff << PAGE_SHIFT;
4258 + info.threadstack_offset = offset;
4259 addr = vm_unmapped_area(&info);
4260
4261 /*
4262 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4263 {
4264 unsigned long random_factor = 0UL;
4265
4266 +#ifdef CONFIG_PAX_RANDMMAP
4267 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4268 +#endif
4269 +
4270 /* 8 bits of randomness in 20 address space bits */
4271 if ((current->flags & PF_RANDOMIZE) &&
4272 !(current->personality & ADDR_NO_RANDOMIZE))
4273 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4274
4275 if (mmap_is_legacy()) {
4276 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4277 +
4278 +#ifdef CONFIG_PAX_RANDMMAP
4279 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4280 + mm->mmap_base += mm->delta_mmap;
4281 +#endif
4282 +
4283 mm->get_unmapped_area = arch_get_unmapped_area;
4284 } else {
4285 mm->mmap_base = mmap_base(random_factor);
4286 +
4287 +#ifdef CONFIG_PAX_RANDMMAP
4288 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4289 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4290 +#endif
4291 +
4292 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4293 }
4294 }
4295 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4296 index a623cb3..a896d84 100644
4297 --- a/arch/arm/mm/mmu.c
4298 +++ b/arch/arm/mm/mmu.c
4299 @@ -39,6 +39,22 @@
4300 #include "mm.h"
4301 #include "tcm.h"
4302
4303 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4304 +void modify_domain(unsigned int dom, unsigned int type)
4305 +{
4306 + struct thread_info *thread = current_thread_info();
4307 + unsigned int domain = thread->cpu_domain;
4308 + /*
4309 + * DOMAIN_MANAGER might be defined to some other value,
4310 + * use the arch-defined constant
4311 + */
4312 + domain &= ~domain_val(dom, 3);
4313 + thread->cpu_domain = domain | domain_val(dom, type);
4314 + set_domain(thread->cpu_domain);
4315 +}
4316 +EXPORT_SYMBOL(modify_domain);
4317 +#endif
4318 +
4319 /*
4320 * empty_zero_page is a special page that is used for
4321 * zero-initialized data and COW.
4322 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4323 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4324 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4325
4326 -static struct mem_type mem_types[] = {
4327 +#ifdef CONFIG_PAX_KERNEXEC
4328 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4329 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4330 +#else
4331 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4332 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4333 +#endif
4334 +
4335 +static struct mem_type mem_types[] __read_only = {
4336 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4337 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4338 L_PTE_SHARED,
4339 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4340 .prot_sect = PROT_SECT_DEVICE,
4341 .domain = DOMAIN_IO,
4342 },
4343 - [MT_UNCACHED] = {
4344 + [MT_UNCACHED_RW] = {
4345 .prot_pte = PROT_PTE_DEVICE,
4346 .prot_l1 = PMD_TYPE_TABLE,
4347 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4348 .domain = DOMAIN_IO,
4349 },
4350 - [MT_CACHECLEAN] = {
4351 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4352 + [MT_CACHECLEAN_RO] = {
4353 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4354 .domain = DOMAIN_KERNEL,
4355 },
4356 #ifndef CONFIG_ARM_LPAE
4357 - [MT_MINICLEAN] = {
4358 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4359 + [MT_MINICLEAN_RO] = {
4360 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4361 .domain = DOMAIN_KERNEL,
4362 },
4363 #endif
4364 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4365 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4366 L_PTE_RDONLY,
4367 .prot_l1 = PMD_TYPE_TABLE,
4368 - .domain = DOMAIN_USER,
4369 + .domain = DOMAIN_VECTORS,
4370 },
4371 [MT_HIGH_VECTORS] = {
4372 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4373 L_PTE_USER | L_PTE_RDONLY,
4374 .prot_l1 = PMD_TYPE_TABLE,
4375 - .domain = DOMAIN_USER,
4376 + .domain = DOMAIN_VECTORS,
4377 },
4378 - [MT_MEMORY_RWX] = {
4379 + [__MT_MEMORY_RWX] = {
4380 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4381 .prot_l1 = PMD_TYPE_TABLE,
4382 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4383 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4384 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4385 .domain = DOMAIN_KERNEL,
4386 },
4387 - [MT_ROM] = {
4388 - .prot_sect = PMD_TYPE_SECT,
4389 + [MT_MEMORY_RX] = {
4390 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4391 + .prot_l1 = PMD_TYPE_TABLE,
4392 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4393 + .domain = DOMAIN_KERNEL,
4394 + },
4395 + [MT_ROM_RX] = {
4396 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4397 .domain = DOMAIN_KERNEL,
4398 },
4399 - [MT_MEMORY_RWX_NONCACHED] = {
4400 + [MT_MEMORY_RW_NONCACHED] = {
4401 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4402 L_PTE_MT_BUFFERABLE,
4403 .prot_l1 = PMD_TYPE_TABLE,
4404 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4405 .domain = DOMAIN_KERNEL,
4406 },
4407 + [MT_MEMORY_RX_NONCACHED] = {
4408 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4409 + L_PTE_MT_BUFFERABLE,
4410 + .prot_l1 = PMD_TYPE_TABLE,
4411 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4412 + .domain = DOMAIN_KERNEL,
4413 + },
4414 [MT_MEMORY_RW_DTCM] = {
4415 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4416 L_PTE_XN,
4417 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4418 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4419 .domain = DOMAIN_KERNEL,
4420 },
4421 - [MT_MEMORY_RWX_ITCM] = {
4422 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4423 + [MT_MEMORY_RX_ITCM] = {
4424 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4425 .prot_l1 = PMD_TYPE_TABLE,
4426 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4427 .domain = DOMAIN_KERNEL,
4428 },
4429 [MT_MEMORY_RW_SO] = {
4430 @@ -524,9 +562,14 @@ static void __init build_mem_type_table(void)
4431 * Mark cache clean areas and XIP ROM read only
4432 * from SVC mode and no access from userspace.
4433 */
4434 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4436 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4438 +#ifdef CONFIG_PAX_KERNEXEC
4439 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4440 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4442 +#endif
4443 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4444 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4445 #endif
4446
4447 if (is_smp()) {
4448 @@ -542,13 +585,17 @@ static void __init build_mem_type_table(void)
4449 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4450 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4451 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4452 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4453 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4454 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4455 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4456 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4457 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4458 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4459 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4460 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4461 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4462 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4463 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4464 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4465 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4466 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4467 }
4468 }
4469
4470 @@ -559,15 +606,20 @@ static void __init build_mem_type_table(void)
4471 if (cpu_arch >= CPU_ARCH_ARMv6) {
4472 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4473 /* Non-cacheable Normal is XCB = 001 */
4474 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4475 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4476 + PMD_SECT_BUFFERED;
4477 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4478 PMD_SECT_BUFFERED;
4479 } else {
4480 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4481 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4482 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4483 + PMD_SECT_TEX(1);
4484 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4485 PMD_SECT_TEX(1);
4486 }
4487 } else {
4488 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4489 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4490 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4491 }
4492
4493 #ifdef CONFIG_ARM_LPAE
4494 @@ -583,6 +635,8 @@ static void __init build_mem_type_table(void)
4495 vecs_pgprot |= PTE_EXT_AF;
4496 #endif
4497
4498 + user_pgprot |= __supported_pte_mask;
4499 +
4500 for (i = 0; i < 16; i++) {
4501 pteval_t v = pgprot_val(protection_map[i]);
4502 protection_map[i] = __pgprot(v | user_pgprot);
4503 @@ -600,21 +654,24 @@ static void __init build_mem_type_table(void)
4504
4505 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4506 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4507 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4508 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4509 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4510 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4511 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4512 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4513 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4514 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4515 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4516 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4517 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4518 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4519 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4520 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4521
4522 switch (cp->pmd) {
4523 case PMD_SECT_WT:
4524 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4525 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4526 break;
4527 case PMD_SECT_WB:
4528 case PMD_SECT_WBWA:
4529 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4530 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4531 break;
4532 }
4533 pr_info("Memory policy: %sData cache %s\n",
4534 @@ -832,7 +889,7 @@ static void __init create_mapping(struct map_desc *md)
4535 return;
4536 }
4537
4538 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4539 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4540 md->virtual >= PAGE_OFFSET &&
4541 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4542 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4543 @@ -1247,18 +1304,15 @@ void __init arm_mm_memblock_reserve(void)
4544 * called function. This means you can't use any function or debugging
4545 * method which may touch any device, otherwise the kernel _will_ crash.
4546 */
4547 +
4548 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4549 +
4550 static void __init devicemaps_init(const struct machine_desc *mdesc)
4551 {
4552 struct map_desc map;
4553 unsigned long addr;
4554 - void *vectors;
4555
4556 - /*
4557 - * Allocate the vector page early.
4558 - */
4559 - vectors = early_alloc(PAGE_SIZE * 2);
4560 -
4561 - early_trap_init(vectors);
4562 + early_trap_init(&vectors);
4563
4564 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4565 pmd_clear(pmd_off_k(addr));
4566 @@ -1271,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4567 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4568 map.virtual = MODULES_VADDR;
4569 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4570 - map.type = MT_ROM;
4571 + map.type = MT_ROM_RX;
4572 create_mapping(&map);
4573 #endif
4574
4575 @@ -1282,14 +1336,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4576 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4577 map.virtual = FLUSH_BASE;
4578 map.length = SZ_1M;
4579 - map.type = MT_CACHECLEAN;
4580 + map.type = MT_CACHECLEAN_RO;
4581 create_mapping(&map);
4582 #endif
4583 #ifdef FLUSH_BASE_MINICACHE
4584 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4585 map.virtual = FLUSH_BASE_MINICACHE;
4586 map.length = SZ_1M;
4587 - map.type = MT_MINICLEAN;
4588 + map.type = MT_MINICLEAN_RO;
4589 create_mapping(&map);
4590 #endif
4591
4592 @@ -1298,7 +1352,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4593 * location (0xffff0000). If we aren't using high-vectors, also
4594 * create a mapping at the low-vectors virtual address.
4595 */
4596 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4597 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4598 map.virtual = 0xffff0000;
4599 map.length = PAGE_SIZE;
4600 #ifdef CONFIG_KUSER_HELPERS
4601 @@ -1355,8 +1409,10 @@ static void __init kmap_init(void)
4602 static void __init map_lowmem(void)
4603 {
4604 struct memblock_region *reg;
4605 +#ifndef CONFIG_PAX_KERNEXEC
4606 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4607 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4608 +#endif
4609
4610 /* Map all the lowmem memory banks. */
4611 for_each_memblock(memory, reg) {
4612 @@ -1369,11 +1425,48 @@ static void __init map_lowmem(void)
4613 if (start >= end)
4614 break;
4615
4616 +#ifdef CONFIG_PAX_KERNEXEC
4617 + map.pfn = __phys_to_pfn(start);
4618 + map.virtual = __phys_to_virt(start);
4619 + map.length = end - start;
4620 +
4621 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4622 + struct map_desc kernel;
4623 + struct map_desc initmap;
4624 +
4625 + /* when freeing initmem we will make this RW */
4626 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4627 + initmap.virtual = (unsigned long)__init_begin;
4628 + initmap.length = _sdata - __init_begin;
4629 + initmap.type = __MT_MEMORY_RWX;
4630 + create_mapping(&initmap);
4631 +
4632 + /* when freeing initmem we will make this RX */
4633 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4634 + kernel.virtual = (unsigned long)_stext;
4635 + kernel.length = __init_begin - _stext;
4636 + kernel.type = __MT_MEMORY_RWX;
4637 + create_mapping(&kernel);
4638 +
4639 + if (map.virtual < (unsigned long)_stext) {
4640 + map.length = (unsigned long)_stext - map.virtual;
4641 + map.type = __MT_MEMORY_RWX;
4642 + create_mapping(&map);
4643 + }
4644 +
4645 + map.pfn = __phys_to_pfn(__pa(_sdata));
4646 + map.virtual = (unsigned long)_sdata;
4647 + map.length = end - __pa(_sdata);
4648 + }
4649 +
4650 + map.type = MT_MEMORY_RW;
4651 + create_mapping(&map);
4652 +#else
4653 if (end < kernel_x_start || start >= kernel_x_end) {
4654 map.pfn = __phys_to_pfn(start);
4655 map.virtual = __phys_to_virt(start);
4656 map.length = end - start;
4657 - map.type = MT_MEMORY_RWX;
4658 + map.type = __MT_MEMORY_RWX;
4659
4660 create_mapping(&map);
4661 } else {
4662 @@ -1390,7 +1483,7 @@ static void __init map_lowmem(void)
4663 map.pfn = __phys_to_pfn(kernel_x_start);
4664 map.virtual = __phys_to_virt(kernel_x_start);
4665 map.length = kernel_x_end - kernel_x_start;
4666 - map.type = MT_MEMORY_RWX;
4667 + map.type = __MT_MEMORY_RWX;
4668
4669 create_mapping(&map);
4670
4671 @@ -1403,6 +1496,7 @@ static void __init map_lowmem(void)
4672 create_mapping(&map);
4673 }
4674 }
4675 +#endif
4676 }
4677 }
4678
4679 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4680 index 5b217f4..c23f40e 100644
4681 --- a/arch/arm/plat-iop/setup.c
4682 +++ b/arch/arm/plat-iop/setup.c
4683 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4684 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4685 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4686 .length = IOP3XX_PERIPHERAL_SIZE,
4687 - .type = MT_UNCACHED,
4688 + .type = MT_UNCACHED_RW,
4689 },
4690 };
4691
4692 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4693 index a5bc92d..0bb4730 100644
4694 --- a/arch/arm/plat-omap/sram.c
4695 +++ b/arch/arm/plat-omap/sram.c
4696 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4697 * Looks like we need to preserve some bootloader code at the
4698 * beginning of SRAM for jumping to flash for reboot to work...
4699 */
4700 + pax_open_kernel();
4701 memset_io(omap_sram_base + omap_sram_skip, 0,
4702 omap_sram_size - omap_sram_skip);
4703 + pax_close_kernel();
4704 }
4705 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4706 index ce6d763..cfea917 100644
4707 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4708 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4709 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4710 int (*started)(unsigned ch);
4711 int (*flush)(unsigned ch);
4712 int (*stop)(unsigned ch);
4713 -};
4714 +} __no_const;
4715
4716 extern void *samsung_dmadev_get_ops(void);
4717 extern void *s3c_dma_get_ops(void);
4718 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4719 index 6c0f684..5faea9d 100644
4720 --- a/arch/arm64/include/asm/uaccess.h
4721 +++ b/arch/arm64/include/asm/uaccess.h
4722 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4723 flag; \
4724 })
4725
4726 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4727 #define access_ok(type, addr, size) __range_ok(addr, size)
4728 #define user_addr_max get_fs
4729
4730 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4731 index c3a58a1..78fbf54 100644
4732 --- a/arch/avr32/include/asm/cache.h
4733 +++ b/arch/avr32/include/asm/cache.h
4734 @@ -1,8 +1,10 @@
4735 #ifndef __ASM_AVR32_CACHE_H
4736 #define __ASM_AVR32_CACHE_H
4737
4738 +#include <linux/const.h>
4739 +
4740 #define L1_CACHE_SHIFT 5
4741 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4742 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4743
4744 /*
4745 * Memory returned by kmalloc() may be used for DMA, so we must make
4746 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4747 index d232888..87c8df1 100644
4748 --- a/arch/avr32/include/asm/elf.h
4749 +++ b/arch/avr32/include/asm/elf.h
4750 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4751 the loader. We need to make sure that it is out of the way of the program
4752 that it will "exec", and that there is sufficient room for the brk. */
4753
4754 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4755 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4756
4757 +#ifdef CONFIG_PAX_ASLR
4758 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4759 +
4760 +#define PAX_DELTA_MMAP_LEN 15
4761 +#define PAX_DELTA_STACK_LEN 15
4762 +#endif
4763
4764 /* This yields a mask that user programs can use to figure out what
4765 instruction set this CPU supports. This could be done in user space,
4766 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4767 index 479330b..53717a8 100644
4768 --- a/arch/avr32/include/asm/kmap_types.h
4769 +++ b/arch/avr32/include/asm/kmap_types.h
4770 @@ -2,9 +2,9 @@
4771 #define __ASM_AVR32_KMAP_TYPES_H
4772
4773 #ifdef CONFIG_DEBUG_HIGHMEM
4774 -# define KM_TYPE_NR 29
4775 +# define KM_TYPE_NR 30
4776 #else
4777 -# define KM_TYPE_NR 14
4778 +# define KM_TYPE_NR 15
4779 #endif
4780
4781 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4782 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4783 index 0eca933..eb78c7b 100644
4784 --- a/arch/avr32/mm/fault.c
4785 +++ b/arch/avr32/mm/fault.c
4786 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4787
4788 int exception_trace = 1;
4789
4790 +#ifdef CONFIG_PAX_PAGEEXEC
4791 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4792 +{
4793 + unsigned long i;
4794 +
4795 + printk(KERN_ERR "PAX: bytes at PC: ");
4796 + for (i = 0; i < 20; i++) {
4797 + unsigned char c;
4798 + if (get_user(c, (unsigned char *)pc+i))
4799 + printk(KERN_CONT "???????? ");
4800 + else
4801 + printk(KERN_CONT "%02x ", c);
4802 + }
4803 + printk("\n");
4804 +}
4805 +#endif
4806 +
4807 /*
4808 * This routine handles page faults. It determines the address and the
4809 * problem, and then passes it off to one of the appropriate routines.
4810 @@ -176,6 +193,16 @@ bad_area:
4811 up_read(&mm->mmap_sem);
4812
4813 if (user_mode(regs)) {
4814 +
4815 +#ifdef CONFIG_PAX_PAGEEXEC
4816 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4817 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4818 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4819 + do_group_exit(SIGKILL);
4820 + }
4821 + }
4822 +#endif
4823 +
4824 if (exception_trace && printk_ratelimit())
4825 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4826 "sp %08lx ecr %lu\n",
4827 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4828 index 568885a..f8008df 100644
4829 --- a/arch/blackfin/include/asm/cache.h
4830 +++ b/arch/blackfin/include/asm/cache.h
4831 @@ -7,6 +7,7 @@
4832 #ifndef __ARCH_BLACKFIN_CACHE_H
4833 #define __ARCH_BLACKFIN_CACHE_H
4834
4835 +#include <linux/const.h>
4836 #include <linux/linkage.h> /* for asmlinkage */
4837
4838 /*
4839 @@ -14,7 +15,7 @@
4840 * Blackfin loads 32 bytes for cache
4841 */
4842 #define L1_CACHE_SHIFT 5
4843 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4844 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4845 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4846
4847 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4848 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4849 index aea2718..3639a60 100644
4850 --- a/arch/cris/include/arch-v10/arch/cache.h
4851 +++ b/arch/cris/include/arch-v10/arch/cache.h
4852 @@ -1,8 +1,9 @@
4853 #ifndef _ASM_ARCH_CACHE_H
4854 #define _ASM_ARCH_CACHE_H
4855
4856 +#include <linux/const.h>
4857 /* Etrax 100LX have 32-byte cache-lines. */
4858 -#define L1_CACHE_BYTES 32
4859 #define L1_CACHE_SHIFT 5
4860 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4861
4862 #endif /* _ASM_ARCH_CACHE_H */
4863 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4864 index 7caf25d..ee65ac5 100644
4865 --- a/arch/cris/include/arch-v32/arch/cache.h
4866 +++ b/arch/cris/include/arch-v32/arch/cache.h
4867 @@ -1,11 +1,12 @@
4868 #ifndef _ASM_CRIS_ARCH_CACHE_H
4869 #define _ASM_CRIS_ARCH_CACHE_H
4870
4871 +#include <linux/const.h>
4872 #include <arch/hwregs/dma.h>
4873
4874 /* A cache-line is 32 bytes. */
4875 -#define L1_CACHE_BYTES 32
4876 #define L1_CACHE_SHIFT 5
4877 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4878
4879 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4880
4881 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4882 index b86329d..6709906 100644
4883 --- a/arch/frv/include/asm/atomic.h
4884 +++ b/arch/frv/include/asm/atomic.h
4885 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4886 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4887 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4888
4889 +#define atomic64_read_unchecked(v) atomic64_read(v)
4890 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4891 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4892 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4893 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4894 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4895 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4896 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4897 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4898 +
4899 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4900 {
4901 int c, old;
4902 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4903 index 2797163..c2a401d 100644
4904 --- a/arch/frv/include/asm/cache.h
4905 +++ b/arch/frv/include/asm/cache.h
4906 @@ -12,10 +12,11 @@
4907 #ifndef __ASM_CACHE_H
4908 #define __ASM_CACHE_H
4909
4910 +#include <linux/const.h>
4911
4912 /* bytes per L1 cache line */
4913 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4914 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4915 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4916
4917 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4918 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4919 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4920 index 43901f2..0d8b865 100644
4921 --- a/arch/frv/include/asm/kmap_types.h
4922 +++ b/arch/frv/include/asm/kmap_types.h
4923 @@ -2,6 +2,6 @@
4924 #ifndef _ASM_KMAP_TYPES_H
4925 #define _ASM_KMAP_TYPES_H
4926
4927 -#define KM_TYPE_NR 17
4928 +#define KM_TYPE_NR 18
4929
4930 #endif
4931 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4932 index 836f147..4cf23f5 100644
4933 --- a/arch/frv/mm/elf-fdpic.c
4934 +++ b/arch/frv/mm/elf-fdpic.c
4935 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4936 {
4937 struct vm_area_struct *vma;
4938 struct vm_unmapped_area_info info;
4939 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4940
4941 if (len > TASK_SIZE)
4942 return -ENOMEM;
4943 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4944 if (addr) {
4945 addr = PAGE_ALIGN(addr);
4946 vma = find_vma(current->mm, addr);
4947 - if (TASK_SIZE - len >= addr &&
4948 - (!vma || addr + len <= vma->vm_start))
4949 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4950 goto success;
4951 }
4952
4953 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4954 info.high_limit = (current->mm->start_stack - 0x00200000);
4955 info.align_mask = 0;
4956 info.align_offset = 0;
4957 + info.threadstack_offset = offset;
4958 addr = vm_unmapped_area(&info);
4959 if (!(addr & ~PAGE_MASK))
4960 goto success;
4961 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4962 index f4ca594..adc72fd6 100644
4963 --- a/arch/hexagon/include/asm/cache.h
4964 +++ b/arch/hexagon/include/asm/cache.h
4965 @@ -21,9 +21,11 @@
4966 #ifndef __ASM_CACHE_H
4967 #define __ASM_CACHE_H
4968
4969 +#include <linux/const.h>
4970 +
4971 /* Bytes per L1 cache line */
4972 -#define L1_CACHE_SHIFT (5)
4973 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4974 +#define L1_CACHE_SHIFT 5
4975 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4976
4977 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4978 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4979 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4980 index 0c8e553..112d734 100644
4981 --- a/arch/ia64/Kconfig
4982 +++ b/arch/ia64/Kconfig
4983 @@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4984 config KEXEC
4985 bool "kexec system call"
4986 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4987 + depends on !GRKERNSEC_KMEM
4988 help
4989 kexec is a system call that implements the ability to shutdown your
4990 current kernel, and to start another kernel. It is like a reboot
4991 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4992 index 6e6fe18..a6ae668 100644
4993 --- a/arch/ia64/include/asm/atomic.h
4994 +++ b/arch/ia64/include/asm/atomic.h
4995 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4996 #define atomic64_inc(v) atomic64_add(1, (v))
4997 #define atomic64_dec(v) atomic64_sub(1, (v))
4998
4999 +#define atomic64_read_unchecked(v) atomic64_read(v)
5000 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5001 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5002 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5003 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5004 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5005 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5006 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5007 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5008 +
5009 /* Atomic operations are already serializing */
5010 #define smp_mb__before_atomic_dec() barrier()
5011 #define smp_mb__after_atomic_dec() barrier()
5012 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5013 index 988254a..e1ee885 100644
5014 --- a/arch/ia64/include/asm/cache.h
5015 +++ b/arch/ia64/include/asm/cache.h
5016 @@ -1,6 +1,7 @@
5017 #ifndef _ASM_IA64_CACHE_H
5018 #define _ASM_IA64_CACHE_H
5019
5020 +#include <linux/const.h>
5021
5022 /*
5023 * Copyright (C) 1998-2000 Hewlett-Packard Co
5024 @@ -9,7 +10,7 @@
5025
5026 /* Bytes per L1 (data) cache line. */
5027 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5028 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5029 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5030
5031 #ifdef CONFIG_SMP
5032 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5033 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5034 index 5a83c5c..4d7f553 100644
5035 --- a/arch/ia64/include/asm/elf.h
5036 +++ b/arch/ia64/include/asm/elf.h
5037 @@ -42,6 +42,13 @@
5038 */
5039 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5040
5041 +#ifdef CONFIG_PAX_ASLR
5042 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5043 +
5044 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5045 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5046 +#endif
5047 +
5048 #define PT_IA_64_UNWIND 0x70000001
5049
5050 /* IA-64 relocations: */
5051 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5052 index 5767cdf..7462574 100644
5053 --- a/arch/ia64/include/asm/pgalloc.h
5054 +++ b/arch/ia64/include/asm/pgalloc.h
5055 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5056 pgd_val(*pgd_entry) = __pa(pud);
5057 }
5058
5059 +static inline void
5060 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5061 +{
5062 + pgd_populate(mm, pgd_entry, pud);
5063 +}
5064 +
5065 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5066 {
5067 return quicklist_alloc(0, GFP_KERNEL, NULL);
5068 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5069 pud_val(*pud_entry) = __pa(pmd);
5070 }
5071
5072 +static inline void
5073 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5074 +{
5075 + pud_populate(mm, pud_entry, pmd);
5076 +}
5077 +
5078 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5079 {
5080 return quicklist_alloc(0, GFP_KERNEL, NULL);
5081 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5082 index 7935115..c0eca6a 100644
5083 --- a/arch/ia64/include/asm/pgtable.h
5084 +++ b/arch/ia64/include/asm/pgtable.h
5085 @@ -12,7 +12,7 @@
5086 * David Mosberger-Tang <davidm@hpl.hp.com>
5087 */
5088
5089 -
5090 +#include <linux/const.h>
5091 #include <asm/mman.h>
5092 #include <asm/page.h>
5093 #include <asm/processor.h>
5094 @@ -142,6 +142,17 @@
5095 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5096 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5097 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5098 +
5099 +#ifdef CONFIG_PAX_PAGEEXEC
5100 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5101 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5102 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5103 +#else
5104 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5105 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5106 +# define PAGE_COPY_NOEXEC PAGE_COPY
5107 +#endif
5108 +
5109 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5110 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5111 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5112 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5113 index 45698cd..e8e2dbc 100644
5114 --- a/arch/ia64/include/asm/spinlock.h
5115 +++ b/arch/ia64/include/asm/spinlock.h
5116 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5117 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5118
5119 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5120 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5121 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5122 }
5123
5124 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5125 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5126 index 449c8c0..3d4b1e9 100644
5127 --- a/arch/ia64/include/asm/uaccess.h
5128 +++ b/arch/ia64/include/asm/uaccess.h
5129 @@ -70,6 +70,7 @@
5130 && ((segment).seg == KERNEL_DS.seg \
5131 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5132 })
5133 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5134 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5135
5136 /*
5137 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5138 static inline unsigned long
5139 __copy_to_user (void __user *to, const void *from, unsigned long count)
5140 {
5141 + if (count > INT_MAX)
5142 + return count;
5143 +
5144 + if (!__builtin_constant_p(count))
5145 + check_object_size(from, count, true);
5146 +
5147 return __copy_user(to, (__force void __user *) from, count);
5148 }
5149
5150 static inline unsigned long
5151 __copy_from_user (void *to, const void __user *from, unsigned long count)
5152 {
5153 + if (count > INT_MAX)
5154 + return count;
5155 +
5156 + if (!__builtin_constant_p(count))
5157 + check_object_size(to, count, false);
5158 +
5159 return __copy_user((__force void __user *) to, from, count);
5160 }
5161
5162 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5163 ({ \
5164 void __user *__cu_to = (to); \
5165 const void *__cu_from = (from); \
5166 - long __cu_len = (n); \
5167 + unsigned long __cu_len = (n); \
5168 \
5169 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5170 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5171 + if (!__builtin_constant_p(n)) \
5172 + check_object_size(__cu_from, __cu_len, true); \
5173 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5174 + } \
5175 __cu_len; \
5176 })
5177
5178 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5179 ({ \
5180 void *__cu_to = (to); \
5181 const void __user *__cu_from = (from); \
5182 - long __cu_len = (n); \
5183 + unsigned long __cu_len = (n); \
5184 \
5185 __chk_user_ptr(__cu_from); \
5186 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5187 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5188 + if (!__builtin_constant_p(n)) \
5189 + check_object_size(__cu_to, __cu_len, false); \
5190 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5191 + } \
5192 __cu_len; \
5193 })
5194
5195 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5196 index 24603be..948052d 100644
5197 --- a/arch/ia64/kernel/module.c
5198 +++ b/arch/ia64/kernel/module.c
5199 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5200 void
5201 module_free (struct module *mod, void *module_region)
5202 {
5203 - if (mod && mod->arch.init_unw_table &&
5204 - module_region == mod->module_init) {
5205 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5206 unw_remove_unwind_table(mod->arch.init_unw_table);
5207 mod->arch.init_unw_table = NULL;
5208 }
5209 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5210 }
5211
5212 static inline int
5213 +in_init_rx (const struct module *mod, uint64_t addr)
5214 +{
5215 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5216 +}
5217 +
5218 +static inline int
5219 +in_init_rw (const struct module *mod, uint64_t addr)
5220 +{
5221 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5222 +}
5223 +
5224 +static inline int
5225 in_init (const struct module *mod, uint64_t addr)
5226 {
5227 - return addr - (uint64_t) mod->module_init < mod->init_size;
5228 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5229 +}
5230 +
5231 +static inline int
5232 +in_core_rx (const struct module *mod, uint64_t addr)
5233 +{
5234 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5235 +}
5236 +
5237 +static inline int
5238 +in_core_rw (const struct module *mod, uint64_t addr)
5239 +{
5240 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5241 }
5242
5243 static inline int
5244 in_core (const struct module *mod, uint64_t addr)
5245 {
5246 - return addr - (uint64_t) mod->module_core < mod->core_size;
5247 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5248 }
5249
5250 static inline int
5251 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5252 break;
5253
5254 case RV_BDREL:
5255 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5256 + if (in_init_rx(mod, val))
5257 + val -= (uint64_t) mod->module_init_rx;
5258 + else if (in_init_rw(mod, val))
5259 + val -= (uint64_t) mod->module_init_rw;
5260 + else if (in_core_rx(mod, val))
5261 + val -= (uint64_t) mod->module_core_rx;
5262 + else if (in_core_rw(mod, val))
5263 + val -= (uint64_t) mod->module_core_rw;
5264 break;
5265
5266 case RV_LTV:
5267 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5268 * addresses have been selected...
5269 */
5270 uint64_t gp;
5271 - if (mod->core_size > MAX_LTOFF)
5272 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5273 /*
5274 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5275 * at the end of the module.
5276 */
5277 - gp = mod->core_size - MAX_LTOFF / 2;
5278 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5279 else
5280 - gp = mod->core_size / 2;
5281 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5282 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5283 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5284 mod->arch.gp = gp;
5285 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5286 }
5287 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5288 index ab33328..f39506c 100644
5289 --- a/arch/ia64/kernel/palinfo.c
5290 +++ b/arch/ia64/kernel/palinfo.c
5291 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5292 return NOTIFY_OK;
5293 }
5294
5295 -static struct notifier_block __refdata palinfo_cpu_notifier =
5296 +static struct notifier_block palinfo_cpu_notifier =
5297 {
5298 .notifier_call = palinfo_cpu_callback,
5299 .priority = 0,
5300 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5301 index 41e33f8..65180b2a 100644
5302 --- a/arch/ia64/kernel/sys_ia64.c
5303 +++ b/arch/ia64/kernel/sys_ia64.c
5304 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5305 unsigned long align_mask = 0;
5306 struct mm_struct *mm = current->mm;
5307 struct vm_unmapped_area_info info;
5308 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5309
5310 if (len > RGN_MAP_LIMIT)
5311 return -ENOMEM;
5312 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5313 if (REGION_NUMBER(addr) == RGN_HPAGE)
5314 addr = 0;
5315 #endif
5316 +
5317 +#ifdef CONFIG_PAX_RANDMMAP
5318 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5319 + addr = mm->free_area_cache;
5320 + else
5321 +#endif
5322 +
5323 if (!addr)
5324 addr = TASK_UNMAPPED_BASE;
5325
5326 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5327 info.high_limit = TASK_SIZE;
5328 info.align_mask = align_mask;
5329 info.align_offset = 0;
5330 + info.threadstack_offset = offset;
5331 return vm_unmapped_area(&info);
5332 }
5333
5334 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5335 index 84f8a52..7c76178 100644
5336 --- a/arch/ia64/kernel/vmlinux.lds.S
5337 +++ b/arch/ia64/kernel/vmlinux.lds.S
5338 @@ -192,7 +192,7 @@ SECTIONS {
5339 /* Per-cpu data: */
5340 . = ALIGN(PERCPU_PAGE_SIZE);
5341 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5342 - __phys_per_cpu_start = __per_cpu_load;
5343 + __phys_per_cpu_start = per_cpu_load;
5344 /*
5345 * ensure percpu data fits
5346 * into percpu page size
5347 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5348 index 7225dad..2a7c8256 100644
5349 --- a/arch/ia64/mm/fault.c
5350 +++ b/arch/ia64/mm/fault.c
5351 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5352 return pte_present(pte);
5353 }
5354
5355 +#ifdef CONFIG_PAX_PAGEEXEC
5356 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5357 +{
5358 + unsigned long i;
5359 +
5360 + printk(KERN_ERR "PAX: bytes at PC: ");
5361 + for (i = 0; i < 8; i++) {
5362 + unsigned int c;
5363 + if (get_user(c, (unsigned int *)pc+i))
5364 + printk(KERN_CONT "???????? ");
5365 + else
5366 + printk(KERN_CONT "%08x ", c);
5367 + }
5368 + printk("\n");
5369 +}
5370 +#endif
5371 +
5372 # define VM_READ_BIT 0
5373 # define VM_WRITE_BIT 1
5374 # define VM_EXEC_BIT 2
5375 @@ -151,8 +168,21 @@ retry:
5376 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5377 goto bad_area;
5378
5379 - if ((vma->vm_flags & mask) != mask)
5380 + if ((vma->vm_flags & mask) != mask) {
5381 +
5382 +#ifdef CONFIG_PAX_PAGEEXEC
5383 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5384 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5385 + goto bad_area;
5386 +
5387 + up_read(&mm->mmap_sem);
5388 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5389 + do_group_exit(SIGKILL);
5390 + }
5391 +#endif
5392 +
5393 goto bad_area;
5394 + }
5395
5396 /*
5397 * If for any reason at all we couldn't handle the fault, make
5398 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5399 index 68232db..6ca80af 100644
5400 --- a/arch/ia64/mm/hugetlbpage.c
5401 +++ b/arch/ia64/mm/hugetlbpage.c
5402 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5403 unsigned long pgoff, unsigned long flags)
5404 {
5405 struct vm_unmapped_area_info info;
5406 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5407
5408 if (len > RGN_MAP_LIMIT)
5409 return -ENOMEM;
5410 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5411 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5412 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5413 info.align_offset = 0;
5414 + info.threadstack_offset = offset;
5415 return vm_unmapped_area(&info);
5416 }
5417
5418 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5419 index 25c3502..560dae7 100644
5420 --- a/arch/ia64/mm/init.c
5421 +++ b/arch/ia64/mm/init.c
5422 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5423 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5424 vma->vm_end = vma->vm_start + PAGE_SIZE;
5425 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5426 +
5427 +#ifdef CONFIG_PAX_PAGEEXEC
5428 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5429 + vma->vm_flags &= ~VM_EXEC;
5430 +
5431 +#ifdef CONFIG_PAX_MPROTECT
5432 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5433 + vma->vm_flags &= ~VM_MAYEXEC;
5434 +#endif
5435 +
5436 + }
5437 +#endif
5438 +
5439 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5440 down_write(&current->mm->mmap_sem);
5441 if (insert_vm_struct(current->mm, vma)) {
5442 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5443 index 40b3ee9..8c2c112 100644
5444 --- a/arch/m32r/include/asm/cache.h
5445 +++ b/arch/m32r/include/asm/cache.h
5446 @@ -1,8 +1,10 @@
5447 #ifndef _ASM_M32R_CACHE_H
5448 #define _ASM_M32R_CACHE_H
5449
5450 +#include <linux/const.h>
5451 +
5452 /* L1 cache line size */
5453 #define L1_CACHE_SHIFT 4
5454 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5455 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5456
5457 #endif /* _ASM_M32R_CACHE_H */
5458 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5459 index 82abd15..d95ae5d 100644
5460 --- a/arch/m32r/lib/usercopy.c
5461 +++ b/arch/m32r/lib/usercopy.c
5462 @@ -14,6 +14,9 @@
5463 unsigned long
5464 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5465 {
5466 + if ((long)n < 0)
5467 + return n;
5468 +
5469 prefetch(from);
5470 if (access_ok(VERIFY_WRITE, to, n))
5471 __copy_user(to,from,n);
5472 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5473 unsigned long
5474 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5475 {
5476 + if ((long)n < 0)
5477 + return n;
5478 +
5479 prefetchw(to);
5480 if (access_ok(VERIFY_READ, from, n))
5481 __copy_user_zeroing(to,from,n);
5482 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5483 index 0395c51..5f26031 100644
5484 --- a/arch/m68k/include/asm/cache.h
5485 +++ b/arch/m68k/include/asm/cache.h
5486 @@ -4,9 +4,11 @@
5487 #ifndef __ARCH_M68K_CACHE_H
5488 #define __ARCH_M68K_CACHE_H
5489
5490 +#include <linux/const.h>
5491 +
5492 /* bytes per L1 cache line */
5493 #define L1_CACHE_SHIFT 4
5494 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5495 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5496
5497 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5498
5499 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5500 index 0424315..defcca9 100644
5501 --- a/arch/metag/mm/hugetlbpage.c
5502 +++ b/arch/metag/mm/hugetlbpage.c
5503 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5504 info.high_limit = TASK_SIZE;
5505 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5506 info.align_offset = 0;
5507 + info.threadstack_offset = 0;
5508 return vm_unmapped_area(&info);
5509 }
5510
5511 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5512 index 4efe96a..60e8699 100644
5513 --- a/arch/microblaze/include/asm/cache.h
5514 +++ b/arch/microblaze/include/asm/cache.h
5515 @@ -13,11 +13,12 @@
5516 #ifndef _ASM_MICROBLAZE_CACHE_H
5517 #define _ASM_MICROBLAZE_CACHE_H
5518
5519 +#include <linux/const.h>
5520 #include <asm/registers.h>
5521
5522 #define L1_CACHE_SHIFT 5
5523 /* word-granular cache in microblaze */
5524 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5525 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5526
5527 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5528
5529 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5530 index 95fa1f1..56a6fa2 100644
5531 --- a/arch/mips/Kconfig
5532 +++ b/arch/mips/Kconfig
5533 @@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5534
5535 config KEXEC
5536 bool "Kexec system call"
5537 + depends on !GRKERNSEC_KMEM
5538 help
5539 kexec is a system call that implements the ability to shutdown your
5540 current kernel, and to start another kernel. It is like a reboot
5541 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5542 index 02f2444..506969c 100644
5543 --- a/arch/mips/cavium-octeon/dma-octeon.c
5544 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5545 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5546 if (dma_release_from_coherent(dev, order, vaddr))
5547 return;
5548
5549 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5550 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5551 }
5552
5553 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5554 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5555 index 7eed2f2..c4e385d 100644
5556 --- a/arch/mips/include/asm/atomic.h
5557 +++ b/arch/mips/include/asm/atomic.h
5558 @@ -21,15 +21,39 @@
5559 #include <asm/cmpxchg.h>
5560 #include <asm/war.h>
5561
5562 +#ifdef CONFIG_GENERIC_ATOMIC64
5563 +#include <asm-generic/atomic64.h>
5564 +#endif
5565 +
5566 #define ATOMIC_INIT(i) { (i) }
5567
5568 +#ifdef CONFIG_64BIT
5569 +#define _ASM_EXTABLE(from, to) \
5570 +" .section __ex_table,\"a\"\n" \
5571 +" .dword " #from ", " #to"\n" \
5572 +" .previous\n"
5573 +#else
5574 +#define _ASM_EXTABLE(from, to) \
5575 +" .section __ex_table,\"a\"\n" \
5576 +" .word " #from ", " #to"\n" \
5577 +" .previous\n"
5578 +#endif
5579 +
5580 /*
5581 * atomic_read - read atomic variable
5582 * @v: pointer of type atomic_t
5583 *
5584 * Atomically reads the value of @v.
5585 */
5586 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5587 +static inline int atomic_read(const atomic_t *v)
5588 +{
5589 + return (*(volatile const int *) &v->counter);
5590 +}
5591 +
5592 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5593 +{
5594 + return (*(volatile const int *) &v->counter);
5595 +}
5596
5597 /*
5598 * atomic_set - set atomic variable
5599 @@ -38,7 +62,15 @@
5600 *
5601 * Atomically sets the value of @v to @i.
5602 */
5603 -#define atomic_set(v, i) ((v)->counter = (i))
5604 +static inline void atomic_set(atomic_t *v, int i)
5605 +{
5606 + v->counter = i;
5607 +}
5608 +
5609 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5610 +{
5611 + v->counter = i;
5612 +}
5613
5614 /*
5615 * atomic_add - add integer to atomic variable
5616 @@ -47,7 +79,67 @@
5617 *
5618 * Atomically adds @i to @v.
5619 */
5620 -static __inline__ void atomic_add(int i, atomic_t * v)
5621 +static __inline__ void atomic_add(int i, atomic_t *v)
5622 +{
5623 + int temp;
5624 +
5625 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5626 + __asm__ __volatile__(
5627 + " .set mips3 \n"
5628 + "1: ll %0, %1 # atomic_add \n"
5629 +#ifdef CONFIG_PAX_REFCOUNT
5630 + /* Exception on overflow. */
5631 + "2: add %0, %2 \n"
5632 +#else
5633 + " addu %0, %2 \n"
5634 +#endif
5635 + " sc %0, %1 \n"
5636 + " beqzl %0, 1b \n"
5637 +#ifdef CONFIG_PAX_REFCOUNT
5638 + "3: \n"
5639 + _ASM_EXTABLE(2b, 3b)
5640 +#endif
5641 + " .set mips0 \n"
5642 + : "=&r" (temp), "+m" (v->counter)
5643 + : "Ir" (i));
5644 + } else if (kernel_uses_llsc) {
5645 + __asm__ __volatile__(
5646 + " .set mips3 \n"
5647 + "1: ll %0, %1 # atomic_add \n"
5648 +#ifdef CONFIG_PAX_REFCOUNT
5649 + /* Exception on overflow. */
5650 + "2: add %0, %2 \n"
5651 +#else
5652 + " addu %0, %2 \n"
5653 +#endif
5654 + " sc %0, %1 \n"
5655 + " beqz %0, 1b \n"
5656 +#ifdef CONFIG_PAX_REFCOUNT
5657 + "3: \n"
5658 + _ASM_EXTABLE(2b, 3b)
5659 +#endif
5660 + " .set mips0 \n"
5661 + : "=&r" (temp), "+m" (v->counter)
5662 + : "Ir" (i));
5663 + } else {
5664 + unsigned long flags;
5665 +
5666 + raw_local_irq_save(flags);
5667 + __asm__ __volatile__(
5668 +#ifdef CONFIG_PAX_REFCOUNT
5669 + /* Exception on overflow. */
5670 + "1: add %0, %1 \n"
5671 + "2: \n"
5672 + _ASM_EXTABLE(1b, 2b)
5673 +#else
5674 + " addu %0, %1 \n"
5675 +#endif
5676 + : "+r" (v->counter) : "Ir" (i));
5677 + raw_local_irq_restore(flags);
5678 + }
5679 +}
5680 +
5681 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5682 {
5683 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5684 int temp;
5685 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5686 *
5687 * Atomically subtracts @i from @v.
5688 */
5689 -static __inline__ void atomic_sub(int i, atomic_t * v)
5690 +static __inline__ void atomic_sub(int i, atomic_t *v)
5691 +{
5692 + int temp;
5693 +
5694 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5695 + __asm__ __volatile__(
5696 + " .set mips3 \n"
5697 + "1: ll %0, %1 # atomic64_sub \n"
5698 +#ifdef CONFIG_PAX_REFCOUNT
5699 + /* Exception on overflow. */
5700 + "2: sub %0, %2 \n"
5701 +#else
5702 + " subu %0, %2 \n"
5703 +#endif
5704 + " sc %0, %1 \n"
5705 + " beqzl %0, 1b \n"
5706 +#ifdef CONFIG_PAX_REFCOUNT
5707 + "3: \n"
5708 + _ASM_EXTABLE(2b, 3b)
5709 +#endif
5710 + " .set mips0 \n"
5711 + : "=&r" (temp), "+m" (v->counter)
5712 + : "Ir" (i));
5713 + } else if (kernel_uses_llsc) {
5714 + __asm__ __volatile__(
5715 + " .set mips3 \n"
5716 + "1: ll %0, %1 # atomic64_sub \n"
5717 +#ifdef CONFIG_PAX_REFCOUNT
5718 + /* Exception on overflow. */
5719 + "2: sub %0, %2 \n"
5720 +#else
5721 + " subu %0, %2 \n"
5722 +#endif
5723 + " sc %0, %1 \n"
5724 + " beqz %0, 1b \n"
5725 +#ifdef CONFIG_PAX_REFCOUNT
5726 + "3: \n"
5727 + _ASM_EXTABLE(2b, 3b)
5728 +#endif
5729 + " .set mips0 \n"
5730 + : "=&r" (temp), "+m" (v->counter)
5731 + : "Ir" (i));
5732 + } else {
5733 + unsigned long flags;
5734 +
5735 + raw_local_irq_save(flags);
5736 + __asm__ __volatile__(
5737 +#ifdef CONFIG_PAX_REFCOUNT
5738 + /* Exception on overflow. */
5739 + "1: sub %0, %1 \n"
5740 + "2: \n"
5741 + _ASM_EXTABLE(1b, 2b)
5742 +#else
5743 + " subu %0, %1 \n"
5744 +#endif
5745 + : "+r" (v->counter) : "Ir" (i));
5746 + raw_local_irq_restore(flags);
5747 + }
5748 +}
5749 +
5750 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5751 {
5752 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5753 int temp;
5754 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5755 /*
5756 * Same as above, but return the result value
5757 */
5758 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5759 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5760 +{
5761 + int result;
5762 + int temp;
5763 +
5764 + smp_mb__before_llsc();
5765 +
5766 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5767 + __asm__ __volatile__(
5768 + " .set mips3 \n"
5769 + "1: ll %1, %2 # atomic_add_return \n"
5770 +#ifdef CONFIG_PAX_REFCOUNT
5771 + "2: add %0, %1, %3 \n"
5772 +#else
5773 + " addu %0, %1, %3 \n"
5774 +#endif
5775 + " sc %0, %2 \n"
5776 + " beqzl %0, 1b \n"
5777 +#ifdef CONFIG_PAX_REFCOUNT
5778 + " b 4f \n"
5779 + " .set noreorder \n"
5780 + "3: b 5f \n"
5781 + " move %0, %1 \n"
5782 + " .set reorder \n"
5783 + _ASM_EXTABLE(2b, 3b)
5784 +#endif
5785 + "4: addu %0, %1, %3 \n"
5786 +#ifdef CONFIG_PAX_REFCOUNT
5787 + "5: \n"
5788 +#endif
5789 + " .set mips0 \n"
5790 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5791 + : "Ir" (i));
5792 + } else if (kernel_uses_llsc) {
5793 + __asm__ __volatile__(
5794 + " .set mips3 \n"
5795 + "1: ll %1, %2 # atomic_add_return \n"
5796 +#ifdef CONFIG_PAX_REFCOUNT
5797 + "2: add %0, %1, %3 \n"
5798 +#else
5799 + " addu %0, %1, %3 \n"
5800 +#endif
5801 + " sc %0, %2 \n"
5802 + " bnez %0, 4f \n"
5803 + " b 1b \n"
5804 +#ifdef CONFIG_PAX_REFCOUNT
5805 + " .set noreorder \n"
5806 + "3: b 5f \n"
5807 + " move %0, %1 \n"
5808 + " .set reorder \n"
5809 + _ASM_EXTABLE(2b, 3b)
5810 +#endif
5811 + "4: addu %0, %1, %3 \n"
5812 +#ifdef CONFIG_PAX_REFCOUNT
5813 + "5: \n"
5814 +#endif
5815 + " .set mips0 \n"
5816 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5817 + : "Ir" (i));
5818 + } else {
5819 + unsigned long flags;
5820 +
5821 + raw_local_irq_save(flags);
5822 + __asm__ __volatile__(
5823 + " lw %0, %1 \n"
5824 +#ifdef CONFIG_PAX_REFCOUNT
5825 + /* Exception on overflow. */
5826 + "1: add %0, %2 \n"
5827 +#else
5828 + " addu %0, %2 \n"
5829 +#endif
5830 + " sw %0, %1 \n"
5831 +#ifdef CONFIG_PAX_REFCOUNT
5832 + /* Note: Dest reg is not modified on overflow */
5833 + "2: \n"
5834 + _ASM_EXTABLE(1b, 2b)
5835 +#endif
5836 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5837 + raw_local_irq_restore(flags);
5838 + }
5839 +
5840 + smp_llsc_mb();
5841 +
5842 + return result;
5843 +}
5844 +
5845 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5846 {
5847 int result;
5848
5849 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5850 return result;
5851 }
5852
5853 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5854 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5855 +{
5856 + int result;
5857 + int temp;
5858 +
5859 + smp_mb__before_llsc();
5860 +
5861 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5862 + __asm__ __volatile__(
5863 + " .set mips3 \n"
5864 + "1: ll %1, %2 # atomic_sub_return \n"
5865 +#ifdef CONFIG_PAX_REFCOUNT
5866 + "2: sub %0, %1, %3 \n"
5867 +#else
5868 + " subu %0, %1, %3 \n"
5869 +#endif
5870 + " sc %0, %2 \n"
5871 + " beqzl %0, 1b \n"
5872 +#ifdef CONFIG_PAX_REFCOUNT
5873 + " b 4f \n"
5874 + " .set noreorder \n"
5875 + "3: b 5f \n"
5876 + " move %0, %1 \n"
5877 + " .set reorder \n"
5878 + _ASM_EXTABLE(2b, 3b)
5879 +#endif
5880 + "4: subu %0, %1, %3 \n"
5881 +#ifdef CONFIG_PAX_REFCOUNT
5882 + "5: \n"
5883 +#endif
5884 + " .set mips0 \n"
5885 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5886 + : "Ir" (i), "m" (v->counter)
5887 + : "memory");
5888 + } else if (kernel_uses_llsc) {
5889 + __asm__ __volatile__(
5890 + " .set mips3 \n"
5891 + "1: ll %1, %2 # atomic_sub_return \n"
5892 +#ifdef CONFIG_PAX_REFCOUNT
5893 + "2: sub %0, %1, %3 \n"
5894 +#else
5895 + " subu %0, %1, %3 \n"
5896 +#endif
5897 + " sc %0, %2 \n"
5898 + " bnez %0, 4f \n"
5899 + " b 1b \n"
5900 +#ifdef CONFIG_PAX_REFCOUNT
5901 + " .set noreorder \n"
5902 + "3: b 5f \n"
5903 + " move %0, %1 \n"
5904 + " .set reorder \n"
5905 + _ASM_EXTABLE(2b, 3b)
5906 +#endif
5907 + "4: subu %0, %1, %3 \n"
5908 +#ifdef CONFIG_PAX_REFCOUNT
5909 + "5: \n"
5910 +#endif
5911 + " .set mips0 \n"
5912 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5913 + : "Ir" (i));
5914 + } else {
5915 + unsigned long flags;
5916 +
5917 + raw_local_irq_save(flags);
5918 + __asm__ __volatile__(
5919 + " lw %0, %1 \n"
5920 +#ifdef CONFIG_PAX_REFCOUNT
5921 + /* Exception on overflow. */
5922 + "1: sub %0, %2 \n"
5923 +#else
5924 + " subu %0, %2 \n"
5925 +#endif
5926 + " sw %0, %1 \n"
5927 +#ifdef CONFIG_PAX_REFCOUNT
5928 + /* Note: Dest reg is not modified on overflow */
5929 + "2: \n"
5930 + _ASM_EXTABLE(1b, 2b)
5931 +#endif
5932 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5933 + raw_local_irq_restore(flags);
5934 + }
5935 +
5936 + smp_llsc_mb();
5937 +
5938 + return result;
5939 +}
5940 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5941 {
5942 int result;
5943
5944 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5945 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5946 * The function returns the old value of @v minus @i.
5947 */
5948 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5949 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5950 {
5951 int result;
5952
5953 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5954 return result;
5955 }
5956
5957 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5958 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5959 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5960 +{
5961 + return cmpxchg(&v->counter, old, new);
5962 +}
5963 +
5964 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5965 + int new)
5966 +{
5967 + return cmpxchg(&(v->counter), old, new);
5968 +}
5969 +
5970 +static inline int atomic_xchg(atomic_t *v, int new)
5971 +{
5972 + return xchg(&v->counter, new);
5973 +}
5974 +
5975 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5976 +{
5977 + return xchg(&(v->counter), new);
5978 +}
5979
5980 /**
5981 * __atomic_add_unless - add unless the number is a given value
5982 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5983
5984 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5985 #define atomic_inc_return(v) atomic_add_return(1, (v))
5986 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5987 +{
5988 + return atomic_add_return_unchecked(1, v);
5989 +}
5990
5991 /*
5992 * atomic_sub_and_test - subtract value from variable and test result
5993 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5994 * other cases.
5995 */
5996 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5997 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5998 +{
5999 + return atomic_add_return_unchecked(1, v) == 0;
6000 +}
6001
6002 /*
6003 * atomic_dec_and_test - decrement by 1 and test
6004 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6005 * Atomically increments @v by 1.
6006 */
6007 #define atomic_inc(v) atomic_add(1, (v))
6008 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6009 +{
6010 + atomic_add_unchecked(1, v);
6011 +}
6012
6013 /*
6014 * atomic_dec - decrement and test
6015 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6016 * Atomically decrements @v by 1.
6017 */
6018 #define atomic_dec(v) atomic_sub(1, (v))
6019 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6020 +{
6021 + atomic_sub_unchecked(1, v);
6022 +}
6023
6024 /*
6025 * atomic_add_negative - add and test if negative
6026 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6027 * @v: pointer of type atomic64_t
6028 *
6029 */
6030 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6031 +static inline long atomic64_read(const atomic64_t *v)
6032 +{
6033 + return (*(volatile const long *) &v->counter);
6034 +}
6035 +
6036 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6037 +{
6038 + return (*(volatile const long *) &v->counter);
6039 +}
6040
6041 /*
6042 * atomic64_set - set atomic variable
6043 * @v: pointer of type atomic64_t
6044 * @i: required value
6045 */
6046 -#define atomic64_set(v, i) ((v)->counter = (i))
6047 +static inline void atomic64_set(atomic64_t *v, long i)
6048 +{
6049 + v->counter = i;
6050 +}
6051 +
6052 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6053 +{
6054 + v->counter = i;
6055 +}
6056
6057 /*
6058 * atomic64_add - add integer to atomic variable
6059 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6060 *
6061 * Atomically adds @i to @v.
6062 */
6063 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6064 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6065 +{
6066 + long temp;
6067 +
6068 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6069 + __asm__ __volatile__(
6070 + " .set mips3 \n"
6071 + "1: lld %0, %1 # atomic64_add \n"
6072 +#ifdef CONFIG_PAX_REFCOUNT
6073 + /* Exception on overflow. */
6074 + "2: dadd %0, %2 \n"
6075 +#else
6076 + " daddu %0, %2 \n"
6077 +#endif
6078 + " scd %0, %1 \n"
6079 + " beqzl %0, 1b \n"
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + "3: \n"
6082 + _ASM_EXTABLE(2b, 3b)
6083 +#endif
6084 + " .set mips0 \n"
6085 + : "=&r" (temp), "+m" (v->counter)
6086 + : "Ir" (i));
6087 + } else if (kernel_uses_llsc) {
6088 + __asm__ __volatile__(
6089 + " .set mips3 \n"
6090 + "1: lld %0, %1 # atomic64_add \n"
6091 +#ifdef CONFIG_PAX_REFCOUNT
6092 + /* Exception on overflow. */
6093 + "2: dadd %0, %2 \n"
6094 +#else
6095 + " daddu %0, %2 \n"
6096 +#endif
6097 + " scd %0, %1 \n"
6098 + " beqz %0, 1b \n"
6099 +#ifdef CONFIG_PAX_REFCOUNT
6100 + "3: \n"
6101 + _ASM_EXTABLE(2b, 3b)
6102 +#endif
6103 + " .set mips0 \n"
6104 + : "=&r" (temp), "+m" (v->counter)
6105 + : "Ir" (i));
6106 + } else {
6107 + unsigned long flags;
6108 +
6109 + raw_local_irq_save(flags);
6110 + __asm__ __volatile__(
6111 +#ifdef CONFIG_PAX_REFCOUNT
6112 + /* Exception on overflow. */
6113 + "1: dadd %0, %1 \n"
6114 + "2: \n"
6115 + _ASM_EXTABLE(1b, 2b)
6116 +#else
6117 + " daddu %0, %1 \n"
6118 +#endif
6119 + : "+r" (v->counter) : "Ir" (i));
6120 + raw_local_irq_restore(flags);
6121 + }
6122 +}
6123 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6124 {
6125 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6126 long temp;
6127 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6128 *
6129 * Atomically subtracts @i from @v.
6130 */
6131 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6132 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6133 +{
6134 + long temp;
6135 +
6136 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6137 + __asm__ __volatile__(
6138 + " .set mips3 \n"
6139 + "1: lld %0, %1 # atomic64_sub \n"
6140 +#ifdef CONFIG_PAX_REFCOUNT
6141 + /* Exception on overflow. */
6142 + "2: dsub %0, %2 \n"
6143 +#else
6144 + " dsubu %0, %2 \n"
6145 +#endif
6146 + " scd %0, %1 \n"
6147 + " beqzl %0, 1b \n"
6148 +#ifdef CONFIG_PAX_REFCOUNT
6149 + "3: \n"
6150 + _ASM_EXTABLE(2b, 3b)
6151 +#endif
6152 + " .set mips0 \n"
6153 + : "=&r" (temp), "+m" (v->counter)
6154 + : "Ir" (i));
6155 + } else if (kernel_uses_llsc) {
6156 + __asm__ __volatile__(
6157 + " .set mips3 \n"
6158 + "1: lld %0, %1 # atomic64_sub \n"
6159 +#ifdef CONFIG_PAX_REFCOUNT
6160 + /* Exception on overflow. */
6161 + "2: dsub %0, %2 \n"
6162 +#else
6163 + " dsubu %0, %2 \n"
6164 +#endif
6165 + " scd %0, %1 \n"
6166 + " beqz %0, 1b \n"
6167 +#ifdef CONFIG_PAX_REFCOUNT
6168 + "3: \n"
6169 + _ASM_EXTABLE(2b, 3b)
6170 +#endif
6171 + " .set mips0 \n"
6172 + : "=&r" (temp), "+m" (v->counter)
6173 + : "Ir" (i));
6174 + } else {
6175 + unsigned long flags;
6176 +
6177 + raw_local_irq_save(flags);
6178 + __asm__ __volatile__(
6179 +#ifdef CONFIG_PAX_REFCOUNT
6180 + /* Exception on overflow. */
6181 + "1: dsub %0, %1 \n"
6182 + "2: \n"
6183 + _ASM_EXTABLE(1b, 2b)
6184 +#else
6185 + " dsubu %0, %1 \n"
6186 +#endif
6187 + : "+r" (v->counter) : "Ir" (i));
6188 + raw_local_irq_restore(flags);
6189 + }
6190 +}
6191 +
6192 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6193 {
6194 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6195 long temp;
6196 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6197 /*
6198 * Same as above, but return the result value
6199 */
6200 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6201 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6202 +{
6203 + long result;
6204 + long temp;
6205 +
6206 + smp_mb__before_llsc();
6207 +
6208 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6209 + __asm__ __volatile__(
6210 + " .set mips3 \n"
6211 + "1: lld %1, %2 # atomic64_add_return \n"
6212 +#ifdef CONFIG_PAX_REFCOUNT
6213 + "2: dadd %0, %1, %3 \n"
6214 +#else
6215 + " daddu %0, %1, %3 \n"
6216 +#endif
6217 + " scd %0, %2 \n"
6218 + " beqzl %0, 1b \n"
6219 +#ifdef CONFIG_PAX_REFCOUNT
6220 + " b 4f \n"
6221 + " .set noreorder \n"
6222 + "3: b 5f \n"
6223 + " move %0, %1 \n"
6224 + " .set reorder \n"
6225 + _ASM_EXTABLE(2b, 3b)
6226 +#endif
6227 + "4: daddu %0, %1, %3 \n"
6228 +#ifdef CONFIG_PAX_REFCOUNT
6229 + "5: \n"
6230 +#endif
6231 + " .set mips0 \n"
6232 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6233 + : "Ir" (i));
6234 + } else if (kernel_uses_llsc) {
6235 + __asm__ __volatile__(
6236 + " .set mips3 \n"
6237 + "1: lld %1, %2 # atomic64_add_return \n"
6238 +#ifdef CONFIG_PAX_REFCOUNT
6239 + "2: dadd %0, %1, %3 \n"
6240 +#else
6241 + " daddu %0, %1, %3 \n"
6242 +#endif
6243 + " scd %0, %2 \n"
6244 + " bnez %0, 4f \n"
6245 + " b 1b \n"
6246 +#ifdef CONFIG_PAX_REFCOUNT
6247 + " .set noreorder \n"
6248 + "3: b 5f \n"
6249 + " move %0, %1 \n"
6250 + " .set reorder \n"
6251 + _ASM_EXTABLE(2b, 3b)
6252 +#endif
6253 + "4: daddu %0, %1, %3 \n"
6254 +#ifdef CONFIG_PAX_REFCOUNT
6255 + "5: \n"
6256 +#endif
6257 + " .set mips0 \n"
6258 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6259 + : "Ir" (i), "m" (v->counter)
6260 + : "memory");
6261 + } else {
6262 + unsigned long flags;
6263 +
6264 + raw_local_irq_save(flags);
6265 + __asm__ __volatile__(
6266 + " ld %0, %1 \n"
6267 +#ifdef CONFIG_PAX_REFCOUNT
6268 + /* Exception on overflow. */
6269 + "1: dadd %0, %2 \n"
6270 +#else
6271 + " daddu %0, %2 \n"
6272 +#endif
6273 + " sd %0, %1 \n"
6274 +#ifdef CONFIG_PAX_REFCOUNT
6275 + /* Note: Dest reg is not modified on overflow */
6276 + "2: \n"
6277 + _ASM_EXTABLE(1b, 2b)
6278 +#endif
6279 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6280 + raw_local_irq_restore(flags);
6281 + }
6282 +
6283 + smp_llsc_mb();
6284 +
6285 + return result;
6286 +}
6287 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6288 {
6289 long result;
6290
6291 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6292 return result;
6293 }
6294
6295 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6296 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6297 +{
6298 + long result;
6299 + long temp;
6300 +
6301 + smp_mb__before_llsc();
6302 +
6303 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6304 + long temp;
6305 +
6306 + __asm__ __volatile__(
6307 + " .set mips3 \n"
6308 + "1: lld %1, %2 # atomic64_sub_return \n"
6309 +#ifdef CONFIG_PAX_REFCOUNT
6310 + "2: dsub %0, %1, %3 \n"
6311 +#else
6312 + " dsubu %0, %1, %3 \n"
6313 +#endif
6314 + " scd %0, %2 \n"
6315 + " beqzl %0, 1b \n"
6316 +#ifdef CONFIG_PAX_REFCOUNT
6317 + " b 4f \n"
6318 + " .set noreorder \n"
6319 + "3: b 5f \n"
6320 + " move %0, %1 \n"
6321 + " .set reorder \n"
6322 + _ASM_EXTABLE(2b, 3b)
6323 +#endif
6324 + "4: dsubu %0, %1, %3 \n"
6325 +#ifdef CONFIG_PAX_REFCOUNT
6326 + "5: \n"
6327 +#endif
6328 + " .set mips0 \n"
6329 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6330 + : "Ir" (i), "m" (v->counter)
6331 + : "memory");
6332 + } else if (kernel_uses_llsc) {
6333 + __asm__ __volatile__(
6334 + " .set mips3 \n"
6335 + "1: lld %1, %2 # atomic64_sub_return \n"
6336 +#ifdef CONFIG_PAX_REFCOUNT
6337 + "2: dsub %0, %1, %3 \n"
6338 +#else
6339 + " dsubu %0, %1, %3 \n"
6340 +#endif
6341 + " scd %0, %2 \n"
6342 + " bnez %0, 4f \n"
6343 + " b 1b \n"
6344 +#ifdef CONFIG_PAX_REFCOUNT
6345 + " .set noreorder \n"
6346 + "3: b 5f \n"
6347 + " move %0, %1 \n"
6348 + " .set reorder \n"
6349 + _ASM_EXTABLE(2b, 3b)
6350 +#endif
6351 + "4: dsubu %0, %1, %3 \n"
6352 +#ifdef CONFIG_PAX_REFCOUNT
6353 + "5: \n"
6354 +#endif
6355 + " .set mips0 \n"
6356 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6357 + : "Ir" (i), "m" (v->counter)
6358 + : "memory");
6359 + } else {
6360 + unsigned long flags;
6361 +
6362 + raw_local_irq_save(flags);
6363 + __asm__ __volatile__(
6364 + " ld %0, %1 \n"
6365 +#ifdef CONFIG_PAX_REFCOUNT
6366 + /* Exception on overflow. */
6367 + "1: dsub %0, %2 \n"
6368 +#else
6369 + " dsubu %0, %2 \n"
6370 +#endif
6371 + " sd %0, %1 \n"
6372 +#ifdef CONFIG_PAX_REFCOUNT
6373 + /* Note: Dest reg is not modified on overflow */
6374 + "2: \n"
6375 + _ASM_EXTABLE(1b, 2b)
6376 +#endif
6377 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6378 + raw_local_irq_restore(flags);
6379 + }
6380 +
6381 + smp_llsc_mb();
6382 +
6383 + return result;
6384 +}
6385 +
6386 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6387 {
6388 long result;
6389
6390 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6391 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6392 * The function returns the old value of @v minus @i.
6393 */
6394 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6395 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6396 {
6397 long result;
6398
6399 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6400 return result;
6401 }
6402
6403 -#define atomic64_cmpxchg(v, o, n) \
6404 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6405 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6406 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6407 +{
6408 + return cmpxchg(&v->counter, old, new);
6409 +}
6410 +
6411 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6412 + long new)
6413 +{
6414 + return cmpxchg(&(v->counter), old, new);
6415 +}
6416 +
6417 +static inline long atomic64_xchg(atomic64_t *v, long new)
6418 +{
6419 + return xchg(&v->counter, new);
6420 +}
6421 +
6422 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6423 +{
6424 + return xchg(&(v->counter), new);
6425 +}
6426
6427 /**
6428 * atomic64_add_unless - add unless the number is a given value
6429 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6430
6431 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6432 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6433 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6434
6435 /*
6436 * atomic64_sub_and_test - subtract value from variable and test result
6437 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6438 * other cases.
6439 */
6440 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6441 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6442
6443 /*
6444 * atomic64_dec_and_test - decrement by 1 and test
6445 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6446 * Atomically increments @v by 1.
6447 */
6448 #define atomic64_inc(v) atomic64_add(1, (v))
6449 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6450
6451 /*
6452 * atomic64_dec - decrement and test
6453 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6454 * Atomically decrements @v by 1.
6455 */
6456 #define atomic64_dec(v) atomic64_sub(1, (v))
6457 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6458
6459 /*
6460 * atomic64_add_negative - add and test if negative
6461 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6462 index b4db69f..8f3b093 100644
6463 --- a/arch/mips/include/asm/cache.h
6464 +++ b/arch/mips/include/asm/cache.h
6465 @@ -9,10 +9,11 @@
6466 #ifndef _ASM_CACHE_H
6467 #define _ASM_CACHE_H
6468
6469 +#include <linux/const.h>
6470 #include <kmalloc.h>
6471
6472 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6473 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6474 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6475
6476 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6477 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6478 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6479 index d414405..6bb4ba2 100644
6480 --- a/arch/mips/include/asm/elf.h
6481 +++ b/arch/mips/include/asm/elf.h
6482 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6483 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6484 #endif
6485
6486 +#ifdef CONFIG_PAX_ASLR
6487 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6488 +
6489 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6490 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6491 +#endif
6492 +
6493 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6494 struct linux_binprm;
6495 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6496 int uses_interp);
6497
6498 -struct mm_struct;
6499 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6500 -#define arch_randomize_brk arch_randomize_brk
6501 -
6502 #endif /* _ASM_ELF_H */
6503 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6504 index c1f6afa..38cc6e9 100644
6505 --- a/arch/mips/include/asm/exec.h
6506 +++ b/arch/mips/include/asm/exec.h
6507 @@ -12,6 +12,6 @@
6508 #ifndef _ASM_EXEC_H
6509 #define _ASM_EXEC_H
6510
6511 -extern unsigned long arch_align_stack(unsigned long sp);
6512 +#define arch_align_stack(x) ((x) & ~0xfUL)
6513
6514 #endif /* _ASM_EXEC_H */
6515 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6516 index 9e8ef59..1139d6b 100644
6517 --- a/arch/mips/include/asm/hw_irq.h
6518 +++ b/arch/mips/include/asm/hw_irq.h
6519 @@ -10,7 +10,7 @@
6520
6521 #include <linux/atomic.h>
6522
6523 -extern atomic_t irq_err_count;
6524 +extern atomic_unchecked_t irq_err_count;
6525
6526 /*
6527 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6528 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6529 index d44622c..64990d2 100644
6530 --- a/arch/mips/include/asm/local.h
6531 +++ b/arch/mips/include/asm/local.h
6532 @@ -12,15 +12,25 @@ typedef struct
6533 atomic_long_t a;
6534 } local_t;
6535
6536 +typedef struct {
6537 + atomic_long_unchecked_t a;
6538 +} local_unchecked_t;
6539 +
6540 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6541
6542 #define local_read(l) atomic_long_read(&(l)->a)
6543 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6544 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6545 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6546
6547 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6548 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6549 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6550 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6551 #define local_inc(l) atomic_long_inc(&(l)->a)
6552 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6553 #define local_dec(l) atomic_long_dec(&(l)->a)
6554 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6555
6556 /*
6557 * Same as above, but return the result value
6558 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6559 return result;
6560 }
6561
6562 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6563 +{
6564 + unsigned long result;
6565 +
6566 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6567 + unsigned long temp;
6568 +
6569 + __asm__ __volatile__(
6570 + " .set mips3 \n"
6571 + "1:" __LL "%1, %2 # local_add_return \n"
6572 + " addu %0, %1, %3 \n"
6573 + __SC "%0, %2 \n"
6574 + " beqzl %0, 1b \n"
6575 + " addu %0, %1, %3 \n"
6576 + " .set mips0 \n"
6577 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6578 + : "Ir" (i), "m" (l->a.counter)
6579 + : "memory");
6580 + } else if (kernel_uses_llsc) {
6581 + unsigned long temp;
6582 +
6583 + __asm__ __volatile__(
6584 + " .set mips3 \n"
6585 + "1:" __LL "%1, %2 # local_add_return \n"
6586 + " addu %0, %1, %3 \n"
6587 + __SC "%0, %2 \n"
6588 + " beqz %0, 1b \n"
6589 + " addu %0, %1, %3 \n"
6590 + " .set mips0 \n"
6591 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6592 + : "Ir" (i), "m" (l->a.counter)
6593 + : "memory");
6594 + } else {
6595 + unsigned long flags;
6596 +
6597 + local_irq_save(flags);
6598 + result = l->a.counter;
6599 + result += i;
6600 + l->a.counter = result;
6601 + local_irq_restore(flags);
6602 + }
6603 +
6604 + return result;
6605 +}
6606 +
6607 static __inline__ long local_sub_return(long i, local_t * l)
6608 {
6609 unsigned long result;
6610 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6611
6612 #define local_cmpxchg(l, o, n) \
6613 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6614 +#define local_cmpxchg_unchecked(l, o, n) \
6615 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6616 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6617
6618 /**
6619 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6620 index 5e08bcc..cfedefc 100644
6621 --- a/arch/mips/include/asm/page.h
6622 +++ b/arch/mips/include/asm/page.h
6623 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6624 #ifdef CONFIG_CPU_MIPS32
6625 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6626 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6627 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6628 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6629 #else
6630 typedef struct { unsigned long long pte; } pte_t;
6631 #define pte_val(x) ((x).pte)
6632 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6633 index b336037..5b874cc 100644
6634 --- a/arch/mips/include/asm/pgalloc.h
6635 +++ b/arch/mips/include/asm/pgalloc.h
6636 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6637 {
6638 set_pud(pud, __pud((unsigned long)pmd));
6639 }
6640 +
6641 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6642 +{
6643 + pud_populate(mm, pud, pmd);
6644 +}
6645 #endif
6646
6647 /*
6648 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6649 index 008324d..f67c239 100644
6650 --- a/arch/mips/include/asm/pgtable.h
6651 +++ b/arch/mips/include/asm/pgtable.h
6652 @@ -20,6 +20,9 @@
6653 #include <asm/io.h>
6654 #include <asm/pgtable-bits.h>
6655
6656 +#define ktla_ktva(addr) (addr)
6657 +#define ktva_ktla(addr) (addr)
6658 +
6659 struct mm_struct;
6660 struct vm_area_struct;
6661
6662 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6663 index 25da651..ae2a259 100644
6664 --- a/arch/mips/include/asm/smtc_proc.h
6665 +++ b/arch/mips/include/asm/smtc_proc.h
6666 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6667
6668 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6669
6670 -extern atomic_t smtc_fpu_recoveries;
6671 +extern atomic_unchecked_t smtc_fpu_recoveries;
6672
6673 #endif /* __ASM_SMTC_PROC_H */
6674 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6675 index 24846f9..61c49f0 100644
6676 --- a/arch/mips/include/asm/thread_info.h
6677 +++ b/arch/mips/include/asm/thread_info.h
6678 @@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6679 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6680 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6681 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6682 +/* li takes a 32bit immediate */
6683 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6684 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6685
6686 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6687 @@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6688 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6689 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6690 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6691 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6692
6693 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6694 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6695 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6696
6697 /* work to do in syscall_trace_leave() */
6698 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6699 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6700 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6701
6702 /* work to do on interrupt/exception return */
6703 #define _TIF_WORK_MASK \
6704 @@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6705 /* work to do on any return to u-space */
6706 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6707 _TIF_WORK_SYSCALL_EXIT | \
6708 - _TIF_SYSCALL_TRACEPOINT)
6709 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6710
6711 /*
6712 * We stash processor id into a COP0 register to retrieve it fast
6713 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6714 index f3fa375..3af6637 100644
6715 --- a/arch/mips/include/asm/uaccess.h
6716 +++ b/arch/mips/include/asm/uaccess.h
6717 @@ -128,6 +128,7 @@ extern u64 __ua_limit;
6718 __ok == 0; \
6719 })
6720
6721 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6722 #define access_ok(type, addr, size) \
6723 likely(__access_ok((addr), (size), __access_mask))
6724
6725 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6726 index 1188e00..41cf144 100644
6727 --- a/arch/mips/kernel/binfmt_elfn32.c
6728 +++ b/arch/mips/kernel/binfmt_elfn32.c
6729 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6730 #undef ELF_ET_DYN_BASE
6731 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6732
6733 +#ifdef CONFIG_PAX_ASLR
6734 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6735 +
6736 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6737 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6738 +#endif
6739 +
6740 #include <asm/processor.h>
6741 #include <linux/module.h>
6742 #include <linux/elfcore.h>
6743 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6744 index 7faf5f2..f3d3cf4 100644
6745 --- a/arch/mips/kernel/binfmt_elfo32.c
6746 +++ b/arch/mips/kernel/binfmt_elfo32.c
6747 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6748 #undef ELF_ET_DYN_BASE
6749 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6750
6751 +#ifdef CONFIG_PAX_ASLR
6752 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6753 +
6754 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6755 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6756 +#endif
6757 +
6758 #include <asm/processor.h>
6759
6760 /*
6761 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6762 index 2b91fe8..fe4f6b4 100644
6763 --- a/arch/mips/kernel/i8259.c
6764 +++ b/arch/mips/kernel/i8259.c
6765 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6766 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6767 spurious_irq_mask |= irqmask;
6768 }
6769 - atomic_inc(&irq_err_count);
6770 + atomic_inc_unchecked(&irq_err_count);
6771 /*
6772 * Theoretically we do not have to handle this IRQ,
6773 * but in Linux this does not cause problems and is
6774 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6775 index 44a1f79..2bd6aa3 100644
6776 --- a/arch/mips/kernel/irq-gt641xx.c
6777 +++ b/arch/mips/kernel/irq-gt641xx.c
6778 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6779 }
6780 }
6781
6782 - atomic_inc(&irq_err_count);
6783 + atomic_inc_unchecked(&irq_err_count);
6784 }
6785
6786 void __init gt641xx_irq_init(void)
6787 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6788 index d1fea7a..45602ea 100644
6789 --- a/arch/mips/kernel/irq.c
6790 +++ b/arch/mips/kernel/irq.c
6791 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6792 printk("unexpected IRQ # %d\n", irq);
6793 }
6794
6795 -atomic_t irq_err_count;
6796 +atomic_unchecked_t irq_err_count;
6797
6798 int arch_show_interrupts(struct seq_file *p, int prec)
6799 {
6800 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6801 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6802 return 0;
6803 }
6804
6805 asmlinkage void spurious_interrupt(void)
6806 {
6807 - atomic_inc(&irq_err_count);
6808 + atomic_inc_unchecked(&irq_err_count);
6809 }
6810
6811 void __init init_IRQ(void)
6812 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6813 index 6ae540e..b7396dc 100644
6814 --- a/arch/mips/kernel/process.c
6815 +++ b/arch/mips/kernel/process.c
6816 @@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6817 out:
6818 return pc;
6819 }
6820 -
6821 -/*
6822 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6823 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6824 - */
6825 -unsigned long arch_align_stack(unsigned long sp)
6826 -{
6827 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6828 - sp -= get_random_int() & ~PAGE_MASK;
6829 -
6830 - return sp & ALMASK;
6831 -}
6832 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6833 index 7da9b76..21578be 100644
6834 --- a/arch/mips/kernel/ptrace.c
6835 +++ b/arch/mips/kernel/ptrace.c
6836 @@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6837 return ret;
6838 }
6839
6840 +#ifdef CONFIG_GRKERNSEC_SETXID
6841 +extern void gr_delayed_cred_worker(void);
6842 +#endif
6843 +
6844 /*
6845 * Notification of system call entry/exit
6846 * - triggered by current->work.syscall_trace
6847 @@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6848 tracehook_report_syscall_entry(regs))
6849 ret = -1;
6850
6851 +#ifdef CONFIG_GRKERNSEC_SETXID
6852 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6853 + gr_delayed_cred_worker();
6854 +#endif
6855 +
6856 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6857 trace_sys_enter(regs, regs->regs[2]);
6858
6859 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6860 index 07fc524..b9d7f28 100644
6861 --- a/arch/mips/kernel/reset.c
6862 +++ b/arch/mips/kernel/reset.c
6863 @@ -13,6 +13,7 @@
6864 #include <linux/reboot.h>
6865
6866 #include <asm/reboot.h>
6867 +#include <asm/bug.h>
6868
6869 /*
6870 * Urgs ... Too many MIPS machines to handle this in a generic way.
6871 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6872 {
6873 if (_machine_restart)
6874 _machine_restart(command);
6875 + BUG();
6876 }
6877
6878 void machine_halt(void)
6879 {
6880 if (_machine_halt)
6881 _machine_halt();
6882 + BUG();
6883 }
6884
6885 void machine_power_off(void)
6886 {
6887 if (pm_power_off)
6888 pm_power_off();
6889 + BUG();
6890 }
6891 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6892 index c10aa84..9ec2e60 100644
6893 --- a/arch/mips/kernel/smtc-proc.c
6894 +++ b/arch/mips/kernel/smtc-proc.c
6895 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6896
6897 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6898
6899 -atomic_t smtc_fpu_recoveries;
6900 +atomic_unchecked_t smtc_fpu_recoveries;
6901
6902 static int smtc_proc_show(struct seq_file *m, void *v)
6903 {
6904 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6905 for(i = 0; i < NR_CPUS; i++)
6906 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6907 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6908 - atomic_read(&smtc_fpu_recoveries));
6909 + atomic_read_unchecked(&smtc_fpu_recoveries));
6910 return 0;
6911 }
6912
6913 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6914 smtc_cpu_stats[i].selfipis = 0;
6915 }
6916
6917 - atomic_set(&smtc_fpu_recoveries, 0);
6918 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6919
6920 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6921 }
6922 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6923 index dfc1b91..11a2c07 100644
6924 --- a/arch/mips/kernel/smtc.c
6925 +++ b/arch/mips/kernel/smtc.c
6926 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6927 }
6928 smtc_ipi_qdump();
6929 printk("%d Recoveries of \"stolen\" FPU\n",
6930 - atomic_read(&smtc_fpu_recoveries));
6931 + atomic_read_unchecked(&smtc_fpu_recoveries));
6932 }
6933
6934
6935 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6936 index c24ad5f..9983ab2 100644
6937 --- a/arch/mips/kernel/sync-r4k.c
6938 +++ b/arch/mips/kernel/sync-r4k.c
6939 @@ -20,8 +20,8 @@
6940 #include <asm/mipsregs.h>
6941
6942 static atomic_t count_start_flag = ATOMIC_INIT(0);
6943 -static atomic_t count_count_start = ATOMIC_INIT(0);
6944 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6945 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6946 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6947 static atomic_t count_reference = ATOMIC_INIT(0);
6948
6949 #define COUNTON 100
6950 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6951
6952 for (i = 0; i < NR_LOOPS; i++) {
6953 /* slaves loop on '!= 2' */
6954 - while (atomic_read(&count_count_start) != 1)
6955 + while (atomic_read_unchecked(&count_count_start) != 1)
6956 mb();
6957 - atomic_set(&count_count_stop, 0);
6958 + atomic_set_unchecked(&count_count_stop, 0);
6959 smp_wmb();
6960
6961 /* this lets the slaves write their count register */
6962 - atomic_inc(&count_count_start);
6963 + atomic_inc_unchecked(&count_count_start);
6964
6965 /*
6966 * Everyone initialises count in the last loop:
6967 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6968 /*
6969 * Wait for all slaves to leave the synchronization point:
6970 */
6971 - while (atomic_read(&count_count_stop) != 1)
6972 + while (atomic_read_unchecked(&count_count_stop) != 1)
6973 mb();
6974 - atomic_set(&count_count_start, 0);
6975 + atomic_set_unchecked(&count_count_start, 0);
6976 smp_wmb();
6977 - atomic_inc(&count_count_stop);
6978 + atomic_inc_unchecked(&count_count_stop);
6979 }
6980 /* Arrange for an interrupt in a short while */
6981 write_c0_compare(read_c0_count() + COUNTON);
6982 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
6983 initcount = atomic_read(&count_reference);
6984
6985 for (i = 0; i < NR_LOOPS; i++) {
6986 - atomic_inc(&count_count_start);
6987 - while (atomic_read(&count_count_start) != 2)
6988 + atomic_inc_unchecked(&count_count_start);
6989 + while (atomic_read_unchecked(&count_count_start) != 2)
6990 mb();
6991
6992 /*
6993 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
6994 if (i == NR_LOOPS-1)
6995 write_c0_count(initcount);
6996
6997 - atomic_inc(&count_count_stop);
6998 - while (atomic_read(&count_count_stop) != 2)
6999 + atomic_inc_unchecked(&count_count_stop);
7000 + while (atomic_read_unchecked(&count_count_stop) != 2)
7001 mb();
7002 }
7003 /* Arrange for an interrupt in a short while */
7004 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7005 index e0b4996..6b43ce7 100644
7006 --- a/arch/mips/kernel/traps.c
7007 +++ b/arch/mips/kernel/traps.c
7008 @@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7009 siginfo_t info;
7010
7011 prev_state = exception_enter();
7012 - die_if_kernel("Integer overflow", regs);
7013 + if (unlikely(!user_mode(regs))) {
7014 +
7015 +#ifdef CONFIG_PAX_REFCOUNT
7016 + if (fixup_exception(regs)) {
7017 + pax_report_refcount_overflow(regs);
7018 + exception_exit(prev_state);
7019 + return;
7020 + }
7021 +#endif
7022 +
7023 + die("Integer overflow", regs);
7024 + }
7025
7026 info.si_code = FPE_INTOVF;
7027 info.si_signo = SIGFPE;
7028 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7029 index becc42b..9e43d4b 100644
7030 --- a/arch/mips/mm/fault.c
7031 +++ b/arch/mips/mm/fault.c
7032 @@ -28,6 +28,23 @@
7033 #include <asm/highmem.h> /* For VMALLOC_END */
7034 #include <linux/kdebug.h>
7035
7036 +#ifdef CONFIG_PAX_PAGEEXEC
7037 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7038 +{
7039 + unsigned long i;
7040 +
7041 + printk(KERN_ERR "PAX: bytes at PC: ");
7042 + for (i = 0; i < 5; i++) {
7043 + unsigned int c;
7044 + if (get_user(c, (unsigned int *)pc+i))
7045 + printk(KERN_CONT "???????? ");
7046 + else
7047 + printk(KERN_CONT "%08x ", c);
7048 + }
7049 + printk("\n");
7050 +}
7051 +#endif
7052 +
7053 /*
7054 * This routine handles page faults. It determines the address,
7055 * and the problem, and then passes it off to one of the appropriate
7056 @@ -199,6 +216,14 @@ bad_area:
7057 bad_area_nosemaphore:
7058 /* User mode accesses just cause a SIGSEGV */
7059 if (user_mode(regs)) {
7060 +
7061 +#ifdef CONFIG_PAX_PAGEEXEC
7062 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7063 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7064 + do_group_exit(SIGKILL);
7065 + }
7066 +#endif
7067 +
7068 tsk->thread.cp0_badvaddr = address;
7069 tsk->thread.error_code = write;
7070 #if 0
7071 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7072 index f1baadd..5472dca 100644
7073 --- a/arch/mips/mm/mmap.c
7074 +++ b/arch/mips/mm/mmap.c
7075 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7076 struct vm_area_struct *vma;
7077 unsigned long addr = addr0;
7078 int do_color_align;
7079 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7080 struct vm_unmapped_area_info info;
7081
7082 if (unlikely(len > TASK_SIZE))
7083 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7084 do_color_align = 1;
7085
7086 /* requesting a specific address */
7087 +
7088 +#ifdef CONFIG_PAX_RANDMMAP
7089 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7090 +#endif
7091 +
7092 if (addr) {
7093 if (do_color_align)
7094 addr = COLOUR_ALIGN(addr, pgoff);
7095 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7096 addr = PAGE_ALIGN(addr);
7097
7098 vma = find_vma(mm, addr);
7099 - if (TASK_SIZE - len >= addr &&
7100 - (!vma || addr + len <= vma->vm_start))
7101 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7102 return addr;
7103 }
7104
7105 info.length = len;
7106 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7107 info.align_offset = pgoff << PAGE_SHIFT;
7108 + info.threadstack_offset = offset;
7109
7110 if (dir == DOWN) {
7111 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7112 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7113 {
7114 unsigned long random_factor = 0UL;
7115
7116 +#ifdef CONFIG_PAX_RANDMMAP
7117 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7118 +#endif
7119 +
7120 if (current->flags & PF_RANDOMIZE) {
7121 random_factor = get_random_int();
7122 random_factor = random_factor << PAGE_SHIFT;
7123 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7124
7125 if (mmap_is_legacy()) {
7126 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7127 +
7128 +#ifdef CONFIG_PAX_RANDMMAP
7129 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7130 + mm->mmap_base += mm->delta_mmap;
7131 +#endif
7132 +
7133 mm->get_unmapped_area = arch_get_unmapped_area;
7134 } else {
7135 mm->mmap_base = mmap_base(random_factor);
7136 +
7137 +#ifdef CONFIG_PAX_RANDMMAP
7138 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7139 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7140 +#endif
7141 +
7142 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7143 }
7144 }
7145
7146 -static inline unsigned long brk_rnd(void)
7147 -{
7148 - unsigned long rnd = get_random_int();
7149 -
7150 - rnd = rnd << PAGE_SHIFT;
7151 - /* 8MB for 32bit, 256MB for 64bit */
7152 - if (TASK_IS_32BIT_ADDR)
7153 - rnd = rnd & 0x7ffffful;
7154 - else
7155 - rnd = rnd & 0xffffffful;
7156 -
7157 - return rnd;
7158 -}
7159 -
7160 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7161 -{
7162 - unsigned long base = mm->brk;
7163 - unsigned long ret;
7164 -
7165 - ret = PAGE_ALIGN(base + brk_rnd());
7166 -
7167 - if (ret < mm->brk)
7168 - return mm->brk;
7169 -
7170 - return ret;
7171 -}
7172 -
7173 int __virt_addr_valid(const volatile void *kaddr)
7174 {
7175 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7176 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7177 index 59cccd9..f39ac2f 100644
7178 --- a/arch/mips/pci/pci-octeon.c
7179 +++ b/arch/mips/pci/pci-octeon.c
7180 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7181
7182
7183 static struct pci_ops octeon_pci_ops = {
7184 - octeon_read_config,
7185 - octeon_write_config,
7186 + .read = octeon_read_config,
7187 + .write = octeon_write_config,
7188 };
7189
7190 static struct resource octeon_pci_mem_resource = {
7191 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7192 index 5e36c33..eb4a17b 100644
7193 --- a/arch/mips/pci/pcie-octeon.c
7194 +++ b/arch/mips/pci/pcie-octeon.c
7195 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7196 }
7197
7198 static struct pci_ops octeon_pcie0_ops = {
7199 - octeon_pcie0_read_config,
7200 - octeon_pcie0_write_config,
7201 + .read = octeon_pcie0_read_config,
7202 + .write = octeon_pcie0_write_config,
7203 };
7204
7205 static struct resource octeon_pcie0_mem_resource = {
7206 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7207 };
7208
7209 static struct pci_ops octeon_pcie1_ops = {
7210 - octeon_pcie1_read_config,
7211 - octeon_pcie1_write_config,
7212 + .read = octeon_pcie1_read_config,
7213 + .write = octeon_pcie1_write_config,
7214 };
7215
7216 static struct resource octeon_pcie1_mem_resource = {
7217 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7218 };
7219
7220 static struct pci_ops octeon_dummy_ops = {
7221 - octeon_dummy_read_config,
7222 - octeon_dummy_write_config,
7223 + .read = octeon_dummy_read_config,
7224 + .write = octeon_dummy_write_config,
7225 };
7226
7227 static struct resource octeon_dummy_mem_resource = {
7228 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7229 index a2358b4..7cead4f 100644
7230 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7231 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7232 @@ -187,9 +187,9 @@ void
7233 cont_nmi_dump(void)
7234 {
7235 #ifndef REAL_NMI_SIGNAL
7236 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7237 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7238
7239 - atomic_inc(&nmied_cpus);
7240 + atomic_inc_unchecked(&nmied_cpus);
7241 #endif
7242 /*
7243 * Only allow 1 cpu to proceed
7244 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7245 udelay(10000);
7246 }
7247 #else
7248 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7249 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7250 #endif
7251
7252 /*
7253 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7254 index a046b30..6799527 100644
7255 --- a/arch/mips/sni/rm200.c
7256 +++ b/arch/mips/sni/rm200.c
7257 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7258 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7259 spurious_irq_mask |= irqmask;
7260 }
7261 - atomic_inc(&irq_err_count);
7262 + atomic_inc_unchecked(&irq_err_count);
7263 /*
7264 * Theoretically we do not have to handle this IRQ,
7265 * but in Linux this does not cause problems and is
7266 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7267 index 41e873b..34d33a7 100644
7268 --- a/arch/mips/vr41xx/common/icu.c
7269 +++ b/arch/mips/vr41xx/common/icu.c
7270 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7271
7272 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7273
7274 - atomic_inc(&irq_err_count);
7275 + atomic_inc_unchecked(&irq_err_count);
7276
7277 return -1;
7278 }
7279 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7280 index ae0e4ee..e8f0692 100644
7281 --- a/arch/mips/vr41xx/common/irq.c
7282 +++ b/arch/mips/vr41xx/common/irq.c
7283 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7284 irq_cascade_t *cascade;
7285
7286 if (irq >= NR_IRQS) {
7287 - atomic_inc(&irq_err_count);
7288 + atomic_inc_unchecked(&irq_err_count);
7289 return;
7290 }
7291
7292 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7293 ret = cascade->get_irq(irq);
7294 irq = ret;
7295 if (ret < 0)
7296 - atomic_inc(&irq_err_count);
7297 + atomic_inc_unchecked(&irq_err_count);
7298 else
7299 irq_dispatch(irq);
7300 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7301 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7302 index 967d144..db12197 100644
7303 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7304 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7305 @@ -11,12 +11,14 @@
7306 #ifndef _ASM_PROC_CACHE_H
7307 #define _ASM_PROC_CACHE_H
7308
7309 +#include <linux/const.h>
7310 +
7311 /* L1 cache */
7312
7313 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7314 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7315 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7316 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7317 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7318 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7319
7320 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7321 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7322 index bcb5df2..84fabd2 100644
7323 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7324 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7325 @@ -16,13 +16,15 @@
7326 #ifndef _ASM_PROC_CACHE_H
7327 #define _ASM_PROC_CACHE_H
7328
7329 +#include <linux/const.h>
7330 +
7331 /*
7332 * L1 cache
7333 */
7334 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7335 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7336 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7337 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7338 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7339 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7340
7341 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7342 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7343 index 4ce7a01..449202a 100644
7344 --- a/arch/openrisc/include/asm/cache.h
7345 +++ b/arch/openrisc/include/asm/cache.h
7346 @@ -19,11 +19,13 @@
7347 #ifndef __ASM_OPENRISC_CACHE_H
7348 #define __ASM_OPENRISC_CACHE_H
7349
7350 +#include <linux/const.h>
7351 +
7352 /* FIXME: How can we replace these with values from the CPU...
7353 * they shouldn't be hard-coded!
7354 */
7355
7356 -#define L1_CACHE_BYTES 16
7357 #define L1_CACHE_SHIFT 4
7358 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7359
7360 #endif /* __ASM_OPENRISC_CACHE_H */
7361 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7362 index 472886c..00e7df9 100644
7363 --- a/arch/parisc/include/asm/atomic.h
7364 +++ b/arch/parisc/include/asm/atomic.h
7365 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7366 return dec;
7367 }
7368
7369 +#define atomic64_read_unchecked(v) atomic64_read(v)
7370 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7371 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7372 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7373 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7374 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7375 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7376 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7377 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7378 +
7379 #endif /* !CONFIG_64BIT */
7380
7381
7382 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7383 index 47f11c7..3420df2 100644
7384 --- a/arch/parisc/include/asm/cache.h
7385 +++ b/arch/parisc/include/asm/cache.h
7386 @@ -5,6 +5,7 @@
7387 #ifndef __ARCH_PARISC_CACHE_H
7388 #define __ARCH_PARISC_CACHE_H
7389
7390 +#include <linux/const.h>
7391
7392 /*
7393 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7394 @@ -15,13 +16,13 @@
7395 * just ruin performance.
7396 */
7397 #ifdef CONFIG_PA20
7398 -#define L1_CACHE_BYTES 64
7399 #define L1_CACHE_SHIFT 6
7400 #else
7401 -#define L1_CACHE_BYTES 32
7402 #define L1_CACHE_SHIFT 5
7403 #endif
7404
7405 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7406 +
7407 #ifndef __ASSEMBLY__
7408
7409 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7410 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7411 index 3391d06..c23a2cc 100644
7412 --- a/arch/parisc/include/asm/elf.h
7413 +++ b/arch/parisc/include/asm/elf.h
7414 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7415
7416 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7417
7418 +#ifdef CONFIG_PAX_ASLR
7419 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7420 +
7421 +#define PAX_DELTA_MMAP_LEN 16
7422 +#define PAX_DELTA_STACK_LEN 16
7423 +#endif
7424 +
7425 /* This yields a mask that user programs can use to figure out what
7426 instruction set this CPU supports. This could be done in user space,
7427 but it's not easy, and we've already done it here. */
7428 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7429 index f213f5b..0af3e8e 100644
7430 --- a/arch/parisc/include/asm/pgalloc.h
7431 +++ b/arch/parisc/include/asm/pgalloc.h
7432 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7433 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7434 }
7435
7436 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7437 +{
7438 + pgd_populate(mm, pgd, pmd);
7439 +}
7440 +
7441 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7442 {
7443 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7444 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7445 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7446 #define pmd_free(mm, x) do { } while (0)
7447 #define pgd_populate(mm, pmd, pte) BUG()
7448 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7449
7450 #endif
7451
7452 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7453 index 22b89d1..ce34230 100644
7454 --- a/arch/parisc/include/asm/pgtable.h
7455 +++ b/arch/parisc/include/asm/pgtable.h
7456 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7457 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7458 #define PAGE_COPY PAGE_EXECREAD
7459 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7460 +
7461 +#ifdef CONFIG_PAX_PAGEEXEC
7462 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7463 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7464 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7465 +#else
7466 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7467 +# define PAGE_COPY_NOEXEC PAGE_COPY
7468 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7469 +#endif
7470 +
7471 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7472 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7473 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7474 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7475 index 4006964..fcb3cc2 100644
7476 --- a/arch/parisc/include/asm/uaccess.h
7477 +++ b/arch/parisc/include/asm/uaccess.h
7478 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7479 const void __user *from,
7480 unsigned long n)
7481 {
7482 - int sz = __compiletime_object_size(to);
7483 + size_t sz = __compiletime_object_size(to);
7484 int ret = -EFAULT;
7485
7486 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7487 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7488 ret = __copy_from_user(to, from, n);
7489 else
7490 copy_from_user_overflow();
7491 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7492 index 50dfafc..b9fc230 100644
7493 --- a/arch/parisc/kernel/module.c
7494 +++ b/arch/parisc/kernel/module.c
7495 @@ -98,16 +98,38 @@
7496
7497 /* three functions to determine where in the module core
7498 * or init pieces the location is */
7499 +static inline int in_init_rx(struct module *me, void *loc)
7500 +{
7501 + return (loc >= me->module_init_rx &&
7502 + loc < (me->module_init_rx + me->init_size_rx));
7503 +}
7504 +
7505 +static inline int in_init_rw(struct module *me, void *loc)
7506 +{
7507 + return (loc >= me->module_init_rw &&
7508 + loc < (me->module_init_rw + me->init_size_rw));
7509 +}
7510 +
7511 static inline int in_init(struct module *me, void *loc)
7512 {
7513 - return (loc >= me->module_init &&
7514 - loc <= (me->module_init + me->init_size));
7515 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7516 +}
7517 +
7518 +static inline int in_core_rx(struct module *me, void *loc)
7519 +{
7520 + return (loc >= me->module_core_rx &&
7521 + loc < (me->module_core_rx + me->core_size_rx));
7522 +}
7523 +
7524 +static inline int in_core_rw(struct module *me, void *loc)
7525 +{
7526 + return (loc >= me->module_core_rw &&
7527 + loc < (me->module_core_rw + me->core_size_rw));
7528 }
7529
7530 static inline int in_core(struct module *me, void *loc)
7531 {
7532 - return (loc >= me->module_core &&
7533 - loc <= (me->module_core + me->core_size));
7534 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7535 }
7536
7537 static inline int in_local(struct module *me, void *loc)
7538 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7539 }
7540
7541 /* align things a bit */
7542 - me->core_size = ALIGN(me->core_size, 16);
7543 - me->arch.got_offset = me->core_size;
7544 - me->core_size += gots * sizeof(struct got_entry);
7545 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7546 + me->arch.got_offset = me->core_size_rw;
7547 + me->core_size_rw += gots * sizeof(struct got_entry);
7548
7549 - me->core_size = ALIGN(me->core_size, 16);
7550 - me->arch.fdesc_offset = me->core_size;
7551 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7552 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7553 + me->arch.fdesc_offset = me->core_size_rw;
7554 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7555
7556 me->arch.got_max = gots;
7557 me->arch.fdesc_max = fdescs;
7558 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7559
7560 BUG_ON(value == 0);
7561
7562 - got = me->module_core + me->arch.got_offset;
7563 + got = me->module_core_rw + me->arch.got_offset;
7564 for (i = 0; got[i].addr; i++)
7565 if (got[i].addr == value)
7566 goto out;
7567 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7568 #ifdef CONFIG_64BIT
7569 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7570 {
7571 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7572 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7573
7574 if (!value) {
7575 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7576 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7577
7578 /* Create new one */
7579 fdesc->addr = value;
7580 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7581 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7582 return (Elf_Addr)fdesc;
7583 }
7584 #endif /* CONFIG_64BIT */
7585 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7586
7587 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7588 end = table + sechdrs[me->arch.unwind_section].sh_size;
7589 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7590 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7591
7592 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7593 me->arch.unwind_section, table, end, gp);
7594 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7595 index b7cadc4..bf4a32d 100644
7596 --- a/arch/parisc/kernel/sys_parisc.c
7597 +++ b/arch/parisc/kernel/sys_parisc.c
7598 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7599 unsigned long task_size = TASK_SIZE;
7600 int do_color_align, last_mmap;
7601 struct vm_unmapped_area_info info;
7602 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7603
7604 if (len > task_size)
7605 return -ENOMEM;
7606 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7607 goto found_addr;
7608 }
7609
7610 +#ifdef CONFIG_PAX_RANDMMAP
7611 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7612 +#endif
7613 +
7614 if (addr) {
7615 if (do_color_align && last_mmap)
7616 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7617 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7618 info.high_limit = mmap_upper_limit();
7619 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7620 info.align_offset = shared_align_offset(last_mmap, pgoff);
7621 + info.threadstack_offset = offset;
7622 addr = vm_unmapped_area(&info);
7623
7624 found_addr:
7625 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7626 unsigned long addr = addr0;
7627 int do_color_align, last_mmap;
7628 struct vm_unmapped_area_info info;
7629 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7630
7631 #ifdef CONFIG_64BIT
7632 /* This should only ever run for 32-bit processes. */
7633 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7634 }
7635
7636 /* requesting a specific address */
7637 +#ifdef CONFIG_PAX_RANDMMAP
7638 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7639 +#endif
7640 +
7641 if (addr) {
7642 if (do_color_align && last_mmap)
7643 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7644 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7645 info.high_limit = mm->mmap_base;
7646 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7647 info.align_offset = shared_align_offset(last_mmap, pgoff);
7648 + info.threadstack_offset = offset;
7649 addr = vm_unmapped_area(&info);
7650 if (!(addr & ~PAGE_MASK))
7651 goto found_addr;
7652 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7653 mm->mmap_legacy_base = mmap_legacy_base();
7654 mm->mmap_base = mmap_upper_limit();
7655
7656 +#ifdef CONFIG_PAX_RANDMMAP
7657 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7658 + mm->mmap_legacy_base += mm->delta_mmap;
7659 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7660 + }
7661 +#endif
7662 +
7663 if (mmap_is_legacy()) {
7664 mm->mmap_base = mm->mmap_legacy_base;
7665 mm->get_unmapped_area = arch_get_unmapped_area;
7666 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7667 index 1cd1d0c..44ec918 100644
7668 --- a/arch/parisc/kernel/traps.c
7669 +++ b/arch/parisc/kernel/traps.c
7670 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7671
7672 down_read(&current->mm->mmap_sem);
7673 vma = find_vma(current->mm,regs->iaoq[0]);
7674 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7675 - && (vma->vm_flags & VM_EXEC)) {
7676 -
7677 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7678 fault_address = regs->iaoq[0];
7679 fault_space = regs->iasq[0];
7680
7681 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7682 index 9d08c71..e2b4d20 100644
7683 --- a/arch/parisc/mm/fault.c
7684 +++ b/arch/parisc/mm/fault.c
7685 @@ -15,6 +15,7 @@
7686 #include <linux/sched.h>
7687 #include <linux/interrupt.h>
7688 #include <linux/module.h>
7689 +#include <linux/unistd.h>
7690
7691 #include <asm/uaccess.h>
7692 #include <asm/traps.h>
7693 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7694 static unsigned long
7695 parisc_acctyp(unsigned long code, unsigned int inst)
7696 {
7697 - if (code == 6 || code == 16)
7698 + if (code == 6 || code == 7 || code == 16)
7699 return VM_EXEC;
7700
7701 switch (inst & 0xf0000000) {
7702 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7703 }
7704 #endif
7705
7706 +#ifdef CONFIG_PAX_PAGEEXEC
7707 +/*
7708 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7709 + *
7710 + * returns 1 when task should be killed
7711 + * 2 when rt_sigreturn trampoline was detected
7712 + * 3 when unpatched PLT trampoline was detected
7713 + */
7714 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7715 +{
7716 +
7717 +#ifdef CONFIG_PAX_EMUPLT
7718 + int err;
7719 +
7720 + do { /* PaX: unpatched PLT emulation */
7721 + unsigned int bl, depwi;
7722 +
7723 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7724 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7725 +
7726 + if (err)
7727 + break;
7728 +
7729 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7730 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7731 +
7732 + err = get_user(ldw, (unsigned int *)addr);
7733 + err |= get_user(bv, (unsigned int *)(addr+4));
7734 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7735 +
7736 + if (err)
7737 + break;
7738 +
7739 + if (ldw == 0x0E801096U &&
7740 + bv == 0xEAC0C000U &&
7741 + ldw2 == 0x0E881095U)
7742 + {
7743 + unsigned int resolver, map;
7744 +
7745 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7746 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7747 + if (err)
7748 + break;
7749 +
7750 + regs->gr[20] = instruction_pointer(regs)+8;
7751 + regs->gr[21] = map;
7752 + regs->gr[22] = resolver;
7753 + regs->iaoq[0] = resolver | 3UL;
7754 + regs->iaoq[1] = regs->iaoq[0] + 4;
7755 + return 3;
7756 + }
7757 + }
7758 + } while (0);
7759 +#endif
7760 +
7761 +#ifdef CONFIG_PAX_EMUTRAMP
7762 +
7763 +#ifndef CONFIG_PAX_EMUSIGRT
7764 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7765 + return 1;
7766 +#endif
7767 +
7768 + do { /* PaX: rt_sigreturn emulation */
7769 + unsigned int ldi1, ldi2, bel, nop;
7770 +
7771 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7772 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7773 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7774 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7775 +
7776 + if (err)
7777 + break;
7778 +
7779 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7780 + ldi2 == 0x3414015AU &&
7781 + bel == 0xE4008200U &&
7782 + nop == 0x08000240U)
7783 + {
7784 + regs->gr[25] = (ldi1 & 2) >> 1;
7785 + regs->gr[20] = __NR_rt_sigreturn;
7786 + regs->gr[31] = regs->iaoq[1] + 16;
7787 + regs->sr[0] = regs->iasq[1];
7788 + regs->iaoq[0] = 0x100UL;
7789 + regs->iaoq[1] = regs->iaoq[0] + 4;
7790 + regs->iasq[0] = regs->sr[2];
7791 + regs->iasq[1] = regs->sr[2];
7792 + return 2;
7793 + }
7794 + } while (0);
7795 +#endif
7796 +
7797 + return 1;
7798 +}
7799 +
7800 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7801 +{
7802 + unsigned long i;
7803 +
7804 + printk(KERN_ERR "PAX: bytes at PC: ");
7805 + for (i = 0; i < 5; i++) {
7806 + unsigned int c;
7807 + if (get_user(c, (unsigned int *)pc+i))
7808 + printk(KERN_CONT "???????? ");
7809 + else
7810 + printk(KERN_CONT "%08x ", c);
7811 + }
7812 + printk("\n");
7813 +}
7814 +#endif
7815 +
7816 int fixup_exception(struct pt_regs *regs)
7817 {
7818 const struct exception_table_entry *fix;
7819 @@ -210,8 +321,33 @@ retry:
7820
7821 good_area:
7822
7823 - if ((vma->vm_flags & acc_type) != acc_type)
7824 + if ((vma->vm_flags & acc_type) != acc_type) {
7825 +
7826 +#ifdef CONFIG_PAX_PAGEEXEC
7827 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7828 + (address & ~3UL) == instruction_pointer(regs))
7829 + {
7830 + up_read(&mm->mmap_sem);
7831 + switch (pax_handle_fetch_fault(regs)) {
7832 +
7833 +#ifdef CONFIG_PAX_EMUPLT
7834 + case 3:
7835 + return;
7836 +#endif
7837 +
7838 +#ifdef CONFIG_PAX_EMUTRAMP
7839 + case 2:
7840 + return;
7841 +#endif
7842 +
7843 + }
7844 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7845 + do_group_exit(SIGKILL);
7846 + }
7847 +#endif
7848 +
7849 goto bad_area;
7850 + }
7851
7852 /*
7853 * If for any reason at all we couldn't handle the fault, make
7854 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7855 index 957bf34..3430cc8 100644
7856 --- a/arch/powerpc/Kconfig
7857 +++ b/arch/powerpc/Kconfig
7858 @@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7859 config KEXEC
7860 bool "kexec system call"
7861 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7862 + depends on !GRKERNSEC_KMEM
7863 help
7864 kexec is a system call that implements the ability to shutdown your
7865 current kernel, and to start another kernel. It is like a reboot
7866 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7867 index e3b1d41..8e81edf 100644
7868 --- a/arch/powerpc/include/asm/atomic.h
7869 +++ b/arch/powerpc/include/asm/atomic.h
7870 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7871 return t1;
7872 }
7873
7874 +#define atomic64_read_unchecked(v) atomic64_read(v)
7875 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7876 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7877 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7878 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7879 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7880 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7881 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7882 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7883 +
7884 #endif /* __powerpc64__ */
7885
7886 #endif /* __KERNEL__ */
7887 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7888 index ed0afc1..0332825 100644
7889 --- a/arch/powerpc/include/asm/cache.h
7890 +++ b/arch/powerpc/include/asm/cache.h
7891 @@ -3,6 +3,7 @@
7892
7893 #ifdef __KERNEL__
7894
7895 +#include <linux/const.h>
7896
7897 /* bytes per L1 cache line */
7898 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7899 @@ -22,7 +23,7 @@
7900 #define L1_CACHE_SHIFT 7
7901 #endif
7902
7903 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7904 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7905
7906 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7907
7908 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7909 index 935b5e7..7001d2d 100644
7910 --- a/arch/powerpc/include/asm/elf.h
7911 +++ b/arch/powerpc/include/asm/elf.h
7912 @@ -28,8 +28,19 @@
7913 the loader. We need to make sure that it is out of the way of the program
7914 that it will "exec", and that there is sufficient room for the brk. */
7915
7916 -extern unsigned long randomize_et_dyn(unsigned long base);
7917 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7918 +#define ELF_ET_DYN_BASE (0x20000000)
7919 +
7920 +#ifdef CONFIG_PAX_ASLR
7921 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7922 +
7923 +#ifdef __powerpc64__
7924 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7925 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7926 +#else
7927 +#define PAX_DELTA_MMAP_LEN 15
7928 +#define PAX_DELTA_STACK_LEN 15
7929 +#endif
7930 +#endif
7931
7932 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7933
7934 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7935 (0x7ff >> (PAGE_SHIFT - 12)) : \
7936 (0x3ffff >> (PAGE_SHIFT - 12)))
7937
7938 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7939 -#define arch_randomize_brk arch_randomize_brk
7940 -
7941 -
7942 #ifdef CONFIG_SPU_BASE
7943 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7944 #define NT_SPU 1
7945 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7946 index 8196e9c..d83a9f3 100644
7947 --- a/arch/powerpc/include/asm/exec.h
7948 +++ b/arch/powerpc/include/asm/exec.h
7949 @@ -4,6 +4,6 @@
7950 #ifndef _ASM_POWERPC_EXEC_H
7951 #define _ASM_POWERPC_EXEC_H
7952
7953 -extern unsigned long arch_align_stack(unsigned long sp);
7954 +#define arch_align_stack(x) ((x) & ~0xfUL)
7955
7956 #endif /* _ASM_POWERPC_EXEC_H */
7957 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7958 index 5acabbd..7ea14fa 100644
7959 --- a/arch/powerpc/include/asm/kmap_types.h
7960 +++ b/arch/powerpc/include/asm/kmap_types.h
7961 @@ -10,7 +10,7 @@
7962 * 2 of the License, or (at your option) any later version.
7963 */
7964
7965 -#define KM_TYPE_NR 16
7966 +#define KM_TYPE_NR 17
7967
7968 #endif /* __KERNEL__ */
7969 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7970 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
7971 index b8da913..60b608a 100644
7972 --- a/arch/powerpc/include/asm/local.h
7973 +++ b/arch/powerpc/include/asm/local.h
7974 @@ -9,15 +9,26 @@ typedef struct
7975 atomic_long_t a;
7976 } local_t;
7977
7978 +typedef struct
7979 +{
7980 + atomic_long_unchecked_t a;
7981 +} local_unchecked_t;
7982 +
7983 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7984
7985 #define local_read(l) atomic_long_read(&(l)->a)
7986 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7987 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
7988 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
7989
7990 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
7991 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
7992 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
7993 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
7994 #define local_inc(l) atomic_long_inc(&(l)->a)
7995 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7996 #define local_dec(l) atomic_long_dec(&(l)->a)
7997 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7998
7999 static __inline__ long local_add_return(long a, local_t *l)
8000 {
8001 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8002
8003 return t;
8004 }
8005 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8006
8007 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8008
8009 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8010
8011 return t;
8012 }
8013 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8014
8015 static __inline__ long local_inc_return(local_t *l)
8016 {
8017 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8018
8019 #define local_cmpxchg(l, o, n) \
8020 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8021 +#define local_cmpxchg_unchecked(l, o, n) \
8022 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8023 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8024
8025 /**
8026 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8027 index 8565c25..2865190 100644
8028 --- a/arch/powerpc/include/asm/mman.h
8029 +++ b/arch/powerpc/include/asm/mman.h
8030 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8031 }
8032 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8033
8034 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8035 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8036 {
8037 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8038 }
8039 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8040 index 32e4e21..62afb12 100644
8041 --- a/arch/powerpc/include/asm/page.h
8042 +++ b/arch/powerpc/include/asm/page.h
8043 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8044 * and needs to be executable. This means the whole heap ends
8045 * up being executable.
8046 */
8047 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8048 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8049 +#define VM_DATA_DEFAULT_FLAGS32 \
8050 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8051 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8052
8053 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8054 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8055 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8056 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8057 #endif
8058
8059 +#define ktla_ktva(addr) (addr)
8060 +#define ktva_ktla(addr) (addr)
8061 +
8062 #ifndef CONFIG_PPC_BOOK3S_64
8063 /*
8064 * Use the top bit of the higher-level page table entries to indicate whether
8065 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8066 index 88693ce..ac6f9ab 100644
8067 --- a/arch/powerpc/include/asm/page_64.h
8068 +++ b/arch/powerpc/include/asm/page_64.h
8069 @@ -153,15 +153,18 @@ do { \
8070 * stack by default, so in the absence of a PT_GNU_STACK program header
8071 * we turn execute permission off.
8072 */
8073 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8074 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8075 +#define VM_STACK_DEFAULT_FLAGS32 \
8076 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8077 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8078
8079 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8080 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8081
8082 +#ifndef CONFIG_PAX_PAGEEXEC
8083 #define VM_STACK_DEFAULT_FLAGS \
8084 (is_32bit_task() ? \
8085 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8086 +#endif
8087
8088 #include <asm-generic/getorder.h>
8089
8090 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8091 index 4b0be20..c15a27d 100644
8092 --- a/arch/powerpc/include/asm/pgalloc-64.h
8093 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8094 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8095 #ifndef CONFIG_PPC_64K_PAGES
8096
8097 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8098 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8099
8100 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8101 {
8102 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8103 pud_set(pud, (unsigned long)pmd);
8104 }
8105
8106 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8107 +{
8108 + pud_populate(mm, pud, pmd);
8109 +}
8110 +
8111 #define pmd_populate(mm, pmd, pte_page) \
8112 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8113 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8114 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8115 #endif
8116
8117 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8118 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8119
8120 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8121 pte_t *pte)
8122 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8123 index 3ebb188..e17dddf 100644
8124 --- a/arch/powerpc/include/asm/pgtable.h
8125 +++ b/arch/powerpc/include/asm/pgtable.h
8126 @@ -2,6 +2,7 @@
8127 #define _ASM_POWERPC_PGTABLE_H
8128 #ifdef __KERNEL__
8129
8130 +#include <linux/const.h>
8131 #ifndef __ASSEMBLY__
8132 #include <linux/mmdebug.h>
8133 #include <asm/processor.h> /* For TASK_SIZE */
8134 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8135 index 4aad413..85d86bf 100644
8136 --- a/arch/powerpc/include/asm/pte-hash32.h
8137 +++ b/arch/powerpc/include/asm/pte-hash32.h
8138 @@ -21,6 +21,7 @@
8139 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8140 #define _PAGE_USER 0x004 /* usermode access allowed */
8141 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8142 +#define _PAGE_EXEC _PAGE_GUARDED
8143 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8144 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8145 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8146 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8147 index 90c06ec..3517221 100644
8148 --- a/arch/powerpc/include/asm/reg.h
8149 +++ b/arch/powerpc/include/asm/reg.h
8150 @@ -248,6 +248,7 @@
8151 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8152 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8153 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8154 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8155 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8156 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8157 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8158 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8159 index 084e080..9415a3d 100644
8160 --- a/arch/powerpc/include/asm/smp.h
8161 +++ b/arch/powerpc/include/asm/smp.h
8162 @@ -51,7 +51,7 @@ struct smp_ops_t {
8163 int (*cpu_disable)(void);
8164 void (*cpu_die)(unsigned int nr);
8165 int (*cpu_bootable)(unsigned int nr);
8166 -};
8167 +} __no_const;
8168
8169 extern void smp_send_debugger_break(void);
8170 extern void start_secondary_resume(void);
8171 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8172 index b034ecd..af7e31f 100644
8173 --- a/arch/powerpc/include/asm/thread_info.h
8174 +++ b/arch/powerpc/include/asm/thread_info.h
8175 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8176 #if defined(CONFIG_PPC64)
8177 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8178 #endif
8179 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8180 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8181
8182 /* as above, but as bit values */
8183 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8184 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8185 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8186 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8187 #define _TIF_NOHZ (1<<TIF_NOHZ)
8188 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8189 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8190 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8191 - _TIF_NOHZ)
8192 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8193
8194 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8195 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8196 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8197 index 9485b43..3bd3c16 100644
8198 --- a/arch/powerpc/include/asm/uaccess.h
8199 +++ b/arch/powerpc/include/asm/uaccess.h
8200 @@ -58,6 +58,7 @@
8201
8202 #endif
8203
8204 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8205 #define access_ok(type, addr, size) \
8206 (__chk_user_ptr(addr), \
8207 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8208 @@ -318,52 +319,6 @@ do { \
8209 extern unsigned long __copy_tofrom_user(void __user *to,
8210 const void __user *from, unsigned long size);
8211
8212 -#ifndef __powerpc64__
8213 -
8214 -static inline unsigned long copy_from_user(void *to,
8215 - const void __user *from, unsigned long n)
8216 -{
8217 - unsigned long over;
8218 -
8219 - if (access_ok(VERIFY_READ, from, n))
8220 - return __copy_tofrom_user((__force void __user *)to, from, n);
8221 - if ((unsigned long)from < TASK_SIZE) {
8222 - over = (unsigned long)from + n - TASK_SIZE;
8223 - return __copy_tofrom_user((__force void __user *)to, from,
8224 - n - over) + over;
8225 - }
8226 - return n;
8227 -}
8228 -
8229 -static inline unsigned long copy_to_user(void __user *to,
8230 - const void *from, unsigned long n)
8231 -{
8232 - unsigned long over;
8233 -
8234 - if (access_ok(VERIFY_WRITE, to, n))
8235 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8236 - if ((unsigned long)to < TASK_SIZE) {
8237 - over = (unsigned long)to + n - TASK_SIZE;
8238 - return __copy_tofrom_user(to, (__force void __user *)from,
8239 - n - over) + over;
8240 - }
8241 - return n;
8242 -}
8243 -
8244 -#else /* __powerpc64__ */
8245 -
8246 -#define __copy_in_user(to, from, size) \
8247 - __copy_tofrom_user((to), (from), (size))
8248 -
8249 -extern unsigned long copy_from_user(void *to, const void __user *from,
8250 - unsigned long n);
8251 -extern unsigned long copy_to_user(void __user *to, const void *from,
8252 - unsigned long n);
8253 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8254 - unsigned long n);
8255 -
8256 -#endif /* __powerpc64__ */
8257 -
8258 static inline unsigned long __copy_from_user_inatomic(void *to,
8259 const void __user *from, unsigned long n)
8260 {
8261 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8262 if (ret == 0)
8263 return 0;
8264 }
8265 +
8266 + if (!__builtin_constant_p(n))
8267 + check_object_size(to, n, false);
8268 +
8269 return __copy_tofrom_user((__force void __user *)to, from, n);
8270 }
8271
8272 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8273 if (ret == 0)
8274 return 0;
8275 }
8276 +
8277 + if (!__builtin_constant_p(n))
8278 + check_object_size(from, n, true);
8279 +
8280 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8281 }
8282
8283 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8284 return __copy_to_user_inatomic(to, from, size);
8285 }
8286
8287 +#ifndef __powerpc64__
8288 +
8289 +static inline unsigned long __must_check copy_from_user(void *to,
8290 + const void __user *from, unsigned long n)
8291 +{
8292 + unsigned long over;
8293 +
8294 + if ((long)n < 0)
8295 + return n;
8296 +
8297 + if (access_ok(VERIFY_READ, from, n)) {
8298 + if (!__builtin_constant_p(n))
8299 + check_object_size(to, n, false);
8300 + return __copy_tofrom_user((__force void __user *)to, from, n);
8301 + }
8302 + if ((unsigned long)from < TASK_SIZE) {
8303 + over = (unsigned long)from + n - TASK_SIZE;
8304 + if (!__builtin_constant_p(n - over))
8305 + check_object_size(to, n - over, false);
8306 + return __copy_tofrom_user((__force void __user *)to, from,
8307 + n - over) + over;
8308 + }
8309 + return n;
8310 +}
8311 +
8312 +static inline unsigned long __must_check copy_to_user(void __user *to,
8313 + const void *from, unsigned long n)
8314 +{
8315 + unsigned long over;
8316 +
8317 + if ((long)n < 0)
8318 + return n;
8319 +
8320 + if (access_ok(VERIFY_WRITE, to, n)) {
8321 + if (!__builtin_constant_p(n))
8322 + check_object_size(from, n, true);
8323 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8324 + }
8325 + if ((unsigned long)to < TASK_SIZE) {
8326 + over = (unsigned long)to + n - TASK_SIZE;
8327 + if (!__builtin_constant_p(n))
8328 + check_object_size(from, n - over, true);
8329 + return __copy_tofrom_user(to, (__force void __user *)from,
8330 + n - over) + over;
8331 + }
8332 + return n;
8333 +}
8334 +
8335 +#else /* __powerpc64__ */
8336 +
8337 +#define __copy_in_user(to, from, size) \
8338 + __copy_tofrom_user((to), (from), (size))
8339 +
8340 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8341 +{
8342 + if ((long)n < 0 || n > INT_MAX)
8343 + return n;
8344 +
8345 + if (!__builtin_constant_p(n))
8346 + check_object_size(to, n, false);
8347 +
8348 + if (likely(access_ok(VERIFY_READ, from, n)))
8349 + n = __copy_from_user(to, from, n);
8350 + else
8351 + memset(to, 0, n);
8352 + return n;
8353 +}
8354 +
8355 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8356 +{
8357 + if ((long)n < 0 || n > INT_MAX)
8358 + return n;
8359 +
8360 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8361 + if (!__builtin_constant_p(n))
8362 + check_object_size(from, n, true);
8363 + n = __copy_to_user(to, from, n);
8364 + }
8365 + return n;
8366 +}
8367 +
8368 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8369 + unsigned long n);
8370 +
8371 +#endif /* __powerpc64__ */
8372 +
8373 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8374
8375 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8376 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8377 index fcc9a89..07be2bb 100644
8378 --- a/arch/powerpc/kernel/Makefile
8379 +++ b/arch/powerpc/kernel/Makefile
8380 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8381 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8382 endif
8383
8384 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8385 +
8386 obj-y := cputable.o ptrace.o syscalls.o \
8387 irq.o align.o signal_32.o pmc.o vdso.o \
8388 process.o systbl.o idle.o \
8389 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8390 index 063b65d..7a26e9d 100644
8391 --- a/arch/powerpc/kernel/exceptions-64e.S
8392 +++ b/arch/powerpc/kernel/exceptions-64e.S
8393 @@ -771,6 +771,7 @@ storage_fault_common:
8394 std r14,_DAR(r1)
8395 std r15,_DSISR(r1)
8396 addi r3,r1,STACK_FRAME_OVERHEAD
8397 + bl .save_nvgprs
8398 mr r4,r14
8399 mr r5,r15
8400 ld r14,PACA_EXGEN+EX_R14(r13)
8401 @@ -779,8 +780,7 @@ storage_fault_common:
8402 cmpdi r3,0
8403 bne- 1f
8404 b .ret_from_except_lite
8405 -1: bl .save_nvgprs
8406 - mr r5,r3
8407 +1: mr r5,r3
8408 addi r3,r1,STACK_FRAME_OVERHEAD
8409 ld r4,_DAR(r1)
8410 bl .bad_page_fault
8411 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8412 index 38d5073..f00af8d 100644
8413 --- a/arch/powerpc/kernel/exceptions-64s.S
8414 +++ b/arch/powerpc/kernel/exceptions-64s.S
8415 @@ -1584,10 +1584,10 @@ handle_page_fault:
8416 11: ld r4,_DAR(r1)
8417 ld r5,_DSISR(r1)
8418 addi r3,r1,STACK_FRAME_OVERHEAD
8419 + bl .save_nvgprs
8420 bl .do_page_fault
8421 cmpdi r3,0
8422 beq+ 12f
8423 - bl .save_nvgprs
8424 mr r5,r3
8425 addi r3,r1,STACK_FRAME_OVERHEAD
8426 lwz r4,_DAR(r1)
8427 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8428 index 6cff040..74ac5d1 100644
8429 --- a/arch/powerpc/kernel/module_32.c
8430 +++ b/arch/powerpc/kernel/module_32.c
8431 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8432 me->arch.core_plt_section = i;
8433 }
8434 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8435 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8436 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8437 return -ENOEXEC;
8438 }
8439
8440 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8441
8442 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8443 /* Init, or core PLT? */
8444 - if (location >= mod->module_core
8445 - && location < mod->module_core + mod->core_size)
8446 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8447 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8448 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8449 - else
8450 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8451 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8452 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8453 + else {
8454 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8455 + return ~0UL;
8456 + }
8457
8458 /* Find this entry, or if that fails, the next avail. entry */
8459 while (entry->jump[0]) {
8460 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8461 }
8462 #ifdef CONFIG_DYNAMIC_FTRACE
8463 module->arch.tramp =
8464 - do_plt_call(module->module_core,
8465 + do_plt_call(module->module_core_rx,
8466 (unsigned long)ftrace_caller,
8467 sechdrs, module);
8468 #endif
8469 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8470 index af064d2..ce56147 100644
8471 --- a/arch/powerpc/kernel/process.c
8472 +++ b/arch/powerpc/kernel/process.c
8473 @@ -1009,8 +1009,8 @@ void show_regs(struct pt_regs * regs)
8474 * Lookup NIP late so we have the best change of getting the
8475 * above info out without failing
8476 */
8477 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8478 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8479 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8480 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8481 #endif
8482 show_stack(current, (unsigned long *) regs->gpr[1]);
8483 if (!user_mode(regs))
8484 @@ -1532,10 +1532,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8485 newsp = stack[0];
8486 ip = stack[STACK_FRAME_LR_SAVE];
8487 if (!firstframe || ip != lr) {
8488 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8489 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8490 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8491 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8492 - printk(" (%pS)",
8493 + printk(" (%pA)",
8494 (void *)current->ret_stack[curr_frame].ret);
8495 curr_frame--;
8496 }
8497 @@ -1555,7 +1555,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8498 struct pt_regs *regs = (struct pt_regs *)
8499 (sp + STACK_FRAME_OVERHEAD);
8500 lr = regs->link;
8501 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8502 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8503 regs->trap, (void *)regs->nip, (void *)lr);
8504 firstframe = 1;
8505 }
8506 @@ -1591,58 +1591,3 @@ void notrace __ppc64_runlatch_off(void)
8507 mtspr(SPRN_CTRLT, ctrl);
8508 }
8509 #endif /* CONFIG_PPC64 */
8510 -
8511 -unsigned long arch_align_stack(unsigned long sp)
8512 -{
8513 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8514 - sp -= get_random_int() & ~PAGE_MASK;
8515 - return sp & ~0xf;
8516 -}
8517 -
8518 -static inline unsigned long brk_rnd(void)
8519 -{
8520 - unsigned long rnd = 0;
8521 -
8522 - /* 8MB for 32bit, 1GB for 64bit */
8523 - if (is_32bit_task())
8524 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8525 - else
8526 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8527 -
8528 - return rnd << PAGE_SHIFT;
8529 -}
8530 -
8531 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8532 -{
8533 - unsigned long base = mm->brk;
8534 - unsigned long ret;
8535 -
8536 -#ifdef CONFIG_PPC_STD_MMU_64
8537 - /*
8538 - * If we are using 1TB segments and we are allowed to randomise
8539 - * the heap, we can put it above 1TB so it is backed by a 1TB
8540 - * segment. Otherwise the heap will be in the bottom 1TB
8541 - * which always uses 256MB segments and this may result in a
8542 - * performance penalty.
8543 - */
8544 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8545 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8546 -#endif
8547 -
8548 - ret = PAGE_ALIGN(base + brk_rnd());
8549 -
8550 - if (ret < mm->brk)
8551 - return mm->brk;
8552 -
8553 - return ret;
8554 -}
8555 -
8556 -unsigned long randomize_et_dyn(unsigned long base)
8557 -{
8558 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8559 -
8560 - if (ret < base)
8561 - return base;
8562 -
8563 - return ret;
8564 -}
8565 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8566 index 2e3d2bf..35df241 100644
8567 --- a/arch/powerpc/kernel/ptrace.c
8568 +++ b/arch/powerpc/kernel/ptrace.c
8569 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8570 return ret;
8571 }
8572
8573 +#ifdef CONFIG_GRKERNSEC_SETXID
8574 +extern void gr_delayed_cred_worker(void);
8575 +#endif
8576 +
8577 /*
8578 * We must return the syscall number to actually look up in the table.
8579 * This can be -1L to skip running any syscall at all.
8580 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8581
8582 secure_computing_strict(regs->gpr[0]);
8583
8584 +#ifdef CONFIG_GRKERNSEC_SETXID
8585 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8586 + gr_delayed_cred_worker();
8587 +#endif
8588 +
8589 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8590 tracehook_report_syscall_entry(regs))
8591 /*
8592 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8593 {
8594 int step;
8595
8596 +#ifdef CONFIG_GRKERNSEC_SETXID
8597 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8598 + gr_delayed_cred_worker();
8599 +#endif
8600 +
8601 audit_syscall_exit(regs);
8602
8603 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8604 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8605 index a67e00a..f71d8c7 100644
8606 --- a/arch/powerpc/kernel/signal_32.c
8607 +++ b/arch/powerpc/kernel/signal_32.c
8608 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8609 /* Save user registers on the stack */
8610 frame = &rt_sf->uc.uc_mcontext;
8611 addr = frame;
8612 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8613 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8614 sigret = 0;
8615 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8616 } else {
8617 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8618 index 8d253c2..405b337 100644
8619 --- a/arch/powerpc/kernel/signal_64.c
8620 +++ b/arch/powerpc/kernel/signal_64.c
8621 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8622 current->thread.fp_state.fpscr = 0;
8623
8624 /* Set up to return from userspace. */
8625 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8626 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8627 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8628 } else {
8629 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8630 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8631 index 33cd7a0..d615344 100644
8632 --- a/arch/powerpc/kernel/traps.c
8633 +++ b/arch/powerpc/kernel/traps.c
8634 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8635 return flags;
8636 }
8637
8638 +extern void gr_handle_kernel_exploit(void);
8639 +
8640 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8641 int signr)
8642 {
8643 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8644 panic("Fatal exception in interrupt");
8645 if (panic_on_oops)
8646 panic("Fatal exception");
8647 +
8648 + gr_handle_kernel_exploit();
8649 +
8650 do_exit(signr);
8651 }
8652
8653 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8654 index 094e45c..d82b848 100644
8655 --- a/arch/powerpc/kernel/vdso.c
8656 +++ b/arch/powerpc/kernel/vdso.c
8657 @@ -35,6 +35,7 @@
8658 #include <asm/vdso.h>
8659 #include <asm/vdso_datapage.h>
8660 #include <asm/setup.h>
8661 +#include <asm/mman.h>
8662
8663 #undef DEBUG
8664
8665 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8666 vdso_base = VDSO32_MBASE;
8667 #endif
8668
8669 - current->mm->context.vdso_base = 0;
8670 + current->mm->context.vdso_base = ~0UL;
8671
8672 /* vDSO has a problem and was disabled, just don't "enable" it for the
8673 * process
8674 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8675 vdso_base = get_unmapped_area(NULL, vdso_base,
8676 (vdso_pages << PAGE_SHIFT) +
8677 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8678 - 0, 0);
8679 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8680 if (IS_ERR_VALUE(vdso_base)) {
8681 rc = vdso_base;
8682 goto fail_mmapsem;
8683 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8684 index 3cf541a..ab2d825 100644
8685 --- a/arch/powerpc/kvm/powerpc.c
8686 +++ b/arch/powerpc/kvm/powerpc.c
8687 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8688 }
8689 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8690
8691 -int kvm_arch_init(void *opaque)
8692 +int kvm_arch_init(const void *opaque)
8693 {
8694 return 0;
8695 }
8696 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8697 index 5eea6f3..5d10396 100644
8698 --- a/arch/powerpc/lib/usercopy_64.c
8699 +++ b/arch/powerpc/lib/usercopy_64.c
8700 @@ -9,22 +9,6 @@
8701 #include <linux/module.h>
8702 #include <asm/uaccess.h>
8703
8704 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8705 -{
8706 - if (likely(access_ok(VERIFY_READ, from, n)))
8707 - n = __copy_from_user(to, from, n);
8708 - else
8709 - memset(to, 0, n);
8710 - return n;
8711 -}
8712 -
8713 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8714 -{
8715 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8716 - n = __copy_to_user(to, from, n);
8717 - return n;
8718 -}
8719 -
8720 unsigned long copy_in_user(void __user *to, const void __user *from,
8721 unsigned long n)
8722 {
8723 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8724 return n;
8725 }
8726
8727 -EXPORT_SYMBOL(copy_from_user);
8728 -EXPORT_SYMBOL(copy_to_user);
8729 EXPORT_SYMBOL(copy_in_user);
8730
8731 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8732 index 51ab9e7..7d3c78b 100644
8733 --- a/arch/powerpc/mm/fault.c
8734 +++ b/arch/powerpc/mm/fault.c
8735 @@ -33,6 +33,10 @@
8736 #include <linux/magic.h>
8737 #include <linux/ratelimit.h>
8738 #include <linux/context_tracking.h>
8739 +#include <linux/slab.h>
8740 +#include <linux/pagemap.h>
8741 +#include <linux/compiler.h>
8742 +#include <linux/unistd.h>
8743
8744 #include <asm/firmware.h>
8745 #include <asm/page.h>
8746 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8747 }
8748 #endif
8749
8750 +#ifdef CONFIG_PAX_PAGEEXEC
8751 +/*
8752 + * PaX: decide what to do with offenders (regs->nip = fault address)
8753 + *
8754 + * returns 1 when task should be killed
8755 + */
8756 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8757 +{
8758 + return 1;
8759 +}
8760 +
8761 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8762 +{
8763 + unsigned long i;
8764 +
8765 + printk(KERN_ERR "PAX: bytes at PC: ");
8766 + for (i = 0; i < 5; i++) {
8767 + unsigned int c;
8768 + if (get_user(c, (unsigned int __user *)pc+i))
8769 + printk(KERN_CONT "???????? ");
8770 + else
8771 + printk(KERN_CONT "%08x ", c);
8772 + }
8773 + printk("\n");
8774 +}
8775 +#endif
8776 +
8777 /*
8778 * Check whether the instruction at regs->nip is a store using
8779 * an update addressing form which will update r1.
8780 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8781 * indicate errors in DSISR but can validly be set in SRR1.
8782 */
8783 if (trap == 0x400)
8784 - error_code &= 0x48200000;
8785 + error_code &= 0x58200000;
8786 else
8787 is_write = error_code & DSISR_ISSTORE;
8788 #else
8789 @@ -378,7 +409,7 @@ good_area:
8790 * "undefined". Of those that can be set, this is the only
8791 * one which seems bad.
8792 */
8793 - if (error_code & 0x10000000)
8794 + if (error_code & DSISR_GUARDED)
8795 /* Guarded storage error. */
8796 goto bad_area;
8797 #endif /* CONFIG_8xx */
8798 @@ -393,7 +424,7 @@ good_area:
8799 * processors use the same I/D cache coherency mechanism
8800 * as embedded.
8801 */
8802 - if (error_code & DSISR_PROTFAULT)
8803 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8804 goto bad_area;
8805 #endif /* CONFIG_PPC_STD_MMU */
8806
8807 @@ -483,6 +514,23 @@ bad_area:
8808 bad_area_nosemaphore:
8809 /* User mode accesses cause a SIGSEGV */
8810 if (user_mode(regs)) {
8811 +
8812 +#ifdef CONFIG_PAX_PAGEEXEC
8813 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8814 +#ifdef CONFIG_PPC_STD_MMU
8815 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8816 +#else
8817 + if (is_exec && regs->nip == address) {
8818 +#endif
8819 + switch (pax_handle_fetch_fault(regs)) {
8820 + }
8821 +
8822 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8823 + do_group_exit(SIGKILL);
8824 + }
8825 + }
8826 +#endif
8827 +
8828 _exception(SIGSEGV, regs, code, address);
8829 goto bail;
8830 }
8831 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8832 index cb8bdbe..cde4bc7 100644
8833 --- a/arch/powerpc/mm/mmap.c
8834 +++ b/arch/powerpc/mm/mmap.c
8835 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8836 return sysctl_legacy_va_layout;
8837 }
8838
8839 -static unsigned long mmap_rnd(void)
8840 +static unsigned long mmap_rnd(struct mm_struct *mm)
8841 {
8842 unsigned long rnd = 0;
8843
8844 +#ifdef CONFIG_PAX_RANDMMAP
8845 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8846 +#endif
8847 +
8848 if (current->flags & PF_RANDOMIZE) {
8849 /* 8MB for 32bit, 1GB for 64bit */
8850 if (is_32bit_task())
8851 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8852 return rnd << PAGE_SHIFT;
8853 }
8854
8855 -static inline unsigned long mmap_base(void)
8856 +static inline unsigned long mmap_base(struct mm_struct *mm)
8857 {
8858 unsigned long gap = rlimit(RLIMIT_STACK);
8859
8860 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8861 else if (gap > MAX_GAP)
8862 gap = MAX_GAP;
8863
8864 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8865 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8866 }
8867
8868 /*
8869 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8870 */
8871 if (mmap_is_legacy()) {
8872 mm->mmap_base = TASK_UNMAPPED_BASE;
8873 +
8874 +#ifdef CONFIG_PAX_RANDMMAP
8875 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8876 + mm->mmap_base += mm->delta_mmap;
8877 +#endif
8878 +
8879 mm->get_unmapped_area = arch_get_unmapped_area;
8880 } else {
8881 - mm->mmap_base = mmap_base();
8882 + mm->mmap_base = mmap_base(mm);
8883 +
8884 +#ifdef CONFIG_PAX_RANDMMAP
8885 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8886 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8887 +#endif
8888 +
8889 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8890 }
8891 }
8892 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8893 index b0c75cc..ef7fb93 100644
8894 --- a/arch/powerpc/mm/slice.c
8895 +++ b/arch/powerpc/mm/slice.c
8896 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8897 if ((mm->task_size - len) < addr)
8898 return 0;
8899 vma = find_vma(mm, addr);
8900 - return (!vma || (addr + len) <= vma->vm_start);
8901 + return check_heap_stack_gap(vma, addr, len, 0);
8902 }
8903
8904 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8905 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8906 info.align_offset = 0;
8907
8908 addr = TASK_UNMAPPED_BASE;
8909 +
8910 +#ifdef CONFIG_PAX_RANDMMAP
8911 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8912 + addr += mm->delta_mmap;
8913 +#endif
8914 +
8915 while (addr < TASK_SIZE) {
8916 info.low_limit = addr;
8917 if (!slice_scan_available(addr, available, 1, &addr))
8918 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8919 if (fixed && addr > (mm->task_size - len))
8920 return -ENOMEM;
8921
8922 +#ifdef CONFIG_PAX_RANDMMAP
8923 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8924 + addr = 0;
8925 +#endif
8926 +
8927 /* If hint, make sure it matches our alignment restrictions */
8928 if (!fixed && addr) {
8929 addr = _ALIGN_UP(addr, 1ul << pshift);
8930 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8931 index 4278acf..67fd0e6 100644
8932 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8933 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8934 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8935 }
8936
8937 static struct pci_ops scc_pciex_pci_ops = {
8938 - scc_pciex_read_config,
8939 - scc_pciex_write_config,
8940 + .read = scc_pciex_read_config,
8941 + .write = scc_pciex_write_config,
8942 };
8943
8944 static void pciex_clear_intr_all(unsigned int __iomem *base)
8945 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8946 index 9098692..3d54cd1 100644
8947 --- a/arch/powerpc/platforms/cell/spufs/file.c
8948 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8949 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8950 return VM_FAULT_NOPAGE;
8951 }
8952
8953 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8954 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8955 unsigned long address,
8956 - void *buf, int len, int write)
8957 + void *buf, size_t len, int write)
8958 {
8959 struct spu_context *ctx = vma->vm_file->private_data;
8960 unsigned long offset = address - vma->vm_start;
8961 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8962 index fa9aaf7..3f5d836 100644
8963 --- a/arch/s390/include/asm/atomic.h
8964 +++ b/arch/s390/include/asm/atomic.h
8965 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8966 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8967 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8968
8969 +#define atomic64_read_unchecked(v) atomic64_read(v)
8970 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8971 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8972 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8973 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8974 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8975 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8976 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8977 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8978 +
8979 #define smp_mb__before_atomic_dec() smp_mb()
8980 #define smp_mb__after_atomic_dec() smp_mb()
8981 #define smp_mb__before_atomic_inc() smp_mb()
8982 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8983 index 4d7ccac..d03d0ad 100644
8984 --- a/arch/s390/include/asm/cache.h
8985 +++ b/arch/s390/include/asm/cache.h
8986 @@ -9,8 +9,10 @@
8987 #ifndef __ARCH_S390_CACHE_H
8988 #define __ARCH_S390_CACHE_H
8989
8990 -#define L1_CACHE_BYTES 256
8991 +#include <linux/const.h>
8992 +
8993 #define L1_CACHE_SHIFT 8
8994 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8995 #define NET_SKB_PAD 32
8996
8997 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8998 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8999 index 78f4f87..598ce39 100644
9000 --- a/arch/s390/include/asm/elf.h
9001 +++ b/arch/s390/include/asm/elf.h
9002 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9003 the loader. We need to make sure that it is out of the way of the program
9004 that it will "exec", and that there is sufficient room for the brk. */
9005
9006 -extern unsigned long randomize_et_dyn(unsigned long base);
9007 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9008 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9009 +
9010 +#ifdef CONFIG_PAX_ASLR
9011 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9012 +
9013 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9014 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9015 +#endif
9016
9017 /* This yields a mask that user programs can use to figure out what
9018 instruction set this CPU supports. */
9019 @@ -222,9 +228,6 @@ struct linux_binprm;
9020 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9021 int arch_setup_additional_pages(struct linux_binprm *, int);
9022
9023 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9024 -#define arch_randomize_brk arch_randomize_brk
9025 -
9026 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9027
9028 #endif
9029 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9030 index c4a93d6..4d2a9b4 100644
9031 --- a/arch/s390/include/asm/exec.h
9032 +++ b/arch/s390/include/asm/exec.h
9033 @@ -7,6 +7,6 @@
9034 #ifndef __ASM_EXEC_H
9035 #define __ASM_EXEC_H
9036
9037 -extern unsigned long arch_align_stack(unsigned long sp);
9038 +#define arch_align_stack(x) ((x) & ~0xfUL)
9039
9040 #endif /* __ASM_EXEC_H */
9041 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9042 index 79330af..254cf37 100644
9043 --- a/arch/s390/include/asm/uaccess.h
9044 +++ b/arch/s390/include/asm/uaccess.h
9045 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9046 __range_ok((unsigned long)(addr), (size)); \
9047 })
9048
9049 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9050 #define access_ok(type, addr, size) __access_ok(addr, size)
9051
9052 /*
9053 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9054 copy_to_user(void __user *to, const void *from, unsigned long n)
9055 {
9056 might_fault();
9057 +
9058 + if ((long)n < 0)
9059 + return n;
9060 +
9061 return __copy_to_user(to, from, n);
9062 }
9063
9064 @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9065 static inline unsigned long __must_check
9066 __copy_from_user(void *to, const void __user *from, unsigned long n)
9067 {
9068 + if ((long)n < 0)
9069 + return n;
9070 +
9071 return uaccess.copy_from_user(n, from, to);
9072 }
9073
9074 @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9075 static inline unsigned long __must_check
9076 copy_from_user(void *to, const void __user *from, unsigned long n)
9077 {
9078 - unsigned int sz = __compiletime_object_size(to);
9079 + size_t sz = __compiletime_object_size(to);
9080
9081 might_fault();
9082 - if (unlikely(sz != -1 && sz < n)) {
9083 +
9084 + if ((long)n < 0)
9085 + return n;
9086 +
9087 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9088 copy_from_user_overflow();
9089 return n;
9090 }
9091 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9092 index b89b591..fd9609d 100644
9093 --- a/arch/s390/kernel/module.c
9094 +++ b/arch/s390/kernel/module.c
9095 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9096
9097 /* Increase core size by size of got & plt and set start
9098 offsets for got and plt. */
9099 - me->core_size = ALIGN(me->core_size, 4);
9100 - me->arch.got_offset = me->core_size;
9101 - me->core_size += me->arch.got_size;
9102 - me->arch.plt_offset = me->core_size;
9103 - me->core_size += me->arch.plt_size;
9104 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9105 + me->arch.got_offset = me->core_size_rw;
9106 + me->core_size_rw += me->arch.got_size;
9107 + me->arch.plt_offset = me->core_size_rx;
9108 + me->core_size_rx += me->arch.plt_size;
9109 return 0;
9110 }
9111
9112 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9113 if (info->got_initialized == 0) {
9114 Elf_Addr *gotent;
9115
9116 - gotent = me->module_core + me->arch.got_offset +
9117 + gotent = me->module_core_rw + me->arch.got_offset +
9118 info->got_offset;
9119 *gotent = val;
9120 info->got_initialized = 1;
9121 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9122 rc = apply_rela_bits(loc, val, 0, 64, 0);
9123 else if (r_type == R_390_GOTENT ||
9124 r_type == R_390_GOTPLTENT) {
9125 - val += (Elf_Addr) me->module_core - loc;
9126 + val += (Elf_Addr) me->module_core_rw - loc;
9127 rc = apply_rela_bits(loc, val, 1, 32, 1);
9128 }
9129 break;
9130 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9131 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9132 if (info->plt_initialized == 0) {
9133 unsigned int *ip;
9134 - ip = me->module_core + me->arch.plt_offset +
9135 + ip = me->module_core_rx + me->arch.plt_offset +
9136 info->plt_offset;
9137 #ifndef CONFIG_64BIT
9138 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9139 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9140 val - loc + 0xffffUL < 0x1ffffeUL) ||
9141 (r_type == R_390_PLT32DBL &&
9142 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9143 - val = (Elf_Addr) me->module_core +
9144 + val = (Elf_Addr) me->module_core_rx +
9145 me->arch.plt_offset +
9146 info->plt_offset;
9147 val += rela->r_addend - loc;
9148 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9149 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9150 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9151 val = val + rela->r_addend -
9152 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9153 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9154 if (r_type == R_390_GOTOFF16)
9155 rc = apply_rela_bits(loc, val, 0, 16, 0);
9156 else if (r_type == R_390_GOTOFF32)
9157 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9158 break;
9159 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9160 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9161 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9162 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9163 rela->r_addend - loc;
9164 if (r_type == R_390_GOTPC)
9165 rc = apply_rela_bits(loc, val, 1, 32, 0);
9166 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9167 index dd14532..1dfc145 100644
9168 --- a/arch/s390/kernel/process.c
9169 +++ b/arch/s390/kernel/process.c
9170 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9171 }
9172 return 0;
9173 }
9174 -
9175 -unsigned long arch_align_stack(unsigned long sp)
9176 -{
9177 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9178 - sp -= get_random_int() & ~PAGE_MASK;
9179 - return sp & ~0xf;
9180 -}
9181 -
9182 -static inline unsigned long brk_rnd(void)
9183 -{
9184 - /* 8MB for 32bit, 1GB for 64bit */
9185 - if (is_32bit_task())
9186 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9187 - else
9188 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9189 -}
9190 -
9191 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9192 -{
9193 - unsigned long ret;
9194 -
9195 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9196 - return (ret > mm->brk) ? ret : mm->brk;
9197 -}
9198 -
9199 -unsigned long randomize_et_dyn(unsigned long base)
9200 -{
9201 - unsigned long ret;
9202 -
9203 - if (!(current->flags & PF_RANDOMIZE))
9204 - return base;
9205 - ret = PAGE_ALIGN(base + brk_rnd());
9206 - return (ret > base) ? ret : base;
9207 -}
9208 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9209 index 9b436c2..54fbf0a 100644
9210 --- a/arch/s390/mm/mmap.c
9211 +++ b/arch/s390/mm/mmap.c
9212 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9213 */
9214 if (mmap_is_legacy()) {
9215 mm->mmap_base = mmap_base_legacy();
9216 +
9217 +#ifdef CONFIG_PAX_RANDMMAP
9218 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9219 + mm->mmap_base += mm->delta_mmap;
9220 +#endif
9221 +
9222 mm->get_unmapped_area = arch_get_unmapped_area;
9223 } else {
9224 mm->mmap_base = mmap_base();
9225 +
9226 +#ifdef CONFIG_PAX_RANDMMAP
9227 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9228 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9229 +#endif
9230 +
9231 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9232 }
9233 }
9234 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9235 */
9236 if (mmap_is_legacy()) {
9237 mm->mmap_base = mmap_base_legacy();
9238 +
9239 +#ifdef CONFIG_PAX_RANDMMAP
9240 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9241 + mm->mmap_base += mm->delta_mmap;
9242 +#endif
9243 +
9244 mm->get_unmapped_area = s390_get_unmapped_area;
9245 } else {
9246 mm->mmap_base = mmap_base();
9247 +
9248 +#ifdef CONFIG_PAX_RANDMMAP
9249 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9250 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9251 +#endif
9252 +
9253 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9254 }
9255 }
9256 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9257 index ae3d59f..f65f075 100644
9258 --- a/arch/score/include/asm/cache.h
9259 +++ b/arch/score/include/asm/cache.h
9260 @@ -1,7 +1,9 @@
9261 #ifndef _ASM_SCORE_CACHE_H
9262 #define _ASM_SCORE_CACHE_H
9263
9264 +#include <linux/const.h>
9265 +
9266 #define L1_CACHE_SHIFT 4
9267 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9268 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9269
9270 #endif /* _ASM_SCORE_CACHE_H */
9271 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9272 index f9f3cd5..58ff438 100644
9273 --- a/arch/score/include/asm/exec.h
9274 +++ b/arch/score/include/asm/exec.h
9275 @@ -1,6 +1,6 @@
9276 #ifndef _ASM_SCORE_EXEC_H
9277 #define _ASM_SCORE_EXEC_H
9278
9279 -extern unsigned long arch_align_stack(unsigned long sp);
9280 +#define arch_align_stack(x) (x)
9281
9282 #endif /* _ASM_SCORE_EXEC_H */
9283 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9284 index a1519ad3..e8ac1ff 100644
9285 --- a/arch/score/kernel/process.c
9286 +++ b/arch/score/kernel/process.c
9287 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9288
9289 return task_pt_regs(task)->cp0_epc;
9290 }
9291 -
9292 -unsigned long arch_align_stack(unsigned long sp)
9293 -{
9294 - return sp;
9295 -}
9296 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9297 index ef9e555..331bd29 100644
9298 --- a/arch/sh/include/asm/cache.h
9299 +++ b/arch/sh/include/asm/cache.h
9300 @@ -9,10 +9,11 @@
9301 #define __ASM_SH_CACHE_H
9302 #ifdef __KERNEL__
9303
9304 +#include <linux/const.h>
9305 #include <linux/init.h>
9306 #include <cpu/cache.h>
9307
9308 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9309 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9310
9311 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9312
9313 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9314 index 6777177..cb5e44f 100644
9315 --- a/arch/sh/mm/mmap.c
9316 +++ b/arch/sh/mm/mmap.c
9317 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9318 struct mm_struct *mm = current->mm;
9319 struct vm_area_struct *vma;
9320 int do_colour_align;
9321 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9322 struct vm_unmapped_area_info info;
9323
9324 if (flags & MAP_FIXED) {
9325 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9326 if (filp || (flags & MAP_SHARED))
9327 do_colour_align = 1;
9328
9329 +#ifdef CONFIG_PAX_RANDMMAP
9330 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9331 +#endif
9332 +
9333 if (addr) {
9334 if (do_colour_align)
9335 addr = COLOUR_ALIGN(addr, pgoff);
9336 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9337 addr = PAGE_ALIGN(addr);
9338
9339 vma = find_vma(mm, addr);
9340 - if (TASK_SIZE - len >= addr &&
9341 - (!vma || addr + len <= vma->vm_start))
9342 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9343 return addr;
9344 }
9345
9346 info.flags = 0;
9347 info.length = len;
9348 - info.low_limit = TASK_UNMAPPED_BASE;
9349 + info.low_limit = mm->mmap_base;
9350 info.high_limit = TASK_SIZE;
9351 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9352 info.align_offset = pgoff << PAGE_SHIFT;
9353 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9354 struct mm_struct *mm = current->mm;
9355 unsigned long addr = addr0;
9356 int do_colour_align;
9357 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9358 struct vm_unmapped_area_info info;
9359
9360 if (flags & MAP_FIXED) {
9361 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9362 if (filp || (flags & MAP_SHARED))
9363 do_colour_align = 1;
9364
9365 +#ifdef CONFIG_PAX_RANDMMAP
9366 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9367 +#endif
9368 +
9369 /* requesting a specific address */
9370 if (addr) {
9371 if (do_colour_align)
9372 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9373 addr = PAGE_ALIGN(addr);
9374
9375 vma = find_vma(mm, addr);
9376 - if (TASK_SIZE - len >= addr &&
9377 - (!vma || addr + len <= vma->vm_start))
9378 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9379 return addr;
9380 }
9381
9382 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9383 VM_BUG_ON(addr != -ENOMEM);
9384 info.flags = 0;
9385 info.low_limit = TASK_UNMAPPED_BASE;
9386 +
9387 +#ifdef CONFIG_PAX_RANDMMAP
9388 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9389 + info.low_limit += mm->delta_mmap;
9390 +#endif
9391 +
9392 info.high_limit = TASK_SIZE;
9393 addr = vm_unmapped_area(&info);
9394 }
9395 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9396 index be56a24..443328f 100644
9397 --- a/arch/sparc/include/asm/atomic_64.h
9398 +++ b/arch/sparc/include/asm/atomic_64.h
9399 @@ -14,18 +14,40 @@
9400 #define ATOMIC64_INIT(i) { (i) }
9401
9402 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9403 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9404 +{
9405 + return v->counter;
9406 +}
9407 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9408 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9409 +{
9410 + return v->counter;
9411 +}
9412
9413 #define atomic_set(v, i) (((v)->counter) = i)
9414 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9415 +{
9416 + v->counter = i;
9417 +}
9418 #define atomic64_set(v, i) (((v)->counter) = i)
9419 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9420 +{
9421 + v->counter = i;
9422 +}
9423
9424 extern void atomic_add(int, atomic_t *);
9425 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9426 extern void atomic64_add(long, atomic64_t *);
9427 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9428 extern void atomic_sub(int, atomic_t *);
9429 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9430 extern void atomic64_sub(long, atomic64_t *);
9431 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9432
9433 extern int atomic_add_ret(int, atomic_t *);
9434 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9435 extern long atomic64_add_ret(long, atomic64_t *);
9436 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9437 extern int atomic_sub_ret(int, atomic_t *);
9438 extern long atomic64_sub_ret(long, atomic64_t *);
9439
9440 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9441 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9442
9443 #define atomic_inc_return(v) atomic_add_ret(1, v)
9444 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9445 +{
9446 + return atomic_add_ret_unchecked(1, v);
9447 +}
9448 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9449 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9450 +{
9451 + return atomic64_add_ret_unchecked(1, v);
9452 +}
9453
9454 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9455 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9456
9457 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9458 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9459 +{
9460 + return atomic_add_ret_unchecked(i, v);
9461 +}
9462 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9463 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9464 +{
9465 + return atomic64_add_ret_unchecked(i, v);
9466 +}
9467
9468 /*
9469 * atomic_inc_and_test - increment and test
9470 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9471 * other cases.
9472 */
9473 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9474 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9475 +{
9476 + return atomic_inc_return_unchecked(v) == 0;
9477 +}
9478 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9479
9480 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9481 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9482 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9483
9484 #define atomic_inc(v) atomic_add(1, v)
9485 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9486 +{
9487 + atomic_add_unchecked(1, v);
9488 +}
9489 #define atomic64_inc(v) atomic64_add(1, v)
9490 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9491 +{
9492 + atomic64_add_unchecked(1, v);
9493 +}
9494
9495 #define atomic_dec(v) atomic_sub(1, v)
9496 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9497 +{
9498 + atomic_sub_unchecked(1, v);
9499 +}
9500 #define atomic64_dec(v) atomic64_sub(1, v)
9501 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9502 +{
9503 + atomic64_sub_unchecked(1, v);
9504 +}
9505
9506 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9507 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9508
9509 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9510 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9511 +{
9512 + return cmpxchg(&v->counter, old, new);
9513 +}
9514 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9515 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9516 +{
9517 + return xchg(&v->counter, new);
9518 +}
9519
9520 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9521 {
9522 - int c, old;
9523 + int c, old, new;
9524 c = atomic_read(v);
9525 for (;;) {
9526 - if (unlikely(c == (u)))
9527 + if (unlikely(c == u))
9528 break;
9529 - old = atomic_cmpxchg((v), c, c + (a));
9530 +
9531 + asm volatile("addcc %2, %0, %0\n"
9532 +
9533 +#ifdef CONFIG_PAX_REFCOUNT
9534 + "tvs %%icc, 6\n"
9535 +#endif
9536 +
9537 + : "=r" (new)
9538 + : "0" (c), "ir" (a)
9539 + : "cc");
9540 +
9541 + old = atomic_cmpxchg(v, c, new);
9542 if (likely(old == c))
9543 break;
9544 c = old;
9545 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9546 #define atomic64_cmpxchg(v, o, n) \
9547 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9548 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9549 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9550 +{
9551 + return xchg(&v->counter, new);
9552 +}
9553
9554 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9555 {
9556 - long c, old;
9557 + long c, old, new;
9558 c = atomic64_read(v);
9559 for (;;) {
9560 - if (unlikely(c == (u)))
9561 + if (unlikely(c == u))
9562 break;
9563 - old = atomic64_cmpxchg((v), c, c + (a));
9564 +
9565 + asm volatile("addcc %2, %0, %0\n"
9566 +
9567 +#ifdef CONFIG_PAX_REFCOUNT
9568 + "tvs %%xcc, 6\n"
9569 +#endif
9570 +
9571 + : "=r" (new)
9572 + : "0" (c), "ir" (a)
9573 + : "cc");
9574 +
9575 + old = atomic64_cmpxchg(v, c, new);
9576 if (likely(old == c))
9577 break;
9578 c = old;
9579 }
9580 - return c != (u);
9581 + return c != u;
9582 }
9583
9584 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9585 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9586 index 5bb6991..5c2132e 100644
9587 --- a/arch/sparc/include/asm/cache.h
9588 +++ b/arch/sparc/include/asm/cache.h
9589 @@ -7,10 +7,12 @@
9590 #ifndef _SPARC_CACHE_H
9591 #define _SPARC_CACHE_H
9592
9593 +#include <linux/const.h>
9594 +
9595 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9596
9597 #define L1_CACHE_SHIFT 5
9598 -#define L1_CACHE_BYTES 32
9599 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9600
9601 #ifdef CONFIG_SPARC32
9602 #define SMP_CACHE_BYTES_SHIFT 5
9603 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9604 index a24e41f..47677ff 100644
9605 --- a/arch/sparc/include/asm/elf_32.h
9606 +++ b/arch/sparc/include/asm/elf_32.h
9607 @@ -114,6 +114,13 @@ typedef struct {
9608
9609 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9610
9611 +#ifdef CONFIG_PAX_ASLR
9612 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9613 +
9614 +#define PAX_DELTA_MMAP_LEN 16
9615 +#define PAX_DELTA_STACK_LEN 16
9616 +#endif
9617 +
9618 /* This yields a mask that user programs can use to figure out what
9619 instruction set this cpu supports. This can NOT be done in userspace
9620 on Sparc. */
9621 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9622 index 370ca1e..d4f4a98 100644
9623 --- a/arch/sparc/include/asm/elf_64.h
9624 +++ b/arch/sparc/include/asm/elf_64.h
9625 @@ -189,6 +189,13 @@ typedef struct {
9626 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9627 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9628
9629 +#ifdef CONFIG_PAX_ASLR
9630 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9631 +
9632 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9633 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9634 +#endif
9635 +
9636 extern unsigned long sparc64_elf_hwcap;
9637 #define ELF_HWCAP sparc64_elf_hwcap
9638
9639 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9640 index 9b1c36d..209298b 100644
9641 --- a/arch/sparc/include/asm/pgalloc_32.h
9642 +++ b/arch/sparc/include/asm/pgalloc_32.h
9643 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9644 }
9645
9646 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9647 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9648
9649 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9650 unsigned long address)
9651 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9652 index bcfe063..b333142 100644
9653 --- a/arch/sparc/include/asm/pgalloc_64.h
9654 +++ b/arch/sparc/include/asm/pgalloc_64.h
9655 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9656 }
9657
9658 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9659 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9660
9661 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9662 {
9663 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9664 index 59ba6f6..4518128 100644
9665 --- a/arch/sparc/include/asm/pgtable.h
9666 +++ b/arch/sparc/include/asm/pgtable.h
9667 @@ -5,4 +5,8 @@
9668 #else
9669 #include <asm/pgtable_32.h>
9670 #endif
9671 +
9672 +#define ktla_ktva(addr) (addr)
9673 +#define ktva_ktla(addr) (addr)
9674 +
9675 #endif
9676 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9677 index 502f632..da1917f 100644
9678 --- a/arch/sparc/include/asm/pgtable_32.h
9679 +++ b/arch/sparc/include/asm/pgtable_32.h
9680 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9681 #define PAGE_SHARED SRMMU_PAGE_SHARED
9682 #define PAGE_COPY SRMMU_PAGE_COPY
9683 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9684 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9685 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9686 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9687 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9688
9689 /* Top-level page directory - dummy used by init-mm.
9690 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9691
9692 /* xwr */
9693 #define __P000 PAGE_NONE
9694 -#define __P001 PAGE_READONLY
9695 -#define __P010 PAGE_COPY
9696 -#define __P011 PAGE_COPY
9697 +#define __P001 PAGE_READONLY_NOEXEC
9698 +#define __P010 PAGE_COPY_NOEXEC
9699 +#define __P011 PAGE_COPY_NOEXEC
9700 #define __P100 PAGE_READONLY
9701 #define __P101 PAGE_READONLY
9702 #define __P110 PAGE_COPY
9703 #define __P111 PAGE_COPY
9704
9705 #define __S000 PAGE_NONE
9706 -#define __S001 PAGE_READONLY
9707 -#define __S010 PAGE_SHARED
9708 -#define __S011 PAGE_SHARED
9709 +#define __S001 PAGE_READONLY_NOEXEC
9710 +#define __S010 PAGE_SHARED_NOEXEC
9711 +#define __S011 PAGE_SHARED_NOEXEC
9712 #define __S100 PAGE_READONLY
9713 #define __S101 PAGE_READONLY
9714 #define __S110 PAGE_SHARED
9715 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9716 index 79da178..c2eede8 100644
9717 --- a/arch/sparc/include/asm/pgtsrmmu.h
9718 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9719 @@ -115,6 +115,11 @@
9720 SRMMU_EXEC | SRMMU_REF)
9721 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9722 SRMMU_EXEC | SRMMU_REF)
9723 +
9724 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9725 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9726 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9727 +
9728 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9729 SRMMU_DIRTY | SRMMU_REF)
9730
9731 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9732 index 9689176..63c18ea 100644
9733 --- a/arch/sparc/include/asm/spinlock_64.h
9734 +++ b/arch/sparc/include/asm/spinlock_64.h
9735 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9736
9737 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9738
9739 -static void inline arch_read_lock(arch_rwlock_t *lock)
9740 +static inline void arch_read_lock(arch_rwlock_t *lock)
9741 {
9742 unsigned long tmp1, tmp2;
9743
9744 __asm__ __volatile__ (
9745 "1: ldsw [%2], %0\n"
9746 " brlz,pn %0, 2f\n"
9747 -"4: add %0, 1, %1\n"
9748 +"4: addcc %0, 1, %1\n"
9749 +
9750 +#ifdef CONFIG_PAX_REFCOUNT
9751 +" tvs %%icc, 6\n"
9752 +#endif
9753 +
9754 " cas [%2], %0, %1\n"
9755 " cmp %0, %1\n"
9756 " bne,pn %%icc, 1b\n"
9757 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9758 " .previous"
9759 : "=&r" (tmp1), "=&r" (tmp2)
9760 : "r" (lock)
9761 - : "memory");
9762 + : "memory", "cc");
9763 }
9764
9765 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9766 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9767 {
9768 int tmp1, tmp2;
9769
9770 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9771 "1: ldsw [%2], %0\n"
9772 " brlz,a,pn %0, 2f\n"
9773 " mov 0, %0\n"
9774 -" add %0, 1, %1\n"
9775 +" addcc %0, 1, %1\n"
9776 +
9777 +#ifdef CONFIG_PAX_REFCOUNT
9778 +" tvs %%icc, 6\n"
9779 +#endif
9780 +
9781 " cas [%2], %0, %1\n"
9782 " cmp %0, %1\n"
9783 " bne,pn %%icc, 1b\n"
9784 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9785 return tmp1;
9786 }
9787
9788 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9789 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9790 {
9791 unsigned long tmp1, tmp2;
9792
9793 __asm__ __volatile__(
9794 "1: lduw [%2], %0\n"
9795 -" sub %0, 1, %1\n"
9796 +" subcc %0, 1, %1\n"
9797 +
9798 +#ifdef CONFIG_PAX_REFCOUNT
9799 +" tvs %%icc, 6\n"
9800 +#endif
9801 +
9802 " cas [%2], %0, %1\n"
9803 " cmp %0, %1\n"
9804 " bne,pn %%xcc, 1b\n"
9805 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9806 : "memory");
9807 }
9808
9809 -static void inline arch_write_lock(arch_rwlock_t *lock)
9810 +static inline void arch_write_lock(arch_rwlock_t *lock)
9811 {
9812 unsigned long mask, tmp1, tmp2;
9813
9814 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9815 : "memory");
9816 }
9817
9818 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9819 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9820 {
9821 __asm__ __volatile__(
9822 " stw %%g0, [%0]"
9823 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9824 : "memory");
9825 }
9826
9827 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9828 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9829 {
9830 unsigned long mask, tmp1, tmp2, result;
9831
9832 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9833 index 96efa7a..16858bf 100644
9834 --- a/arch/sparc/include/asm/thread_info_32.h
9835 +++ b/arch/sparc/include/asm/thread_info_32.h
9836 @@ -49,6 +49,8 @@ struct thread_info {
9837 unsigned long w_saved;
9838
9839 struct restart_block restart_block;
9840 +
9841 + unsigned long lowest_stack;
9842 };
9843
9844 /*
9845 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9846 index a5f01ac..703b554 100644
9847 --- a/arch/sparc/include/asm/thread_info_64.h
9848 +++ b/arch/sparc/include/asm/thread_info_64.h
9849 @@ -63,6 +63,8 @@ struct thread_info {
9850 struct pt_regs *kern_una_regs;
9851 unsigned int kern_una_insn;
9852
9853 + unsigned long lowest_stack;
9854 +
9855 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9856 };
9857
9858 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9859 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9860 /* flag bit 4 is available */
9861 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9862 -/* flag bit 6 is available */
9863 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9864 #define TIF_32BIT 7 /* 32-bit binary */
9865 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9866 #define TIF_SECCOMP 9 /* secure computing */
9867 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9868 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9869 +
9870 /* NOTE: Thread flags >= 12 should be ones we have no interest
9871 * in using in assembly, else we can't use the mask as
9872 * an immediate value in instructions such as andcc.
9873 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9874 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9875 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9876 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9877 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9878
9879 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9880 _TIF_DO_NOTIFY_RESUME_MASK | \
9881 _TIF_NEED_RESCHED)
9882 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9883
9884 +#define _TIF_WORK_SYSCALL \
9885 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9886 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9887 +
9888 +
9889 /*
9890 * Thread-synchronous status.
9891 *
9892 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9893 index 0167d26..767bb0c 100644
9894 --- a/arch/sparc/include/asm/uaccess.h
9895 +++ b/arch/sparc/include/asm/uaccess.h
9896 @@ -1,5 +1,6 @@
9897 #ifndef ___ASM_SPARC_UACCESS_H
9898 #define ___ASM_SPARC_UACCESS_H
9899 +
9900 #if defined(__sparc__) && defined(__arch64__)
9901 #include <asm/uaccess_64.h>
9902 #else
9903 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9904 index 53a28dd..50c38c3 100644
9905 --- a/arch/sparc/include/asm/uaccess_32.h
9906 +++ b/arch/sparc/include/asm/uaccess_32.h
9907 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9908
9909 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9910 {
9911 - if (n && __access_ok((unsigned long) to, n))
9912 + if ((long)n < 0)
9913 + return n;
9914 +
9915 + if (n && __access_ok((unsigned long) to, n)) {
9916 + if (!__builtin_constant_p(n))
9917 + check_object_size(from, n, true);
9918 return __copy_user(to, (__force void __user *) from, n);
9919 - else
9920 + } else
9921 return n;
9922 }
9923
9924 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9925 {
9926 + if ((long)n < 0)
9927 + return n;
9928 +
9929 + if (!__builtin_constant_p(n))
9930 + check_object_size(from, n, true);
9931 +
9932 return __copy_user(to, (__force void __user *) from, n);
9933 }
9934
9935 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9936 {
9937 - if (n && __access_ok((unsigned long) from, n))
9938 + if ((long)n < 0)
9939 + return n;
9940 +
9941 + if (n && __access_ok((unsigned long) from, n)) {
9942 + if (!__builtin_constant_p(n))
9943 + check_object_size(to, n, false);
9944 return __copy_user((__force void __user *) to, from, n);
9945 - else
9946 + } else
9947 return n;
9948 }
9949
9950 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9951 {
9952 + if ((long)n < 0)
9953 + return n;
9954 +
9955 return __copy_user((__force void __user *) to, from, n);
9956 }
9957
9958 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9959 index ad7e178..c9e7423 100644
9960 --- a/arch/sparc/include/asm/uaccess_64.h
9961 +++ b/arch/sparc/include/asm/uaccess_64.h
9962 @@ -10,6 +10,7 @@
9963 #include <linux/compiler.h>
9964 #include <linux/string.h>
9965 #include <linux/thread_info.h>
9966 +#include <linux/kernel.h>
9967 #include <asm/asi.h>
9968 #include <asm/spitfire.h>
9969 #include <asm-generic/uaccess-unaligned.h>
9970 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9971 static inline unsigned long __must_check
9972 copy_from_user(void *to, const void __user *from, unsigned long size)
9973 {
9974 - unsigned long ret = ___copy_from_user(to, from, size);
9975 + unsigned long ret;
9976
9977 + if ((long)size < 0 || size > INT_MAX)
9978 + return size;
9979 +
9980 + if (!__builtin_constant_p(size))
9981 + check_object_size(to, size, false);
9982 +
9983 + ret = ___copy_from_user(to, from, size);
9984 if (unlikely(ret))
9985 ret = copy_from_user_fixup(to, from, size);
9986
9987 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9988 static inline unsigned long __must_check
9989 copy_to_user(void __user *to, const void *from, unsigned long size)
9990 {
9991 - unsigned long ret = ___copy_to_user(to, from, size);
9992 + unsigned long ret;
9993
9994 + if ((long)size < 0 || size > INT_MAX)
9995 + return size;
9996 +
9997 + if (!__builtin_constant_p(size))
9998 + check_object_size(from, size, true);
9999 +
10000 + ret = ___copy_to_user(to, from, size);
10001 if (unlikely(ret))
10002 ret = copy_to_user_fixup(to, from, size);
10003 return ret;
10004 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10005 index d15cc17..d0ae796 100644
10006 --- a/arch/sparc/kernel/Makefile
10007 +++ b/arch/sparc/kernel/Makefile
10008 @@ -4,7 +4,7 @@
10009 #
10010
10011 asflags-y := -ansi
10012 -ccflags-y := -Werror
10013 +#ccflags-y := -Werror
10014
10015 extra-y := head_$(BITS).o
10016
10017 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10018 index 510baec..9ff2607 100644
10019 --- a/arch/sparc/kernel/process_32.c
10020 +++ b/arch/sparc/kernel/process_32.c
10021 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10022
10023 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10024 r->psr, r->pc, r->npc, r->y, print_tainted());
10025 - printk("PC: <%pS>\n", (void *) r->pc);
10026 + printk("PC: <%pA>\n", (void *) r->pc);
10027 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10028 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10029 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10030 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10031 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10032 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10033 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10034 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10035
10036 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10037 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10038 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10039 rw = (struct reg_window32 *) fp;
10040 pc = rw->ins[7];
10041 printk("[%08lx : ", pc);
10042 - printk("%pS ] ", (void *) pc);
10043 + printk("%pA ] ", (void *) pc);
10044 fp = rw->ins[6];
10045 } while (++count < 16);
10046 printk("\n");
10047 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10048 index d7b4967..2edf827 100644
10049 --- a/arch/sparc/kernel/process_64.c
10050 +++ b/arch/sparc/kernel/process_64.c
10051 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10052 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10053 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10054 if (regs->tstate & TSTATE_PRIV)
10055 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10056 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10057 }
10058
10059 void show_regs(struct pt_regs *regs)
10060 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10061
10062 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10063 regs->tpc, regs->tnpc, regs->y, print_tainted());
10064 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10065 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10066 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10067 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10068 regs->u_regs[3]);
10069 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10070 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10071 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10072 regs->u_regs[15]);
10073 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10074 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10075 show_regwindow(regs);
10076 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10077 }
10078 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10079 ((tp && tp->task) ? tp->task->pid : -1));
10080
10081 if (gp->tstate & TSTATE_PRIV) {
10082 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10083 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10084 (void *) gp->tpc,
10085 (void *) gp->o7,
10086 (void *) gp->i7,
10087 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10088 index 79cc0d1..ec62734 100644
10089 --- a/arch/sparc/kernel/prom_common.c
10090 +++ b/arch/sparc/kernel/prom_common.c
10091 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10092
10093 unsigned int prom_early_allocated __initdata;
10094
10095 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10096 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10097 .nextprop = prom_common_nextprop,
10098 .getproplen = prom_getproplen,
10099 .getproperty = prom_getproperty,
10100 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10101 index c13c9f2..d572c34 100644
10102 --- a/arch/sparc/kernel/ptrace_64.c
10103 +++ b/arch/sparc/kernel/ptrace_64.c
10104 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10105 return ret;
10106 }
10107
10108 +#ifdef CONFIG_GRKERNSEC_SETXID
10109 +extern void gr_delayed_cred_worker(void);
10110 +#endif
10111 +
10112 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10113 {
10114 int ret = 0;
10115 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10116 if (test_thread_flag(TIF_NOHZ))
10117 user_exit();
10118
10119 +#ifdef CONFIG_GRKERNSEC_SETXID
10120 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10121 + gr_delayed_cred_worker();
10122 +#endif
10123 +
10124 if (test_thread_flag(TIF_SYSCALL_TRACE))
10125 ret = tracehook_report_syscall_entry(regs);
10126
10127 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10128 if (test_thread_flag(TIF_NOHZ))
10129 user_exit();
10130
10131 +#ifdef CONFIG_GRKERNSEC_SETXID
10132 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10133 + gr_delayed_cred_worker();
10134 +#endif
10135 +
10136 audit_syscall_exit(regs);
10137
10138 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10139 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10140 index b085311..6f885f7 100644
10141 --- a/arch/sparc/kernel/smp_64.c
10142 +++ b/arch/sparc/kernel/smp_64.c
10143 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10144 extern unsigned long xcall_flush_dcache_page_spitfire;
10145
10146 #ifdef CONFIG_DEBUG_DCFLUSH
10147 -extern atomic_t dcpage_flushes;
10148 -extern atomic_t dcpage_flushes_xcall;
10149 +extern atomic_unchecked_t dcpage_flushes;
10150 +extern atomic_unchecked_t dcpage_flushes_xcall;
10151 #endif
10152
10153 static inline void __local_flush_dcache_page(struct page *page)
10154 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10155 return;
10156
10157 #ifdef CONFIG_DEBUG_DCFLUSH
10158 - atomic_inc(&dcpage_flushes);
10159 + atomic_inc_unchecked(&dcpage_flushes);
10160 #endif
10161
10162 this_cpu = get_cpu();
10163 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10164 xcall_deliver(data0, __pa(pg_addr),
10165 (u64) pg_addr, cpumask_of(cpu));
10166 #ifdef CONFIG_DEBUG_DCFLUSH
10167 - atomic_inc(&dcpage_flushes_xcall);
10168 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10169 #endif
10170 }
10171 }
10172 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10173 preempt_disable();
10174
10175 #ifdef CONFIG_DEBUG_DCFLUSH
10176 - atomic_inc(&dcpage_flushes);
10177 + atomic_inc_unchecked(&dcpage_flushes);
10178 #endif
10179 data0 = 0;
10180 pg_addr = page_address(page);
10181 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10182 xcall_deliver(data0, __pa(pg_addr),
10183 (u64) pg_addr, cpu_online_mask);
10184 #ifdef CONFIG_DEBUG_DCFLUSH
10185 - atomic_inc(&dcpage_flushes_xcall);
10186 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10187 #endif
10188 }
10189 __local_flush_dcache_page(page);
10190 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10191 index 3a8d184..49498a8 100644
10192 --- a/arch/sparc/kernel/sys_sparc_32.c
10193 +++ b/arch/sparc/kernel/sys_sparc_32.c
10194 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10195 if (len > TASK_SIZE - PAGE_SIZE)
10196 return -ENOMEM;
10197 if (!addr)
10198 - addr = TASK_UNMAPPED_BASE;
10199 + addr = current->mm->mmap_base;
10200
10201 info.flags = 0;
10202 info.length = len;
10203 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10204 index beb0b5a..5a153f7 100644
10205 --- a/arch/sparc/kernel/sys_sparc_64.c
10206 +++ b/arch/sparc/kernel/sys_sparc_64.c
10207 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10208 struct vm_area_struct * vma;
10209 unsigned long task_size = TASK_SIZE;
10210 int do_color_align;
10211 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10212 struct vm_unmapped_area_info info;
10213
10214 if (flags & MAP_FIXED) {
10215 /* We do not accept a shared mapping if it would violate
10216 * cache aliasing constraints.
10217 */
10218 - if ((flags & MAP_SHARED) &&
10219 + if ((filp || (flags & MAP_SHARED)) &&
10220 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10221 return -EINVAL;
10222 return addr;
10223 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10224 if (filp || (flags & MAP_SHARED))
10225 do_color_align = 1;
10226
10227 +#ifdef CONFIG_PAX_RANDMMAP
10228 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10229 +#endif
10230 +
10231 if (addr) {
10232 if (do_color_align)
10233 addr = COLOR_ALIGN(addr, pgoff);
10234 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10235 addr = PAGE_ALIGN(addr);
10236
10237 vma = find_vma(mm, addr);
10238 - if (task_size - len >= addr &&
10239 - (!vma || addr + len <= vma->vm_start))
10240 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10241 return addr;
10242 }
10243
10244 info.flags = 0;
10245 info.length = len;
10246 - info.low_limit = TASK_UNMAPPED_BASE;
10247 + info.low_limit = mm->mmap_base;
10248 info.high_limit = min(task_size, VA_EXCLUDE_START);
10249 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10250 info.align_offset = pgoff << PAGE_SHIFT;
10251 + info.threadstack_offset = offset;
10252 addr = vm_unmapped_area(&info);
10253
10254 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10255 VM_BUG_ON(addr != -ENOMEM);
10256 info.low_limit = VA_EXCLUDE_END;
10257 +
10258 +#ifdef CONFIG_PAX_RANDMMAP
10259 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10260 + info.low_limit += mm->delta_mmap;
10261 +#endif
10262 +
10263 info.high_limit = task_size;
10264 addr = vm_unmapped_area(&info);
10265 }
10266 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10267 unsigned long task_size = STACK_TOP32;
10268 unsigned long addr = addr0;
10269 int do_color_align;
10270 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10271 struct vm_unmapped_area_info info;
10272
10273 /* This should only ever run for 32-bit processes. */
10274 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10275 /* We do not accept a shared mapping if it would violate
10276 * cache aliasing constraints.
10277 */
10278 - if ((flags & MAP_SHARED) &&
10279 + if ((filp || (flags & MAP_SHARED)) &&
10280 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10281 return -EINVAL;
10282 return addr;
10283 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10284 if (filp || (flags & MAP_SHARED))
10285 do_color_align = 1;
10286
10287 +#ifdef CONFIG_PAX_RANDMMAP
10288 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10289 +#endif
10290 +
10291 /* requesting a specific address */
10292 if (addr) {
10293 if (do_color_align)
10294 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10295 addr = PAGE_ALIGN(addr);
10296
10297 vma = find_vma(mm, addr);
10298 - if (task_size - len >= addr &&
10299 - (!vma || addr + len <= vma->vm_start))
10300 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10301 return addr;
10302 }
10303
10304 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10305 info.high_limit = mm->mmap_base;
10306 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10307 info.align_offset = pgoff << PAGE_SHIFT;
10308 + info.threadstack_offset = offset;
10309 addr = vm_unmapped_area(&info);
10310
10311 /*
10312 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10313 VM_BUG_ON(addr != -ENOMEM);
10314 info.flags = 0;
10315 info.low_limit = TASK_UNMAPPED_BASE;
10316 +
10317 +#ifdef CONFIG_PAX_RANDMMAP
10318 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10319 + info.low_limit += mm->delta_mmap;
10320 +#endif
10321 +
10322 info.high_limit = STACK_TOP32;
10323 addr = vm_unmapped_area(&info);
10324 }
10325 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10326 EXPORT_SYMBOL(get_fb_unmapped_area);
10327
10328 /* Essentially the same as PowerPC. */
10329 -static unsigned long mmap_rnd(void)
10330 +static unsigned long mmap_rnd(struct mm_struct *mm)
10331 {
10332 unsigned long rnd = 0UL;
10333
10334 +#ifdef CONFIG_PAX_RANDMMAP
10335 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10336 +#endif
10337 +
10338 if (current->flags & PF_RANDOMIZE) {
10339 unsigned long val = get_random_int();
10340 if (test_thread_flag(TIF_32BIT))
10341 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10342
10343 void arch_pick_mmap_layout(struct mm_struct *mm)
10344 {
10345 - unsigned long random_factor = mmap_rnd();
10346 + unsigned long random_factor = mmap_rnd(mm);
10347 unsigned long gap;
10348
10349 /*
10350 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10351 gap == RLIM_INFINITY ||
10352 sysctl_legacy_va_layout) {
10353 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10354 +
10355 +#ifdef CONFIG_PAX_RANDMMAP
10356 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10357 + mm->mmap_base += mm->delta_mmap;
10358 +#endif
10359 +
10360 mm->get_unmapped_area = arch_get_unmapped_area;
10361 } else {
10362 /* We know it's 32-bit */
10363 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10364 gap = (task_size / 6 * 5);
10365
10366 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10367 +
10368 +#ifdef CONFIG_PAX_RANDMMAP
10369 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10370 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10371 +#endif
10372 +
10373 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10374 }
10375 }
10376 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10377 index 33a17e7..d87fb1f 100644
10378 --- a/arch/sparc/kernel/syscalls.S
10379 +++ b/arch/sparc/kernel/syscalls.S
10380 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10381 #endif
10382 .align 32
10383 1: ldx [%g6 + TI_FLAGS], %l5
10384 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10385 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10386 be,pt %icc, rtrap
10387 nop
10388 call syscall_trace_leave
10389 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10390
10391 srl %i3, 0, %o3 ! IEU0
10392 srl %i2, 0, %o2 ! IEU0 Group
10393 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10394 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10395 bne,pn %icc, linux_syscall_trace32 ! CTI
10396 mov %i0, %l5 ! IEU1
10397 5: call %l7 ! CTI Group brk forced
10398 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10399
10400 mov %i3, %o3 ! IEU1
10401 mov %i4, %o4 ! IEU0 Group
10402 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10403 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10404 bne,pn %icc, linux_syscall_trace ! CTI Group
10405 mov %i0, %l5 ! IEU0
10406 2: call %l7 ! CTI Group brk forced
10407 @@ -223,7 +223,7 @@ ret_sys_call:
10408
10409 cmp %o0, -ERESTART_RESTARTBLOCK
10410 bgeu,pn %xcc, 1f
10411 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10412 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10413 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10414
10415 2:
10416 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10417 index 6629829..036032d 100644
10418 --- a/arch/sparc/kernel/traps_32.c
10419 +++ b/arch/sparc/kernel/traps_32.c
10420 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10421 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10422 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10423
10424 +extern void gr_handle_kernel_exploit(void);
10425 +
10426 void die_if_kernel(char *str, struct pt_regs *regs)
10427 {
10428 static int die_counter;
10429 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10430 count++ < 30 &&
10431 (((unsigned long) rw) >= PAGE_OFFSET) &&
10432 !(((unsigned long) rw) & 0x7)) {
10433 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10434 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10435 (void *) rw->ins[7]);
10436 rw = (struct reg_window32 *)rw->ins[6];
10437 }
10438 }
10439 printk("Instruction DUMP:");
10440 instruction_dump ((unsigned long *) regs->pc);
10441 - if(regs->psr & PSR_PS)
10442 + if(regs->psr & PSR_PS) {
10443 + gr_handle_kernel_exploit();
10444 do_exit(SIGKILL);
10445 + }
10446 do_exit(SIGSEGV);
10447 }
10448
10449 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10450 index 4ced92f..965eeed 100644
10451 --- a/arch/sparc/kernel/traps_64.c
10452 +++ b/arch/sparc/kernel/traps_64.c
10453 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10454 i + 1,
10455 p->trapstack[i].tstate, p->trapstack[i].tpc,
10456 p->trapstack[i].tnpc, p->trapstack[i].tt);
10457 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10458 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10459 }
10460 }
10461
10462 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10463
10464 lvl -= 0x100;
10465 if (regs->tstate & TSTATE_PRIV) {
10466 +
10467 +#ifdef CONFIG_PAX_REFCOUNT
10468 + if (lvl == 6)
10469 + pax_report_refcount_overflow(regs);
10470 +#endif
10471 +
10472 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10473 die_if_kernel(buffer, regs);
10474 }
10475 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10476 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10477 {
10478 char buffer[32];
10479 -
10480 +
10481 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10482 0, lvl, SIGTRAP) == NOTIFY_STOP)
10483 return;
10484
10485 +#ifdef CONFIG_PAX_REFCOUNT
10486 + if (lvl == 6)
10487 + pax_report_refcount_overflow(regs);
10488 +#endif
10489 +
10490 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10491
10492 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10493 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10494 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10495 printk("%s" "ERROR(%d): ",
10496 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10497 - printk("TPC<%pS>\n", (void *) regs->tpc);
10498 + printk("TPC<%pA>\n", (void *) regs->tpc);
10499 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10500 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10501 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10502 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10503 smp_processor_id(),
10504 (type & 0x1) ? 'I' : 'D',
10505 regs->tpc);
10506 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10507 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10508 panic("Irrecoverable Cheetah+ parity error.");
10509 }
10510
10511 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10512 smp_processor_id(),
10513 (type & 0x1) ? 'I' : 'D',
10514 regs->tpc);
10515 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10516 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10517 }
10518
10519 struct sun4v_error_entry {
10520 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10521 /*0x38*/u64 reserved_5;
10522 };
10523
10524 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10525 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10526 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10527 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10528
10529 static const char *sun4v_err_type_to_str(u8 type)
10530 {
10531 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10532 }
10533
10534 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10535 - int cpu, const char *pfx, atomic_t *ocnt)
10536 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10537 {
10538 u64 *raw_ptr = (u64 *) ent;
10539 u32 attrs;
10540 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10541
10542 show_regs(regs);
10543
10544 - if ((cnt = atomic_read(ocnt)) != 0) {
10545 - atomic_set(ocnt, 0);
10546 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10547 + atomic_set_unchecked(ocnt, 0);
10548 wmb();
10549 printk("%s: Queue overflowed %d times.\n",
10550 pfx, cnt);
10551 @@ -2046,7 +2057,7 @@ out:
10552 */
10553 void sun4v_resum_overflow(struct pt_regs *regs)
10554 {
10555 - atomic_inc(&sun4v_resum_oflow_cnt);
10556 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10557 }
10558
10559 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10560 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10561 /* XXX Actually even this can make not that much sense. Perhaps
10562 * XXX we should just pull the plug and panic directly from here?
10563 */
10564 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10565 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10566 }
10567
10568 unsigned long sun4v_err_itlb_vaddr;
10569 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10570
10571 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10572 regs->tpc, tl);
10573 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10574 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10575 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10576 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10577 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10578 (void *) regs->u_regs[UREG_I7]);
10579 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10580 "pte[%lx] error[%lx]\n",
10581 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10582
10583 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10584 regs->tpc, tl);
10585 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10586 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10587 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10588 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10589 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10590 (void *) regs->u_regs[UREG_I7]);
10591 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10592 "pte[%lx] error[%lx]\n",
10593 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10594 fp = (unsigned long)sf->fp + STACK_BIAS;
10595 }
10596
10597 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10598 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10599 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10600 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10601 int index = tsk->curr_ret_stack;
10602 if (tsk->ret_stack && index >= graph) {
10603 pc = tsk->ret_stack[index - graph].ret;
10604 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10605 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10606 graph++;
10607 }
10608 }
10609 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10610 return (struct reg_window *) (fp + STACK_BIAS);
10611 }
10612
10613 +extern void gr_handle_kernel_exploit(void);
10614 +
10615 void die_if_kernel(char *str, struct pt_regs *regs)
10616 {
10617 static int die_counter;
10618 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10619 while (rw &&
10620 count++ < 30 &&
10621 kstack_valid(tp, (unsigned long) rw)) {
10622 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10623 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10624 (void *) rw->ins[7]);
10625
10626 rw = kernel_stack_up(rw);
10627 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10628 }
10629 user_instruction_dump ((unsigned int __user *) regs->tpc);
10630 }
10631 - if (regs->tstate & TSTATE_PRIV)
10632 + if (regs->tstate & TSTATE_PRIV) {
10633 + gr_handle_kernel_exploit();
10634 do_exit(SIGKILL);
10635 + }
10636 do_exit(SIGSEGV);
10637 }
10638 EXPORT_SYMBOL(die_if_kernel);
10639 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10640 index 3c1a7cb..73e1923 100644
10641 --- a/arch/sparc/kernel/unaligned_64.c
10642 +++ b/arch/sparc/kernel/unaligned_64.c
10643 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10644 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10645
10646 if (__ratelimit(&ratelimit)) {
10647 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10648 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10649 regs->tpc, (void *) regs->tpc);
10650 }
10651 }
10652 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10653 index dbe119b..089c7c1 100644
10654 --- a/arch/sparc/lib/Makefile
10655 +++ b/arch/sparc/lib/Makefile
10656 @@ -2,7 +2,7 @@
10657 #
10658
10659 asflags-y := -ansi -DST_DIV0=0x02
10660 -ccflags-y := -Werror
10661 +#ccflags-y := -Werror
10662
10663 lib-$(CONFIG_SPARC32) += ashrdi3.o
10664 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10665 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10666 index 85c233d..68500e0 100644
10667 --- a/arch/sparc/lib/atomic_64.S
10668 +++ b/arch/sparc/lib/atomic_64.S
10669 @@ -17,7 +17,12 @@
10670 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10671 BACKOFF_SETUP(%o2)
10672 1: lduw [%o1], %g1
10673 - add %g1, %o0, %g7
10674 + addcc %g1, %o0, %g7
10675 +
10676 +#ifdef CONFIG_PAX_REFCOUNT
10677 + tvs %icc, 6
10678 +#endif
10679 +
10680 cas [%o1], %g1, %g7
10681 cmp %g1, %g7
10682 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10683 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10684 2: BACKOFF_SPIN(%o2, %o3, 1b)
10685 ENDPROC(atomic_add)
10686
10687 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10688 + BACKOFF_SETUP(%o2)
10689 +1: lduw [%o1], %g1
10690 + add %g1, %o0, %g7
10691 + cas [%o1], %g1, %g7
10692 + cmp %g1, %g7
10693 + bne,pn %icc, 2f
10694 + nop
10695 + retl
10696 + nop
10697 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10698 +ENDPROC(atomic_add_unchecked)
10699 +
10700 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10701 BACKOFF_SETUP(%o2)
10702 1: lduw [%o1], %g1
10703 - sub %g1, %o0, %g7
10704 + subcc %g1, %o0, %g7
10705 +
10706 +#ifdef CONFIG_PAX_REFCOUNT
10707 + tvs %icc, 6
10708 +#endif
10709 +
10710 cas [%o1], %g1, %g7
10711 cmp %g1, %g7
10712 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10713 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10714 2: BACKOFF_SPIN(%o2, %o3, 1b)
10715 ENDPROC(atomic_sub)
10716
10717 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10718 + BACKOFF_SETUP(%o2)
10719 +1: lduw [%o1], %g1
10720 + sub %g1, %o0, %g7
10721 + cas [%o1], %g1, %g7
10722 + cmp %g1, %g7
10723 + bne,pn %icc, 2f
10724 + nop
10725 + retl
10726 + nop
10727 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10728 +ENDPROC(atomic_sub_unchecked)
10729 +
10730 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10731 BACKOFF_SETUP(%o2)
10732 1: lduw [%o1], %g1
10733 - add %g1, %o0, %g7
10734 + addcc %g1, %o0, %g7
10735 +
10736 +#ifdef CONFIG_PAX_REFCOUNT
10737 + tvs %icc, 6
10738 +#endif
10739 +
10740 cas [%o1], %g1, %g7
10741 cmp %g1, %g7
10742 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10743 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10744 2: BACKOFF_SPIN(%o2, %o3, 1b)
10745 ENDPROC(atomic_add_ret)
10746
10747 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10748 + BACKOFF_SETUP(%o2)
10749 +1: lduw [%o1], %g1
10750 + addcc %g1, %o0, %g7
10751 + cas [%o1], %g1, %g7
10752 + cmp %g1, %g7
10753 + bne,pn %icc, 2f
10754 + add %g7, %o0, %g7
10755 + sra %g7, 0, %o0
10756 + retl
10757 + nop
10758 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10759 +ENDPROC(atomic_add_ret_unchecked)
10760 +
10761 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10762 BACKOFF_SETUP(%o2)
10763 1: lduw [%o1], %g1
10764 - sub %g1, %o0, %g7
10765 + subcc %g1, %o0, %g7
10766 +
10767 +#ifdef CONFIG_PAX_REFCOUNT
10768 + tvs %icc, 6
10769 +#endif
10770 +
10771 cas [%o1], %g1, %g7
10772 cmp %g1, %g7
10773 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10774 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10775 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10776 BACKOFF_SETUP(%o2)
10777 1: ldx [%o1], %g1
10778 - add %g1, %o0, %g7
10779 + addcc %g1, %o0, %g7
10780 +
10781 +#ifdef CONFIG_PAX_REFCOUNT
10782 + tvs %xcc, 6
10783 +#endif
10784 +
10785 casx [%o1], %g1, %g7
10786 cmp %g1, %g7
10787 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10788 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10789 2: BACKOFF_SPIN(%o2, %o3, 1b)
10790 ENDPROC(atomic64_add)
10791
10792 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10793 + BACKOFF_SETUP(%o2)
10794 +1: ldx [%o1], %g1
10795 + addcc %g1, %o0, %g7
10796 + casx [%o1], %g1, %g7
10797 + cmp %g1, %g7
10798 + bne,pn %xcc, 2f
10799 + nop
10800 + retl
10801 + nop
10802 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10803 +ENDPROC(atomic64_add_unchecked)
10804 +
10805 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10806 BACKOFF_SETUP(%o2)
10807 1: ldx [%o1], %g1
10808 - sub %g1, %o0, %g7
10809 + subcc %g1, %o0, %g7
10810 +
10811 +#ifdef CONFIG_PAX_REFCOUNT
10812 + tvs %xcc, 6
10813 +#endif
10814 +
10815 casx [%o1], %g1, %g7
10816 cmp %g1, %g7
10817 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10818 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10819 2: BACKOFF_SPIN(%o2, %o3, 1b)
10820 ENDPROC(atomic64_sub)
10821
10822 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10823 + BACKOFF_SETUP(%o2)
10824 +1: ldx [%o1], %g1
10825 + subcc %g1, %o0, %g7
10826 + casx [%o1], %g1, %g7
10827 + cmp %g1, %g7
10828 + bne,pn %xcc, 2f
10829 + nop
10830 + retl
10831 + nop
10832 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10833 +ENDPROC(atomic64_sub_unchecked)
10834 +
10835 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10836 BACKOFF_SETUP(%o2)
10837 1: ldx [%o1], %g1
10838 - add %g1, %o0, %g7
10839 + addcc %g1, %o0, %g7
10840 +
10841 +#ifdef CONFIG_PAX_REFCOUNT
10842 + tvs %xcc, 6
10843 +#endif
10844 +
10845 casx [%o1], %g1, %g7
10846 cmp %g1, %g7
10847 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10848 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10849 2: BACKOFF_SPIN(%o2, %o3, 1b)
10850 ENDPROC(atomic64_add_ret)
10851
10852 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10853 + BACKOFF_SETUP(%o2)
10854 +1: ldx [%o1], %g1
10855 + addcc %g1, %o0, %g7
10856 + casx [%o1], %g1, %g7
10857 + cmp %g1, %g7
10858 + bne,pn %xcc, 2f
10859 + add %g7, %o0, %g7
10860 + mov %g7, %o0
10861 + retl
10862 + nop
10863 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10864 +ENDPROC(atomic64_add_ret_unchecked)
10865 +
10866 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10867 BACKOFF_SETUP(%o2)
10868 1: ldx [%o1], %g1
10869 - sub %g1, %o0, %g7
10870 + subcc %g1, %o0, %g7
10871 +
10872 +#ifdef CONFIG_PAX_REFCOUNT
10873 + tvs %xcc, 6
10874 +#endif
10875 +
10876 casx [%o1], %g1, %g7
10877 cmp %g1, %g7
10878 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10879 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10880 index 323335b..ed85ea2 100644
10881 --- a/arch/sparc/lib/ksyms.c
10882 +++ b/arch/sparc/lib/ksyms.c
10883 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10884
10885 /* Atomic counter implementation. */
10886 EXPORT_SYMBOL(atomic_add);
10887 +EXPORT_SYMBOL(atomic_add_unchecked);
10888 EXPORT_SYMBOL(atomic_add_ret);
10889 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10890 EXPORT_SYMBOL(atomic_sub);
10891 +EXPORT_SYMBOL(atomic_sub_unchecked);
10892 EXPORT_SYMBOL(atomic_sub_ret);
10893 EXPORT_SYMBOL(atomic64_add);
10894 +EXPORT_SYMBOL(atomic64_add_unchecked);
10895 EXPORT_SYMBOL(atomic64_add_ret);
10896 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10897 EXPORT_SYMBOL(atomic64_sub);
10898 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10899 EXPORT_SYMBOL(atomic64_sub_ret);
10900 EXPORT_SYMBOL(atomic64_dec_if_positive);
10901
10902 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10903 index 30c3ecc..736f015 100644
10904 --- a/arch/sparc/mm/Makefile
10905 +++ b/arch/sparc/mm/Makefile
10906 @@ -2,7 +2,7 @@
10907 #
10908
10909 asflags-y := -ansi
10910 -ccflags-y := -Werror
10911 +#ccflags-y := -Werror
10912
10913 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10914 obj-y += fault_$(BITS).o
10915 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10916 index 59dbd46..1dd7f5e 100644
10917 --- a/arch/sparc/mm/fault_32.c
10918 +++ b/arch/sparc/mm/fault_32.c
10919 @@ -21,6 +21,9 @@
10920 #include <linux/perf_event.h>
10921 #include <linux/interrupt.h>
10922 #include <linux/kdebug.h>
10923 +#include <linux/slab.h>
10924 +#include <linux/pagemap.h>
10925 +#include <linux/compiler.h>
10926
10927 #include <asm/page.h>
10928 #include <asm/pgtable.h>
10929 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10930 return safe_compute_effective_address(regs, insn);
10931 }
10932
10933 +#ifdef CONFIG_PAX_PAGEEXEC
10934 +#ifdef CONFIG_PAX_DLRESOLVE
10935 +static void pax_emuplt_close(struct vm_area_struct *vma)
10936 +{
10937 + vma->vm_mm->call_dl_resolve = 0UL;
10938 +}
10939 +
10940 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10941 +{
10942 + unsigned int *kaddr;
10943 +
10944 + vmf->page = alloc_page(GFP_HIGHUSER);
10945 + if (!vmf->page)
10946 + return VM_FAULT_OOM;
10947 +
10948 + kaddr = kmap(vmf->page);
10949 + memset(kaddr, 0, PAGE_SIZE);
10950 + kaddr[0] = 0x9DE3BFA8U; /* save */
10951 + flush_dcache_page(vmf->page);
10952 + kunmap(vmf->page);
10953 + return VM_FAULT_MAJOR;
10954 +}
10955 +
10956 +static const struct vm_operations_struct pax_vm_ops = {
10957 + .close = pax_emuplt_close,
10958 + .fault = pax_emuplt_fault
10959 +};
10960 +
10961 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10962 +{
10963 + int ret;
10964 +
10965 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10966 + vma->vm_mm = current->mm;
10967 + vma->vm_start = addr;
10968 + vma->vm_end = addr + PAGE_SIZE;
10969 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10970 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10971 + vma->vm_ops = &pax_vm_ops;
10972 +
10973 + ret = insert_vm_struct(current->mm, vma);
10974 + if (ret)
10975 + return ret;
10976 +
10977 + ++current->mm->total_vm;
10978 + return 0;
10979 +}
10980 +#endif
10981 +
10982 +/*
10983 + * PaX: decide what to do with offenders (regs->pc = fault address)
10984 + *
10985 + * returns 1 when task should be killed
10986 + * 2 when patched PLT trampoline was detected
10987 + * 3 when unpatched PLT trampoline was detected
10988 + */
10989 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10990 +{
10991 +
10992 +#ifdef CONFIG_PAX_EMUPLT
10993 + int err;
10994 +
10995 + do { /* PaX: patched PLT emulation #1 */
10996 + unsigned int sethi1, sethi2, jmpl;
10997 +
10998 + err = get_user(sethi1, (unsigned int *)regs->pc);
10999 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11000 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11001 +
11002 + if (err)
11003 + break;
11004 +
11005 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11006 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11007 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11008 + {
11009 + unsigned int addr;
11010 +
11011 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11012 + addr = regs->u_regs[UREG_G1];
11013 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11014 + regs->pc = addr;
11015 + regs->npc = addr+4;
11016 + return 2;
11017 + }
11018 + } while (0);
11019 +
11020 + do { /* PaX: patched PLT emulation #2 */
11021 + unsigned int ba;
11022 +
11023 + err = get_user(ba, (unsigned int *)regs->pc);
11024 +
11025 + if (err)
11026 + break;
11027 +
11028 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11029 + unsigned int addr;
11030 +
11031 + if ((ba & 0xFFC00000U) == 0x30800000U)
11032 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11033 + else
11034 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11035 + regs->pc = addr;
11036 + regs->npc = addr+4;
11037 + return 2;
11038 + }
11039 + } while (0);
11040 +
11041 + do { /* PaX: patched PLT emulation #3 */
11042 + unsigned int sethi, bajmpl, nop;
11043 +
11044 + err = get_user(sethi, (unsigned int *)regs->pc);
11045 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11046 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11047 +
11048 + if (err)
11049 + break;
11050 +
11051 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11052 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11053 + nop == 0x01000000U)
11054 + {
11055 + unsigned int addr;
11056 +
11057 + addr = (sethi & 0x003FFFFFU) << 10;
11058 + regs->u_regs[UREG_G1] = addr;
11059 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11060 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11061 + else
11062 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11063 + regs->pc = addr;
11064 + regs->npc = addr+4;
11065 + return 2;
11066 + }
11067 + } while (0);
11068 +
11069 + do { /* PaX: unpatched PLT emulation step 1 */
11070 + unsigned int sethi, ba, nop;
11071 +
11072 + err = get_user(sethi, (unsigned int *)regs->pc);
11073 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11074 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11075 +
11076 + if (err)
11077 + break;
11078 +
11079 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11080 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11081 + nop == 0x01000000U)
11082 + {
11083 + unsigned int addr, save, call;
11084 +
11085 + if ((ba & 0xFFC00000U) == 0x30800000U)
11086 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11087 + else
11088 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11089 +
11090 + err = get_user(save, (unsigned int *)addr);
11091 + err |= get_user(call, (unsigned int *)(addr+4));
11092 + err |= get_user(nop, (unsigned int *)(addr+8));
11093 + if (err)
11094 + break;
11095 +
11096 +#ifdef CONFIG_PAX_DLRESOLVE
11097 + if (save == 0x9DE3BFA8U &&
11098 + (call & 0xC0000000U) == 0x40000000U &&
11099 + nop == 0x01000000U)
11100 + {
11101 + struct vm_area_struct *vma;
11102 + unsigned long call_dl_resolve;
11103 +
11104 + down_read(&current->mm->mmap_sem);
11105 + call_dl_resolve = current->mm->call_dl_resolve;
11106 + up_read(&current->mm->mmap_sem);
11107 + if (likely(call_dl_resolve))
11108 + goto emulate;
11109 +
11110 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11111 +
11112 + down_write(&current->mm->mmap_sem);
11113 + if (current->mm->call_dl_resolve) {
11114 + call_dl_resolve = current->mm->call_dl_resolve;
11115 + up_write(&current->mm->mmap_sem);
11116 + if (vma)
11117 + kmem_cache_free(vm_area_cachep, vma);
11118 + goto emulate;
11119 + }
11120 +
11121 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11122 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11123 + up_write(&current->mm->mmap_sem);
11124 + if (vma)
11125 + kmem_cache_free(vm_area_cachep, vma);
11126 + return 1;
11127 + }
11128 +
11129 + if (pax_insert_vma(vma, call_dl_resolve)) {
11130 + up_write(&current->mm->mmap_sem);
11131 + kmem_cache_free(vm_area_cachep, vma);
11132 + return 1;
11133 + }
11134 +
11135 + current->mm->call_dl_resolve = call_dl_resolve;
11136 + up_write(&current->mm->mmap_sem);
11137 +
11138 +emulate:
11139 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11140 + regs->pc = call_dl_resolve;
11141 + regs->npc = addr+4;
11142 + return 3;
11143 + }
11144 +#endif
11145 +
11146 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11147 + if ((save & 0xFFC00000U) == 0x05000000U &&
11148 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11149 + nop == 0x01000000U)
11150 + {
11151 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11152 + regs->u_regs[UREG_G2] = addr + 4;
11153 + addr = (save & 0x003FFFFFU) << 10;
11154 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11155 + regs->pc = addr;
11156 + regs->npc = addr+4;
11157 + return 3;
11158 + }
11159 + }
11160 + } while (0);
11161 +
11162 + do { /* PaX: unpatched PLT emulation step 2 */
11163 + unsigned int save, call, nop;
11164 +
11165 + err = get_user(save, (unsigned int *)(regs->pc-4));
11166 + err |= get_user(call, (unsigned int *)regs->pc);
11167 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11168 + if (err)
11169 + break;
11170 +
11171 + if (save == 0x9DE3BFA8U &&
11172 + (call & 0xC0000000U) == 0x40000000U &&
11173 + nop == 0x01000000U)
11174 + {
11175 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11176 +
11177 + regs->u_regs[UREG_RETPC] = regs->pc;
11178 + regs->pc = dl_resolve;
11179 + regs->npc = dl_resolve+4;
11180 + return 3;
11181 + }
11182 + } while (0);
11183 +#endif
11184 +
11185 + return 1;
11186 +}
11187 +
11188 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11189 +{
11190 + unsigned long i;
11191 +
11192 + printk(KERN_ERR "PAX: bytes at PC: ");
11193 + for (i = 0; i < 8; i++) {
11194 + unsigned int c;
11195 + if (get_user(c, (unsigned int *)pc+i))
11196 + printk(KERN_CONT "???????? ");
11197 + else
11198 + printk(KERN_CONT "%08x ", c);
11199 + }
11200 + printk("\n");
11201 +}
11202 +#endif
11203 +
11204 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11205 int text_fault)
11206 {
11207 @@ -229,6 +503,24 @@ good_area:
11208 if (!(vma->vm_flags & VM_WRITE))
11209 goto bad_area;
11210 } else {
11211 +
11212 +#ifdef CONFIG_PAX_PAGEEXEC
11213 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11214 + up_read(&mm->mmap_sem);
11215 + switch (pax_handle_fetch_fault(regs)) {
11216 +
11217 +#ifdef CONFIG_PAX_EMUPLT
11218 + case 2:
11219 + case 3:
11220 + return;
11221 +#endif
11222 +
11223 + }
11224 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11225 + do_group_exit(SIGKILL);
11226 + }
11227 +#endif
11228 +
11229 /* Allow reads even for write-only mappings */
11230 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11231 goto bad_area;
11232 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11233 index 69bb818..6ca35c8 100644
11234 --- a/arch/sparc/mm/fault_64.c
11235 +++ b/arch/sparc/mm/fault_64.c
11236 @@ -22,6 +22,9 @@
11237 #include <linux/kdebug.h>
11238 #include <linux/percpu.h>
11239 #include <linux/context_tracking.h>
11240 +#include <linux/slab.h>
11241 +#include <linux/pagemap.h>
11242 +#include <linux/compiler.h>
11243
11244 #include <asm/page.h>
11245 #include <asm/pgtable.h>
11246 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11247 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11248 regs->tpc);
11249 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11250 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11251 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11252 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11253 dump_stack();
11254 unhandled_fault(regs->tpc, current, regs);
11255 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11256 show_regs(regs);
11257 }
11258
11259 +#ifdef CONFIG_PAX_PAGEEXEC
11260 +#ifdef CONFIG_PAX_DLRESOLVE
11261 +static void pax_emuplt_close(struct vm_area_struct *vma)
11262 +{
11263 + vma->vm_mm->call_dl_resolve = 0UL;
11264 +}
11265 +
11266 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11267 +{
11268 + unsigned int *kaddr;
11269 +
11270 + vmf->page = alloc_page(GFP_HIGHUSER);
11271 + if (!vmf->page)
11272 + return VM_FAULT_OOM;
11273 +
11274 + kaddr = kmap(vmf->page);
11275 + memset(kaddr, 0, PAGE_SIZE);
11276 + kaddr[0] = 0x9DE3BFA8U; /* save */
11277 + flush_dcache_page(vmf->page);
11278 + kunmap(vmf->page);
11279 + return VM_FAULT_MAJOR;
11280 +}
11281 +
11282 +static const struct vm_operations_struct pax_vm_ops = {
11283 + .close = pax_emuplt_close,
11284 + .fault = pax_emuplt_fault
11285 +};
11286 +
11287 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11288 +{
11289 + int ret;
11290 +
11291 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11292 + vma->vm_mm = current->mm;
11293 + vma->vm_start = addr;
11294 + vma->vm_end = addr + PAGE_SIZE;
11295 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11296 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11297 + vma->vm_ops = &pax_vm_ops;
11298 +
11299 + ret = insert_vm_struct(current->mm, vma);
11300 + if (ret)
11301 + return ret;
11302 +
11303 + ++current->mm->total_vm;
11304 + return 0;
11305 +}
11306 +#endif
11307 +
11308 +/*
11309 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11310 + *
11311 + * returns 1 when task should be killed
11312 + * 2 when patched PLT trampoline was detected
11313 + * 3 when unpatched PLT trampoline was detected
11314 + */
11315 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11316 +{
11317 +
11318 +#ifdef CONFIG_PAX_EMUPLT
11319 + int err;
11320 +
11321 + do { /* PaX: patched PLT emulation #1 */
11322 + unsigned int sethi1, sethi2, jmpl;
11323 +
11324 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11325 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11326 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11327 +
11328 + if (err)
11329 + break;
11330 +
11331 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11332 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11333 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11334 + {
11335 + unsigned long addr;
11336 +
11337 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11338 + addr = regs->u_regs[UREG_G1];
11339 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11340 +
11341 + if (test_thread_flag(TIF_32BIT))
11342 + addr &= 0xFFFFFFFFUL;
11343 +
11344 + regs->tpc = addr;
11345 + regs->tnpc = addr+4;
11346 + return 2;
11347 + }
11348 + } while (0);
11349 +
11350 + do { /* PaX: patched PLT emulation #2 */
11351 + unsigned int ba;
11352 +
11353 + err = get_user(ba, (unsigned int *)regs->tpc);
11354 +
11355 + if (err)
11356 + break;
11357 +
11358 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11359 + unsigned long addr;
11360 +
11361 + if ((ba & 0xFFC00000U) == 0x30800000U)
11362 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11363 + else
11364 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11365 +
11366 + if (test_thread_flag(TIF_32BIT))
11367 + addr &= 0xFFFFFFFFUL;
11368 +
11369 + regs->tpc = addr;
11370 + regs->tnpc = addr+4;
11371 + return 2;
11372 + }
11373 + } while (0);
11374 +
11375 + do { /* PaX: patched PLT emulation #3 */
11376 + unsigned int sethi, bajmpl, nop;
11377 +
11378 + err = get_user(sethi, (unsigned int *)regs->tpc);
11379 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11380 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11381 +
11382 + if (err)
11383 + break;
11384 +
11385 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11386 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11387 + nop == 0x01000000U)
11388 + {
11389 + unsigned long addr;
11390 +
11391 + addr = (sethi & 0x003FFFFFU) << 10;
11392 + regs->u_regs[UREG_G1] = addr;
11393 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11394 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11395 + else
11396 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11397 +
11398 + if (test_thread_flag(TIF_32BIT))
11399 + addr &= 0xFFFFFFFFUL;
11400 +
11401 + regs->tpc = addr;
11402 + regs->tnpc = addr+4;
11403 + return 2;
11404 + }
11405 + } while (0);
11406 +
11407 + do { /* PaX: patched PLT emulation #4 */
11408 + unsigned int sethi, mov1, call, mov2;
11409 +
11410 + err = get_user(sethi, (unsigned int *)regs->tpc);
11411 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11412 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11413 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11414 +
11415 + if (err)
11416 + break;
11417 +
11418 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11419 + mov1 == 0x8210000FU &&
11420 + (call & 0xC0000000U) == 0x40000000U &&
11421 + mov2 == 0x9E100001U)
11422 + {
11423 + unsigned long addr;
11424 +
11425 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11426 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11427 +
11428 + if (test_thread_flag(TIF_32BIT))
11429 + addr &= 0xFFFFFFFFUL;
11430 +
11431 + regs->tpc = addr;
11432 + regs->tnpc = addr+4;
11433 + return 2;
11434 + }
11435 + } while (0);
11436 +
11437 + do { /* PaX: patched PLT emulation #5 */
11438 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11439 +
11440 + err = get_user(sethi, (unsigned int *)regs->tpc);
11441 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11442 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11443 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11444 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11445 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11446 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11447 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11448 +
11449 + if (err)
11450 + break;
11451 +
11452 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11453 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11454 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11455 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11456 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11457 + sllx == 0x83287020U &&
11458 + jmpl == 0x81C04005U &&
11459 + nop == 0x01000000U)
11460 + {
11461 + unsigned long addr;
11462 +
11463 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11464 + regs->u_regs[UREG_G1] <<= 32;
11465 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11466 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11467 + regs->tpc = addr;
11468 + regs->tnpc = addr+4;
11469 + return 2;
11470 + }
11471 + } while (0);
11472 +
11473 + do { /* PaX: patched PLT emulation #6 */
11474 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11475 +
11476 + err = get_user(sethi, (unsigned int *)regs->tpc);
11477 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11478 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11479 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11480 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11481 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11482 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11483 +
11484 + if (err)
11485 + break;
11486 +
11487 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11488 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11489 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11490 + sllx == 0x83287020U &&
11491 + (or & 0xFFFFE000U) == 0x8A116000U &&
11492 + jmpl == 0x81C04005U &&
11493 + nop == 0x01000000U)
11494 + {
11495 + unsigned long addr;
11496 +
11497 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11498 + regs->u_regs[UREG_G1] <<= 32;
11499 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11500 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11501 + regs->tpc = addr;
11502 + regs->tnpc = addr+4;
11503 + return 2;
11504 + }
11505 + } while (0);
11506 +
11507 + do { /* PaX: unpatched PLT emulation step 1 */
11508 + unsigned int sethi, ba, nop;
11509 +
11510 + err = get_user(sethi, (unsigned int *)regs->tpc);
11511 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11512 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11513 +
11514 + if (err)
11515 + break;
11516 +
11517 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11518 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11519 + nop == 0x01000000U)
11520 + {
11521 + unsigned long addr;
11522 + unsigned int save, call;
11523 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11524 +
11525 + if ((ba & 0xFFC00000U) == 0x30800000U)
11526 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11527 + else
11528 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11529 +
11530 + if (test_thread_flag(TIF_32BIT))
11531 + addr &= 0xFFFFFFFFUL;
11532 +
11533 + err = get_user(save, (unsigned int *)addr);
11534 + err |= get_user(call, (unsigned int *)(addr+4));
11535 + err |= get_user(nop, (unsigned int *)(addr+8));
11536 + if (err)
11537 + break;
11538 +
11539 +#ifdef CONFIG_PAX_DLRESOLVE
11540 + if (save == 0x9DE3BFA8U &&
11541 + (call & 0xC0000000U) == 0x40000000U &&
11542 + nop == 0x01000000U)
11543 + {
11544 + struct vm_area_struct *vma;
11545 + unsigned long call_dl_resolve;
11546 +
11547 + down_read(&current->mm->mmap_sem);
11548 + call_dl_resolve = current->mm->call_dl_resolve;
11549 + up_read(&current->mm->mmap_sem);
11550 + if (likely(call_dl_resolve))
11551 + goto emulate;
11552 +
11553 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11554 +
11555 + down_write(&current->mm->mmap_sem);
11556 + if (current->mm->call_dl_resolve) {
11557 + call_dl_resolve = current->mm->call_dl_resolve;
11558 + up_write(&current->mm->mmap_sem);
11559 + if (vma)
11560 + kmem_cache_free(vm_area_cachep, vma);
11561 + goto emulate;
11562 + }
11563 +
11564 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11565 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11566 + up_write(&current->mm->mmap_sem);
11567 + if (vma)
11568 + kmem_cache_free(vm_area_cachep, vma);
11569 + return 1;
11570 + }
11571 +
11572 + if (pax_insert_vma(vma, call_dl_resolve)) {
11573 + up_write(&current->mm->mmap_sem);
11574 + kmem_cache_free(vm_area_cachep, vma);
11575 + return 1;
11576 + }
11577 +
11578 + current->mm->call_dl_resolve = call_dl_resolve;
11579 + up_write(&current->mm->mmap_sem);
11580 +
11581 +emulate:
11582 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11583 + regs->tpc = call_dl_resolve;
11584 + regs->tnpc = addr+4;
11585 + return 3;
11586 + }
11587 +#endif
11588 +
11589 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11590 + if ((save & 0xFFC00000U) == 0x05000000U &&
11591 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11592 + nop == 0x01000000U)
11593 + {
11594 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11595 + regs->u_regs[UREG_G2] = addr + 4;
11596 + addr = (save & 0x003FFFFFU) << 10;
11597 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11598 +
11599 + if (test_thread_flag(TIF_32BIT))
11600 + addr &= 0xFFFFFFFFUL;
11601 +
11602 + regs->tpc = addr;
11603 + regs->tnpc = addr+4;
11604 + return 3;
11605 + }
11606 +
11607 + /* PaX: 64-bit PLT stub */
11608 + err = get_user(sethi1, (unsigned int *)addr);
11609 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11610 + err |= get_user(or1, (unsigned int *)(addr+8));
11611 + err |= get_user(or2, (unsigned int *)(addr+12));
11612 + err |= get_user(sllx, (unsigned int *)(addr+16));
11613 + err |= get_user(add, (unsigned int *)(addr+20));
11614 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11615 + err |= get_user(nop, (unsigned int *)(addr+28));
11616 + if (err)
11617 + break;
11618 +
11619 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11620 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11621 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11622 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11623 + sllx == 0x89293020U &&
11624 + add == 0x8A010005U &&
11625 + jmpl == 0x89C14000U &&
11626 + nop == 0x01000000U)
11627 + {
11628 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11629 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11630 + regs->u_regs[UREG_G4] <<= 32;
11631 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11632 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11633 + regs->u_regs[UREG_G4] = addr + 24;
11634 + addr = regs->u_regs[UREG_G5];
11635 + regs->tpc = addr;
11636 + regs->tnpc = addr+4;
11637 + return 3;
11638 + }
11639 + }
11640 + } while (0);
11641 +
11642 +#ifdef CONFIG_PAX_DLRESOLVE
11643 + do { /* PaX: unpatched PLT emulation step 2 */
11644 + unsigned int save, call, nop;
11645 +
11646 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11647 + err |= get_user(call, (unsigned int *)regs->tpc);
11648 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11649 + if (err)
11650 + break;
11651 +
11652 + if (save == 0x9DE3BFA8U &&
11653 + (call & 0xC0000000U) == 0x40000000U &&
11654 + nop == 0x01000000U)
11655 + {
11656 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11657 +
11658 + if (test_thread_flag(TIF_32BIT))
11659 + dl_resolve &= 0xFFFFFFFFUL;
11660 +
11661 + regs->u_regs[UREG_RETPC] = regs->tpc;
11662 + regs->tpc = dl_resolve;
11663 + regs->tnpc = dl_resolve+4;
11664 + return 3;
11665 + }
11666 + } while (0);
11667 +#endif
11668 +
11669 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11670 + unsigned int sethi, ba, nop;
11671 +
11672 + err = get_user(sethi, (unsigned int *)regs->tpc);
11673 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11674 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11675 +
11676 + if (err)
11677 + break;
11678 +
11679 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11680 + (ba & 0xFFF00000U) == 0x30600000U &&
11681 + nop == 0x01000000U)
11682 + {
11683 + unsigned long addr;
11684 +
11685 + addr = (sethi & 0x003FFFFFU) << 10;
11686 + regs->u_regs[UREG_G1] = addr;
11687 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11688 +
11689 + if (test_thread_flag(TIF_32BIT))
11690 + addr &= 0xFFFFFFFFUL;
11691 +
11692 + regs->tpc = addr;
11693 + regs->tnpc = addr+4;
11694 + return 2;
11695 + }
11696 + } while (0);
11697 +
11698 +#endif
11699 +
11700 + return 1;
11701 +}
11702 +
11703 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11704 +{
11705 + unsigned long i;
11706 +
11707 + printk(KERN_ERR "PAX: bytes at PC: ");
11708 + for (i = 0; i < 8; i++) {
11709 + unsigned int c;
11710 + if (get_user(c, (unsigned int *)pc+i))
11711 + printk(KERN_CONT "???????? ");
11712 + else
11713 + printk(KERN_CONT "%08x ", c);
11714 + }
11715 + printk("\n");
11716 +}
11717 +#endif
11718 +
11719 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11720 {
11721 enum ctx_state prev_state = exception_enter();
11722 @@ -344,6 +807,29 @@ retry:
11723 if (!vma)
11724 goto bad_area;
11725
11726 +#ifdef CONFIG_PAX_PAGEEXEC
11727 + /* PaX: detect ITLB misses on non-exec pages */
11728 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11729 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11730 + {
11731 + if (address != regs->tpc)
11732 + goto good_area;
11733 +
11734 + up_read(&mm->mmap_sem);
11735 + switch (pax_handle_fetch_fault(regs)) {
11736 +
11737 +#ifdef CONFIG_PAX_EMUPLT
11738 + case 2:
11739 + case 3:
11740 + return;
11741 +#endif
11742 +
11743 + }
11744 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11745 + do_group_exit(SIGKILL);
11746 + }
11747 +#endif
11748 +
11749 /* Pure DTLB misses do not tell us whether the fault causing
11750 * load/store/atomic was a write or not, it only says that there
11751 * was no match. So in such a case we (carefully) read the
11752 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11753 index 9bd9ce8..dc84852 100644
11754 --- a/arch/sparc/mm/hugetlbpage.c
11755 +++ b/arch/sparc/mm/hugetlbpage.c
11756 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11757 unsigned long addr,
11758 unsigned long len,
11759 unsigned long pgoff,
11760 - unsigned long flags)
11761 + unsigned long flags,
11762 + unsigned long offset)
11763 {
11764 + struct mm_struct *mm = current->mm;
11765 unsigned long task_size = TASK_SIZE;
11766 struct vm_unmapped_area_info info;
11767
11768 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11769
11770 info.flags = 0;
11771 info.length = len;
11772 - info.low_limit = TASK_UNMAPPED_BASE;
11773 + info.low_limit = mm->mmap_base;
11774 info.high_limit = min(task_size, VA_EXCLUDE_START);
11775 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11776 info.align_offset = 0;
11777 + info.threadstack_offset = offset;
11778 addr = vm_unmapped_area(&info);
11779
11780 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11781 VM_BUG_ON(addr != -ENOMEM);
11782 info.low_limit = VA_EXCLUDE_END;
11783 +
11784 +#ifdef CONFIG_PAX_RANDMMAP
11785 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11786 + info.low_limit += mm->delta_mmap;
11787 +#endif
11788 +
11789 info.high_limit = task_size;
11790 addr = vm_unmapped_area(&info);
11791 }
11792 @@ -55,7 +64,8 @@ static unsigned long
11793 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11794 const unsigned long len,
11795 const unsigned long pgoff,
11796 - const unsigned long flags)
11797 + const unsigned long flags,
11798 + const unsigned long offset)
11799 {
11800 struct mm_struct *mm = current->mm;
11801 unsigned long addr = addr0;
11802 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11803 info.high_limit = mm->mmap_base;
11804 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11805 info.align_offset = 0;
11806 + info.threadstack_offset = offset;
11807 addr = vm_unmapped_area(&info);
11808
11809 /*
11810 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11811 VM_BUG_ON(addr != -ENOMEM);
11812 info.flags = 0;
11813 info.low_limit = TASK_UNMAPPED_BASE;
11814 +
11815 +#ifdef CONFIG_PAX_RANDMMAP
11816 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11817 + info.low_limit += mm->delta_mmap;
11818 +#endif
11819 +
11820 info.high_limit = STACK_TOP32;
11821 addr = vm_unmapped_area(&info);
11822 }
11823 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11824 struct mm_struct *mm = current->mm;
11825 struct vm_area_struct *vma;
11826 unsigned long task_size = TASK_SIZE;
11827 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11828
11829 if (test_thread_flag(TIF_32BIT))
11830 task_size = STACK_TOP32;
11831 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11832 return addr;
11833 }
11834
11835 +#ifdef CONFIG_PAX_RANDMMAP
11836 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11837 +#endif
11838 +
11839 if (addr) {
11840 addr = ALIGN(addr, HPAGE_SIZE);
11841 vma = find_vma(mm, addr);
11842 - if (task_size - len >= addr &&
11843 - (!vma || addr + len <= vma->vm_start))
11844 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11845 return addr;
11846 }
11847 if (mm->get_unmapped_area == arch_get_unmapped_area)
11848 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11849 - pgoff, flags);
11850 + pgoff, flags, offset);
11851 else
11852 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11853 - pgoff, flags);
11854 + pgoff, flags, offset);
11855 }
11856
11857 pte_t *huge_pte_alloc(struct mm_struct *mm,
11858 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11859 index eafbc65..5a8070d 100644
11860 --- a/arch/sparc/mm/init_64.c
11861 +++ b/arch/sparc/mm/init_64.c
11862 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11863 int num_kernel_image_mappings;
11864
11865 #ifdef CONFIG_DEBUG_DCFLUSH
11866 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11867 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11868 #ifdef CONFIG_SMP
11869 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11870 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11871 #endif
11872 #endif
11873
11874 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11875 {
11876 BUG_ON(tlb_type == hypervisor);
11877 #ifdef CONFIG_DEBUG_DCFLUSH
11878 - atomic_inc(&dcpage_flushes);
11879 + atomic_inc_unchecked(&dcpage_flushes);
11880 #endif
11881
11882 #ifdef DCACHE_ALIASING_POSSIBLE
11883 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11884
11885 #ifdef CONFIG_DEBUG_DCFLUSH
11886 seq_printf(m, "DCPageFlushes\t: %d\n",
11887 - atomic_read(&dcpage_flushes));
11888 + atomic_read_unchecked(&dcpage_flushes));
11889 #ifdef CONFIG_SMP
11890 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11891 - atomic_read(&dcpage_flushes_xcall));
11892 + atomic_read_unchecked(&dcpage_flushes_xcall));
11893 #endif /* CONFIG_SMP */
11894 #endif /* CONFIG_DEBUG_DCFLUSH */
11895 }
11896 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11897 index b3692ce..e4517c9 100644
11898 --- a/arch/tile/Kconfig
11899 +++ b/arch/tile/Kconfig
11900 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11901
11902 config KEXEC
11903 bool "kexec system call"
11904 + depends on !GRKERNSEC_KMEM
11905 ---help---
11906 kexec is a system call that implements the ability to shutdown your
11907 current kernel, and to start another kernel. It is like a reboot
11908 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11909 index ad220ee..2f537b3 100644
11910 --- a/arch/tile/include/asm/atomic_64.h
11911 +++ b/arch/tile/include/asm/atomic_64.h
11912 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11913
11914 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11915
11916 +#define atomic64_read_unchecked(v) atomic64_read(v)
11917 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11918 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11919 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11920 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11921 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11922 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11923 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11924 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11925 +
11926 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11927 #define smp_mb__before_atomic_dec() smp_mb()
11928 #define smp_mb__after_atomic_dec() smp_mb()
11929 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11930 index 6160761..00cac88 100644
11931 --- a/arch/tile/include/asm/cache.h
11932 +++ b/arch/tile/include/asm/cache.h
11933 @@ -15,11 +15,12 @@
11934 #ifndef _ASM_TILE_CACHE_H
11935 #define _ASM_TILE_CACHE_H
11936
11937 +#include <linux/const.h>
11938 #include <arch/chip.h>
11939
11940 /* bytes per L1 data cache line */
11941 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11942 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11943 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11944
11945 /* bytes per L2 cache line */
11946 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11947 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11948 index b6cde32..c0cb736 100644
11949 --- a/arch/tile/include/asm/uaccess.h
11950 +++ b/arch/tile/include/asm/uaccess.h
11951 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11952 const void __user *from,
11953 unsigned long n)
11954 {
11955 - int sz = __compiletime_object_size(to);
11956 + size_t sz = __compiletime_object_size(to);
11957
11958 - if (likely(sz == -1 || sz >= n))
11959 + if (likely(sz == (size_t)-1 || sz >= n))
11960 n = _copy_from_user(to, from, n);
11961 else
11962 copy_from_user_overflow();
11963 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11964 index 0cb3bba..7338b2d 100644
11965 --- a/arch/tile/mm/hugetlbpage.c
11966 +++ b/arch/tile/mm/hugetlbpage.c
11967 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11968 info.high_limit = TASK_SIZE;
11969 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11970 info.align_offset = 0;
11971 + info.threadstack_offset = 0;
11972 return vm_unmapped_area(&info);
11973 }
11974
11975 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11976 info.high_limit = current->mm->mmap_base;
11977 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11978 info.align_offset = 0;
11979 + info.threadstack_offset = 0;
11980 addr = vm_unmapped_area(&info);
11981
11982 /*
11983 diff --git a/arch/um/Makefile b/arch/um/Makefile
11984 index 36e658a..71a5c5a 100644
11985 --- a/arch/um/Makefile
11986 +++ b/arch/um/Makefile
11987 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11988 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11989 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11990
11991 +ifdef CONSTIFY_PLUGIN
11992 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11993 +endif
11994 +
11995 #This will adjust *FLAGS accordingly to the platform.
11996 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11997
11998 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11999 index 19e1bdd..3665b77 100644
12000 --- a/arch/um/include/asm/cache.h
12001 +++ b/arch/um/include/asm/cache.h
12002 @@ -1,6 +1,7 @@
12003 #ifndef __UM_CACHE_H
12004 #define __UM_CACHE_H
12005
12006 +#include <linux/const.h>
12007
12008 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12009 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12010 @@ -12,6 +13,6 @@
12011 # define L1_CACHE_SHIFT 5
12012 #endif
12013
12014 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12015 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12016
12017 #endif
12018 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12019 index 2e0a6b1..a64d0f5 100644
12020 --- a/arch/um/include/asm/kmap_types.h
12021 +++ b/arch/um/include/asm/kmap_types.h
12022 @@ -8,6 +8,6 @@
12023
12024 /* No more #include "asm/arch/kmap_types.h" ! */
12025
12026 -#define KM_TYPE_NR 14
12027 +#define KM_TYPE_NR 15
12028
12029 #endif
12030 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12031 index 5ff53d9..5850cdf 100644
12032 --- a/arch/um/include/asm/page.h
12033 +++ b/arch/um/include/asm/page.h
12034 @@ -14,6 +14,9 @@
12035 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12036 #define PAGE_MASK (~(PAGE_SIZE-1))
12037
12038 +#define ktla_ktva(addr) (addr)
12039 +#define ktva_ktla(addr) (addr)
12040 +
12041 #ifndef __ASSEMBLY__
12042
12043 struct page;
12044 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12045 index 0032f92..cd151e0 100644
12046 --- a/arch/um/include/asm/pgtable-3level.h
12047 +++ b/arch/um/include/asm/pgtable-3level.h
12048 @@ -58,6 +58,7 @@
12049 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12050 #define pud_populate(mm, pud, pmd) \
12051 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12052 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12053
12054 #ifdef CONFIG_64BIT
12055 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12056 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12057 index eecc414..48adb87 100644
12058 --- a/arch/um/kernel/process.c
12059 +++ b/arch/um/kernel/process.c
12060 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12061 return 2;
12062 }
12063
12064 -/*
12065 - * Only x86 and x86_64 have an arch_align_stack().
12066 - * All other arches have "#define arch_align_stack(x) (x)"
12067 - * in their asm/system.h
12068 - * As this is included in UML from asm-um/system-generic.h,
12069 - * we can use it to behave as the subarch does.
12070 - */
12071 -#ifndef arch_align_stack
12072 -unsigned long arch_align_stack(unsigned long sp)
12073 -{
12074 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12075 - sp -= get_random_int() % 8192;
12076 - return sp & ~0xf;
12077 -}
12078 -#endif
12079 -
12080 unsigned long get_wchan(struct task_struct *p)
12081 {
12082 unsigned long stack_page, sp, ip;
12083 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12084 index ad8f795..2c7eec6 100644
12085 --- a/arch/unicore32/include/asm/cache.h
12086 +++ b/arch/unicore32/include/asm/cache.h
12087 @@ -12,8 +12,10 @@
12088 #ifndef __UNICORE_CACHE_H__
12089 #define __UNICORE_CACHE_H__
12090
12091 -#define L1_CACHE_SHIFT (5)
12092 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12093 +#include <linux/const.h>
12094 +
12095 +#define L1_CACHE_SHIFT 5
12096 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12097
12098 /*
12099 * Memory returned by kmalloc() may be used for DMA, so we must make
12100 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12101 index 0af5250..59f9597 100644
12102 --- a/arch/x86/Kconfig
12103 +++ b/arch/x86/Kconfig
12104 @@ -126,7 +126,7 @@ config X86
12105 select RTC_LIB
12106 select HAVE_DEBUG_STACKOVERFLOW
12107 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12108 - select HAVE_CC_STACKPROTECTOR
12109 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12110
12111 config INSTRUCTION_DECODER
12112 def_bool y
12113 @@ -251,7 +251,7 @@ config X86_HT
12114
12115 config X86_32_LAZY_GS
12116 def_bool y
12117 - depends on X86_32 && !CC_STACKPROTECTOR
12118 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12119
12120 config ARCH_HWEIGHT_CFLAGS
12121 string
12122 @@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12123
12124 menuconfig HYPERVISOR_GUEST
12125 bool "Linux guest support"
12126 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12127 ---help---
12128 Say Y here to enable options for running Linux under various hyper-
12129 visors. This option enables basic hypervisor detection and platform
12130 @@ -1111,7 +1112,7 @@ choice
12131
12132 config NOHIGHMEM
12133 bool "off"
12134 - depends on !X86_NUMAQ
12135 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12136 ---help---
12137 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12138 However, the address space of 32-bit x86 processors is only 4
12139 @@ -1148,7 +1149,7 @@ config NOHIGHMEM
12140
12141 config HIGHMEM4G
12142 bool "4GB"
12143 - depends on !X86_NUMAQ
12144 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12145 ---help---
12146 Select this if you have a 32-bit processor and between 1 and 4
12147 gigabytes of physical RAM.
12148 @@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12149 hex
12150 default 0xB0000000 if VMSPLIT_3G_OPT
12151 default 0x80000000 if VMSPLIT_2G
12152 - default 0x78000000 if VMSPLIT_2G_OPT
12153 + default 0x70000000 if VMSPLIT_2G_OPT
12154 default 0x40000000 if VMSPLIT_1G
12155 default 0xC0000000
12156 depends on X86_32
12157 @@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12158
12159 config KEXEC
12160 bool "kexec system call"
12161 + depends on !GRKERNSEC_KMEM
12162 ---help---
12163 kexec is a system call that implements the ability to shutdown your
12164 current kernel, and to start another kernel. It is like a reboot
12165 @@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12166
12167 config PHYSICAL_ALIGN
12168 hex "Alignment value to which kernel should be aligned"
12169 - default "0x200000"
12170 + default "0x1000000"
12171 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12172 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12173 range 0x2000 0x1000000 if X86_32
12174 range 0x200000 0x1000000 if X86_64
12175 ---help---
12176 @@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12177 If unsure, say N.
12178
12179 config COMPAT_VDSO
12180 - def_bool y
12181 + def_bool n
12182 prompt "Compat VDSO support"
12183 depends on X86_32 || IA32_EMULATION
12184 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12185 ---help---
12186 Map the 32-bit VDSO to the predictable old-style address too.
12187
12188 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12189 index f3aaf23..a1d3c49 100644
12190 --- a/arch/x86/Kconfig.cpu
12191 +++ b/arch/x86/Kconfig.cpu
12192 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12193
12194 config X86_F00F_BUG
12195 def_bool y
12196 - depends on M586MMX || M586TSC || M586 || M486
12197 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12198
12199 config X86_INVD_BUG
12200 def_bool y
12201 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12202
12203 config X86_ALIGNMENT_16
12204 def_bool y
12205 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12206 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12207
12208 config X86_INTEL_USERCOPY
12209 def_bool y
12210 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12211 # generates cmov.
12212 config X86_CMOV
12213 def_bool y
12214 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12215 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12216
12217 config X86_MINIMUM_CPU_FAMILY
12218 int
12219 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12220 index 321a52c..3d51a5e 100644
12221 --- a/arch/x86/Kconfig.debug
12222 +++ b/arch/x86/Kconfig.debug
12223 @@ -84,7 +84,7 @@ config X86_PTDUMP
12224 config DEBUG_RODATA
12225 bool "Write protect kernel read-only data structures"
12226 default y
12227 - depends on DEBUG_KERNEL
12228 + depends on DEBUG_KERNEL && BROKEN
12229 ---help---
12230 Mark the kernel read-only data as write-protected in the pagetables,
12231 in order to catch accidental (and incorrect) writes to such const
12232 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12233
12234 config DEBUG_SET_MODULE_RONX
12235 bool "Set loadable kernel module data as NX and text as RO"
12236 - depends on MODULES
12237 + depends on MODULES && BROKEN
12238 ---help---
12239 This option helps catch unintended modifications to loadable
12240 kernel module's text and read-only data. It also prevents execution
12241 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12242 index eeda43a..5a238be 100644
12243 --- a/arch/x86/Makefile
12244 +++ b/arch/x86/Makefile
12245 @@ -71,14 +71,12 @@ ifeq ($(CONFIG_X86_32),y)
12246 # CPU-specific tuning. Anything which can be shared with UML should go here.
12247 include $(srctree)/arch/x86/Makefile_32.cpu
12248 KBUILD_CFLAGS += $(cflags-y)
12249 -
12250 - # temporary until string.h is fixed
12251 - KBUILD_CFLAGS += -ffreestanding
12252 else
12253 BITS := 64
12254 UTS_MACHINE := x86_64
12255 CHECKFLAGS += -D__x86_64__ -m64
12256
12257 + biarch := $(call cc-option,-m64)
12258 KBUILD_AFLAGS += -m64
12259 KBUILD_CFLAGS += -m64
12260
12261 @@ -111,6 +109,9 @@ else
12262 KBUILD_CFLAGS += -maccumulate-outgoing-args
12263 endif
12264
12265 +# temporary until string.h is fixed
12266 +KBUILD_CFLAGS += -ffreestanding
12267 +
12268 # Make sure compiler does not have buggy stack-protector support.
12269 ifdef CONFIG_CC_STACKPROTECTOR
12270 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12271 @@ -267,3 +268,12 @@ define archhelp
12272 echo ' FDINITRD=file initrd for the booted kernel'
12273 echo ' kvmconfig - Enable additional options for guest kernel support'
12274 endef
12275 +
12276 +define OLD_LD
12277 +
12278 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12279 +*** Please upgrade your binutils to 2.18 or newer
12280 +endef
12281 +
12282 +archprepare:
12283 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12284 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12285 index 878df7e..a803913 100644
12286 --- a/arch/x86/boot/Makefile
12287 +++ b/arch/x86/boot/Makefile
12288 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12289 # ---------------------------------------------------------------------------
12290
12291 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12292 +ifdef CONSTIFY_PLUGIN
12293 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12294 +endif
12295 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12296 GCOV_PROFILE := n
12297
12298 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12299 index 878e4b9..20537ab 100644
12300 --- a/arch/x86/boot/bitops.h
12301 +++ b/arch/x86/boot/bitops.h
12302 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12303 u8 v;
12304 const u32 *p = (const u32 *)addr;
12305
12306 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12307 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12308 return v;
12309 }
12310
12311 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12312
12313 static inline void set_bit(int nr, void *addr)
12314 {
12315 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12316 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12317 }
12318
12319 #endif /* BOOT_BITOPS_H */
12320 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12321 index 50f8c5e..4f84fff 100644
12322 --- a/arch/x86/boot/boot.h
12323 +++ b/arch/x86/boot/boot.h
12324 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12325 static inline u16 ds(void)
12326 {
12327 u16 seg;
12328 - asm("movw %%ds,%0" : "=rm" (seg));
12329 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12330 return seg;
12331 }
12332
12333 @@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12334 static inline int memcmp(const void *s1, const void *s2, size_t len)
12335 {
12336 u8 diff;
12337 - asm("repe; cmpsb; setnz %0"
12338 + asm volatile("repe; cmpsb; setnz %0"
12339 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12340 return diff;
12341 }
12342 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12343 index 0fcd913..3bb5c42 100644
12344 --- a/arch/x86/boot/compressed/Makefile
12345 +++ b/arch/x86/boot/compressed/Makefile
12346 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12347 KBUILD_CFLAGS += -mno-mmx -mno-sse
12348 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12349 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12350 +ifdef CONSTIFY_PLUGIN
12351 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12352 +endif
12353
12354 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12355 GCOV_PROFILE := n
12356 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12357 index a53440e..c3dbf1e 100644
12358 --- a/arch/x86/boot/compressed/efi_stub_32.S
12359 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12360 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12361 * parameter 2, ..., param n. To make things easy, we save the return
12362 * address of efi_call_phys in a global variable.
12363 */
12364 - popl %ecx
12365 - movl %ecx, saved_return_addr(%edx)
12366 - /* get the function pointer into ECX*/
12367 - popl %ecx
12368 - movl %ecx, efi_rt_function_ptr(%edx)
12369 + popl saved_return_addr(%edx)
12370 + popl efi_rt_function_ptr(%edx)
12371
12372 /*
12373 * 3. Call the physical function.
12374 */
12375 - call *%ecx
12376 + call *efi_rt_function_ptr(%edx)
12377
12378 /*
12379 * 4. Balance the stack. And because EAX contain the return value,
12380 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12381 1: popl %edx
12382 subl $1b, %edx
12383
12384 - movl efi_rt_function_ptr(%edx), %ecx
12385 - pushl %ecx
12386 + pushl efi_rt_function_ptr(%edx)
12387
12388 /*
12389 * 10. Push the saved return address onto the stack and return.
12390 */
12391 - movl saved_return_addr(%edx), %ecx
12392 - pushl %ecx
12393 - ret
12394 + jmpl *saved_return_addr(%edx)
12395 ENDPROC(efi_call_phys)
12396 .previous
12397
12398 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12399 index 9116aac..abbcdb1 100644
12400 --- a/arch/x86/boot/compressed/head_32.S
12401 +++ b/arch/x86/boot/compressed/head_32.S
12402 @@ -117,10 +117,10 @@ preferred_addr:
12403 addl %eax, %ebx
12404 notl %eax
12405 andl %eax, %ebx
12406 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12407 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12408 jge 1f
12409 #endif
12410 - movl $LOAD_PHYSICAL_ADDR, %ebx
12411 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12412 1:
12413
12414 /* Target address to relocate to for decompression */
12415 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12416 index c5c1ae0..2e76d0e 100644
12417 --- a/arch/x86/boot/compressed/head_64.S
12418 +++ b/arch/x86/boot/compressed/head_64.S
12419 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12420 addl %eax, %ebx
12421 notl %eax
12422 andl %eax, %ebx
12423 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12424 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12425 jge 1f
12426 #endif
12427 - movl $LOAD_PHYSICAL_ADDR, %ebx
12428 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12429 1:
12430
12431 /* Target address to relocate to for decompression */
12432 @@ -271,10 +271,10 @@ preferred_addr:
12433 addq %rax, %rbp
12434 notq %rax
12435 andq %rax, %rbp
12436 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12437 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12438 jge 1f
12439 #endif
12440 - movq $LOAD_PHYSICAL_ADDR, %rbp
12441 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12442 1:
12443
12444 /* Target address to relocate to for decompression */
12445 @@ -366,8 +366,8 @@ gdt:
12446 .long gdt
12447 .word 0
12448 .quad 0x0000000000000000 /* NULL descriptor */
12449 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12450 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12451 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12452 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12453 .quad 0x0080890000000000 /* TS descriptor */
12454 .quad 0x0000000000000000 /* TS continued */
12455 gdt_end:
12456 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12457 index 196eaf3..c96716d 100644
12458 --- a/arch/x86/boot/compressed/misc.c
12459 +++ b/arch/x86/boot/compressed/misc.c
12460 @@ -218,7 +218,7 @@ void __putstr(const char *s)
12461
12462 void *memset(void *s, int c, size_t n)
12463 {
12464 - int i;
12465 + size_t i;
12466 char *ss = s;
12467
12468 for (i = 0; i < n; i++)
12469 @@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12470 * Calculate the delta between where vmlinux was linked to load
12471 * and where it was actually loaded.
12472 */
12473 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12474 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12475 if (!delta) {
12476 debug_putstr("No relocation needed... ");
12477 return;
12478 @@ -347,7 +347,7 @@ static void parse_elf(void *output)
12479 Elf32_Ehdr ehdr;
12480 Elf32_Phdr *phdrs, *phdr;
12481 #endif
12482 - void *dest;
12483 + void *dest, *prev;
12484 int i;
12485
12486 memcpy(&ehdr, output, sizeof(ehdr));
12487 @@ -374,13 +374,16 @@ static void parse_elf(void *output)
12488 case PT_LOAD:
12489 #ifdef CONFIG_RELOCATABLE
12490 dest = output;
12491 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12492 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12493 #else
12494 dest = (void *)(phdr->p_paddr);
12495 #endif
12496 memcpy(dest,
12497 output + phdr->p_offset,
12498 phdr->p_filesz);
12499 + if (i)
12500 + memset(prev, 0xff, dest - prev);
12501 + prev = dest + phdr->p_filesz;
12502 break;
12503 default: /* Ignore other PT_* */ break;
12504 }
12505 @@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12506 error("Destination address too large");
12507 #endif
12508 #ifndef CONFIG_RELOCATABLE
12509 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12510 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12511 error("Wrong destination address");
12512 #endif
12513
12514 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12515 index 100a9a1..bb3bdb0 100644
12516 --- a/arch/x86/boot/cpucheck.c
12517 +++ b/arch/x86/boot/cpucheck.c
12518 @@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12519 u32 ecx = MSR_K7_HWCR;
12520 u32 eax, edx;
12521
12522 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12523 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12524 eax &= ~(1 << 15);
12525 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12526 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12527
12528 get_cpuflags(); /* Make sure it really did something */
12529 err = check_cpuflags();
12530 @@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12531 u32 ecx = MSR_VIA_FCR;
12532 u32 eax, edx;
12533
12534 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12535 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12536 eax |= (1<<1)|(1<<7);
12537 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12538 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12539
12540 set_bit(X86_FEATURE_CX8, cpu.flags);
12541 err = check_cpuflags();
12542 @@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12543 u32 eax, edx;
12544 u32 level = 1;
12545
12546 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12547 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12548 - asm("cpuid"
12549 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12550 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12551 + asm volatile("cpuid"
12552 : "+a" (level), "=d" (cpu.flags[0])
12553 : : "ecx", "ebx");
12554 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12555 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12556
12557 err = check_cpuflags();
12558 }
12559 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12560 index ec3b8ba..6a0db1f 100644
12561 --- a/arch/x86/boot/header.S
12562 +++ b/arch/x86/boot/header.S
12563 @@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12564 # single linked list of
12565 # struct setup_data
12566
12567 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12568 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12569
12570 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12571 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12572 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12573 +#else
12574 #define VO_INIT_SIZE (VO__end - VO__text)
12575 +#endif
12576 #if ZO_INIT_SIZE > VO_INIT_SIZE
12577 #define INIT_SIZE ZO_INIT_SIZE
12578 #else
12579 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12580 index db75d07..8e6d0af 100644
12581 --- a/arch/x86/boot/memory.c
12582 +++ b/arch/x86/boot/memory.c
12583 @@ -19,7 +19,7 @@
12584
12585 static int detect_memory_e820(void)
12586 {
12587 - int count = 0;
12588 + unsigned int count = 0;
12589 struct biosregs ireg, oreg;
12590 struct e820entry *desc = boot_params.e820_map;
12591 static struct e820entry buf; /* static so it is zeroed */
12592 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12593 index 11e8c6e..fdbb1ed 100644
12594 --- a/arch/x86/boot/video-vesa.c
12595 +++ b/arch/x86/boot/video-vesa.c
12596 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12597
12598 boot_params.screen_info.vesapm_seg = oreg.es;
12599 boot_params.screen_info.vesapm_off = oreg.di;
12600 + boot_params.screen_info.vesapm_size = oreg.cx;
12601 }
12602
12603 /*
12604 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12605 index 43eda28..5ab5fdb 100644
12606 --- a/arch/x86/boot/video.c
12607 +++ b/arch/x86/boot/video.c
12608 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12609 static unsigned int get_entry(void)
12610 {
12611 char entry_buf[4];
12612 - int i, len = 0;
12613 + unsigned int i, len = 0;
12614 int key;
12615 unsigned int v;
12616
12617 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12618 index 9105655..41779c1 100644
12619 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12620 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12621 @@ -8,6 +8,8 @@
12622 * including this sentence is retained in full.
12623 */
12624
12625 +#include <asm/alternative-asm.h>
12626 +
12627 .extern crypto_ft_tab
12628 .extern crypto_it_tab
12629 .extern crypto_fl_tab
12630 @@ -70,6 +72,8 @@
12631 je B192; \
12632 leaq 32(r9),r9;
12633
12634 +#define ret pax_force_retaddr; ret
12635 +
12636 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12637 movq r1,r2; \
12638 movq r3,r4; \
12639 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12640 index 477e9d7..c92c7d8 100644
12641 --- a/arch/x86/crypto/aesni-intel_asm.S
12642 +++ b/arch/x86/crypto/aesni-intel_asm.S
12643 @@ -31,6 +31,7 @@
12644
12645 #include <linux/linkage.h>
12646 #include <asm/inst.h>
12647 +#include <asm/alternative-asm.h>
12648
12649 #ifdef __x86_64__
12650 .data
12651 @@ -205,7 +206,7 @@ enc: .octa 0x2
12652 * num_initial_blocks = b mod 4
12653 * encrypt the initial num_initial_blocks blocks and apply ghash on
12654 * the ciphertext
12655 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12656 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12657 * are clobbered
12658 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12659 */
12660 @@ -214,8 +215,8 @@ enc: .octa 0x2
12661 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12662 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12663 mov arg7, %r10 # %r10 = AAD
12664 - mov arg8, %r12 # %r12 = aadLen
12665 - mov %r12, %r11
12666 + mov arg8, %r15 # %r15 = aadLen
12667 + mov %r15, %r11
12668 pxor %xmm\i, %xmm\i
12669 _get_AAD_loop\num_initial_blocks\operation:
12670 movd (%r10), \TMP1
12671 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12672 psrldq $4, %xmm\i
12673 pxor \TMP1, %xmm\i
12674 add $4, %r10
12675 - sub $4, %r12
12676 + sub $4, %r15
12677 jne _get_AAD_loop\num_initial_blocks\operation
12678 cmp $16, %r11
12679 je _get_AAD_loop2_done\num_initial_blocks\operation
12680 - mov $16, %r12
12681 + mov $16, %r15
12682 _get_AAD_loop2\num_initial_blocks\operation:
12683 psrldq $4, %xmm\i
12684 - sub $4, %r12
12685 - cmp %r11, %r12
12686 + sub $4, %r15
12687 + cmp %r11, %r15
12688 jne _get_AAD_loop2\num_initial_blocks\operation
12689 _get_AAD_loop2_done\num_initial_blocks\operation:
12690 movdqa SHUF_MASK(%rip), %xmm14
12691 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12692 * num_initial_blocks = b mod 4
12693 * encrypt the initial num_initial_blocks blocks and apply ghash on
12694 * the ciphertext
12695 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12696 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12697 * are clobbered
12698 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12699 */
12700 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12701 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12702 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12703 mov arg7, %r10 # %r10 = AAD
12704 - mov arg8, %r12 # %r12 = aadLen
12705 - mov %r12, %r11
12706 + mov arg8, %r15 # %r15 = aadLen
12707 + mov %r15, %r11
12708 pxor %xmm\i, %xmm\i
12709 _get_AAD_loop\num_initial_blocks\operation:
12710 movd (%r10), \TMP1
12711 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12712 psrldq $4, %xmm\i
12713 pxor \TMP1, %xmm\i
12714 add $4, %r10
12715 - sub $4, %r12
12716 + sub $4, %r15
12717 jne _get_AAD_loop\num_initial_blocks\operation
12718 cmp $16, %r11
12719 je _get_AAD_loop2_done\num_initial_blocks\operation
12720 - mov $16, %r12
12721 + mov $16, %r15
12722 _get_AAD_loop2\num_initial_blocks\operation:
12723 psrldq $4, %xmm\i
12724 - sub $4, %r12
12725 - cmp %r11, %r12
12726 + sub $4, %r15
12727 + cmp %r11, %r15
12728 jne _get_AAD_loop2\num_initial_blocks\operation
12729 _get_AAD_loop2_done\num_initial_blocks\operation:
12730 movdqa SHUF_MASK(%rip), %xmm14
12731 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12732 *
12733 *****************************************************************************/
12734 ENTRY(aesni_gcm_dec)
12735 - push %r12
12736 + push %r15
12737 push %r13
12738 push %r14
12739 mov %rsp, %r14
12740 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12741 */
12742 sub $VARIABLE_OFFSET, %rsp
12743 and $~63, %rsp # align rsp to 64 bytes
12744 - mov %arg6, %r12
12745 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12746 + mov %arg6, %r15
12747 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12748 movdqa SHUF_MASK(%rip), %xmm2
12749 PSHUFB_XMM %xmm2, %xmm13
12750
12751 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12752 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12753 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12754 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12755 - mov %r13, %r12
12756 - and $(3<<4), %r12
12757 + mov %r13, %r15
12758 + and $(3<<4), %r15
12759 jz _initial_num_blocks_is_0_decrypt
12760 - cmp $(2<<4), %r12
12761 + cmp $(2<<4), %r15
12762 jb _initial_num_blocks_is_1_decrypt
12763 je _initial_num_blocks_is_2_decrypt
12764 _initial_num_blocks_is_3_decrypt:
12765 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12766 sub $16, %r11
12767 add %r13, %r11
12768 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12769 - lea SHIFT_MASK+16(%rip), %r12
12770 - sub %r13, %r12
12771 + lea SHIFT_MASK+16(%rip), %r15
12772 + sub %r13, %r15
12773 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12774 # (%r13 is the number of bytes in plaintext mod 16)
12775 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12776 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12777 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12778
12779 movdqa %xmm1, %xmm2
12780 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12781 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12782 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12783 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12784 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12785 pand %xmm1, %xmm2
12786 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12787 sub $1, %r13
12788 jne _less_than_8_bytes_left_decrypt
12789 _multiple_of_16_bytes_decrypt:
12790 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12791 - shl $3, %r12 # convert into number of bits
12792 - movd %r12d, %xmm15 # len(A) in %xmm15
12793 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12794 + shl $3, %r15 # convert into number of bits
12795 + movd %r15d, %xmm15 # len(A) in %xmm15
12796 shl $3, %arg4 # len(C) in bits (*128)
12797 MOVQ_R64_XMM %arg4, %xmm1
12798 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12799 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12800 mov %r14, %rsp
12801 pop %r14
12802 pop %r13
12803 - pop %r12
12804 + pop %r15
12805 + pax_force_retaddr
12806 ret
12807 ENDPROC(aesni_gcm_dec)
12808
12809 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12810 * poly = x^128 + x^127 + x^126 + x^121 + 1
12811 ***************************************************************************/
12812 ENTRY(aesni_gcm_enc)
12813 - push %r12
12814 + push %r15
12815 push %r13
12816 push %r14
12817 mov %rsp, %r14
12818 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12819 #
12820 sub $VARIABLE_OFFSET, %rsp
12821 and $~63, %rsp
12822 - mov %arg6, %r12
12823 - movdqu (%r12), %xmm13
12824 + mov %arg6, %r15
12825 + movdqu (%r15), %xmm13
12826 movdqa SHUF_MASK(%rip), %xmm2
12827 PSHUFB_XMM %xmm2, %xmm13
12828
12829 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12830 movdqa %xmm13, HashKey(%rsp)
12831 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12832 and $-16, %r13
12833 - mov %r13, %r12
12834 + mov %r13, %r15
12835
12836 # Encrypt first few blocks
12837
12838 - and $(3<<4), %r12
12839 + and $(3<<4), %r15
12840 jz _initial_num_blocks_is_0_encrypt
12841 - cmp $(2<<4), %r12
12842 + cmp $(2<<4), %r15
12843 jb _initial_num_blocks_is_1_encrypt
12844 je _initial_num_blocks_is_2_encrypt
12845 _initial_num_blocks_is_3_encrypt:
12846 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12847 sub $16, %r11
12848 add %r13, %r11
12849 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12850 - lea SHIFT_MASK+16(%rip), %r12
12851 - sub %r13, %r12
12852 + lea SHIFT_MASK+16(%rip), %r15
12853 + sub %r13, %r15
12854 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12855 # (%r13 is the number of bytes in plaintext mod 16)
12856 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12857 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12858 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12859 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12860 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12861 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12862 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12863 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12864 movdqa SHUF_MASK(%rip), %xmm10
12865 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12866 sub $1, %r13
12867 jne _less_than_8_bytes_left_encrypt
12868 _multiple_of_16_bytes_encrypt:
12869 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12870 - shl $3, %r12
12871 - movd %r12d, %xmm15 # len(A) in %xmm15
12872 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12873 + shl $3, %r15
12874 + movd %r15d, %xmm15 # len(A) in %xmm15
12875 shl $3, %arg4 # len(C) in bits (*128)
12876 MOVQ_R64_XMM %arg4, %xmm1
12877 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12878 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12879 mov %r14, %rsp
12880 pop %r14
12881 pop %r13
12882 - pop %r12
12883 + pop %r15
12884 + pax_force_retaddr
12885 ret
12886 ENDPROC(aesni_gcm_enc)
12887
12888 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12889 pxor %xmm1, %xmm0
12890 movaps %xmm0, (TKEYP)
12891 add $0x10, TKEYP
12892 + pax_force_retaddr
12893 ret
12894 ENDPROC(_key_expansion_128)
12895 ENDPROC(_key_expansion_256a)
12896 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12897 shufps $0b01001110, %xmm2, %xmm1
12898 movaps %xmm1, 0x10(TKEYP)
12899 add $0x20, TKEYP
12900 + pax_force_retaddr
12901 ret
12902 ENDPROC(_key_expansion_192a)
12903
12904 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
12905
12906 movaps %xmm0, (TKEYP)
12907 add $0x10, TKEYP
12908 + pax_force_retaddr
12909 ret
12910 ENDPROC(_key_expansion_192b)
12911
12912 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
12913 pxor %xmm1, %xmm2
12914 movaps %xmm2, (TKEYP)
12915 add $0x10, TKEYP
12916 + pax_force_retaddr
12917 ret
12918 ENDPROC(_key_expansion_256b)
12919
12920 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12921 #ifndef __x86_64__
12922 popl KEYP
12923 #endif
12924 + pax_force_retaddr
12925 ret
12926 ENDPROC(aesni_set_key)
12927
12928 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12929 popl KLEN
12930 popl KEYP
12931 #endif
12932 + pax_force_retaddr
12933 ret
12934 ENDPROC(aesni_enc)
12935
12936 @@ -1974,6 +1983,7 @@ _aesni_enc1:
12937 AESENC KEY STATE
12938 movaps 0x70(TKEYP), KEY
12939 AESENCLAST KEY STATE
12940 + pax_force_retaddr
12941 ret
12942 ENDPROC(_aesni_enc1)
12943
12944 @@ -2083,6 +2093,7 @@ _aesni_enc4:
12945 AESENCLAST KEY STATE2
12946 AESENCLAST KEY STATE3
12947 AESENCLAST KEY STATE4
12948 + pax_force_retaddr
12949 ret
12950 ENDPROC(_aesni_enc4)
12951
12952 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12953 popl KLEN
12954 popl KEYP
12955 #endif
12956 + pax_force_retaddr
12957 ret
12958 ENDPROC(aesni_dec)
12959
12960 @@ -2164,6 +2176,7 @@ _aesni_dec1:
12961 AESDEC KEY STATE
12962 movaps 0x70(TKEYP), KEY
12963 AESDECLAST KEY STATE
12964 + pax_force_retaddr
12965 ret
12966 ENDPROC(_aesni_dec1)
12967
12968 @@ -2273,6 +2286,7 @@ _aesni_dec4:
12969 AESDECLAST KEY STATE2
12970 AESDECLAST KEY STATE3
12971 AESDECLAST KEY STATE4
12972 + pax_force_retaddr
12973 ret
12974 ENDPROC(_aesni_dec4)
12975
12976 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12977 popl KEYP
12978 popl LEN
12979 #endif
12980 + pax_force_retaddr
12981 ret
12982 ENDPROC(aesni_ecb_enc)
12983
12984 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12985 popl KEYP
12986 popl LEN
12987 #endif
12988 + pax_force_retaddr
12989 ret
12990 ENDPROC(aesni_ecb_dec)
12991
12992 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12993 popl LEN
12994 popl IVP
12995 #endif
12996 + pax_force_retaddr
12997 ret
12998 ENDPROC(aesni_cbc_enc)
12999
13000 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13001 popl LEN
13002 popl IVP
13003 #endif
13004 + pax_force_retaddr
13005 ret
13006 ENDPROC(aesni_cbc_dec)
13007
13008 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13009 mov $1, TCTR_LOW
13010 MOVQ_R64_XMM TCTR_LOW INC
13011 MOVQ_R64_XMM CTR TCTR_LOW
13012 + pax_force_retaddr
13013 ret
13014 ENDPROC(_aesni_inc_init)
13015
13016 @@ -2579,6 +2598,7 @@ _aesni_inc:
13017 .Linc_low:
13018 movaps CTR, IV
13019 PSHUFB_XMM BSWAP_MASK IV
13020 + pax_force_retaddr
13021 ret
13022 ENDPROC(_aesni_inc)
13023
13024 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13025 .Lctr_enc_ret:
13026 movups IV, (IVP)
13027 .Lctr_enc_just_ret:
13028 + pax_force_retaddr
13029 ret
13030 ENDPROC(aesni_ctr_enc)
13031
13032 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13033 pxor INC, STATE4
13034 movdqu STATE4, 0x70(OUTP)
13035
13036 + pax_force_retaddr
13037 ret
13038 ENDPROC(aesni_xts_crypt8)
13039
13040 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13041 index 246c670..466e2d6 100644
13042 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13043 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13044 @@ -21,6 +21,7 @@
13045 */
13046
13047 #include <linux/linkage.h>
13048 +#include <asm/alternative-asm.h>
13049
13050 .file "blowfish-x86_64-asm.S"
13051 .text
13052 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13053 jnz .L__enc_xor;
13054
13055 write_block();
13056 + pax_force_retaddr
13057 ret;
13058 .L__enc_xor:
13059 xor_block();
13060 + pax_force_retaddr
13061 ret;
13062 ENDPROC(__blowfish_enc_blk)
13063
13064 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13065
13066 movq %r11, %rbp;
13067
13068 + pax_force_retaddr
13069 ret;
13070 ENDPROC(blowfish_dec_blk)
13071
13072 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13073
13074 popq %rbx;
13075 popq %rbp;
13076 + pax_force_retaddr
13077 ret;
13078
13079 .L__enc_xor4:
13080 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13081
13082 popq %rbx;
13083 popq %rbp;
13084 + pax_force_retaddr
13085 ret;
13086 ENDPROC(__blowfish_enc_blk_4way)
13087
13088 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13089 popq %rbx;
13090 popq %rbp;
13091
13092 + pax_force_retaddr
13093 ret;
13094 ENDPROC(blowfish_dec_blk_4way)
13095 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13096 index ce71f92..1dce7ec 100644
13097 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13098 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13099 @@ -16,6 +16,7 @@
13100 */
13101
13102 #include <linux/linkage.h>
13103 +#include <asm/alternative-asm.h>
13104
13105 #define CAMELLIA_TABLE_BYTE_LEN 272
13106
13107 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13108 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13109 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13110 %rcx, (%r9));
13111 + pax_force_retaddr
13112 ret;
13113 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13114
13115 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13116 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13117 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13118 %rax, (%r9));
13119 + pax_force_retaddr
13120 ret;
13121 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13122
13123 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13124 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13125 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13126
13127 + pax_force_retaddr
13128 ret;
13129
13130 .align 8
13131 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13132 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13133 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13134
13135 + pax_force_retaddr
13136 ret;
13137
13138 .align 8
13139 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13140 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13141 %xmm8, %rsi);
13142
13143 + pax_force_retaddr
13144 ret;
13145 ENDPROC(camellia_ecb_enc_16way)
13146
13147 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13148 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13149 %xmm8, %rsi);
13150
13151 + pax_force_retaddr
13152 ret;
13153 ENDPROC(camellia_ecb_dec_16way)
13154
13155 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13156 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13157 %xmm8, %rsi);
13158
13159 + pax_force_retaddr
13160 ret;
13161 ENDPROC(camellia_cbc_dec_16way)
13162
13163 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13164 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13165 %xmm8, %rsi);
13166
13167 + pax_force_retaddr
13168 ret;
13169 ENDPROC(camellia_ctr_16way)
13170
13171 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13172 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13173 %xmm8, %rsi);
13174
13175 + pax_force_retaddr
13176 ret;
13177 ENDPROC(camellia_xts_crypt_16way)
13178
13179 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13180 index 0e0b886..5a3123c 100644
13181 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13182 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13183 @@ -11,6 +11,7 @@
13184 */
13185
13186 #include <linux/linkage.h>
13187 +#include <asm/alternative-asm.h>
13188
13189 #define CAMELLIA_TABLE_BYTE_LEN 272
13190
13191 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13192 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13193 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13194 %rcx, (%r9));
13195 + pax_force_retaddr
13196 ret;
13197 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13198
13199 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13200 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13201 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13202 %rax, (%r9));
13203 + pax_force_retaddr
13204 ret;
13205 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13206
13207 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13208 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13209 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13210
13211 + pax_force_retaddr
13212 ret;
13213
13214 .align 8
13215 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13216 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13217 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13218
13219 + pax_force_retaddr
13220 ret;
13221
13222 .align 8
13223 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13224
13225 vzeroupper;
13226
13227 + pax_force_retaddr
13228 ret;
13229 ENDPROC(camellia_ecb_enc_32way)
13230
13231 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13232
13233 vzeroupper;
13234
13235 + pax_force_retaddr
13236 ret;
13237 ENDPROC(camellia_ecb_dec_32way)
13238
13239 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13240
13241 vzeroupper;
13242
13243 + pax_force_retaddr
13244 ret;
13245 ENDPROC(camellia_cbc_dec_32way)
13246
13247 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13248
13249 vzeroupper;
13250
13251 + pax_force_retaddr
13252 ret;
13253 ENDPROC(camellia_ctr_32way)
13254
13255 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13256
13257 vzeroupper;
13258
13259 + pax_force_retaddr
13260 ret;
13261 ENDPROC(camellia_xts_crypt_32way)
13262
13263 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13264 index 310319c..db3d7b5 100644
13265 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13266 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13267 @@ -21,6 +21,7 @@
13268 */
13269
13270 #include <linux/linkage.h>
13271 +#include <asm/alternative-asm.h>
13272
13273 .file "camellia-x86_64-asm_64.S"
13274 .text
13275 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13276 enc_outunpack(mov, RT1);
13277
13278 movq RRBP, %rbp;
13279 + pax_force_retaddr
13280 ret;
13281
13282 .L__enc_xor:
13283 enc_outunpack(xor, RT1);
13284
13285 movq RRBP, %rbp;
13286 + pax_force_retaddr
13287 ret;
13288 ENDPROC(__camellia_enc_blk)
13289
13290 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13291 dec_outunpack();
13292
13293 movq RRBP, %rbp;
13294 + pax_force_retaddr
13295 ret;
13296 ENDPROC(camellia_dec_blk)
13297
13298 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13299
13300 movq RRBP, %rbp;
13301 popq %rbx;
13302 + pax_force_retaddr
13303 ret;
13304
13305 .L__enc2_xor:
13306 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13307
13308 movq RRBP, %rbp;
13309 popq %rbx;
13310 + pax_force_retaddr
13311 ret;
13312 ENDPROC(__camellia_enc_blk_2way)
13313
13314 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13315
13316 movq RRBP, %rbp;
13317 movq RXOR, %rbx;
13318 + pax_force_retaddr
13319 ret;
13320 ENDPROC(camellia_dec_blk_2way)
13321 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13322 index c35fd5d..2d8c7db 100644
13323 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13324 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13325 @@ -24,6 +24,7 @@
13326 */
13327
13328 #include <linux/linkage.h>
13329 +#include <asm/alternative-asm.h>
13330
13331 .file "cast5-avx-x86_64-asm_64.S"
13332
13333 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13334 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13335 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13336
13337 + pax_force_retaddr
13338 ret;
13339 ENDPROC(__cast5_enc_blk16)
13340
13341 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13342 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13343 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13344
13345 + pax_force_retaddr
13346 ret;
13347
13348 .L__skip_dec:
13349 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13350 vmovdqu RR4, (6*4*4)(%r11);
13351 vmovdqu RL4, (7*4*4)(%r11);
13352
13353 + pax_force_retaddr
13354 ret;
13355 ENDPROC(cast5_ecb_enc_16way)
13356
13357 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13358 vmovdqu RR4, (6*4*4)(%r11);
13359 vmovdqu RL4, (7*4*4)(%r11);
13360
13361 + pax_force_retaddr
13362 ret;
13363 ENDPROC(cast5_ecb_dec_16way)
13364
13365 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13366 * %rdx: src
13367 */
13368
13369 - pushq %r12;
13370 + pushq %r14;
13371
13372 movq %rsi, %r11;
13373 - movq %rdx, %r12;
13374 + movq %rdx, %r14;
13375
13376 vmovdqu (0*16)(%rdx), RL1;
13377 vmovdqu (1*16)(%rdx), RR1;
13378 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13379 call __cast5_dec_blk16;
13380
13381 /* xor with src */
13382 - vmovq (%r12), RX;
13383 + vmovq (%r14), RX;
13384 vpshufd $0x4f, RX, RX;
13385 vpxor RX, RR1, RR1;
13386 - vpxor 0*16+8(%r12), RL1, RL1;
13387 - vpxor 1*16+8(%r12), RR2, RR2;
13388 - vpxor 2*16+8(%r12), RL2, RL2;
13389 - vpxor 3*16+8(%r12), RR3, RR3;
13390 - vpxor 4*16+8(%r12), RL3, RL3;
13391 - vpxor 5*16+8(%r12), RR4, RR4;
13392 - vpxor 6*16+8(%r12), RL4, RL4;
13393 + vpxor 0*16+8(%r14), RL1, RL1;
13394 + vpxor 1*16+8(%r14), RR2, RR2;
13395 + vpxor 2*16+8(%r14), RL2, RL2;
13396 + vpxor 3*16+8(%r14), RR3, RR3;
13397 + vpxor 4*16+8(%r14), RL3, RL3;
13398 + vpxor 5*16+8(%r14), RR4, RR4;
13399 + vpxor 6*16+8(%r14), RL4, RL4;
13400
13401 vmovdqu RR1, (0*16)(%r11);
13402 vmovdqu RL1, (1*16)(%r11);
13403 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13404 vmovdqu RR4, (6*16)(%r11);
13405 vmovdqu RL4, (7*16)(%r11);
13406
13407 - popq %r12;
13408 + popq %r14;
13409
13410 + pax_force_retaddr
13411 ret;
13412 ENDPROC(cast5_cbc_dec_16way)
13413
13414 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13415 * %rcx: iv (big endian, 64bit)
13416 */
13417
13418 - pushq %r12;
13419 + pushq %r14;
13420
13421 movq %rsi, %r11;
13422 - movq %rdx, %r12;
13423 + movq %rdx, %r14;
13424
13425 vpcmpeqd RTMP, RTMP, RTMP;
13426 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13427 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13428 call __cast5_enc_blk16;
13429
13430 /* dst = src ^ iv */
13431 - vpxor (0*16)(%r12), RR1, RR1;
13432 - vpxor (1*16)(%r12), RL1, RL1;
13433 - vpxor (2*16)(%r12), RR2, RR2;
13434 - vpxor (3*16)(%r12), RL2, RL2;
13435 - vpxor (4*16)(%r12), RR3, RR3;
13436 - vpxor (5*16)(%r12), RL3, RL3;
13437 - vpxor (6*16)(%r12), RR4, RR4;
13438 - vpxor (7*16)(%r12), RL4, RL4;
13439 + vpxor (0*16)(%r14), RR1, RR1;
13440 + vpxor (1*16)(%r14), RL1, RL1;
13441 + vpxor (2*16)(%r14), RR2, RR2;
13442 + vpxor (3*16)(%r14), RL2, RL2;
13443 + vpxor (4*16)(%r14), RR3, RR3;
13444 + vpxor (5*16)(%r14), RL3, RL3;
13445 + vpxor (6*16)(%r14), RR4, RR4;
13446 + vpxor (7*16)(%r14), RL4, RL4;
13447 vmovdqu RR1, (0*16)(%r11);
13448 vmovdqu RL1, (1*16)(%r11);
13449 vmovdqu RR2, (2*16)(%r11);
13450 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13451 vmovdqu RR4, (6*16)(%r11);
13452 vmovdqu RL4, (7*16)(%r11);
13453
13454 - popq %r12;
13455 + popq %r14;
13456
13457 + pax_force_retaddr
13458 ret;
13459 ENDPROC(cast5_ctr_16way)
13460 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13461 index e3531f8..e123f35 100644
13462 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13463 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13464 @@ -24,6 +24,7 @@
13465 */
13466
13467 #include <linux/linkage.h>
13468 +#include <asm/alternative-asm.h>
13469 #include "glue_helper-asm-avx.S"
13470
13471 .file "cast6-avx-x86_64-asm_64.S"
13472 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13473 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13474 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13475
13476 + pax_force_retaddr
13477 ret;
13478 ENDPROC(__cast6_enc_blk8)
13479
13480 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13481 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13482 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13483
13484 + pax_force_retaddr
13485 ret;
13486 ENDPROC(__cast6_dec_blk8)
13487
13488 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13489
13490 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13491
13492 + pax_force_retaddr
13493 ret;
13494 ENDPROC(cast6_ecb_enc_8way)
13495
13496 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13497
13498 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13499
13500 + pax_force_retaddr
13501 ret;
13502 ENDPROC(cast6_ecb_dec_8way)
13503
13504 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13505 * %rdx: src
13506 */
13507
13508 - pushq %r12;
13509 + pushq %r14;
13510
13511 movq %rsi, %r11;
13512 - movq %rdx, %r12;
13513 + movq %rdx, %r14;
13514
13515 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13516
13517 call __cast6_dec_blk8;
13518
13519 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13520 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13521
13522 - popq %r12;
13523 + popq %r14;
13524
13525 + pax_force_retaddr
13526 ret;
13527 ENDPROC(cast6_cbc_dec_8way)
13528
13529 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13530 * %rcx: iv (little endian, 128bit)
13531 */
13532
13533 - pushq %r12;
13534 + pushq %r14;
13535
13536 movq %rsi, %r11;
13537 - movq %rdx, %r12;
13538 + movq %rdx, %r14;
13539
13540 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13541 RD2, RX, RKR, RKM);
13542
13543 call __cast6_enc_blk8;
13544
13545 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13546 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13547
13548 - popq %r12;
13549 + popq %r14;
13550
13551 + pax_force_retaddr
13552 ret;
13553 ENDPROC(cast6_ctr_8way)
13554
13555 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13556 /* dst <= regs xor IVs(in dst) */
13557 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13558
13559 + pax_force_retaddr
13560 ret;
13561 ENDPROC(cast6_xts_enc_8way)
13562
13563 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13564 /* dst <= regs xor IVs(in dst) */
13565 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13566
13567 + pax_force_retaddr
13568 ret;
13569 ENDPROC(cast6_xts_dec_8way)
13570 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13571 index dbc4339..de6e120 100644
13572 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13573 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13574 @@ -45,6 +45,7 @@
13575
13576 #include <asm/inst.h>
13577 #include <linux/linkage.h>
13578 +#include <asm/alternative-asm.h>
13579
13580 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13581
13582 @@ -312,6 +313,7 @@ do_return:
13583 popq %rsi
13584 popq %rdi
13585 popq %rbx
13586 + pax_force_retaddr
13587 ret
13588
13589 ################################################################
13590 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13591 index 185fad4..ff4cd36 100644
13592 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13593 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13594 @@ -18,6 +18,7 @@
13595
13596 #include <linux/linkage.h>
13597 #include <asm/inst.h>
13598 +#include <asm/alternative-asm.h>
13599
13600 .data
13601
13602 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13603 psrlq $1, T2
13604 pxor T2, T1
13605 pxor T1, DATA
13606 + pax_force_retaddr
13607 ret
13608 ENDPROC(__clmul_gf128mul_ble)
13609
13610 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13611 call __clmul_gf128mul_ble
13612 PSHUFB_XMM BSWAP DATA
13613 movups DATA, (%rdi)
13614 + pax_force_retaddr
13615 ret
13616 ENDPROC(clmul_ghash_mul)
13617
13618 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13619 PSHUFB_XMM BSWAP DATA
13620 movups DATA, (%rdi)
13621 .Lupdate_just_ret:
13622 + pax_force_retaddr
13623 ret
13624 ENDPROC(clmul_ghash_update)
13625 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13626 index 9279e0b..c4b3d2c 100644
13627 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13628 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13629 @@ -1,4 +1,5 @@
13630 #include <linux/linkage.h>
13631 +#include <asm/alternative-asm.h>
13632
13633 # enter salsa20_encrypt_bytes
13634 ENTRY(salsa20_encrypt_bytes)
13635 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13636 add %r11,%rsp
13637 mov %rdi,%rax
13638 mov %rsi,%rdx
13639 + pax_force_retaddr
13640 ret
13641 # bytesatleast65:
13642 ._bytesatleast65:
13643 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13644 add %r11,%rsp
13645 mov %rdi,%rax
13646 mov %rsi,%rdx
13647 + pax_force_retaddr
13648 ret
13649 ENDPROC(salsa20_keysetup)
13650
13651 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13652 add %r11,%rsp
13653 mov %rdi,%rax
13654 mov %rsi,%rdx
13655 + pax_force_retaddr
13656 ret
13657 ENDPROC(salsa20_ivsetup)
13658 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13659 index 2f202f4..d9164d6 100644
13660 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13661 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13662 @@ -24,6 +24,7 @@
13663 */
13664
13665 #include <linux/linkage.h>
13666 +#include <asm/alternative-asm.h>
13667 #include "glue_helper-asm-avx.S"
13668
13669 .file "serpent-avx-x86_64-asm_64.S"
13670 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13671 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13672 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13673
13674 + pax_force_retaddr
13675 ret;
13676 ENDPROC(__serpent_enc_blk8_avx)
13677
13678 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13679 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13680 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13681
13682 + pax_force_retaddr
13683 ret;
13684 ENDPROC(__serpent_dec_blk8_avx)
13685
13686 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13687
13688 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13689
13690 + pax_force_retaddr
13691 ret;
13692 ENDPROC(serpent_ecb_enc_8way_avx)
13693
13694 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13695
13696 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13697
13698 + pax_force_retaddr
13699 ret;
13700 ENDPROC(serpent_ecb_dec_8way_avx)
13701
13702 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13703
13704 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13705
13706 + pax_force_retaddr
13707 ret;
13708 ENDPROC(serpent_cbc_dec_8way_avx)
13709
13710 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13711
13712 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13713
13714 + pax_force_retaddr
13715 ret;
13716 ENDPROC(serpent_ctr_8way_avx)
13717
13718 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13719 /* dst <= regs xor IVs(in dst) */
13720 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13721
13722 + pax_force_retaddr
13723 ret;
13724 ENDPROC(serpent_xts_enc_8way_avx)
13725
13726 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13727 /* dst <= regs xor IVs(in dst) */
13728 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13729
13730 + pax_force_retaddr
13731 ret;
13732 ENDPROC(serpent_xts_dec_8way_avx)
13733 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13734 index b222085..abd483c 100644
13735 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13736 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13737 @@ -15,6 +15,7 @@
13738 */
13739
13740 #include <linux/linkage.h>
13741 +#include <asm/alternative-asm.h>
13742 #include "glue_helper-asm-avx2.S"
13743
13744 .file "serpent-avx2-asm_64.S"
13745 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13746 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13747 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13748
13749 + pax_force_retaddr
13750 ret;
13751 ENDPROC(__serpent_enc_blk16)
13752
13753 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13754 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13755 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13756
13757 + pax_force_retaddr
13758 ret;
13759 ENDPROC(__serpent_dec_blk16)
13760
13761 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13762
13763 vzeroupper;
13764
13765 + pax_force_retaddr
13766 ret;
13767 ENDPROC(serpent_ecb_enc_16way)
13768
13769 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13770
13771 vzeroupper;
13772
13773 + pax_force_retaddr
13774 ret;
13775 ENDPROC(serpent_ecb_dec_16way)
13776
13777 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13778
13779 vzeroupper;
13780
13781 + pax_force_retaddr
13782 ret;
13783 ENDPROC(serpent_cbc_dec_16way)
13784
13785 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13786
13787 vzeroupper;
13788
13789 + pax_force_retaddr
13790 ret;
13791 ENDPROC(serpent_ctr_16way)
13792
13793 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13794
13795 vzeroupper;
13796
13797 + pax_force_retaddr
13798 ret;
13799 ENDPROC(serpent_xts_enc_16way)
13800
13801 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13802
13803 vzeroupper;
13804
13805 + pax_force_retaddr
13806 ret;
13807 ENDPROC(serpent_xts_dec_16way)
13808 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13809 index acc066c..1559cc4 100644
13810 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13811 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13812 @@ -25,6 +25,7 @@
13813 */
13814
13815 #include <linux/linkage.h>
13816 +#include <asm/alternative-asm.h>
13817
13818 .file "serpent-sse2-x86_64-asm_64.S"
13819 .text
13820 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13821 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13822 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13823
13824 + pax_force_retaddr
13825 ret;
13826
13827 .L__enc_xor8:
13828 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13829 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13830
13831 + pax_force_retaddr
13832 ret;
13833 ENDPROC(__serpent_enc_blk_8way)
13834
13835 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13836 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13837 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13838
13839 + pax_force_retaddr
13840 ret;
13841 ENDPROC(serpent_dec_blk_8way)
13842 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13843 index a410950..9dfe7ad 100644
13844 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13845 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13846 @@ -29,6 +29,7 @@
13847 */
13848
13849 #include <linux/linkage.h>
13850 +#include <asm/alternative-asm.h>
13851
13852 #define CTX %rdi // arg1
13853 #define BUF %rsi // arg2
13854 @@ -75,9 +76,9 @@
13855
13856 push %rbx
13857 push %rbp
13858 - push %r12
13859 + push %r14
13860
13861 - mov %rsp, %r12
13862 + mov %rsp, %r14
13863 sub $64, %rsp # allocate workspace
13864 and $~15, %rsp # align stack
13865
13866 @@ -99,11 +100,12 @@
13867 xor %rax, %rax
13868 rep stosq
13869
13870 - mov %r12, %rsp # deallocate workspace
13871 + mov %r14, %rsp # deallocate workspace
13872
13873 - pop %r12
13874 + pop %r14
13875 pop %rbp
13876 pop %rbx
13877 + pax_force_retaddr
13878 ret
13879
13880 ENDPROC(\name)
13881 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13882 index 642f156..51a513c 100644
13883 --- a/arch/x86/crypto/sha256-avx-asm.S
13884 +++ b/arch/x86/crypto/sha256-avx-asm.S
13885 @@ -49,6 +49,7 @@
13886
13887 #ifdef CONFIG_AS_AVX
13888 #include <linux/linkage.h>
13889 +#include <asm/alternative-asm.h>
13890
13891 ## assume buffers not aligned
13892 #define VMOVDQ vmovdqu
13893 @@ -460,6 +461,7 @@ done_hash:
13894 popq %r13
13895 popq %rbp
13896 popq %rbx
13897 + pax_force_retaddr
13898 ret
13899 ENDPROC(sha256_transform_avx)
13900
13901 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13902 index 9e86944..3795e6a 100644
13903 --- a/arch/x86/crypto/sha256-avx2-asm.S
13904 +++ b/arch/x86/crypto/sha256-avx2-asm.S
13905 @@ -50,6 +50,7 @@
13906
13907 #ifdef CONFIG_AS_AVX2
13908 #include <linux/linkage.h>
13909 +#include <asm/alternative-asm.h>
13910
13911 ## assume buffers not aligned
13912 #define VMOVDQ vmovdqu
13913 @@ -720,6 +721,7 @@ done_hash:
13914 popq %r12
13915 popq %rbp
13916 popq %rbx
13917 + pax_force_retaddr
13918 ret
13919 ENDPROC(sha256_transform_rorx)
13920
13921 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13922 index f833b74..8c62a9e 100644
13923 --- a/arch/x86/crypto/sha256-ssse3-asm.S
13924 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
13925 @@ -47,6 +47,7 @@
13926 ########################################################################
13927
13928 #include <linux/linkage.h>
13929 +#include <asm/alternative-asm.h>
13930
13931 ## assume buffers not aligned
13932 #define MOVDQ movdqu
13933 @@ -471,6 +472,7 @@ done_hash:
13934 popq %rbp
13935 popq %rbx
13936
13937 + pax_force_retaddr
13938 ret
13939 ENDPROC(sha256_transform_ssse3)
13940
13941 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13942 index 974dde9..a823ff9 100644
13943 --- a/arch/x86/crypto/sha512-avx-asm.S
13944 +++ b/arch/x86/crypto/sha512-avx-asm.S
13945 @@ -49,6 +49,7 @@
13946
13947 #ifdef CONFIG_AS_AVX
13948 #include <linux/linkage.h>
13949 +#include <asm/alternative-asm.h>
13950
13951 .text
13952
13953 @@ -364,6 +365,7 @@ updateblock:
13954 mov frame_RSPSAVE(%rsp), %rsp
13955
13956 nowork:
13957 + pax_force_retaddr
13958 ret
13959 ENDPROC(sha512_transform_avx)
13960
13961 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13962 index 568b961..ed20c37 100644
13963 --- a/arch/x86/crypto/sha512-avx2-asm.S
13964 +++ b/arch/x86/crypto/sha512-avx2-asm.S
13965 @@ -51,6 +51,7 @@
13966
13967 #ifdef CONFIG_AS_AVX2
13968 #include <linux/linkage.h>
13969 +#include <asm/alternative-asm.h>
13970
13971 .text
13972
13973 @@ -678,6 +679,7 @@ done_hash:
13974
13975 # Restore Stack Pointer
13976 mov frame_RSPSAVE(%rsp), %rsp
13977 + pax_force_retaddr
13978 ret
13979 ENDPROC(sha512_transform_rorx)
13980
13981 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13982 index fb56855..6edd768 100644
13983 --- a/arch/x86/crypto/sha512-ssse3-asm.S
13984 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
13985 @@ -48,6 +48,7 @@
13986 ########################################################################
13987
13988 #include <linux/linkage.h>
13989 +#include <asm/alternative-asm.h>
13990
13991 .text
13992
13993 @@ -363,6 +364,7 @@ updateblock:
13994 mov frame_RSPSAVE(%rsp), %rsp
13995
13996 nowork:
13997 + pax_force_retaddr
13998 ret
13999 ENDPROC(sha512_transform_ssse3)
14000
14001 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14002 index 0505813..b067311 100644
14003 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14004 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14005 @@ -24,6 +24,7 @@
14006 */
14007
14008 #include <linux/linkage.h>
14009 +#include <asm/alternative-asm.h>
14010 #include "glue_helper-asm-avx.S"
14011
14012 .file "twofish-avx-x86_64-asm_64.S"
14013 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14014 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14015 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14016
14017 + pax_force_retaddr
14018 ret;
14019 ENDPROC(__twofish_enc_blk8)
14020
14021 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14022 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14023 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14024
14025 + pax_force_retaddr
14026 ret;
14027 ENDPROC(__twofish_dec_blk8)
14028
14029 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14030
14031 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14032
14033 + pax_force_retaddr
14034 ret;
14035 ENDPROC(twofish_ecb_enc_8way)
14036
14037 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14038
14039 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14040
14041 + pax_force_retaddr
14042 ret;
14043 ENDPROC(twofish_ecb_dec_8way)
14044
14045 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14046 * %rdx: src
14047 */
14048
14049 - pushq %r12;
14050 + pushq %r14;
14051
14052 movq %rsi, %r11;
14053 - movq %rdx, %r12;
14054 + movq %rdx, %r14;
14055
14056 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14057
14058 call __twofish_dec_blk8;
14059
14060 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14061 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14062
14063 - popq %r12;
14064 + popq %r14;
14065
14066 + pax_force_retaddr
14067 ret;
14068 ENDPROC(twofish_cbc_dec_8way)
14069
14070 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14071 * %rcx: iv (little endian, 128bit)
14072 */
14073
14074 - pushq %r12;
14075 + pushq %r14;
14076
14077 movq %rsi, %r11;
14078 - movq %rdx, %r12;
14079 + movq %rdx, %r14;
14080
14081 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14082 RD2, RX0, RX1, RY0);
14083
14084 call __twofish_enc_blk8;
14085
14086 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14087 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14088
14089 - popq %r12;
14090 + popq %r14;
14091
14092 + pax_force_retaddr
14093 ret;
14094 ENDPROC(twofish_ctr_8way)
14095
14096 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14097 /* dst <= regs xor IVs(in dst) */
14098 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14099
14100 + pax_force_retaddr
14101 ret;
14102 ENDPROC(twofish_xts_enc_8way)
14103
14104 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14105 /* dst <= regs xor IVs(in dst) */
14106 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14107
14108 + pax_force_retaddr
14109 ret;
14110 ENDPROC(twofish_xts_dec_8way)
14111 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14112 index 1c3b7ce..02f578d 100644
14113 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14114 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14115 @@ -21,6 +21,7 @@
14116 */
14117
14118 #include <linux/linkage.h>
14119 +#include <asm/alternative-asm.h>
14120
14121 .file "twofish-x86_64-asm-3way.S"
14122 .text
14123 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14124 popq %r13;
14125 popq %r14;
14126 popq %r15;
14127 + pax_force_retaddr
14128 ret;
14129
14130 .L__enc_xor3:
14131 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14132 popq %r13;
14133 popq %r14;
14134 popq %r15;
14135 + pax_force_retaddr
14136 ret;
14137 ENDPROC(__twofish_enc_blk_3way)
14138
14139 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14140 popq %r13;
14141 popq %r14;
14142 popq %r15;
14143 + pax_force_retaddr
14144 ret;
14145 ENDPROC(twofish_dec_blk_3way)
14146 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14147 index a039d21..524b8b2 100644
14148 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14149 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14150 @@ -22,6 +22,7 @@
14151
14152 #include <linux/linkage.h>
14153 #include <asm/asm-offsets.h>
14154 +#include <asm/alternative-asm.h>
14155
14156 #define a_offset 0
14157 #define b_offset 4
14158 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14159
14160 popq R1
14161 movq $1,%rax
14162 + pax_force_retaddr
14163 ret
14164 ENDPROC(twofish_enc_blk)
14165
14166 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14167
14168 popq R1
14169 movq $1,%rax
14170 + pax_force_retaddr
14171 ret
14172 ENDPROC(twofish_dec_blk)
14173 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14174 index d21ff89..6da8e6e 100644
14175 --- a/arch/x86/ia32/ia32_aout.c
14176 +++ b/arch/x86/ia32/ia32_aout.c
14177 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14178 unsigned long dump_start, dump_size;
14179 struct user32 dump;
14180
14181 + memset(&dump, 0, sizeof(dump));
14182 +
14183 fs = get_fs();
14184 set_fs(KERNEL_DS);
14185 has_dumped = 1;
14186 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14187 index 2206757..85cbcfa 100644
14188 --- a/arch/x86/ia32/ia32_signal.c
14189 +++ b/arch/x86/ia32/ia32_signal.c
14190 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14191 if (__get_user(set.sig[0], &frame->sc.oldmask)
14192 || (_COMPAT_NSIG_WORDS > 1
14193 && __copy_from_user((((char *) &set.sig) + 4),
14194 - &frame->extramask,
14195 + frame->extramask,
14196 sizeof(frame->extramask))))
14197 goto badframe;
14198
14199 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14200 sp -= frame_size;
14201 /* Align the stack pointer according to the i386 ABI,
14202 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14203 - sp = ((sp + 4) & -16ul) - 4;
14204 + sp = ((sp - 12) & -16ul) - 4;
14205 return (void __user *) sp;
14206 }
14207
14208 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14209 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14210 sigreturn);
14211 else
14212 - restorer = &frame->retcode;
14213 + restorer = frame->retcode;
14214 }
14215
14216 put_user_try {
14217 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14218 * These are actually not used anymore, but left because some
14219 * gdb versions depend on them as a marker.
14220 */
14221 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14222 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14223 } put_user_catch(err);
14224
14225 if (err)
14226 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14227 0xb8,
14228 __NR_ia32_rt_sigreturn,
14229 0x80cd,
14230 - 0,
14231 + 0
14232 };
14233
14234 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14235 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14236
14237 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14238 restorer = ksig->ka.sa.sa_restorer;
14239 + else if (current->mm->context.vdso)
14240 + /* Return stub is in 32bit vsyscall page */
14241 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14242 else
14243 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14244 - rt_sigreturn);
14245 + restorer = frame->retcode;
14246 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14247
14248 /*
14249 * Not actually used anymore, but left because some gdb
14250 * versions need it.
14251 */
14252 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14253 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14254 } put_user_catch(err);
14255
14256 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14257 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14258 index 4299eb0..c0687a7 100644
14259 --- a/arch/x86/ia32/ia32entry.S
14260 +++ b/arch/x86/ia32/ia32entry.S
14261 @@ -15,8 +15,10 @@
14262 #include <asm/irqflags.h>
14263 #include <asm/asm.h>
14264 #include <asm/smap.h>
14265 +#include <asm/pgtable.h>
14266 #include <linux/linkage.h>
14267 #include <linux/err.h>
14268 +#include <asm/alternative-asm.h>
14269
14270 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14271 #include <linux/elf-em.h>
14272 @@ -62,12 +64,12 @@
14273 */
14274 .macro LOAD_ARGS32 offset, _r9=0
14275 .if \_r9
14276 - movl \offset+16(%rsp),%r9d
14277 + movl \offset+R9(%rsp),%r9d
14278 .endif
14279 - movl \offset+40(%rsp),%ecx
14280 - movl \offset+48(%rsp),%edx
14281 - movl \offset+56(%rsp),%esi
14282 - movl \offset+64(%rsp),%edi
14283 + movl \offset+RCX(%rsp),%ecx
14284 + movl \offset+RDX(%rsp),%edx
14285 + movl \offset+RSI(%rsp),%esi
14286 + movl \offset+RDI(%rsp),%edi
14287 movl %eax,%eax /* zero extension */
14288 .endm
14289
14290 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14291 ENDPROC(native_irq_enable_sysexit)
14292 #endif
14293
14294 + .macro pax_enter_kernel_user
14295 + pax_set_fptr_mask
14296 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14297 + call pax_enter_kernel_user
14298 +#endif
14299 + .endm
14300 +
14301 + .macro pax_exit_kernel_user
14302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14303 + call pax_exit_kernel_user
14304 +#endif
14305 +#ifdef CONFIG_PAX_RANDKSTACK
14306 + pushq %rax
14307 + pushq %r11
14308 + call pax_randomize_kstack
14309 + popq %r11
14310 + popq %rax
14311 +#endif
14312 + .endm
14313 +
14314 + .macro pax_erase_kstack
14315 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14316 + call pax_erase_kstack
14317 +#endif
14318 + .endm
14319 +
14320 /*
14321 * 32bit SYSENTER instruction entry.
14322 *
14323 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14324 CFI_REGISTER rsp,rbp
14325 SWAPGS_UNSAFE_STACK
14326 movq PER_CPU_VAR(kernel_stack), %rsp
14327 - addq $(KERNEL_STACK_OFFSET),%rsp
14328 - /*
14329 - * No need to follow this irqs on/off section: the syscall
14330 - * disabled irqs, here we enable it straight after entry:
14331 - */
14332 - ENABLE_INTERRUPTS(CLBR_NONE)
14333 movl %ebp,%ebp /* zero extension */
14334 pushq_cfi $__USER32_DS
14335 /*CFI_REL_OFFSET ss,0*/
14336 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14337 CFI_REL_OFFSET rsp,0
14338 pushfq_cfi
14339 /*CFI_REL_OFFSET rflags,0*/
14340 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14341 - CFI_REGISTER rip,r10
14342 + orl $X86_EFLAGS_IF,(%rsp)
14343 + GET_THREAD_INFO(%r11)
14344 + movl TI_sysenter_return(%r11), %r11d
14345 + CFI_REGISTER rip,r11
14346 pushq_cfi $__USER32_CS
14347 /*CFI_REL_OFFSET cs,0*/
14348 movl %eax, %eax
14349 - pushq_cfi %r10
14350 + pushq_cfi %r11
14351 CFI_REL_OFFSET rip,0
14352 pushq_cfi %rax
14353 cld
14354 SAVE_ARGS 0,1,0
14355 + pax_enter_kernel_user
14356 +
14357 +#ifdef CONFIG_PAX_RANDKSTACK
14358 + pax_erase_kstack
14359 +#endif
14360 +
14361 + /*
14362 + * No need to follow this irqs on/off section: the syscall
14363 + * disabled irqs, here we enable it straight after entry:
14364 + */
14365 + ENABLE_INTERRUPTS(CLBR_NONE)
14366 /* no need to do an access_ok check here because rbp has been
14367 32bit zero extended */
14368 +
14369 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14370 + addq pax_user_shadow_base,%rbp
14371 + ASM_PAX_OPEN_USERLAND
14372 +#endif
14373 +
14374 ASM_STAC
14375 1: movl (%rbp),%ebp
14376 _ASM_EXTABLE(1b,ia32_badarg)
14377 ASM_CLAC
14378 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14379 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14380 +
14381 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14382 + ASM_PAX_CLOSE_USERLAND
14383 +#endif
14384 +
14385 + GET_THREAD_INFO(%r11)
14386 + orl $TS_COMPAT,TI_status(%r11)
14387 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14388 CFI_REMEMBER_STATE
14389 jnz sysenter_tracesys
14390 cmpq $(IA32_NR_syscalls-1),%rax
14391 @@ -162,15 +209,18 @@ sysenter_do_call:
14392 sysenter_dispatch:
14393 call *ia32_sys_call_table(,%rax,8)
14394 movq %rax,RAX-ARGOFFSET(%rsp)
14395 + GET_THREAD_INFO(%r11)
14396 DISABLE_INTERRUPTS(CLBR_NONE)
14397 TRACE_IRQS_OFF
14398 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14399 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14400 jnz sysexit_audit
14401 sysexit_from_sys_call:
14402 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14403 + pax_exit_kernel_user
14404 + pax_erase_kstack
14405 + andl $~TS_COMPAT,TI_status(%r11)
14406 /* clear IF, that popfq doesn't enable interrupts early */
14407 - andl $~0x200,EFLAGS-R11(%rsp)
14408 - movl RIP-R11(%rsp),%edx /* User %eip */
14409 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14410 + movl RIP(%rsp),%edx /* User %eip */
14411 CFI_REGISTER rip,rdx
14412 RESTORE_ARGS 0,24,0,0,0,0
14413 xorq %r8,%r8
14414 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14415 movl %eax,%esi /* 2nd arg: syscall number */
14416 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14417 call __audit_syscall_entry
14418 +
14419 + pax_erase_kstack
14420 +
14421 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14422 cmpq $(IA32_NR_syscalls-1),%rax
14423 ja ia32_badsys
14424 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14425 .endm
14426
14427 .macro auditsys_exit exit
14428 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14429 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14430 jnz ia32_ret_from_sys_call
14431 TRACE_IRQS_ON
14432 ENABLE_INTERRUPTS(CLBR_NONE)
14433 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14434 1: setbe %al /* 1 if error, 0 if not */
14435 movzbl %al,%edi /* zero-extend that into %edi */
14436 call __audit_syscall_exit
14437 + GET_THREAD_INFO(%r11)
14438 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14439 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14440 DISABLE_INTERRUPTS(CLBR_NONE)
14441 TRACE_IRQS_OFF
14442 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14443 + testl %edi,TI_flags(%r11)
14444 jz \exit
14445 CLEAR_RREGS -ARGOFFSET
14446 jmp int_with_check
14447 @@ -237,7 +291,7 @@ sysexit_audit:
14448
14449 sysenter_tracesys:
14450 #ifdef CONFIG_AUDITSYSCALL
14451 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14452 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14453 jz sysenter_auditsys
14454 #endif
14455 SAVE_REST
14456 @@ -249,6 +303,9 @@ sysenter_tracesys:
14457 RESTORE_REST
14458 cmpq $(IA32_NR_syscalls-1),%rax
14459 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14460 +
14461 + pax_erase_kstack
14462 +
14463 jmp sysenter_do_call
14464 CFI_ENDPROC
14465 ENDPROC(ia32_sysenter_target)
14466 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14467 ENTRY(ia32_cstar_target)
14468 CFI_STARTPROC32 simple
14469 CFI_SIGNAL_FRAME
14470 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14471 + CFI_DEF_CFA rsp,0
14472 CFI_REGISTER rip,rcx
14473 /*CFI_REGISTER rflags,r11*/
14474 SWAPGS_UNSAFE_STACK
14475 movl %esp,%r8d
14476 CFI_REGISTER rsp,r8
14477 movq PER_CPU_VAR(kernel_stack),%rsp
14478 + SAVE_ARGS 8*6,0,0
14479 + pax_enter_kernel_user
14480 +
14481 +#ifdef CONFIG_PAX_RANDKSTACK
14482 + pax_erase_kstack
14483 +#endif
14484 +
14485 /*
14486 * No need to follow this irqs on/off section: the syscall
14487 * disabled irqs and here we enable it straight after entry:
14488 */
14489 ENABLE_INTERRUPTS(CLBR_NONE)
14490 - SAVE_ARGS 8,0,0
14491 movl %eax,%eax /* zero extension */
14492 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14493 movq %rcx,RIP-ARGOFFSET(%rsp)
14494 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14495 /* no need to do an access_ok check here because r8 has been
14496 32bit zero extended */
14497 /* hardware stack frame is complete now */
14498 +
14499 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14500 + ASM_PAX_OPEN_USERLAND
14501 + movq pax_user_shadow_base,%r8
14502 + addq RSP-ARGOFFSET(%rsp),%r8
14503 +#endif
14504 +
14505 ASM_STAC
14506 1: movl (%r8),%r9d
14507 _ASM_EXTABLE(1b,ia32_badarg)
14508 ASM_CLAC
14509 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14510 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14511 +
14512 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14513 + ASM_PAX_CLOSE_USERLAND
14514 +#endif
14515 +
14516 + GET_THREAD_INFO(%r11)
14517 + orl $TS_COMPAT,TI_status(%r11)
14518 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14519 CFI_REMEMBER_STATE
14520 jnz cstar_tracesys
14521 cmpq $IA32_NR_syscalls-1,%rax
14522 @@ -319,13 +395,16 @@ cstar_do_call:
14523 cstar_dispatch:
14524 call *ia32_sys_call_table(,%rax,8)
14525 movq %rax,RAX-ARGOFFSET(%rsp)
14526 + GET_THREAD_INFO(%r11)
14527 DISABLE_INTERRUPTS(CLBR_NONE)
14528 TRACE_IRQS_OFF
14529 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14530 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14531 jnz sysretl_audit
14532 sysretl_from_sys_call:
14533 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14534 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14535 + pax_exit_kernel_user
14536 + pax_erase_kstack
14537 + andl $~TS_COMPAT,TI_status(%r11)
14538 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14539 movl RIP-ARGOFFSET(%rsp),%ecx
14540 CFI_REGISTER rip,rcx
14541 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14542 @@ -352,7 +431,7 @@ sysretl_audit:
14543
14544 cstar_tracesys:
14545 #ifdef CONFIG_AUDITSYSCALL
14546 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14547 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14548 jz cstar_auditsys
14549 #endif
14550 xchgl %r9d,%ebp
14551 @@ -366,11 +445,19 @@ cstar_tracesys:
14552 xchgl %ebp,%r9d
14553 cmpq $(IA32_NR_syscalls-1),%rax
14554 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14555 +
14556 + pax_erase_kstack
14557 +
14558 jmp cstar_do_call
14559 END(ia32_cstar_target)
14560
14561 ia32_badarg:
14562 ASM_CLAC
14563 +
14564 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14565 + ASM_PAX_CLOSE_USERLAND
14566 +#endif
14567 +
14568 movq $-EFAULT,%rax
14569 jmp ia32_sysret
14570 CFI_ENDPROC
14571 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14572 CFI_REL_OFFSET rip,RIP-RIP
14573 PARAVIRT_ADJUST_EXCEPTION_FRAME
14574 SWAPGS
14575 - /*
14576 - * No need to follow this irqs on/off section: the syscall
14577 - * disabled irqs and here we enable it straight after entry:
14578 - */
14579 - ENABLE_INTERRUPTS(CLBR_NONE)
14580 movl %eax,%eax
14581 pushq_cfi %rax
14582 cld
14583 /* note the registers are not zero extended to the sf.
14584 this could be a problem. */
14585 SAVE_ARGS 0,1,0
14586 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14588 + pax_enter_kernel_user
14589 +
14590 +#ifdef CONFIG_PAX_RANDKSTACK
14591 + pax_erase_kstack
14592 +#endif
14593 +
14594 + /*
14595 + * No need to follow this irqs on/off section: the syscall
14596 + * disabled irqs and here we enable it straight after entry:
14597 + */
14598 + ENABLE_INTERRUPTS(CLBR_NONE)
14599 + GET_THREAD_INFO(%r11)
14600 + orl $TS_COMPAT,TI_status(%r11)
14601 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14602 jnz ia32_tracesys
14603 cmpq $(IA32_NR_syscalls-1),%rax
14604 ja ia32_badsys
14605 @@ -442,6 +536,9 @@ ia32_tracesys:
14606 RESTORE_REST
14607 cmpq $(IA32_NR_syscalls-1),%rax
14608 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14609 +
14610 + pax_erase_kstack
14611 +
14612 jmp ia32_do_call
14613 END(ia32_syscall)
14614
14615 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14616 index 8e0ceec..af13504 100644
14617 --- a/arch/x86/ia32/sys_ia32.c
14618 +++ b/arch/x86/ia32/sys_ia32.c
14619 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14620 */
14621 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14622 {
14623 - typeof(ubuf->st_uid) uid = 0;
14624 - typeof(ubuf->st_gid) gid = 0;
14625 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14626 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14627 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14628 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14629 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14630 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14631 index 372231c..51b537d 100644
14632 --- a/arch/x86/include/asm/alternative-asm.h
14633 +++ b/arch/x86/include/asm/alternative-asm.h
14634 @@ -18,6 +18,45 @@
14635 .endm
14636 #endif
14637
14638 +#ifdef KERNEXEC_PLUGIN
14639 + .macro pax_force_retaddr_bts rip=0
14640 + btsq $63,\rip(%rsp)
14641 + .endm
14642 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14643 + .macro pax_force_retaddr rip=0, reload=0
14644 + btsq $63,\rip(%rsp)
14645 + .endm
14646 + .macro pax_force_fptr ptr
14647 + btsq $63,\ptr
14648 + .endm
14649 + .macro pax_set_fptr_mask
14650 + .endm
14651 +#endif
14652 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14653 + .macro pax_force_retaddr rip=0, reload=0
14654 + .if \reload
14655 + pax_set_fptr_mask
14656 + .endif
14657 + orq %r12,\rip(%rsp)
14658 + .endm
14659 + .macro pax_force_fptr ptr
14660 + orq %r12,\ptr
14661 + .endm
14662 + .macro pax_set_fptr_mask
14663 + movabs $0x8000000000000000,%r12
14664 + .endm
14665 +#endif
14666 +#else
14667 + .macro pax_force_retaddr rip=0, reload=0
14668 + .endm
14669 + .macro pax_force_fptr ptr
14670 + .endm
14671 + .macro pax_force_retaddr_bts rip=0
14672 + .endm
14673 + .macro pax_set_fptr_mask
14674 + .endm
14675 +#endif
14676 +
14677 .macro altinstruction_entry orig alt feature orig_len alt_len
14678 .long \orig - .
14679 .long \alt - .
14680 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14681 index 0a3f9c9..c9d081d 100644
14682 --- a/arch/x86/include/asm/alternative.h
14683 +++ b/arch/x86/include/asm/alternative.h
14684 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14685 ".pushsection .discard,\"aw\",@progbits\n" \
14686 DISCARD_ENTRY(1) \
14687 ".popsection\n" \
14688 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14689 + ".pushsection .altinstr_replacement, \"a\"\n" \
14690 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14691 ".popsection"
14692
14693 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14694 DISCARD_ENTRY(1) \
14695 DISCARD_ENTRY(2) \
14696 ".popsection\n" \
14697 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14698 + ".pushsection .altinstr_replacement, \"a\"\n" \
14699 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14700 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14701 ".popsection"
14702 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14703 index 1d2091a..f5074c1 100644
14704 --- a/arch/x86/include/asm/apic.h
14705 +++ b/arch/x86/include/asm/apic.h
14706 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14707
14708 #ifdef CONFIG_X86_LOCAL_APIC
14709
14710 -extern unsigned int apic_verbosity;
14711 +extern int apic_verbosity;
14712 extern int local_apic_timer_c2_ok;
14713
14714 extern int disable_apic;
14715 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14716 index 20370c6..a2eb9b0 100644
14717 --- a/arch/x86/include/asm/apm.h
14718 +++ b/arch/x86/include/asm/apm.h
14719 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14720 __asm__ __volatile__(APM_DO_ZERO_SEGS
14721 "pushl %%edi\n\t"
14722 "pushl %%ebp\n\t"
14723 - "lcall *%%cs:apm_bios_entry\n\t"
14724 + "lcall *%%ss:apm_bios_entry\n\t"
14725 "setc %%al\n\t"
14726 "popl %%ebp\n\t"
14727 "popl %%edi\n\t"
14728 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14729 __asm__ __volatile__(APM_DO_ZERO_SEGS
14730 "pushl %%edi\n\t"
14731 "pushl %%ebp\n\t"
14732 - "lcall *%%cs:apm_bios_entry\n\t"
14733 + "lcall *%%ss:apm_bios_entry\n\t"
14734 "setc %%bl\n\t"
14735 "popl %%ebp\n\t"
14736 "popl %%edi\n\t"
14737 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14738 index b17f4f4..9620151 100644
14739 --- a/arch/x86/include/asm/atomic.h
14740 +++ b/arch/x86/include/asm/atomic.h
14741 @@ -23,7 +23,18 @@
14742 */
14743 static inline int atomic_read(const atomic_t *v)
14744 {
14745 - return (*(volatile int *)&(v)->counter);
14746 + return (*(volatile const int *)&(v)->counter);
14747 +}
14748 +
14749 +/**
14750 + * atomic_read_unchecked - read atomic variable
14751 + * @v: pointer of type atomic_unchecked_t
14752 + *
14753 + * Atomically reads the value of @v.
14754 + */
14755 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14756 +{
14757 + return (*(volatile const int *)&(v)->counter);
14758 }
14759
14760 /**
14761 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14762 }
14763
14764 /**
14765 + * atomic_set_unchecked - set atomic variable
14766 + * @v: pointer of type atomic_unchecked_t
14767 + * @i: required value
14768 + *
14769 + * Atomically sets the value of @v to @i.
14770 + */
14771 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14772 +{
14773 + v->counter = i;
14774 +}
14775 +
14776 +/**
14777 * atomic_add - add integer to atomic variable
14778 * @i: integer value to add
14779 * @v: pointer of type atomic_t
14780 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14781 */
14782 static inline void atomic_add(int i, atomic_t *v)
14783 {
14784 - asm volatile(LOCK_PREFIX "addl %1,%0"
14785 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14786 +
14787 +#ifdef CONFIG_PAX_REFCOUNT
14788 + "jno 0f\n"
14789 + LOCK_PREFIX "subl %1,%0\n"
14790 + "int $4\n0:\n"
14791 + _ASM_EXTABLE(0b, 0b)
14792 +#endif
14793 +
14794 + : "+m" (v->counter)
14795 + : "ir" (i));
14796 +}
14797 +
14798 +/**
14799 + * atomic_add_unchecked - add integer to atomic variable
14800 + * @i: integer value to add
14801 + * @v: pointer of type atomic_unchecked_t
14802 + *
14803 + * Atomically adds @i to @v.
14804 + */
14805 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14806 +{
14807 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14808 : "+m" (v->counter)
14809 : "ir" (i));
14810 }
14811 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14812 */
14813 static inline void atomic_sub(int i, atomic_t *v)
14814 {
14815 - asm volatile(LOCK_PREFIX "subl %1,%0"
14816 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14817 +
14818 +#ifdef CONFIG_PAX_REFCOUNT
14819 + "jno 0f\n"
14820 + LOCK_PREFIX "addl %1,%0\n"
14821 + "int $4\n0:\n"
14822 + _ASM_EXTABLE(0b, 0b)
14823 +#endif
14824 +
14825 + : "+m" (v->counter)
14826 + : "ir" (i));
14827 +}
14828 +
14829 +/**
14830 + * atomic_sub_unchecked - subtract integer from atomic variable
14831 + * @i: integer value to subtract
14832 + * @v: pointer of type atomic_unchecked_t
14833 + *
14834 + * Atomically subtracts @i from @v.
14835 + */
14836 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14837 +{
14838 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14839 : "+m" (v->counter)
14840 : "ir" (i));
14841 }
14842 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14843 */
14844 static inline int atomic_sub_and_test(int i, atomic_t *v)
14845 {
14846 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14847 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14848 }
14849
14850 /**
14851 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14852 */
14853 static inline void atomic_inc(atomic_t *v)
14854 {
14855 - asm volatile(LOCK_PREFIX "incl %0"
14856 + asm volatile(LOCK_PREFIX "incl %0\n"
14857 +
14858 +#ifdef CONFIG_PAX_REFCOUNT
14859 + "jno 0f\n"
14860 + LOCK_PREFIX "decl %0\n"
14861 + "int $4\n0:\n"
14862 + _ASM_EXTABLE(0b, 0b)
14863 +#endif
14864 +
14865 + : "+m" (v->counter));
14866 +}
14867 +
14868 +/**
14869 + * atomic_inc_unchecked - increment atomic variable
14870 + * @v: pointer of type atomic_unchecked_t
14871 + *
14872 + * Atomically increments @v by 1.
14873 + */
14874 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14875 +{
14876 + asm volatile(LOCK_PREFIX "incl %0\n"
14877 : "+m" (v->counter));
14878 }
14879
14880 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14881 */
14882 static inline void atomic_dec(atomic_t *v)
14883 {
14884 - asm volatile(LOCK_PREFIX "decl %0"
14885 + asm volatile(LOCK_PREFIX "decl %0\n"
14886 +
14887 +#ifdef CONFIG_PAX_REFCOUNT
14888 + "jno 0f\n"
14889 + LOCK_PREFIX "incl %0\n"
14890 + "int $4\n0:\n"
14891 + _ASM_EXTABLE(0b, 0b)
14892 +#endif
14893 +
14894 + : "+m" (v->counter));
14895 +}
14896 +
14897 +/**
14898 + * atomic_dec_unchecked - decrement atomic variable
14899 + * @v: pointer of type atomic_unchecked_t
14900 + *
14901 + * Atomically decrements @v by 1.
14902 + */
14903 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14904 +{
14905 + asm volatile(LOCK_PREFIX "decl %0\n"
14906 : "+m" (v->counter));
14907 }
14908
14909 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14910 */
14911 static inline int atomic_dec_and_test(atomic_t *v)
14912 {
14913 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14914 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14915 }
14916
14917 /**
14918 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14919 */
14920 static inline int atomic_inc_and_test(atomic_t *v)
14921 {
14922 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14923 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14924 +}
14925 +
14926 +/**
14927 + * atomic_inc_and_test_unchecked - increment and test
14928 + * @v: pointer of type atomic_unchecked_t
14929 + *
14930 + * Atomically increments @v by 1
14931 + * and returns true if the result is zero, or false for all
14932 + * other cases.
14933 + */
14934 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14935 +{
14936 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14937 }
14938
14939 /**
14940 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14941 */
14942 static inline int atomic_add_negative(int i, atomic_t *v)
14943 {
14944 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14945 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14946 }
14947
14948 /**
14949 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14950 */
14951 static inline int atomic_add_return(int i, atomic_t *v)
14952 {
14953 + return i + xadd_check_overflow(&v->counter, i);
14954 +}
14955 +
14956 +/**
14957 + * atomic_add_return_unchecked - add integer and return
14958 + * @i: integer value to add
14959 + * @v: pointer of type atomic_unchecked_t
14960 + *
14961 + * Atomically adds @i to @v and returns @i + @v
14962 + */
14963 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14964 +{
14965 return i + xadd(&v->counter, i);
14966 }
14967
14968 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14969 }
14970
14971 #define atomic_inc_return(v) (atomic_add_return(1, v))
14972 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14973 +{
14974 + return atomic_add_return_unchecked(1, v);
14975 +}
14976 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14977
14978 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14979 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14980 +{
14981 + return cmpxchg(&v->counter, old, new);
14982 +}
14983 +
14984 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14985 {
14986 return cmpxchg(&v->counter, old, new);
14987 }
14988 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14989 return xchg(&v->counter, new);
14990 }
14991
14992 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14993 +{
14994 + return xchg(&v->counter, new);
14995 +}
14996 +
14997 /**
14998 * __atomic_add_unless - add unless the number is already a given value
14999 * @v: pointer of type atomic_t
15000 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15001 * Atomically adds @a to @v, so long as @v was not already @u.
15002 * Returns the old value of @v.
15003 */
15004 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15005 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15006 {
15007 - int c, old;
15008 + int c, old, new;
15009 c = atomic_read(v);
15010 for (;;) {
15011 - if (unlikely(c == (u)))
15012 + if (unlikely(c == u))
15013 break;
15014 - old = atomic_cmpxchg((v), c, c + (a));
15015 +
15016 + asm volatile("addl %2,%0\n"
15017 +
15018 +#ifdef CONFIG_PAX_REFCOUNT
15019 + "jno 0f\n"
15020 + "subl %2,%0\n"
15021 + "int $4\n0:\n"
15022 + _ASM_EXTABLE(0b, 0b)
15023 +#endif
15024 +
15025 + : "=r" (new)
15026 + : "0" (c), "ir" (a));
15027 +
15028 + old = atomic_cmpxchg(v, c, new);
15029 if (likely(old == c))
15030 break;
15031 c = old;
15032 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15033 }
15034
15035 /**
15036 + * atomic_inc_not_zero_hint - increment if not null
15037 + * @v: pointer of type atomic_t
15038 + * @hint: probable value of the atomic before the increment
15039 + *
15040 + * This version of atomic_inc_not_zero() gives a hint of probable
15041 + * value of the atomic. This helps processor to not read the memory
15042 + * before doing the atomic read/modify/write cycle, lowering
15043 + * number of bus transactions on some arches.
15044 + *
15045 + * Returns: 0 if increment was not done, 1 otherwise.
15046 + */
15047 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15048 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15049 +{
15050 + int val, c = hint, new;
15051 +
15052 + /* sanity test, should be removed by compiler if hint is a constant */
15053 + if (!hint)
15054 + return __atomic_add_unless(v, 1, 0);
15055 +
15056 + do {
15057 + asm volatile("incl %0\n"
15058 +
15059 +#ifdef CONFIG_PAX_REFCOUNT
15060 + "jno 0f\n"
15061 + "decl %0\n"
15062 + "int $4\n0:\n"
15063 + _ASM_EXTABLE(0b, 0b)
15064 +#endif
15065 +
15066 + : "=r" (new)
15067 + : "0" (c));
15068 +
15069 + val = atomic_cmpxchg(v, c, new);
15070 + if (val == c)
15071 + return 1;
15072 + c = val;
15073 + } while (c);
15074 +
15075 + return 0;
15076 +}
15077 +
15078 +/**
15079 * atomic_inc_short - increment of a short integer
15080 * @v: pointer to type int
15081 *
15082 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15083 #endif
15084
15085 /* These are x86-specific, used by some header files */
15086 -#define atomic_clear_mask(mask, addr) \
15087 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15088 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15089 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15090 +{
15091 + asm volatile(LOCK_PREFIX "andl %1,%0"
15092 + : "+m" (v->counter)
15093 + : "r" (~(mask))
15094 + : "memory");
15095 +}
15096
15097 -#define atomic_set_mask(mask, addr) \
15098 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15099 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15100 - : "memory")
15101 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15102 +{
15103 + asm volatile(LOCK_PREFIX "andl %1,%0"
15104 + : "+m" (v->counter)
15105 + : "r" (~(mask))
15106 + : "memory");
15107 +}
15108 +
15109 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15110 +{
15111 + asm volatile(LOCK_PREFIX "orl %1,%0"
15112 + : "+m" (v->counter)
15113 + : "r" (mask)
15114 + : "memory");
15115 +}
15116 +
15117 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15118 +{
15119 + asm volatile(LOCK_PREFIX "orl %1,%0"
15120 + : "+m" (v->counter)
15121 + : "r" (mask)
15122 + : "memory");
15123 +}
15124
15125 /* Atomic operations are already serializing on x86 */
15126 #define smp_mb__before_atomic_dec() barrier()
15127 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15128 index b154de7..bf18a5a 100644
15129 --- a/arch/x86/include/asm/atomic64_32.h
15130 +++ b/arch/x86/include/asm/atomic64_32.h
15131 @@ -12,6 +12,14 @@ typedef struct {
15132 u64 __aligned(8) counter;
15133 } atomic64_t;
15134
15135 +#ifdef CONFIG_PAX_REFCOUNT
15136 +typedef struct {
15137 + u64 __aligned(8) counter;
15138 +} atomic64_unchecked_t;
15139 +#else
15140 +typedef atomic64_t atomic64_unchecked_t;
15141 +#endif
15142 +
15143 #define ATOMIC64_INIT(val) { (val) }
15144
15145 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15146 @@ -37,21 +45,31 @@ typedef struct {
15147 ATOMIC64_DECL_ONE(sym##_386)
15148
15149 ATOMIC64_DECL_ONE(add_386);
15150 +ATOMIC64_DECL_ONE(add_unchecked_386);
15151 ATOMIC64_DECL_ONE(sub_386);
15152 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15153 ATOMIC64_DECL_ONE(inc_386);
15154 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15155 ATOMIC64_DECL_ONE(dec_386);
15156 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15157 #endif
15158
15159 #define alternative_atomic64(f, out, in...) \
15160 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15161
15162 ATOMIC64_DECL(read);
15163 +ATOMIC64_DECL(read_unchecked);
15164 ATOMIC64_DECL(set);
15165 +ATOMIC64_DECL(set_unchecked);
15166 ATOMIC64_DECL(xchg);
15167 ATOMIC64_DECL(add_return);
15168 +ATOMIC64_DECL(add_return_unchecked);
15169 ATOMIC64_DECL(sub_return);
15170 +ATOMIC64_DECL(sub_return_unchecked);
15171 ATOMIC64_DECL(inc_return);
15172 +ATOMIC64_DECL(inc_return_unchecked);
15173 ATOMIC64_DECL(dec_return);
15174 +ATOMIC64_DECL(dec_return_unchecked);
15175 ATOMIC64_DECL(dec_if_positive);
15176 ATOMIC64_DECL(inc_not_zero);
15177 ATOMIC64_DECL(add_unless);
15178 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15179 }
15180
15181 /**
15182 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15183 + * @p: pointer to type atomic64_unchecked_t
15184 + * @o: expected value
15185 + * @n: new value
15186 + *
15187 + * Atomically sets @v to @n if it was equal to @o and returns
15188 + * the old value.
15189 + */
15190 +
15191 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15192 +{
15193 + return cmpxchg64(&v->counter, o, n);
15194 +}
15195 +
15196 +/**
15197 * atomic64_xchg - xchg atomic64 variable
15198 * @v: pointer to type atomic64_t
15199 * @n: value to assign
15200 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15201 }
15202
15203 /**
15204 + * atomic64_set_unchecked - set atomic64 variable
15205 + * @v: pointer to type atomic64_unchecked_t
15206 + * @n: value to assign
15207 + *
15208 + * Atomically sets the value of @v to @n.
15209 + */
15210 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15211 +{
15212 + unsigned high = (unsigned)(i >> 32);
15213 + unsigned low = (unsigned)i;
15214 + alternative_atomic64(set, /* no output */,
15215 + "S" (v), "b" (low), "c" (high)
15216 + : "eax", "edx", "memory");
15217 +}
15218 +
15219 +/**
15220 * atomic64_read - read atomic64 variable
15221 * @v: pointer to type atomic64_t
15222 *
15223 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15224 }
15225
15226 /**
15227 + * atomic64_read_unchecked - read atomic64 variable
15228 + * @v: pointer to type atomic64_unchecked_t
15229 + *
15230 + * Atomically reads the value of @v and returns it.
15231 + */
15232 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15233 +{
15234 + long long r;
15235 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15236 + return r;
15237 + }
15238 +
15239 +/**
15240 * atomic64_add_return - add and return
15241 * @i: integer value to add
15242 * @v: pointer to type atomic64_t
15243 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15244 return i;
15245 }
15246
15247 +/**
15248 + * atomic64_add_return_unchecked - add and return
15249 + * @i: integer value to add
15250 + * @v: pointer to type atomic64_unchecked_t
15251 + *
15252 + * Atomically adds @i to @v and returns @i + *@v
15253 + */
15254 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15255 +{
15256 + alternative_atomic64(add_return_unchecked,
15257 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15258 + ASM_NO_INPUT_CLOBBER("memory"));
15259 + return i;
15260 +}
15261 +
15262 /*
15263 * Other variants with different arithmetic operators:
15264 */
15265 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15266 return a;
15267 }
15268
15269 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15270 +{
15271 + long long a;
15272 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15273 + "S" (v) : "memory", "ecx");
15274 + return a;
15275 +}
15276 +
15277 static inline long long atomic64_dec_return(atomic64_t *v)
15278 {
15279 long long a;
15280 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15281 }
15282
15283 /**
15284 + * atomic64_add_unchecked - add integer to atomic64 variable
15285 + * @i: integer value to add
15286 + * @v: pointer to type atomic64_unchecked_t
15287 + *
15288 + * Atomically adds @i to @v.
15289 + */
15290 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15291 +{
15292 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15293 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15294 + ASM_NO_INPUT_CLOBBER("memory"));
15295 + return i;
15296 +}
15297 +
15298 +/**
15299 * atomic64_sub - subtract the atomic64 variable
15300 * @i: integer value to subtract
15301 * @v: pointer to type atomic64_t
15302 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15303 index 46e9052..ae45136 100644
15304 --- a/arch/x86/include/asm/atomic64_64.h
15305 +++ b/arch/x86/include/asm/atomic64_64.h
15306 @@ -18,7 +18,19 @@
15307 */
15308 static inline long atomic64_read(const atomic64_t *v)
15309 {
15310 - return (*(volatile long *)&(v)->counter);
15311 + return (*(volatile const long *)&(v)->counter);
15312 +}
15313 +
15314 +/**
15315 + * atomic64_read_unchecked - read atomic64 variable
15316 + * @v: pointer of type atomic64_unchecked_t
15317 + *
15318 + * Atomically reads the value of @v.
15319 + * Doesn't imply a read memory barrier.
15320 + */
15321 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15322 +{
15323 + return (*(volatile const long *)&(v)->counter);
15324 }
15325
15326 /**
15327 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15328 }
15329
15330 /**
15331 + * atomic64_set_unchecked - set atomic64 variable
15332 + * @v: pointer to type atomic64_unchecked_t
15333 + * @i: required value
15334 + *
15335 + * Atomically sets the value of @v to @i.
15336 + */
15337 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15338 +{
15339 + v->counter = i;
15340 +}
15341 +
15342 +/**
15343 * atomic64_add - add integer to atomic64 variable
15344 * @i: integer value to add
15345 * @v: pointer to type atomic64_t
15346 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15347 */
15348 static inline void atomic64_add(long i, atomic64_t *v)
15349 {
15350 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15351 +
15352 +#ifdef CONFIG_PAX_REFCOUNT
15353 + "jno 0f\n"
15354 + LOCK_PREFIX "subq %1,%0\n"
15355 + "int $4\n0:\n"
15356 + _ASM_EXTABLE(0b, 0b)
15357 +#endif
15358 +
15359 + : "=m" (v->counter)
15360 + : "er" (i), "m" (v->counter));
15361 +}
15362 +
15363 +/**
15364 + * atomic64_add_unchecked - add integer to atomic64 variable
15365 + * @i: integer value to add
15366 + * @v: pointer to type atomic64_unchecked_t
15367 + *
15368 + * Atomically adds @i to @v.
15369 + */
15370 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15371 +{
15372 asm volatile(LOCK_PREFIX "addq %1,%0"
15373 : "=m" (v->counter)
15374 : "er" (i), "m" (v->counter));
15375 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15376 */
15377 static inline void atomic64_sub(long i, atomic64_t *v)
15378 {
15379 - asm volatile(LOCK_PREFIX "subq %1,%0"
15380 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15381 +
15382 +#ifdef CONFIG_PAX_REFCOUNT
15383 + "jno 0f\n"
15384 + LOCK_PREFIX "addq %1,%0\n"
15385 + "int $4\n0:\n"
15386 + _ASM_EXTABLE(0b, 0b)
15387 +#endif
15388 +
15389 + : "=m" (v->counter)
15390 + : "er" (i), "m" (v->counter));
15391 +}
15392 +
15393 +/**
15394 + * atomic64_sub_unchecked - subtract the atomic64 variable
15395 + * @i: integer value to subtract
15396 + * @v: pointer to type atomic64_unchecked_t
15397 + *
15398 + * Atomically subtracts @i from @v.
15399 + */
15400 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15401 +{
15402 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15403 : "=m" (v->counter)
15404 : "er" (i), "m" (v->counter));
15405 }
15406 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15407 */
15408 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15409 {
15410 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15411 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15412 }
15413
15414 /**
15415 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15416 */
15417 static inline void atomic64_inc(atomic64_t *v)
15418 {
15419 + asm volatile(LOCK_PREFIX "incq %0\n"
15420 +
15421 +#ifdef CONFIG_PAX_REFCOUNT
15422 + "jno 0f\n"
15423 + LOCK_PREFIX "decq %0\n"
15424 + "int $4\n0:\n"
15425 + _ASM_EXTABLE(0b, 0b)
15426 +#endif
15427 +
15428 + : "=m" (v->counter)
15429 + : "m" (v->counter));
15430 +}
15431 +
15432 +/**
15433 + * atomic64_inc_unchecked - increment atomic64 variable
15434 + * @v: pointer to type atomic64_unchecked_t
15435 + *
15436 + * Atomically increments @v by 1.
15437 + */
15438 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15439 +{
15440 asm volatile(LOCK_PREFIX "incq %0"
15441 : "=m" (v->counter)
15442 : "m" (v->counter));
15443 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15444 */
15445 static inline void atomic64_dec(atomic64_t *v)
15446 {
15447 - asm volatile(LOCK_PREFIX "decq %0"
15448 + asm volatile(LOCK_PREFIX "decq %0\n"
15449 +
15450 +#ifdef CONFIG_PAX_REFCOUNT
15451 + "jno 0f\n"
15452 + LOCK_PREFIX "incq %0\n"
15453 + "int $4\n0:\n"
15454 + _ASM_EXTABLE(0b, 0b)
15455 +#endif
15456 +
15457 + : "=m" (v->counter)
15458 + : "m" (v->counter));
15459 +}
15460 +
15461 +/**
15462 + * atomic64_dec_unchecked - decrement atomic64 variable
15463 + * @v: pointer to type atomic64_t
15464 + *
15465 + * Atomically decrements @v by 1.
15466 + */
15467 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15468 +{
15469 + asm volatile(LOCK_PREFIX "decq %0\n"
15470 : "=m" (v->counter)
15471 : "m" (v->counter));
15472 }
15473 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15474 */
15475 static inline int atomic64_dec_and_test(atomic64_t *v)
15476 {
15477 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15478 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15479 }
15480
15481 /**
15482 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15483 */
15484 static inline int atomic64_inc_and_test(atomic64_t *v)
15485 {
15486 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15487 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15488 }
15489
15490 /**
15491 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15492 */
15493 static inline int atomic64_add_negative(long i, atomic64_t *v)
15494 {
15495 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15496 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15497 }
15498
15499 /**
15500 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15501 */
15502 static inline long atomic64_add_return(long i, atomic64_t *v)
15503 {
15504 + return i + xadd_check_overflow(&v->counter, i);
15505 +}
15506 +
15507 +/**
15508 + * atomic64_add_return_unchecked - add and return
15509 + * @i: integer value to add
15510 + * @v: pointer to type atomic64_unchecked_t
15511 + *
15512 + * Atomically adds @i to @v and returns @i + @v
15513 + */
15514 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15515 +{
15516 return i + xadd(&v->counter, i);
15517 }
15518
15519 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15520 }
15521
15522 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15523 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15524 +{
15525 + return atomic64_add_return_unchecked(1, v);
15526 +}
15527 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15528
15529 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15530 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15531 return cmpxchg(&v->counter, old, new);
15532 }
15533
15534 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15535 +{
15536 + return cmpxchg(&v->counter, old, new);
15537 +}
15538 +
15539 static inline long atomic64_xchg(atomic64_t *v, long new)
15540 {
15541 return xchg(&v->counter, new);
15542 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15543 */
15544 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15545 {
15546 - long c, old;
15547 + long c, old, new;
15548 c = atomic64_read(v);
15549 for (;;) {
15550 - if (unlikely(c == (u)))
15551 + if (unlikely(c == u))
15552 break;
15553 - old = atomic64_cmpxchg((v), c, c + (a));
15554 +
15555 + asm volatile("add %2,%0\n"
15556 +
15557 +#ifdef CONFIG_PAX_REFCOUNT
15558 + "jno 0f\n"
15559 + "sub %2,%0\n"
15560 + "int $4\n0:\n"
15561 + _ASM_EXTABLE(0b, 0b)
15562 +#endif
15563 +
15564 + : "=r" (new)
15565 + : "0" (c), "ir" (a));
15566 +
15567 + old = atomic64_cmpxchg(v, c, new);
15568 if (likely(old == c))
15569 break;
15570 c = old;
15571 }
15572 - return c != (u);
15573 + return c != u;
15574 }
15575
15576 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15577 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15578 index 9fc1af7..fc71228 100644
15579 --- a/arch/x86/include/asm/bitops.h
15580 +++ b/arch/x86/include/asm/bitops.h
15581 @@ -49,7 +49,7 @@
15582 * a mask operation on a byte.
15583 */
15584 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15585 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15586 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15587 #define CONST_MASK(nr) (1 << ((nr) & 7))
15588
15589 /**
15590 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15591 */
15592 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15593 {
15594 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15595 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15596 }
15597
15598 /**
15599 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15600 */
15601 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15602 {
15603 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15604 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15605 }
15606
15607 /**
15608 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15609 */
15610 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15611 {
15612 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15613 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15614 }
15615
15616 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15617 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15618 *
15619 * Undefined if no bit exists, so code should check against 0 first.
15620 */
15621 -static inline unsigned long __ffs(unsigned long word)
15622 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15623 {
15624 asm("rep; bsf %1,%0"
15625 : "=r" (word)
15626 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15627 *
15628 * Undefined if no zero exists, so code should check against ~0UL first.
15629 */
15630 -static inline unsigned long ffz(unsigned long word)
15631 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15632 {
15633 asm("rep; bsf %1,%0"
15634 : "=r" (word)
15635 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15636 *
15637 * Undefined if no set bit exists, so code should check against 0 first.
15638 */
15639 -static inline unsigned long __fls(unsigned long word)
15640 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15641 {
15642 asm("bsr %1,%0"
15643 : "=r" (word)
15644 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15645 * set bit if value is nonzero. The last (most significant) bit is
15646 * at position 32.
15647 */
15648 -static inline int fls(int x)
15649 +static inline int __intentional_overflow(-1) fls(int x)
15650 {
15651 int r;
15652
15653 @@ -478,7 +478,7 @@ static inline int fls(int x)
15654 * at position 64.
15655 */
15656 #ifdef CONFIG_X86_64
15657 -static __always_inline int fls64(__u64 x)
15658 +static __always_inline long fls64(__u64 x)
15659 {
15660 int bitpos = -1;
15661 /*
15662 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15663 index 4fa687a..60f2d39 100644
15664 --- a/arch/x86/include/asm/boot.h
15665 +++ b/arch/x86/include/asm/boot.h
15666 @@ -6,10 +6,15 @@
15667 #include <uapi/asm/boot.h>
15668
15669 /* Physical address where kernel should be loaded. */
15670 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15671 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15672 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15673 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15674
15675 +#ifndef __ASSEMBLY__
15676 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15677 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15678 +#endif
15679 +
15680 /* Minimum kernel alignment, as a power of two */
15681 #ifdef CONFIG_X86_64
15682 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15683 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15684 index 48f99f1..d78ebf9 100644
15685 --- a/arch/x86/include/asm/cache.h
15686 +++ b/arch/x86/include/asm/cache.h
15687 @@ -5,12 +5,13 @@
15688
15689 /* L1 cache line size */
15690 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15691 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15692 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15693
15694 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15695 +#define __read_only __attribute__((__section__(".data..read_only")))
15696
15697 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15698 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15699 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15700
15701 #ifdef CONFIG_X86_VSMP
15702 #ifdef CONFIG_SMP
15703 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15704 index 9863ee3..4a1f8e1 100644
15705 --- a/arch/x86/include/asm/cacheflush.h
15706 +++ b/arch/x86/include/asm/cacheflush.h
15707 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15708 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15709
15710 if (pg_flags == _PGMT_DEFAULT)
15711 - return -1;
15712 + return ~0UL;
15713 else if (pg_flags == _PGMT_WC)
15714 return _PAGE_CACHE_WC;
15715 else if (pg_flags == _PGMT_UC_MINUS)
15716 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15717 index cb4c73b..c473c29 100644
15718 --- a/arch/x86/include/asm/calling.h
15719 +++ b/arch/x86/include/asm/calling.h
15720 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15721 #define RSP 152
15722 #define SS 160
15723
15724 -#define ARGOFFSET R11
15725 -#define SWFRAME ORIG_RAX
15726 +#define ARGOFFSET R15
15727
15728 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15729 - subq $9*8+\addskip, %rsp
15730 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15731 - movq_cfi rdi, 8*8
15732 - movq_cfi rsi, 7*8
15733 - movq_cfi rdx, 6*8
15734 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15735 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15736 + movq_cfi rdi, RDI
15737 + movq_cfi rsi, RSI
15738 + movq_cfi rdx, RDX
15739
15740 .if \save_rcx
15741 - movq_cfi rcx, 5*8
15742 + movq_cfi rcx, RCX
15743 .endif
15744
15745 - movq_cfi rax, 4*8
15746 + movq_cfi rax, RAX
15747
15748 .if \save_r891011
15749 - movq_cfi r8, 3*8
15750 - movq_cfi r9, 2*8
15751 - movq_cfi r10, 1*8
15752 - movq_cfi r11, 0*8
15753 + movq_cfi r8, R8
15754 + movq_cfi r9, R9
15755 + movq_cfi r10, R10
15756 + movq_cfi r11, R11
15757 .endif
15758
15759 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15760 + movq_cfi r12, R12
15761 +#endif
15762 +
15763 .endm
15764
15765 -#define ARG_SKIP (9*8)
15766 +#define ARG_SKIP ORIG_RAX
15767
15768 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15769 rstor_r8910=1, rstor_rdx=1
15770 +
15771 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15772 + movq_cfi_restore R12, r12
15773 +#endif
15774 +
15775 .if \rstor_r11
15776 - movq_cfi_restore 0*8, r11
15777 + movq_cfi_restore R11, r11
15778 .endif
15779
15780 .if \rstor_r8910
15781 - movq_cfi_restore 1*8, r10
15782 - movq_cfi_restore 2*8, r9
15783 - movq_cfi_restore 3*8, r8
15784 + movq_cfi_restore R10, r10
15785 + movq_cfi_restore R9, r9
15786 + movq_cfi_restore R8, r8
15787 .endif
15788
15789 .if \rstor_rax
15790 - movq_cfi_restore 4*8, rax
15791 + movq_cfi_restore RAX, rax
15792 .endif
15793
15794 .if \rstor_rcx
15795 - movq_cfi_restore 5*8, rcx
15796 + movq_cfi_restore RCX, rcx
15797 .endif
15798
15799 .if \rstor_rdx
15800 - movq_cfi_restore 6*8, rdx
15801 + movq_cfi_restore RDX, rdx
15802 .endif
15803
15804 - movq_cfi_restore 7*8, rsi
15805 - movq_cfi_restore 8*8, rdi
15806 + movq_cfi_restore RSI, rsi
15807 + movq_cfi_restore RDI, rdi
15808
15809 - .if ARG_SKIP+\addskip > 0
15810 - addq $ARG_SKIP+\addskip, %rsp
15811 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15812 + .if ORIG_RAX+\addskip > 0
15813 + addq $ORIG_RAX+\addskip, %rsp
15814 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15815 .endif
15816 .endm
15817
15818 - .macro LOAD_ARGS offset, skiprax=0
15819 - movq \offset(%rsp), %r11
15820 - movq \offset+8(%rsp), %r10
15821 - movq \offset+16(%rsp), %r9
15822 - movq \offset+24(%rsp), %r8
15823 - movq \offset+40(%rsp), %rcx
15824 - movq \offset+48(%rsp), %rdx
15825 - movq \offset+56(%rsp), %rsi
15826 - movq \offset+64(%rsp), %rdi
15827 + .macro LOAD_ARGS skiprax=0
15828 + movq R11(%rsp), %r11
15829 + movq R10(%rsp), %r10
15830 + movq R9(%rsp), %r9
15831 + movq R8(%rsp), %r8
15832 + movq RCX(%rsp), %rcx
15833 + movq RDX(%rsp), %rdx
15834 + movq RSI(%rsp), %rsi
15835 + movq RDI(%rsp), %rdi
15836 .if \skiprax
15837 .else
15838 - movq \offset+72(%rsp), %rax
15839 + movq RAX(%rsp), %rax
15840 .endif
15841 .endm
15842
15843 -#define REST_SKIP (6*8)
15844 -
15845 .macro SAVE_REST
15846 - subq $REST_SKIP, %rsp
15847 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15848 - movq_cfi rbx, 5*8
15849 - movq_cfi rbp, 4*8
15850 - movq_cfi r12, 3*8
15851 - movq_cfi r13, 2*8
15852 - movq_cfi r14, 1*8
15853 - movq_cfi r15, 0*8
15854 + movq_cfi rbx, RBX
15855 + movq_cfi rbp, RBP
15856 +
15857 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15858 + movq_cfi r12, R12
15859 +#endif
15860 +
15861 + movq_cfi r13, R13
15862 + movq_cfi r14, R14
15863 + movq_cfi r15, R15
15864 .endm
15865
15866 .macro RESTORE_REST
15867 - movq_cfi_restore 0*8, r15
15868 - movq_cfi_restore 1*8, r14
15869 - movq_cfi_restore 2*8, r13
15870 - movq_cfi_restore 3*8, r12
15871 - movq_cfi_restore 4*8, rbp
15872 - movq_cfi_restore 5*8, rbx
15873 - addq $REST_SKIP, %rsp
15874 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15875 + movq_cfi_restore R15, r15
15876 + movq_cfi_restore R14, r14
15877 + movq_cfi_restore R13, r13
15878 +
15879 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15880 + movq_cfi_restore R12, r12
15881 +#endif
15882 +
15883 + movq_cfi_restore RBP, rbp
15884 + movq_cfi_restore RBX, rbx
15885 .endm
15886
15887 .macro SAVE_ALL
15888 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15889 index f50de69..2b0a458 100644
15890 --- a/arch/x86/include/asm/checksum_32.h
15891 +++ b/arch/x86/include/asm/checksum_32.h
15892 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15893 int len, __wsum sum,
15894 int *src_err_ptr, int *dst_err_ptr);
15895
15896 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15897 + int len, __wsum sum,
15898 + int *src_err_ptr, int *dst_err_ptr);
15899 +
15900 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15901 + int len, __wsum sum,
15902 + int *src_err_ptr, int *dst_err_ptr);
15903 +
15904 /*
15905 * Note: when you get a NULL pointer exception here this means someone
15906 * passed in an incorrect kernel address to one of these functions.
15907 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15908
15909 might_sleep();
15910 stac();
15911 - ret = csum_partial_copy_generic((__force void *)src, dst,
15912 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15913 len, sum, err_ptr, NULL);
15914 clac();
15915
15916 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15917 might_sleep();
15918 if (access_ok(VERIFY_WRITE, dst, len)) {
15919 stac();
15920 - ret = csum_partial_copy_generic(src, (__force void *)dst,
15921 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15922 len, sum, NULL, err_ptr);
15923 clac();
15924 return ret;
15925 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15926 index d47786a..2d8883e 100644
15927 --- a/arch/x86/include/asm/cmpxchg.h
15928 +++ b/arch/x86/include/asm/cmpxchg.h
15929 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15930 __compiletime_error("Bad argument size for cmpxchg");
15931 extern void __xadd_wrong_size(void)
15932 __compiletime_error("Bad argument size for xadd");
15933 +extern void __xadd_check_overflow_wrong_size(void)
15934 + __compiletime_error("Bad argument size for xadd_check_overflow");
15935 extern void __add_wrong_size(void)
15936 __compiletime_error("Bad argument size for add");
15937 +extern void __add_check_overflow_wrong_size(void)
15938 + __compiletime_error("Bad argument size for add_check_overflow");
15939
15940 /*
15941 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15942 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
15943 __ret; \
15944 })
15945
15946 +#ifdef CONFIG_PAX_REFCOUNT
15947 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15948 + ({ \
15949 + __typeof__ (*(ptr)) __ret = (arg); \
15950 + switch (sizeof(*(ptr))) { \
15951 + case __X86_CASE_L: \
15952 + asm volatile (lock #op "l %0, %1\n" \
15953 + "jno 0f\n" \
15954 + "mov %0,%1\n" \
15955 + "int $4\n0:\n" \
15956 + _ASM_EXTABLE(0b, 0b) \
15957 + : "+r" (__ret), "+m" (*(ptr)) \
15958 + : : "memory", "cc"); \
15959 + break; \
15960 + case __X86_CASE_Q: \
15961 + asm volatile (lock #op "q %q0, %1\n" \
15962 + "jno 0f\n" \
15963 + "mov %0,%1\n" \
15964 + "int $4\n0:\n" \
15965 + _ASM_EXTABLE(0b, 0b) \
15966 + : "+r" (__ret), "+m" (*(ptr)) \
15967 + : : "memory", "cc"); \
15968 + break; \
15969 + default: \
15970 + __ ## op ## _check_overflow_wrong_size(); \
15971 + } \
15972 + __ret; \
15973 + })
15974 +#else
15975 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
15976 +#endif
15977 +
15978 /*
15979 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15980 * Since this is generally used to protect other memory information, we
15981 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
15982 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15983 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15984
15985 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15986 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15987 +
15988 #define __add(ptr, inc, lock) \
15989 ({ \
15990 __typeof__ (*(ptr)) __ret = (inc); \
15991 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15992 index 59c6c40..5e0b22c 100644
15993 --- a/arch/x86/include/asm/compat.h
15994 +++ b/arch/x86/include/asm/compat.h
15995 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15996 typedef u32 compat_uint_t;
15997 typedef u32 compat_ulong_t;
15998 typedef u64 __attribute__((aligned(4))) compat_u64;
15999 -typedef u32 compat_uptr_t;
16000 +typedef u32 __user compat_uptr_t;
16001
16002 struct compat_timespec {
16003 compat_time_t tv_sec;
16004 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16005 index e099f95..5aa0fb2 100644
16006 --- a/arch/x86/include/asm/cpufeature.h
16007 +++ b/arch/x86/include/asm/cpufeature.h
16008 @@ -203,7 +203,7 @@
16009 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16010 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16011 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16012 -
16013 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16014
16015 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16016 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16017 @@ -211,7 +211,7 @@
16018 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16019 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16020 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16021 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16022 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16023 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16024 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16025 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16026 @@ -354,6 +354,7 @@ extern const char * const x86_power_flags[32];
16027 #undef cpu_has_centaur_mcr
16028 #define cpu_has_centaur_mcr 0
16029
16030 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16031 #endif /* CONFIG_X86_64 */
16032
16033 #if __GNUC__ >= 4
16034 @@ -406,7 +407,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16035
16036 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16037 t_warn:
16038 - warn_pre_alternatives();
16039 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16040 + warn_pre_alternatives();
16041 return false;
16042 #endif
16043
16044 @@ -426,7 +428,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16045 ".section .discard,\"aw\",@progbits\n"
16046 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16047 ".previous\n"
16048 - ".section .altinstr_replacement,\"ax\"\n"
16049 + ".section .altinstr_replacement,\"a\"\n"
16050 "3: movb $1,%0\n"
16051 "4:\n"
16052 ".previous\n"
16053 @@ -463,7 +465,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16054 " .byte 2b - 1b\n" /* src len */
16055 " .byte 4f - 3f\n" /* repl len */
16056 ".previous\n"
16057 - ".section .altinstr_replacement,\"ax\"\n"
16058 + ".section .altinstr_replacement,\"a\"\n"
16059 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16060 "4:\n"
16061 ".previous\n"
16062 @@ -496,7 +498,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16063 ".section .discard,\"aw\",@progbits\n"
16064 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16065 ".previous\n"
16066 - ".section .altinstr_replacement,\"ax\"\n"
16067 + ".section .altinstr_replacement,\"a\"\n"
16068 "3: movb $0,%0\n"
16069 "4:\n"
16070 ".previous\n"
16071 @@ -510,7 +512,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16072 ".section .discard,\"aw\",@progbits\n"
16073 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16074 ".previous\n"
16075 - ".section .altinstr_replacement,\"ax\"\n"
16076 + ".section .altinstr_replacement,\"a\"\n"
16077 "5: movb $1,%0\n"
16078 "6:\n"
16079 ".previous\n"
16080 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16081 index 50d033a..37deb26 100644
16082 --- a/arch/x86/include/asm/desc.h
16083 +++ b/arch/x86/include/asm/desc.h
16084 @@ -4,6 +4,7 @@
16085 #include <asm/desc_defs.h>
16086 #include <asm/ldt.h>
16087 #include <asm/mmu.h>
16088 +#include <asm/pgtable.h>
16089
16090 #include <linux/smp.h>
16091 #include <linux/percpu.h>
16092 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16093
16094 desc->type = (info->read_exec_only ^ 1) << 1;
16095 desc->type |= info->contents << 2;
16096 + desc->type |= info->seg_not_present ^ 1;
16097
16098 desc->s = 1;
16099 desc->dpl = 0x3;
16100 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16101 }
16102
16103 extern struct desc_ptr idt_descr;
16104 -extern gate_desc idt_table[];
16105 -extern struct desc_ptr debug_idt_descr;
16106 -extern gate_desc debug_idt_table[];
16107 -
16108 -struct gdt_page {
16109 - struct desc_struct gdt[GDT_ENTRIES];
16110 -} __attribute__((aligned(PAGE_SIZE)));
16111 -
16112 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16113 +extern gate_desc idt_table[IDT_ENTRIES];
16114 +extern const struct desc_ptr debug_idt_descr;
16115 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16116
16117 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16118 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16119 {
16120 - return per_cpu(gdt_page, cpu).gdt;
16121 + return cpu_gdt_table[cpu];
16122 }
16123
16124 #ifdef CONFIG_X86_64
16125 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16126 unsigned long base, unsigned dpl, unsigned flags,
16127 unsigned short seg)
16128 {
16129 - gate->a = (seg << 16) | (base & 0xffff);
16130 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16131 + gate->gate.offset_low = base;
16132 + gate->gate.seg = seg;
16133 + gate->gate.reserved = 0;
16134 + gate->gate.type = type;
16135 + gate->gate.s = 0;
16136 + gate->gate.dpl = dpl;
16137 + gate->gate.p = 1;
16138 + gate->gate.offset_high = base >> 16;
16139 }
16140
16141 #endif
16142 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16143
16144 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16145 {
16146 + pax_open_kernel();
16147 memcpy(&idt[entry], gate, sizeof(*gate));
16148 + pax_close_kernel();
16149 }
16150
16151 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16152 {
16153 + pax_open_kernel();
16154 memcpy(&ldt[entry], desc, 8);
16155 + pax_close_kernel();
16156 }
16157
16158 static inline void
16159 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16160 default: size = sizeof(*gdt); break;
16161 }
16162
16163 + pax_open_kernel();
16164 memcpy(&gdt[entry], desc, size);
16165 + pax_close_kernel();
16166 }
16167
16168 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16169 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16170
16171 static inline void native_load_tr_desc(void)
16172 {
16173 + pax_open_kernel();
16174 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16175 + pax_close_kernel();
16176 }
16177
16178 static inline void native_load_gdt(const struct desc_ptr *dtr)
16179 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16180 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16181 unsigned int i;
16182
16183 + pax_open_kernel();
16184 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16185 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16186 + pax_close_kernel();
16187 }
16188
16189 #define _LDT_empty(info) \
16190 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16191 preempt_enable();
16192 }
16193
16194 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16195 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16196 {
16197 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16198 }
16199 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16200 }
16201
16202 #ifdef CONFIG_X86_64
16203 -static inline void set_nmi_gate(int gate, void *addr)
16204 +static inline void set_nmi_gate(int gate, const void *addr)
16205 {
16206 gate_desc s;
16207
16208 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16209 #endif
16210
16211 #ifdef CONFIG_TRACING
16212 -extern struct desc_ptr trace_idt_descr;
16213 -extern gate_desc trace_idt_table[];
16214 +extern const struct desc_ptr trace_idt_descr;
16215 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16216 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16217 {
16218 write_idt_entry(trace_idt_table, entry, gate);
16219 }
16220
16221 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16222 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16223 unsigned dpl, unsigned ist, unsigned seg)
16224 {
16225 gate_desc s;
16226 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16227 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16228 #endif
16229
16230 -static inline void _set_gate(int gate, unsigned type, void *addr,
16231 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16232 unsigned dpl, unsigned ist, unsigned seg)
16233 {
16234 gate_desc s;
16235 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16236 #define set_intr_gate(n, addr) \
16237 do { \
16238 BUG_ON((unsigned)n > 0xFF); \
16239 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16240 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16241 __KERNEL_CS); \
16242 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16243 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16244 0, 0, __KERNEL_CS); \
16245 } while (0)
16246
16247 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16248 /*
16249 * This routine sets up an interrupt gate at directory privilege level 3.
16250 */
16251 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16252 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16253 {
16254 BUG_ON((unsigned)n > 0xFF);
16255 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16256 }
16257
16258 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16259 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16260 {
16261 BUG_ON((unsigned)n > 0xFF);
16262 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16263 }
16264
16265 -static inline void set_trap_gate(unsigned int n, void *addr)
16266 +static inline void set_trap_gate(unsigned int n, const void *addr)
16267 {
16268 BUG_ON((unsigned)n > 0xFF);
16269 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16270 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16271 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16272 {
16273 BUG_ON((unsigned)n > 0xFF);
16274 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16275 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16276 }
16277
16278 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16279 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16280 {
16281 BUG_ON((unsigned)n > 0xFF);
16282 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16283 }
16284
16285 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16286 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16287 {
16288 BUG_ON((unsigned)n > 0xFF);
16289 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16290 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16291 else
16292 load_idt((const struct desc_ptr *)&idt_descr);
16293 }
16294 +
16295 +#ifdef CONFIG_X86_32
16296 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16297 +{
16298 + struct desc_struct d;
16299 +
16300 + if (likely(limit))
16301 + limit = (limit - 1UL) >> PAGE_SHIFT;
16302 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16303 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16304 +}
16305 +#endif
16306 +
16307 #endif /* _ASM_X86_DESC_H */
16308 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16309 index 278441f..b95a174 100644
16310 --- a/arch/x86/include/asm/desc_defs.h
16311 +++ b/arch/x86/include/asm/desc_defs.h
16312 @@ -31,6 +31,12 @@ struct desc_struct {
16313 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16314 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16315 };
16316 + struct {
16317 + u16 offset_low;
16318 + u16 seg;
16319 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16320 + unsigned offset_high: 16;
16321 + } gate;
16322 };
16323 } __attribute__((packed));
16324
16325 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16326 index ced283a..ffe04cc 100644
16327 --- a/arch/x86/include/asm/div64.h
16328 +++ b/arch/x86/include/asm/div64.h
16329 @@ -39,7 +39,7 @@
16330 __mod; \
16331 })
16332
16333 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16334 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16335 {
16336 union {
16337 u64 v64;
16338 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16339 index 9c999c1..3860cb8 100644
16340 --- a/arch/x86/include/asm/elf.h
16341 +++ b/arch/x86/include/asm/elf.h
16342 @@ -243,7 +243,25 @@ extern int force_personality32;
16343 the loader. We need to make sure that it is out of the way of the program
16344 that it will "exec", and that there is sufficient room for the brk. */
16345
16346 +#ifdef CONFIG_PAX_SEGMEXEC
16347 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16348 +#else
16349 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16350 +#endif
16351 +
16352 +#ifdef CONFIG_PAX_ASLR
16353 +#ifdef CONFIG_X86_32
16354 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16355 +
16356 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16357 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16358 +#else
16359 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16360 +
16361 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16362 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16363 +#endif
16364 +#endif
16365
16366 /* This yields a mask that user programs can use to figure out what
16367 instruction set this CPU supports. This could be done in user space,
16368 @@ -296,16 +314,12 @@ do { \
16369
16370 #define ARCH_DLINFO \
16371 do { \
16372 - if (vdso_enabled) \
16373 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16374 - (unsigned long)current->mm->context.vdso); \
16375 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16376 } while (0)
16377
16378 #define ARCH_DLINFO_X32 \
16379 do { \
16380 - if (vdso_enabled) \
16381 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16382 - (unsigned long)current->mm->context.vdso); \
16383 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16384 } while (0)
16385
16386 #define AT_SYSINFO 32
16387 @@ -320,7 +334,7 @@ else \
16388
16389 #endif /* !CONFIG_X86_32 */
16390
16391 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16392 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16393
16394 #define VDSO_ENTRY \
16395 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16396 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16397 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16398 #define compat_arch_setup_additional_pages syscall32_setup_pages
16399
16400 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16401 -#define arch_randomize_brk arch_randomize_brk
16402 -
16403 /*
16404 * True on X86_32 or when emulating IA32 on X86_64
16405 */
16406 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16407 index 77a99ac..39ff7f5 100644
16408 --- a/arch/x86/include/asm/emergency-restart.h
16409 +++ b/arch/x86/include/asm/emergency-restart.h
16410 @@ -1,6 +1,6 @@
16411 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16412 #define _ASM_X86_EMERGENCY_RESTART_H
16413
16414 -extern void machine_emergency_restart(void);
16415 +extern void machine_emergency_restart(void) __noreturn;
16416
16417 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16418 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16419 index d3d7469..677ef72 100644
16420 --- a/arch/x86/include/asm/floppy.h
16421 +++ b/arch/x86/include/asm/floppy.h
16422 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16423 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16424 } fd_routine[] = {
16425 {
16426 - request_dma,
16427 - free_dma,
16428 - get_dma_residue,
16429 - dma_mem_alloc,
16430 - hard_dma_setup
16431 + ._request_dma = request_dma,
16432 + ._free_dma = free_dma,
16433 + ._get_dma_residue = get_dma_residue,
16434 + ._dma_mem_alloc = dma_mem_alloc,
16435 + ._dma_setup = hard_dma_setup
16436 },
16437 {
16438 - vdma_request_dma,
16439 - vdma_nop,
16440 - vdma_get_dma_residue,
16441 - vdma_mem_alloc,
16442 - vdma_dma_setup
16443 + ._request_dma = vdma_request_dma,
16444 + ._free_dma = vdma_nop,
16445 + ._get_dma_residue = vdma_get_dma_residue,
16446 + ._dma_mem_alloc = vdma_mem_alloc,
16447 + ._dma_setup = vdma_dma_setup
16448 }
16449 };
16450
16451 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16452 index cea1c76..6c0d79b 100644
16453 --- a/arch/x86/include/asm/fpu-internal.h
16454 +++ b/arch/x86/include/asm/fpu-internal.h
16455 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16456 #define user_insn(insn, output, input...) \
16457 ({ \
16458 int err; \
16459 + pax_open_userland(); \
16460 asm volatile(ASM_STAC "\n" \
16461 - "1:" #insn "\n\t" \
16462 + "1:" \
16463 + __copyuser_seg \
16464 + #insn "\n\t" \
16465 "2: " ASM_CLAC "\n" \
16466 ".section .fixup,\"ax\"\n" \
16467 "3: movl $-1,%[err]\n" \
16468 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16469 _ASM_EXTABLE(1b, 3b) \
16470 : [err] "=r" (err), output \
16471 : "0"(0), input); \
16472 + pax_close_userland(); \
16473 err; \
16474 })
16475
16476 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16477 "fnclex\n\t"
16478 "emms\n\t"
16479 "fildl %P[addr]" /* set F?P to defined value */
16480 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16481 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16482 }
16483
16484 return fpu_restore_checking(&tsk->thread.fpu);
16485 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16486 index b4c1f54..e290c08 100644
16487 --- a/arch/x86/include/asm/futex.h
16488 +++ b/arch/x86/include/asm/futex.h
16489 @@ -12,6 +12,7 @@
16490 #include <asm/smap.h>
16491
16492 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16493 + typecheck(u32 __user *, uaddr); \
16494 asm volatile("\t" ASM_STAC "\n" \
16495 "1:\t" insn "\n" \
16496 "2:\t" ASM_CLAC "\n" \
16497 @@ -20,15 +21,16 @@
16498 "\tjmp\t2b\n" \
16499 "\t.previous\n" \
16500 _ASM_EXTABLE(1b, 3b) \
16501 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16502 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16503 : "i" (-EFAULT), "0" (oparg), "1" (0))
16504
16505 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16506 + typecheck(u32 __user *, uaddr); \
16507 asm volatile("\t" ASM_STAC "\n" \
16508 "1:\tmovl %2, %0\n" \
16509 "\tmovl\t%0, %3\n" \
16510 "\t" insn "\n" \
16511 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16512 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16513 "\tjnz\t1b\n" \
16514 "3:\t" ASM_CLAC "\n" \
16515 "\t.section .fixup,\"ax\"\n" \
16516 @@ -38,7 +40,7 @@
16517 _ASM_EXTABLE(1b, 4b) \
16518 _ASM_EXTABLE(2b, 4b) \
16519 : "=&a" (oldval), "=&r" (ret), \
16520 - "+m" (*uaddr), "=&r" (tem) \
16521 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16522 : "r" (oparg), "i" (-EFAULT), "1" (0))
16523
16524 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16525 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16526
16527 pagefault_disable();
16528
16529 + pax_open_userland();
16530 switch (op) {
16531 case FUTEX_OP_SET:
16532 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16533 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16534 break;
16535 case FUTEX_OP_ADD:
16536 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16537 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16538 uaddr, oparg);
16539 break;
16540 case FUTEX_OP_OR:
16541 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16542 default:
16543 ret = -ENOSYS;
16544 }
16545 + pax_close_userland();
16546
16547 pagefault_enable();
16548
16549 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16550 index 67d69b8..50e4b77 100644
16551 --- a/arch/x86/include/asm/hw_irq.h
16552 +++ b/arch/x86/include/asm/hw_irq.h
16553 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16554 extern void enable_IO_APIC(void);
16555
16556 /* Statistics */
16557 -extern atomic_t irq_err_count;
16558 -extern atomic_t irq_mis_count;
16559 +extern atomic_unchecked_t irq_err_count;
16560 +extern atomic_unchecked_t irq_mis_count;
16561
16562 /* EISA */
16563 extern void eisa_set_level_irq(unsigned int irq);
16564 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16565 index a203659..9889f1c 100644
16566 --- a/arch/x86/include/asm/i8259.h
16567 +++ b/arch/x86/include/asm/i8259.h
16568 @@ -62,7 +62,7 @@ struct legacy_pic {
16569 void (*init)(int auto_eoi);
16570 int (*irq_pending)(unsigned int irq);
16571 void (*make_irq)(unsigned int irq);
16572 -};
16573 +} __do_const;
16574
16575 extern struct legacy_pic *legacy_pic;
16576 extern struct legacy_pic null_legacy_pic;
16577 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16578 index 91d9c69..dfae7d0 100644
16579 --- a/arch/x86/include/asm/io.h
16580 +++ b/arch/x86/include/asm/io.h
16581 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16582 "m" (*(volatile type __force *)addr) barrier); }
16583
16584 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16585 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16586 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16587 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16588 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16589
16590 build_mmio_read(__readb, "b", unsigned char, "=q", )
16591 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16592 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16593 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16594 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16595
16596 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16597 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16598 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16599 return ioremap_nocache(offset, size);
16600 }
16601
16602 -extern void iounmap(volatile void __iomem *addr);
16603 +extern void iounmap(const volatile void __iomem *addr);
16604
16605 extern void set_iounmap_nonlazy(void);
16606
16607 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16608
16609 #include <linux/vmalloc.h>
16610
16611 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16612 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16613 +{
16614 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16615 +}
16616 +
16617 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16618 +{
16619 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16620 +}
16621 +
16622 /*
16623 * Convert a virtual cached pointer to an uncached pointer
16624 */
16625 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16626 index bba3cf8..06bc8da 100644
16627 --- a/arch/x86/include/asm/irqflags.h
16628 +++ b/arch/x86/include/asm/irqflags.h
16629 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16630 sti; \
16631 sysexit
16632
16633 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16634 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16635 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16636 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16637 +
16638 #else
16639 #define INTERRUPT_RETURN iret
16640 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16641 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16642 index 9454c16..e4100e3 100644
16643 --- a/arch/x86/include/asm/kprobes.h
16644 +++ b/arch/x86/include/asm/kprobes.h
16645 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16646 #define RELATIVEJUMP_SIZE 5
16647 #define RELATIVECALL_OPCODE 0xe8
16648 #define RELATIVE_ADDR_SIZE 4
16649 -#define MAX_STACK_SIZE 64
16650 -#define MIN_STACK_SIZE(ADDR) \
16651 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16652 - THREAD_SIZE - (unsigned long)(ADDR))) \
16653 - ? (MAX_STACK_SIZE) \
16654 - : (((unsigned long)current_thread_info()) + \
16655 - THREAD_SIZE - (unsigned long)(ADDR)))
16656 +#define MAX_STACK_SIZE 64UL
16657 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16658
16659 #define flush_insn_slot(p) do { } while (0)
16660
16661 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16662 index 4ad6560..75c7bdd 100644
16663 --- a/arch/x86/include/asm/local.h
16664 +++ b/arch/x86/include/asm/local.h
16665 @@ -10,33 +10,97 @@ typedef struct {
16666 atomic_long_t a;
16667 } local_t;
16668
16669 +typedef struct {
16670 + atomic_long_unchecked_t a;
16671 +} local_unchecked_t;
16672 +
16673 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16674
16675 #define local_read(l) atomic_long_read(&(l)->a)
16676 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16677 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16678 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16679
16680 static inline void local_inc(local_t *l)
16681 {
16682 - asm volatile(_ASM_INC "%0"
16683 + asm volatile(_ASM_INC "%0\n"
16684 +
16685 +#ifdef CONFIG_PAX_REFCOUNT
16686 + "jno 0f\n"
16687 + _ASM_DEC "%0\n"
16688 + "int $4\n0:\n"
16689 + _ASM_EXTABLE(0b, 0b)
16690 +#endif
16691 +
16692 + : "+m" (l->a.counter));
16693 +}
16694 +
16695 +static inline void local_inc_unchecked(local_unchecked_t *l)
16696 +{
16697 + asm volatile(_ASM_INC "%0\n"
16698 : "+m" (l->a.counter));
16699 }
16700
16701 static inline void local_dec(local_t *l)
16702 {
16703 - asm volatile(_ASM_DEC "%0"
16704 + asm volatile(_ASM_DEC "%0\n"
16705 +
16706 +#ifdef CONFIG_PAX_REFCOUNT
16707 + "jno 0f\n"
16708 + _ASM_INC "%0\n"
16709 + "int $4\n0:\n"
16710 + _ASM_EXTABLE(0b, 0b)
16711 +#endif
16712 +
16713 + : "+m" (l->a.counter));
16714 +}
16715 +
16716 +static inline void local_dec_unchecked(local_unchecked_t *l)
16717 +{
16718 + asm volatile(_ASM_DEC "%0\n"
16719 : "+m" (l->a.counter));
16720 }
16721
16722 static inline void local_add(long i, local_t *l)
16723 {
16724 - asm volatile(_ASM_ADD "%1,%0"
16725 + asm volatile(_ASM_ADD "%1,%0\n"
16726 +
16727 +#ifdef CONFIG_PAX_REFCOUNT
16728 + "jno 0f\n"
16729 + _ASM_SUB "%1,%0\n"
16730 + "int $4\n0:\n"
16731 + _ASM_EXTABLE(0b, 0b)
16732 +#endif
16733 +
16734 + : "+m" (l->a.counter)
16735 + : "ir" (i));
16736 +}
16737 +
16738 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16739 +{
16740 + asm volatile(_ASM_ADD "%1,%0\n"
16741 : "+m" (l->a.counter)
16742 : "ir" (i));
16743 }
16744
16745 static inline void local_sub(long i, local_t *l)
16746 {
16747 - asm volatile(_ASM_SUB "%1,%0"
16748 + asm volatile(_ASM_SUB "%1,%0\n"
16749 +
16750 +#ifdef CONFIG_PAX_REFCOUNT
16751 + "jno 0f\n"
16752 + _ASM_ADD "%1,%0\n"
16753 + "int $4\n0:\n"
16754 + _ASM_EXTABLE(0b, 0b)
16755 +#endif
16756 +
16757 + : "+m" (l->a.counter)
16758 + : "ir" (i));
16759 +}
16760 +
16761 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16762 +{
16763 + asm volatile(_ASM_SUB "%1,%0\n"
16764 : "+m" (l->a.counter)
16765 : "ir" (i));
16766 }
16767 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16768 */
16769 static inline int local_sub_and_test(long i, local_t *l)
16770 {
16771 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16772 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16773 }
16774
16775 /**
16776 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16777 */
16778 static inline int local_dec_and_test(local_t *l)
16779 {
16780 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16781 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16782 }
16783
16784 /**
16785 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16786 */
16787 static inline int local_inc_and_test(local_t *l)
16788 {
16789 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16790 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16791 }
16792
16793 /**
16794 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16795 */
16796 static inline int local_add_negative(long i, local_t *l)
16797 {
16798 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16799 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16800 }
16801
16802 /**
16803 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16804 static inline long local_add_return(long i, local_t *l)
16805 {
16806 long __i = i;
16807 + asm volatile(_ASM_XADD "%0, %1\n"
16808 +
16809 +#ifdef CONFIG_PAX_REFCOUNT
16810 + "jno 0f\n"
16811 + _ASM_MOV "%0,%1\n"
16812 + "int $4\n0:\n"
16813 + _ASM_EXTABLE(0b, 0b)
16814 +#endif
16815 +
16816 + : "+r" (i), "+m" (l->a.counter)
16817 + : : "memory");
16818 + return i + __i;
16819 +}
16820 +
16821 +/**
16822 + * local_add_return_unchecked - add and return
16823 + * @i: integer value to add
16824 + * @l: pointer to type local_unchecked_t
16825 + *
16826 + * Atomically adds @i to @l and returns @i + @l
16827 + */
16828 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16829 +{
16830 + long __i = i;
16831 asm volatile(_ASM_XADD "%0, %1;"
16832 : "+r" (i), "+m" (l->a.counter)
16833 : : "memory");
16834 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16835
16836 #define local_cmpxchg(l, o, n) \
16837 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16838 +#define local_cmpxchg_unchecked(l, o, n) \
16839 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16840 /* Always has a lock prefix */
16841 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16842
16843 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16844 new file mode 100644
16845 index 0000000..2bfd3ba
16846 --- /dev/null
16847 +++ b/arch/x86/include/asm/mman.h
16848 @@ -0,0 +1,15 @@
16849 +#ifndef _X86_MMAN_H
16850 +#define _X86_MMAN_H
16851 +
16852 +#include <uapi/asm/mman.h>
16853 +
16854 +#ifdef __KERNEL__
16855 +#ifndef __ASSEMBLY__
16856 +#ifdef CONFIG_X86_32
16857 +#define arch_mmap_check i386_mmap_check
16858 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16859 +#endif
16860 +#endif
16861 +#endif
16862 +
16863 +#endif /* X86_MMAN_H */
16864 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16865 index 5f55e69..e20bfb1 100644
16866 --- a/arch/x86/include/asm/mmu.h
16867 +++ b/arch/x86/include/asm/mmu.h
16868 @@ -9,7 +9,7 @@
16869 * we put the segment information here.
16870 */
16871 typedef struct {
16872 - void *ldt;
16873 + struct desc_struct *ldt;
16874 int size;
16875
16876 #ifdef CONFIG_X86_64
16877 @@ -18,7 +18,19 @@ typedef struct {
16878 #endif
16879
16880 struct mutex lock;
16881 - void *vdso;
16882 + unsigned long vdso;
16883 +
16884 +#ifdef CONFIG_X86_32
16885 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16886 + unsigned long user_cs_base;
16887 + unsigned long user_cs_limit;
16888 +
16889 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16890 + cpumask_t cpu_user_cs_mask;
16891 +#endif
16892 +
16893 +#endif
16894 +#endif
16895 } mm_context_t;
16896
16897 #ifdef CONFIG_SMP
16898 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16899 index be12c53..4d24039 100644
16900 --- a/arch/x86/include/asm/mmu_context.h
16901 +++ b/arch/x86/include/asm/mmu_context.h
16902 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16903
16904 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16905 {
16906 +
16907 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16908 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
16909 + unsigned int i;
16910 + pgd_t *pgd;
16911 +
16912 + pax_open_kernel();
16913 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
16914 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16915 + set_pgd_batched(pgd+i, native_make_pgd(0));
16916 + pax_close_kernel();
16917 + }
16918 +#endif
16919 +
16920 #ifdef CONFIG_SMP
16921 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16922 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16923 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16924 struct task_struct *tsk)
16925 {
16926 unsigned cpu = smp_processor_id();
16927 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16928 + int tlbstate = TLBSTATE_OK;
16929 +#endif
16930
16931 if (likely(prev != next)) {
16932 #ifdef CONFIG_SMP
16933 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16934 + tlbstate = this_cpu_read(cpu_tlbstate.state);
16935 +#endif
16936 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16937 this_cpu_write(cpu_tlbstate.active_mm, next);
16938 #endif
16939 cpumask_set_cpu(cpu, mm_cpumask(next));
16940
16941 /* Re-load page tables */
16942 +#ifdef CONFIG_PAX_PER_CPU_PGD
16943 + pax_open_kernel();
16944 +
16945 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16946 + if (static_cpu_has(X86_FEATURE_PCID))
16947 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16948 + else
16949 +#endif
16950 +
16951 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16952 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16953 + pax_close_kernel();
16954 + 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));
16955 +
16956 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16957 + if (static_cpu_has(X86_FEATURE_PCID)) {
16958 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16959 + u64 descriptor[2];
16960 + descriptor[0] = PCID_USER;
16961 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16962 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16963 + descriptor[0] = PCID_KERNEL;
16964 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16965 + }
16966 + } else {
16967 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16968 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16969 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16970 + else
16971 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16972 + }
16973 + } else
16974 +#endif
16975 +
16976 + load_cr3(get_cpu_pgd(cpu, kernel));
16977 +#else
16978 load_cr3(next->pgd);
16979 +#endif
16980
16981 /* Stop flush ipis for the previous mm */
16982 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16983 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16984 /* Load the LDT, if the LDT is different: */
16985 if (unlikely(prev->context.ldt != next->context.ldt))
16986 load_LDT_nolock(&next->context);
16987 +
16988 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16989 + if (!(__supported_pte_mask & _PAGE_NX)) {
16990 + smp_mb__before_clear_bit();
16991 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16992 + smp_mb__after_clear_bit();
16993 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16994 + }
16995 +#endif
16996 +
16997 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16998 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16999 + prev->context.user_cs_limit != next->context.user_cs_limit))
17000 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17001 +#ifdef CONFIG_SMP
17002 + else if (unlikely(tlbstate != TLBSTATE_OK))
17003 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17004 +#endif
17005 +#endif
17006 +
17007 }
17008 + else {
17009 +
17010 +#ifdef CONFIG_PAX_PER_CPU_PGD
17011 + pax_open_kernel();
17012 +
17013 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17014 + if (static_cpu_has(X86_FEATURE_PCID))
17015 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17016 + else
17017 +#endif
17018 +
17019 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17020 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17021 + pax_close_kernel();
17022 + 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));
17023 +
17024 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17025 + if (static_cpu_has(X86_FEATURE_PCID)) {
17026 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17027 + u64 descriptor[2];
17028 + descriptor[0] = PCID_USER;
17029 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17030 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17031 + descriptor[0] = PCID_KERNEL;
17032 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17033 + }
17034 + } else {
17035 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17036 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17037 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17038 + else
17039 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17040 + }
17041 + } else
17042 +#endif
17043 +
17044 + load_cr3(get_cpu_pgd(cpu, kernel));
17045 +#endif
17046 +
17047 #ifdef CONFIG_SMP
17048 - else {
17049 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17050 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17051
17052 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17053 * tlb flush IPI delivery. We must reload CR3
17054 * to make sure to use no freed page tables.
17055 */
17056 +
17057 +#ifndef CONFIG_PAX_PER_CPU_PGD
17058 load_cr3(next->pgd);
17059 +#endif
17060 +
17061 load_LDT_nolock(&next->context);
17062 +
17063 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17064 + if (!(__supported_pte_mask & _PAGE_NX))
17065 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17066 +#endif
17067 +
17068 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17069 +#ifdef CONFIG_PAX_PAGEEXEC
17070 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17071 +#endif
17072 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17073 +#endif
17074 +
17075 }
17076 +#endif
17077 }
17078 -#endif
17079 }
17080
17081 #define activate_mm(prev, next) \
17082 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17083 index e3b7819..b257c64 100644
17084 --- a/arch/x86/include/asm/module.h
17085 +++ b/arch/x86/include/asm/module.h
17086 @@ -5,6 +5,7 @@
17087
17088 #ifdef CONFIG_X86_64
17089 /* X86_64 does not define MODULE_PROC_FAMILY */
17090 +#define MODULE_PROC_FAMILY ""
17091 #elif defined CONFIG_M486
17092 #define MODULE_PROC_FAMILY "486 "
17093 #elif defined CONFIG_M586
17094 @@ -57,8 +58,20 @@
17095 #error unknown processor family
17096 #endif
17097
17098 -#ifdef CONFIG_X86_32
17099 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17100 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17101 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17102 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17103 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17104 +#else
17105 +#define MODULE_PAX_KERNEXEC ""
17106 #endif
17107
17108 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17109 +#define MODULE_PAX_UDEREF "UDEREF "
17110 +#else
17111 +#define MODULE_PAX_UDEREF ""
17112 +#endif
17113 +
17114 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17115 +
17116 #endif /* _ASM_X86_MODULE_H */
17117 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17118 index 86f9301..b365cda 100644
17119 --- a/arch/x86/include/asm/nmi.h
17120 +++ b/arch/x86/include/asm/nmi.h
17121 @@ -40,11 +40,11 @@ struct nmiaction {
17122 nmi_handler_t handler;
17123 unsigned long flags;
17124 const char *name;
17125 -};
17126 +} __do_const;
17127
17128 #define register_nmi_handler(t, fn, fg, n, init...) \
17129 ({ \
17130 - static struct nmiaction init fn##_na = { \
17131 + static const struct nmiaction init fn##_na = { \
17132 .handler = (fn), \
17133 .name = (n), \
17134 .flags = (fg), \
17135 @@ -52,7 +52,7 @@ struct nmiaction {
17136 __register_nmi_handler((t), &fn##_na); \
17137 })
17138
17139 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17140 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17141
17142 void unregister_nmi_handler(unsigned int, const char *);
17143
17144 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17145 index 775873d..de5f0304 100644
17146 --- a/arch/x86/include/asm/page.h
17147 +++ b/arch/x86/include/asm/page.h
17148 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17149 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17150
17151 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17152 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17153
17154 #define __boot_va(x) __va(x)
17155 #define __boot_pa(x) __pa(x)
17156 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17157 index 0f1ddee..e2fc3d1 100644
17158 --- a/arch/x86/include/asm/page_64.h
17159 +++ b/arch/x86/include/asm/page_64.h
17160 @@ -7,9 +7,9 @@
17161
17162 /* duplicated to the one in bootmem.h */
17163 extern unsigned long max_pfn;
17164 -extern unsigned long phys_base;
17165 +extern const unsigned long phys_base;
17166
17167 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17168 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17169 {
17170 unsigned long y = x - __START_KERNEL_map;
17171
17172 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17173 index cd6e1610..70f4418 100644
17174 --- a/arch/x86/include/asm/paravirt.h
17175 +++ b/arch/x86/include/asm/paravirt.h
17176 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17177 return (pmd_t) { ret };
17178 }
17179
17180 -static inline pmdval_t pmd_val(pmd_t pmd)
17181 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17182 {
17183 pmdval_t ret;
17184
17185 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17186 val);
17187 }
17188
17189 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17190 +{
17191 + pgdval_t val = native_pgd_val(pgd);
17192 +
17193 + if (sizeof(pgdval_t) > sizeof(long))
17194 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17195 + val, (u64)val >> 32);
17196 + else
17197 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17198 + val);
17199 +}
17200 +
17201 static inline void pgd_clear(pgd_t *pgdp)
17202 {
17203 set_pgd(pgdp, __pgd(0));
17204 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17205 pv_mmu_ops.set_fixmap(idx, phys, flags);
17206 }
17207
17208 +#ifdef CONFIG_PAX_KERNEXEC
17209 +static inline unsigned long pax_open_kernel(void)
17210 +{
17211 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17212 +}
17213 +
17214 +static inline unsigned long pax_close_kernel(void)
17215 +{
17216 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17217 +}
17218 +#else
17219 +static inline unsigned long pax_open_kernel(void) { return 0; }
17220 +static inline unsigned long pax_close_kernel(void) { return 0; }
17221 +#endif
17222 +
17223 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17224
17225 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17226 @@ -906,7 +933,7 @@ extern void default_banner(void);
17227
17228 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17229 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17230 -#define PARA_INDIRECT(addr) *%cs:addr
17231 +#define PARA_INDIRECT(addr) *%ss:addr
17232 #endif
17233
17234 #define INTERRUPT_RETURN \
17235 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17236 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17237 CLBR_NONE, \
17238 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17239 +
17240 +#define GET_CR0_INTO_RDI \
17241 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17242 + mov %rax,%rdi
17243 +
17244 +#define SET_RDI_INTO_CR0 \
17245 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17246 +
17247 +#define GET_CR3_INTO_RDI \
17248 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17249 + mov %rax,%rdi
17250 +
17251 +#define SET_RDI_INTO_CR3 \
17252 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17253 +
17254 #endif /* CONFIG_X86_32 */
17255
17256 #endif /* __ASSEMBLY__ */
17257 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17258 index 7549b8b..f0edfda 100644
17259 --- a/arch/x86/include/asm/paravirt_types.h
17260 +++ b/arch/x86/include/asm/paravirt_types.h
17261 @@ -84,7 +84,7 @@ struct pv_init_ops {
17262 */
17263 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17264 unsigned long addr, unsigned len);
17265 -};
17266 +} __no_const __no_randomize_layout;
17267
17268
17269 struct pv_lazy_ops {
17270 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17271 void (*enter)(void);
17272 void (*leave)(void);
17273 void (*flush)(void);
17274 -};
17275 +} __no_randomize_layout;
17276
17277 struct pv_time_ops {
17278 unsigned long long (*sched_clock)(void);
17279 unsigned long long (*steal_clock)(int cpu);
17280 unsigned long (*get_tsc_khz)(void);
17281 -};
17282 +} __no_const __no_randomize_layout;
17283
17284 struct pv_cpu_ops {
17285 /* hooks for various privileged instructions */
17286 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17287
17288 void (*start_context_switch)(struct task_struct *prev);
17289 void (*end_context_switch)(struct task_struct *next);
17290 -};
17291 +} __no_const __no_randomize_layout;
17292
17293 struct pv_irq_ops {
17294 /*
17295 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17296 #ifdef CONFIG_X86_64
17297 void (*adjust_exception_frame)(void);
17298 #endif
17299 -};
17300 +} __no_randomize_layout;
17301
17302 struct pv_apic_ops {
17303 #ifdef CONFIG_X86_LOCAL_APIC
17304 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17305 unsigned long start_eip,
17306 unsigned long start_esp);
17307 #endif
17308 -};
17309 +} __no_const __no_randomize_layout;
17310
17311 struct pv_mmu_ops {
17312 unsigned long (*read_cr2)(void);
17313 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17314 struct paravirt_callee_save make_pud;
17315
17316 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17317 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17318 #endif /* PAGETABLE_LEVELS == 4 */
17319 #endif /* PAGETABLE_LEVELS >= 3 */
17320
17321 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17322 an mfn. We can tell which is which from the index. */
17323 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17324 phys_addr_t phys, pgprot_t flags);
17325 -};
17326 +
17327 +#ifdef CONFIG_PAX_KERNEXEC
17328 + unsigned long (*pax_open_kernel)(void);
17329 + unsigned long (*pax_close_kernel)(void);
17330 +#endif
17331 +
17332 +} __no_randomize_layout;
17333
17334 struct arch_spinlock;
17335 #ifdef CONFIG_SMP
17336 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17337 struct pv_lock_ops {
17338 struct paravirt_callee_save lock_spinning;
17339 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17340 -};
17341 +} __no_randomize_layout;
17342
17343 /* This contains all the paravirt structures: we get a convenient
17344 * number for each function using the offset which we use to indicate
17345 - * what to patch. */
17346 + * what to patch.
17347 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17348 + */
17349 +
17350 struct paravirt_patch_template {
17351 struct pv_init_ops pv_init_ops;
17352 struct pv_time_ops pv_time_ops;
17353 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17354 struct pv_apic_ops pv_apic_ops;
17355 struct pv_mmu_ops pv_mmu_ops;
17356 struct pv_lock_ops pv_lock_ops;
17357 -};
17358 +} __no_randomize_layout;
17359
17360 extern struct pv_info pv_info;
17361 extern struct pv_init_ops pv_init_ops;
17362 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17363 index c4412e9..90e88c5 100644
17364 --- a/arch/x86/include/asm/pgalloc.h
17365 +++ b/arch/x86/include/asm/pgalloc.h
17366 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17367 pmd_t *pmd, pte_t *pte)
17368 {
17369 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17370 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17371 +}
17372 +
17373 +static inline void pmd_populate_user(struct mm_struct *mm,
17374 + pmd_t *pmd, pte_t *pte)
17375 +{
17376 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17377 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17378 }
17379
17380 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17381
17382 #ifdef CONFIG_X86_PAE
17383 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17384 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17385 +{
17386 + pud_populate(mm, pudp, pmd);
17387 +}
17388 #else /* !CONFIG_X86_PAE */
17389 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17390 {
17391 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17392 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17393 }
17394 +
17395 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17396 +{
17397 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17398 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17399 +}
17400 #endif /* CONFIG_X86_PAE */
17401
17402 #if PAGETABLE_LEVELS > 3
17403 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17404 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17405 }
17406
17407 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17408 +{
17409 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17410 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17411 +}
17412 +
17413 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17414 {
17415 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17416 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17417 index 0d193e2..bf59aeb 100644
17418 --- a/arch/x86/include/asm/pgtable-2level.h
17419 +++ b/arch/x86/include/asm/pgtable-2level.h
17420 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17421
17422 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17423 {
17424 + pax_open_kernel();
17425 *pmdp = pmd;
17426 + pax_close_kernel();
17427 }
17428
17429 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17430 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17431 index 81bb91b..9392125 100644
17432 --- a/arch/x86/include/asm/pgtable-3level.h
17433 +++ b/arch/x86/include/asm/pgtable-3level.h
17434 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17435
17436 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17437 {
17438 + pax_open_kernel();
17439 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17440 + pax_close_kernel();
17441 }
17442
17443 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17444 {
17445 + pax_open_kernel();
17446 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17447 + pax_close_kernel();
17448 }
17449
17450 /*
17451 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17452 index bbc8b12..f228861 100644
17453 --- a/arch/x86/include/asm/pgtable.h
17454 +++ b/arch/x86/include/asm/pgtable.h
17455 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17456
17457 #ifndef __PAGETABLE_PUD_FOLDED
17458 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17459 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17460 #define pgd_clear(pgd) native_pgd_clear(pgd)
17461 #endif
17462
17463 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17464
17465 #define arch_end_context_switch(prev) do {} while(0)
17466
17467 +#define pax_open_kernel() native_pax_open_kernel()
17468 +#define pax_close_kernel() native_pax_close_kernel()
17469 #endif /* CONFIG_PARAVIRT */
17470
17471 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17472 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17473 +
17474 +#ifdef CONFIG_PAX_KERNEXEC
17475 +static inline unsigned long native_pax_open_kernel(void)
17476 +{
17477 + unsigned long cr0;
17478 +
17479 + preempt_disable();
17480 + barrier();
17481 + cr0 = read_cr0() ^ X86_CR0_WP;
17482 + BUG_ON(cr0 & X86_CR0_WP);
17483 + write_cr0(cr0);
17484 + return cr0 ^ X86_CR0_WP;
17485 +}
17486 +
17487 +static inline unsigned long native_pax_close_kernel(void)
17488 +{
17489 + unsigned long cr0;
17490 +
17491 + cr0 = read_cr0() ^ X86_CR0_WP;
17492 + BUG_ON(!(cr0 & X86_CR0_WP));
17493 + write_cr0(cr0);
17494 + barrier();
17495 + preempt_enable_no_resched();
17496 + return cr0 ^ X86_CR0_WP;
17497 +}
17498 +#else
17499 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17500 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17501 +#endif
17502 +
17503 /*
17504 * The following only work if pte_present() is true.
17505 * Undefined behaviour if not..
17506 */
17507 +static inline int pte_user(pte_t pte)
17508 +{
17509 + return pte_val(pte) & _PAGE_USER;
17510 +}
17511 +
17512 static inline int pte_dirty(pte_t pte)
17513 {
17514 return pte_flags(pte) & _PAGE_DIRTY;
17515 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17516 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17517 }
17518
17519 +static inline unsigned long pgd_pfn(pgd_t pgd)
17520 +{
17521 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17522 +}
17523 +
17524 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17525
17526 static inline int pmd_large(pmd_t pte)
17527 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17528 return pte_clear_flags(pte, _PAGE_RW);
17529 }
17530
17531 +static inline pte_t pte_mkread(pte_t pte)
17532 +{
17533 + return __pte(pte_val(pte) | _PAGE_USER);
17534 +}
17535 +
17536 static inline pte_t pte_mkexec(pte_t pte)
17537 {
17538 - return pte_clear_flags(pte, _PAGE_NX);
17539 +#ifdef CONFIG_X86_PAE
17540 + if (__supported_pte_mask & _PAGE_NX)
17541 + return pte_clear_flags(pte, _PAGE_NX);
17542 + else
17543 +#endif
17544 + return pte_set_flags(pte, _PAGE_USER);
17545 +}
17546 +
17547 +static inline pte_t pte_exprotect(pte_t pte)
17548 +{
17549 +#ifdef CONFIG_X86_PAE
17550 + if (__supported_pte_mask & _PAGE_NX)
17551 + return pte_set_flags(pte, _PAGE_NX);
17552 + else
17553 +#endif
17554 + return pte_clear_flags(pte, _PAGE_USER);
17555 }
17556
17557 static inline pte_t pte_mkdirty(pte_t pte)
17558 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17559 #endif
17560
17561 #ifndef __ASSEMBLY__
17562 +
17563 +#ifdef CONFIG_PAX_PER_CPU_PGD
17564 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17565 +enum cpu_pgd_type {kernel = 0, user = 1};
17566 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17567 +{
17568 + return cpu_pgd[cpu][type];
17569 +}
17570 +#endif
17571 +
17572 #include <linux/mm_types.h>
17573 #include <linux/mmdebug.h>
17574 #include <linux/log2.h>
17575 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17576 * Currently stuck as a macro due to indirect forward reference to
17577 * linux/mmzone.h's __section_mem_map_addr() definition:
17578 */
17579 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17580 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17581
17582 /* Find an entry in the second-level page table.. */
17583 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17584 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17585 * Currently stuck as a macro due to indirect forward reference to
17586 * linux/mmzone.h's __section_mem_map_addr() definition:
17587 */
17588 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17589 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17590
17591 /* to find an entry in a page-table-directory. */
17592 static inline unsigned long pud_index(unsigned long address)
17593 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17594
17595 static inline int pgd_bad(pgd_t pgd)
17596 {
17597 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17598 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17599 }
17600
17601 static inline int pgd_none(pgd_t pgd)
17602 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17603 * pgd_offset() returns a (pgd_t *)
17604 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17605 */
17606 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17607 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17608 +
17609 +#ifdef CONFIG_PAX_PER_CPU_PGD
17610 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17611 +#endif
17612 +
17613 /*
17614 * a shortcut which implies the use of the kernel's pgd, instead
17615 * of a process's
17616 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17617 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17618 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17619
17620 +#ifdef CONFIG_X86_32
17621 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17622 +#else
17623 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17624 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17625 +
17626 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17627 +#ifdef __ASSEMBLY__
17628 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17629 +#else
17630 +extern unsigned long pax_user_shadow_base;
17631 +extern pgdval_t clone_pgd_mask;
17632 +#endif
17633 +#endif
17634 +
17635 +#endif
17636 +
17637 #ifndef __ASSEMBLY__
17638
17639 extern int direct_gbpages;
17640 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17641 * dst and src can be on the same page, but the range must not overlap,
17642 * and must not cross a page boundary.
17643 */
17644 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17645 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17646 {
17647 - memcpy(dst, src, count * sizeof(pgd_t));
17648 + pax_open_kernel();
17649 + while (count--)
17650 + *dst++ = *src++;
17651 + pax_close_kernel();
17652 }
17653
17654 +#ifdef CONFIG_PAX_PER_CPU_PGD
17655 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17656 +#endif
17657 +
17658 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17659 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17660 +#else
17661 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17662 +#endif
17663 +
17664 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17665 static inline int page_level_shift(enum pg_level level)
17666 {
17667 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17668 index 9ee3221..b979c6b 100644
17669 --- a/arch/x86/include/asm/pgtable_32.h
17670 +++ b/arch/x86/include/asm/pgtable_32.h
17671 @@ -25,9 +25,6 @@
17672 struct mm_struct;
17673 struct vm_area_struct;
17674
17675 -extern pgd_t swapper_pg_dir[1024];
17676 -extern pgd_t initial_page_table[1024];
17677 -
17678 static inline void pgtable_cache_init(void) { }
17679 static inline void check_pgt_cache(void) { }
17680 void paging_init(void);
17681 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17682 # include <asm/pgtable-2level.h>
17683 #endif
17684
17685 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17686 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17687 +#ifdef CONFIG_X86_PAE
17688 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17689 +#endif
17690 +
17691 #if defined(CONFIG_HIGHPTE)
17692 #define pte_offset_map(dir, address) \
17693 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17694 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17695 /* Clear a kernel PTE and flush it from the TLB */
17696 #define kpte_clear_flush(ptep, vaddr) \
17697 do { \
17698 + pax_open_kernel(); \
17699 pte_clear(&init_mm, (vaddr), (ptep)); \
17700 + pax_close_kernel(); \
17701 __flush_tlb_one((vaddr)); \
17702 } while (0)
17703
17704 #endif /* !__ASSEMBLY__ */
17705
17706 +#define HAVE_ARCH_UNMAPPED_AREA
17707 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17708 +
17709 /*
17710 * kern_addr_valid() is (1) for FLATMEM and (0) for
17711 * SPARSEMEM and DISCONTIGMEM
17712 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17713 index ed5903b..c7fe163 100644
17714 --- a/arch/x86/include/asm/pgtable_32_types.h
17715 +++ b/arch/x86/include/asm/pgtable_32_types.h
17716 @@ -8,7 +8,7 @@
17717 */
17718 #ifdef CONFIG_X86_PAE
17719 # include <asm/pgtable-3level_types.h>
17720 -# define PMD_SIZE (1UL << PMD_SHIFT)
17721 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17722 # define PMD_MASK (~(PMD_SIZE - 1))
17723 #else
17724 # include <asm/pgtable-2level_types.h>
17725 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17726 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17727 #endif
17728
17729 +#ifdef CONFIG_PAX_KERNEXEC
17730 +#ifndef __ASSEMBLY__
17731 +extern unsigned char MODULES_EXEC_VADDR[];
17732 +extern unsigned char MODULES_EXEC_END[];
17733 +#endif
17734 +#include <asm/boot.h>
17735 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17736 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17737 +#else
17738 +#define ktla_ktva(addr) (addr)
17739 +#define ktva_ktla(addr) (addr)
17740 +#endif
17741 +
17742 #define MODULES_VADDR VMALLOC_START
17743 #define MODULES_END VMALLOC_END
17744 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17745 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17746 index e22c1db..23a625a 100644
17747 --- a/arch/x86/include/asm/pgtable_64.h
17748 +++ b/arch/x86/include/asm/pgtable_64.h
17749 @@ -16,10 +16,14 @@
17750
17751 extern pud_t level3_kernel_pgt[512];
17752 extern pud_t level3_ident_pgt[512];
17753 +extern pud_t level3_vmalloc_start_pgt[512];
17754 +extern pud_t level3_vmalloc_end_pgt[512];
17755 +extern pud_t level3_vmemmap_pgt[512];
17756 +extern pud_t level2_vmemmap_pgt[512];
17757 extern pmd_t level2_kernel_pgt[512];
17758 extern pmd_t level2_fixmap_pgt[512];
17759 -extern pmd_t level2_ident_pgt[512];
17760 -extern pgd_t init_level4_pgt[];
17761 +extern pmd_t level2_ident_pgt[512*2];
17762 +extern pgd_t init_level4_pgt[512];
17763
17764 #define swapper_pg_dir init_level4_pgt
17765
17766 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17767
17768 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17769 {
17770 + pax_open_kernel();
17771 *pmdp = pmd;
17772 + pax_close_kernel();
17773 }
17774
17775 static inline void native_pmd_clear(pmd_t *pmd)
17776 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17777
17778 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17779 {
17780 + pax_open_kernel();
17781 *pudp = pud;
17782 + pax_close_kernel();
17783 }
17784
17785 static inline void native_pud_clear(pud_t *pud)
17786 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17787
17788 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17789 {
17790 + pax_open_kernel();
17791 + *pgdp = pgd;
17792 + pax_close_kernel();
17793 +}
17794 +
17795 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17796 +{
17797 *pgdp = pgd;
17798 }
17799
17800 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17801 index c883bf7..19970b3 100644
17802 --- a/arch/x86/include/asm/pgtable_64_types.h
17803 +++ b/arch/x86/include/asm/pgtable_64_types.h
17804 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17805 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
17806 #define MODULES_END _AC(0xffffffffff000000, UL)
17807 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17808 +#define MODULES_EXEC_VADDR MODULES_VADDR
17809 +#define MODULES_EXEC_END MODULES_END
17810 +
17811 +#define ktla_ktva(addr) (addr)
17812 +#define ktva_ktla(addr) (addr)
17813
17814 #define EARLY_DYNAMIC_PAGE_TABLES 64
17815
17816 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17817 index 94e40f1..ebd03e4 100644
17818 --- a/arch/x86/include/asm/pgtable_types.h
17819 +++ b/arch/x86/include/asm/pgtable_types.h
17820 @@ -16,13 +16,12 @@
17821 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17822 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17823 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17824 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17825 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17826 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17827 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17828 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17829 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17830 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17831 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17832 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17833 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17834 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17835
17836 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17837 @@ -40,7 +39,6 @@
17838 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17839 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17840 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17841 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17842 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17843 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17844 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17845 @@ -87,8 +85,10 @@
17846
17847 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17848 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17849 -#else
17850 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17851 #define _PAGE_NX (_AT(pteval_t, 0))
17852 +#else
17853 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17854 #endif
17855
17856 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17857 @@ -147,6 +147,9 @@
17858 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17859 _PAGE_ACCESSED)
17860
17861 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17862 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17863 +
17864 #define __PAGE_KERNEL_EXEC \
17865 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17866 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17867 @@ -157,7 +160,7 @@
17868 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17869 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17870 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17871 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17872 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17873 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17874 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17875 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17876 @@ -219,8 +222,8 @@
17877 * bits are combined, this will alow user to access the high address mapped
17878 * VDSO in the presence of CONFIG_COMPAT_VDSO
17879 */
17880 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17881 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17882 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17883 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17884 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17885 #endif
17886
17887 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17888 {
17889 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17890 }
17891 +#endif
17892
17893 +#if PAGETABLE_LEVELS == 3
17894 +#include <asm-generic/pgtable-nopud.h>
17895 +#endif
17896 +
17897 +#if PAGETABLE_LEVELS == 2
17898 +#include <asm-generic/pgtable-nopmd.h>
17899 +#endif
17900 +
17901 +#ifndef __ASSEMBLY__
17902 #if PAGETABLE_LEVELS > 3
17903 typedef struct { pudval_t pud; } pud_t;
17904
17905 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17906 return pud.pud;
17907 }
17908 #else
17909 -#include <asm-generic/pgtable-nopud.h>
17910 -
17911 static inline pudval_t native_pud_val(pud_t pud)
17912 {
17913 return native_pgd_val(pud.pgd);
17914 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17915 return pmd.pmd;
17916 }
17917 #else
17918 -#include <asm-generic/pgtable-nopmd.h>
17919 -
17920 static inline pmdval_t native_pmd_val(pmd_t pmd)
17921 {
17922 return native_pgd_val(pmd.pud.pgd);
17923 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
17924
17925 extern pteval_t __supported_pte_mask;
17926 extern void set_nx(void);
17927 -extern int nx_enabled;
17928
17929 #define pgprot_writecombine pgprot_writecombine
17930 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17931 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17932 index c8b0519..fd29e73 100644
17933 --- a/arch/x86/include/asm/preempt.h
17934 +++ b/arch/x86/include/asm/preempt.h
17935 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17936 */
17937 static __always_inline bool __preempt_count_dec_and_test(void)
17938 {
17939 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17940 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17941 }
17942
17943 /*
17944 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17945 index fdedd38..95c02c2 100644
17946 --- a/arch/x86/include/asm/processor.h
17947 +++ b/arch/x86/include/asm/processor.h
17948 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17949 /* Index into per_cpu list: */
17950 u16 cpu_index;
17951 u32 microcode;
17952 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17953 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17954
17955 #define X86_VENDOR_INTEL 0
17956 #define X86_VENDOR_CYRIX 1
17957 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17958 : "memory");
17959 }
17960
17961 +/* invpcid (%rdx),%rax */
17962 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17963 +
17964 +#define INVPCID_SINGLE_ADDRESS 0UL
17965 +#define INVPCID_SINGLE_CONTEXT 1UL
17966 +#define INVPCID_ALL_GLOBAL 2UL
17967 +#define INVPCID_ALL_MONGLOBAL 3UL
17968 +
17969 +#define PCID_KERNEL 0UL
17970 +#define PCID_USER 1UL
17971 +#define PCID_NOFLUSH (1UL << 63)
17972 +
17973 static inline void load_cr3(pgd_t *pgdir)
17974 {
17975 - write_cr3(__pa(pgdir));
17976 + write_cr3(__pa(pgdir) | PCID_KERNEL);
17977 }
17978
17979 #ifdef CONFIG_X86_32
17980 @@ -283,7 +295,7 @@ struct tss_struct {
17981
17982 } ____cacheline_aligned;
17983
17984 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17985 +extern struct tss_struct init_tss[NR_CPUS];
17986
17987 /*
17988 * Save the original ist values for checking stack pointers during debugging
17989 @@ -470,6 +482,7 @@ struct thread_struct {
17990 unsigned short ds;
17991 unsigned short fsindex;
17992 unsigned short gsindex;
17993 + unsigned short ss;
17994 #endif
17995 #ifdef CONFIG_X86_32
17996 unsigned long ip;
17997 @@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
17998 extern unsigned long mmu_cr4_features;
17999 extern u32 *trampoline_cr4_features;
18000
18001 -static inline void set_in_cr4(unsigned long mask)
18002 -{
18003 - unsigned long cr4;
18004 -
18005 - mmu_cr4_features |= mask;
18006 - if (trampoline_cr4_features)
18007 - *trampoline_cr4_features = mmu_cr4_features;
18008 - cr4 = read_cr4();
18009 - cr4 |= mask;
18010 - write_cr4(cr4);
18011 -}
18012 -
18013 -static inline void clear_in_cr4(unsigned long mask)
18014 -{
18015 - unsigned long cr4;
18016 -
18017 - mmu_cr4_features &= ~mask;
18018 - if (trampoline_cr4_features)
18019 - *trampoline_cr4_features = mmu_cr4_features;
18020 - cr4 = read_cr4();
18021 - cr4 &= ~mask;
18022 - write_cr4(cr4);
18023 -}
18024 +extern void set_in_cr4(unsigned long mask);
18025 +extern void clear_in_cr4(unsigned long mask);
18026
18027 typedef struct {
18028 unsigned long seg;
18029 @@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18030 */
18031 #define TASK_SIZE PAGE_OFFSET
18032 #define TASK_SIZE_MAX TASK_SIZE
18033 +
18034 +#ifdef CONFIG_PAX_SEGMEXEC
18035 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18036 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18037 +#else
18038 #define STACK_TOP TASK_SIZE
18039 -#define STACK_TOP_MAX STACK_TOP
18040 +#endif
18041 +
18042 +#define STACK_TOP_MAX TASK_SIZE
18043
18044 #define INIT_THREAD { \
18045 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18046 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18047 .vm86_info = NULL, \
18048 .sysenter_cs = __KERNEL_CS, \
18049 .io_bitmap_ptr = NULL, \
18050 @@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18051 */
18052 #define INIT_TSS { \
18053 .x86_tss = { \
18054 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18055 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18056 .ss0 = __KERNEL_DS, \
18057 .ss1 = __KERNEL_CS, \
18058 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18059 @@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18060 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18061
18062 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18063 -#define KSTK_TOP(info) \
18064 -({ \
18065 - unsigned long *__ptr = (unsigned long *)(info); \
18066 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18067 -})
18068 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18069
18070 /*
18071 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18072 @@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18073 #define task_pt_regs(task) \
18074 ({ \
18075 struct pt_regs *__regs__; \
18076 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18077 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18078 __regs__ - 1; \
18079 })
18080
18081 @@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18082 /*
18083 * User space process size. 47bits minus one guard page.
18084 */
18085 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18086 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18087
18088 /* This decides where the kernel will search for a free chunk of vm
18089 * space during mmap's.
18090 */
18091 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18092 - 0xc0000000 : 0xFFFFe000)
18093 + 0xc0000000 : 0xFFFFf000)
18094
18095 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18096 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18097 @@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18098 #define STACK_TOP_MAX TASK_SIZE_MAX
18099
18100 #define INIT_THREAD { \
18101 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18102 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18103 }
18104
18105 #define INIT_TSS { \
18106 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18107 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18108 }
18109
18110 /*
18111 @@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18112 */
18113 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18114
18115 +#ifdef CONFIG_PAX_SEGMEXEC
18116 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18117 +#endif
18118 +
18119 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18120
18121 /* Get/set a process' ability to use the timestamp counter instruction */
18122 @@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18123 return 0;
18124 }
18125
18126 -extern unsigned long arch_align_stack(unsigned long sp);
18127 +#define arch_align_stack(x) ((x) & ~0xfUL)
18128 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18129
18130 void default_idle(void);
18131 @@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18132 #define xen_set_default_idle 0
18133 #endif
18134
18135 -void stop_this_cpu(void *dummy);
18136 +void stop_this_cpu(void *dummy) __noreturn;
18137 void df_debug(struct pt_regs *regs, long error_code);
18138 #endif /* _ASM_X86_PROCESSOR_H */
18139 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18140 index 14fd6fd..6740420 100644
18141 --- a/arch/x86/include/asm/ptrace.h
18142 +++ b/arch/x86/include/asm/ptrace.h
18143 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18144 }
18145
18146 /*
18147 - * user_mode_vm(regs) determines whether a register set came from user mode.
18148 + * user_mode(regs) determines whether a register set came from user mode.
18149 * This is true if V8086 mode was enabled OR if the register set was from
18150 * protected mode with RPL-3 CS value. This tricky test checks that with
18151 * one comparison. Many places in the kernel can bypass this full check
18152 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18153 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18154 + * be used.
18155 */
18156 -static inline int user_mode(struct pt_regs *regs)
18157 +static inline int user_mode_novm(struct pt_regs *regs)
18158 {
18159 #ifdef CONFIG_X86_32
18160 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18161 #else
18162 - return !!(regs->cs & 3);
18163 + return !!(regs->cs & SEGMENT_RPL_MASK);
18164 #endif
18165 }
18166
18167 -static inline int user_mode_vm(struct pt_regs *regs)
18168 +static inline int user_mode(struct pt_regs *regs)
18169 {
18170 #ifdef CONFIG_X86_32
18171 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18172 USER_RPL;
18173 #else
18174 - return user_mode(regs);
18175 + return user_mode_novm(regs);
18176 #endif
18177 }
18178
18179 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18180 #ifdef CONFIG_X86_64
18181 static inline bool user_64bit_mode(struct pt_regs *regs)
18182 {
18183 + unsigned long cs = regs->cs & 0xffff;
18184 #ifndef CONFIG_PARAVIRT
18185 /*
18186 * On non-paravirt systems, this is the only long mode CPL 3
18187 * selector. We do not allow long mode selectors in the LDT.
18188 */
18189 - return regs->cs == __USER_CS;
18190 + return cs == __USER_CS;
18191 #else
18192 /* Headers are too twisted for this to go in paravirt.h. */
18193 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18194 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18195 #endif
18196 }
18197
18198 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18199 * Traps from the kernel do not save sp and ss.
18200 * Use the helper function to retrieve sp.
18201 */
18202 - if (offset == offsetof(struct pt_regs, sp) &&
18203 - regs->cs == __KERNEL_CS)
18204 - return kernel_stack_pointer(regs);
18205 + if (offset == offsetof(struct pt_regs, sp)) {
18206 + unsigned long cs = regs->cs & 0xffff;
18207 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18208 + return kernel_stack_pointer(regs);
18209 + }
18210 #endif
18211 return *(unsigned long *)((unsigned long)regs + offset);
18212 }
18213 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18214 index 9c6b890..5305f53 100644
18215 --- a/arch/x86/include/asm/realmode.h
18216 +++ b/arch/x86/include/asm/realmode.h
18217 @@ -22,16 +22,14 @@ struct real_mode_header {
18218 #endif
18219 /* APM/BIOS reboot */
18220 u32 machine_real_restart_asm;
18221 -#ifdef CONFIG_X86_64
18222 u32 machine_real_restart_seg;
18223 -#endif
18224 };
18225
18226 /* This must match data at trampoline_32/64.S */
18227 struct trampoline_header {
18228 #ifdef CONFIG_X86_32
18229 u32 start;
18230 - u16 gdt_pad;
18231 + u16 boot_cs;
18232 u16 gdt_limit;
18233 u32 gdt_base;
18234 #else
18235 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18236 index a82c4f1..ac45053 100644
18237 --- a/arch/x86/include/asm/reboot.h
18238 +++ b/arch/x86/include/asm/reboot.h
18239 @@ -6,13 +6,13 @@
18240 struct pt_regs;
18241
18242 struct machine_ops {
18243 - void (*restart)(char *cmd);
18244 - void (*halt)(void);
18245 - void (*power_off)(void);
18246 + void (* __noreturn restart)(char *cmd);
18247 + void (* __noreturn halt)(void);
18248 + void (* __noreturn power_off)(void);
18249 void (*shutdown)(void);
18250 void (*crash_shutdown)(struct pt_regs *);
18251 - void (*emergency_restart)(void);
18252 -};
18253 + void (* __noreturn emergency_restart)(void);
18254 +} __no_const;
18255
18256 extern struct machine_ops machine_ops;
18257
18258 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18259 index 8f7866a..e442f20 100644
18260 --- a/arch/x86/include/asm/rmwcc.h
18261 +++ b/arch/x86/include/asm/rmwcc.h
18262 @@ -3,7 +3,34 @@
18263
18264 #ifdef CC_HAVE_ASM_GOTO
18265
18266 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18267 +#ifdef CONFIG_PAX_REFCOUNT
18268 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18269 +do { \
18270 + asm_volatile_goto (fullop \
18271 + ";jno 0f\n" \
18272 + fullantiop \
18273 + ";int $4\n0:\n" \
18274 + _ASM_EXTABLE(0b, 0b) \
18275 + ";j" cc " %l[cc_label]" \
18276 + : : "m" (var), ## __VA_ARGS__ \
18277 + : "memory" : cc_label); \
18278 + return 0; \
18279 +cc_label: \
18280 + return 1; \
18281 +} while (0)
18282 +#else
18283 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18284 +do { \
18285 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18286 + : : "m" (var), ## __VA_ARGS__ \
18287 + : "memory" : cc_label); \
18288 + return 0; \
18289 +cc_label: \
18290 + return 1; \
18291 +} while (0)
18292 +#endif
18293 +
18294 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18295 do { \
18296 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18297 : : "m" (var), ## __VA_ARGS__ \
18298 @@ -13,15 +40,46 @@ cc_label: \
18299 return 1; \
18300 } while (0)
18301
18302 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18303 - __GEN_RMWcc(op " " arg0, var, cc)
18304 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18305 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18306
18307 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18308 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18309 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18310 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18311 +
18312 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18313 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18314 +
18315 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18316 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18317
18318 #else /* !CC_HAVE_ASM_GOTO */
18319
18320 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18321 +#ifdef CONFIG_PAX_REFCOUNT
18322 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18323 +do { \
18324 + char c; \
18325 + asm volatile (fullop \
18326 + ";jno 0f\n" \
18327 + fullantiop \
18328 + ";int $4\n0:\n" \
18329 + _ASM_EXTABLE(0b, 0b) \
18330 + "; set" cc " %1" \
18331 + : "+m" (var), "=qm" (c) \
18332 + : __VA_ARGS__ : "memory"); \
18333 + return c != 0; \
18334 +} while (0)
18335 +#else
18336 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18337 +do { \
18338 + char c; \
18339 + asm volatile (fullop "; set" cc " %1" \
18340 + : "+m" (var), "=qm" (c) \
18341 + : __VA_ARGS__ : "memory"); \
18342 + return c != 0; \
18343 +} while (0)
18344 +#endif
18345 +
18346 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18347 do { \
18348 char c; \
18349 asm volatile (fullop "; set" cc " %1" \
18350 @@ -30,11 +88,17 @@ do { \
18351 return c != 0; \
18352 } while (0)
18353
18354 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18355 - __GEN_RMWcc(op " " arg0, var, cc)
18356 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18357 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18358 +
18359 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18360 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18361 +
18362 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18363 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18364
18365 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18366 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18367 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18368 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18369
18370 #endif /* CC_HAVE_ASM_GOTO */
18371
18372 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18373 index cad82c9..2e5c5c1 100644
18374 --- a/arch/x86/include/asm/rwsem.h
18375 +++ b/arch/x86/include/asm/rwsem.h
18376 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18377 {
18378 asm volatile("# beginning down_read\n\t"
18379 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18380 +
18381 +#ifdef CONFIG_PAX_REFCOUNT
18382 + "jno 0f\n"
18383 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18384 + "int $4\n0:\n"
18385 + _ASM_EXTABLE(0b, 0b)
18386 +#endif
18387 +
18388 /* adds 0x00000001 */
18389 " jns 1f\n"
18390 " call call_rwsem_down_read_failed\n"
18391 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18392 "1:\n\t"
18393 " mov %1,%2\n\t"
18394 " add %3,%2\n\t"
18395 +
18396 +#ifdef CONFIG_PAX_REFCOUNT
18397 + "jno 0f\n"
18398 + "sub %3,%2\n"
18399 + "int $4\n0:\n"
18400 + _ASM_EXTABLE(0b, 0b)
18401 +#endif
18402 +
18403 " jle 2f\n\t"
18404 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18405 " jnz 1b\n\t"
18406 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18407 long tmp;
18408 asm volatile("# beginning down_write\n\t"
18409 LOCK_PREFIX " xadd %1,(%2)\n\t"
18410 +
18411 +#ifdef CONFIG_PAX_REFCOUNT
18412 + "jno 0f\n"
18413 + "mov %1,(%2)\n"
18414 + "int $4\n0:\n"
18415 + _ASM_EXTABLE(0b, 0b)
18416 +#endif
18417 +
18418 /* adds 0xffff0001, returns the old value */
18419 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18420 /* was the active mask 0 before? */
18421 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18422 long tmp;
18423 asm volatile("# beginning __up_read\n\t"
18424 LOCK_PREFIX " xadd %1,(%2)\n\t"
18425 +
18426 +#ifdef CONFIG_PAX_REFCOUNT
18427 + "jno 0f\n"
18428 + "mov %1,(%2)\n"
18429 + "int $4\n0:\n"
18430 + _ASM_EXTABLE(0b, 0b)
18431 +#endif
18432 +
18433 /* subtracts 1, returns the old value */
18434 " jns 1f\n\t"
18435 " call call_rwsem_wake\n" /* expects old value in %edx */
18436 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18437 long tmp;
18438 asm volatile("# beginning __up_write\n\t"
18439 LOCK_PREFIX " xadd %1,(%2)\n\t"
18440 +
18441 +#ifdef CONFIG_PAX_REFCOUNT
18442 + "jno 0f\n"
18443 + "mov %1,(%2)\n"
18444 + "int $4\n0:\n"
18445 + _ASM_EXTABLE(0b, 0b)
18446 +#endif
18447 +
18448 /* subtracts 0xffff0001, returns the old value */
18449 " jns 1f\n\t"
18450 " call call_rwsem_wake\n" /* expects old value in %edx */
18451 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18452 {
18453 asm volatile("# beginning __downgrade_write\n\t"
18454 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18455 +
18456 +#ifdef CONFIG_PAX_REFCOUNT
18457 + "jno 0f\n"
18458 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18459 + "int $4\n0:\n"
18460 + _ASM_EXTABLE(0b, 0b)
18461 +#endif
18462 +
18463 /*
18464 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18465 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18466 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18467 */
18468 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18469 {
18470 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18471 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18472 +
18473 +#ifdef CONFIG_PAX_REFCOUNT
18474 + "jno 0f\n"
18475 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18476 + "int $4\n0:\n"
18477 + _ASM_EXTABLE(0b, 0b)
18478 +#endif
18479 +
18480 : "+m" (sem->count)
18481 : "er" (delta));
18482 }
18483 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18484 */
18485 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18486 {
18487 - return delta + xadd(&sem->count, delta);
18488 + return delta + xadd_check_overflow(&sem->count, delta);
18489 }
18490
18491 #endif /* __KERNEL__ */
18492 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18493 index 6f1c3a8..7744f19 100644
18494 --- a/arch/x86/include/asm/segment.h
18495 +++ b/arch/x86/include/asm/segment.h
18496 @@ -64,10 +64,15 @@
18497 * 26 - ESPFIX small SS
18498 * 27 - per-cpu [ offset to per-cpu data area ]
18499 * 28 - stack_canary-20 [ for stack protector ]
18500 - * 29 - unused
18501 - * 30 - unused
18502 + * 29 - PCI BIOS CS
18503 + * 30 - PCI BIOS DS
18504 * 31 - TSS for double fault handler
18505 */
18506 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18507 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18508 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18509 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18510 +
18511 #define GDT_ENTRY_TLS_MIN 6
18512 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18513
18514 @@ -79,6 +84,8 @@
18515
18516 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18517
18518 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18519 +
18520 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18521
18522 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18523 @@ -104,6 +111,12 @@
18524 #define __KERNEL_STACK_CANARY 0
18525 #endif
18526
18527 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18528 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18529 +
18530 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18531 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18532 +
18533 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18534
18535 /*
18536 @@ -141,7 +154,7 @@
18537 */
18538
18539 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18540 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18541 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18542
18543
18544 #else
18545 @@ -165,6 +178,8 @@
18546 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18547 #define __USER32_DS __USER_DS
18548
18549 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18550 +
18551 #define GDT_ENTRY_TSS 8 /* needs two entries */
18552 #define GDT_ENTRY_LDT 10 /* needs two entries */
18553 #define GDT_ENTRY_TLS_MIN 12
18554 @@ -173,6 +188,8 @@
18555 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18556 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18557
18558 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18559 +
18560 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18561 #define FS_TLS 0
18562 #define GS_TLS 1
18563 @@ -180,12 +197,14 @@
18564 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18565 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18566
18567 -#define GDT_ENTRIES 16
18568 +#define GDT_ENTRIES 17
18569
18570 #endif
18571
18572 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18573 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18574 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18575 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18576 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18577 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18578 #ifndef CONFIG_PARAVIRT
18579 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18580 {
18581 unsigned long __limit;
18582 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18583 - return __limit + 1;
18584 + return __limit;
18585 }
18586
18587 #endif /* !__ASSEMBLY__ */
18588 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18589 index 8d3120f..352b440 100644
18590 --- a/arch/x86/include/asm/smap.h
18591 +++ b/arch/x86/include/asm/smap.h
18592 @@ -25,11 +25,40 @@
18593
18594 #include <asm/alternative-asm.h>
18595
18596 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18597 +#define ASM_PAX_OPEN_USERLAND \
18598 + 661: jmp 663f; \
18599 + .pushsection .altinstr_replacement, "a" ; \
18600 + 662: pushq %rax; nop; \
18601 + .popsection ; \
18602 + .pushsection .altinstructions, "a" ; \
18603 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18604 + .popsection ; \
18605 + call __pax_open_userland; \
18606 + popq %rax; \
18607 + 663:
18608 +
18609 +#define ASM_PAX_CLOSE_USERLAND \
18610 + 661: jmp 663f; \
18611 + .pushsection .altinstr_replacement, "a" ; \
18612 + 662: pushq %rax; nop; \
18613 + .popsection; \
18614 + .pushsection .altinstructions, "a" ; \
18615 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18616 + .popsection; \
18617 + call __pax_close_userland; \
18618 + popq %rax; \
18619 + 663:
18620 +#else
18621 +#define ASM_PAX_OPEN_USERLAND
18622 +#define ASM_PAX_CLOSE_USERLAND
18623 +#endif
18624 +
18625 #ifdef CONFIG_X86_SMAP
18626
18627 #define ASM_CLAC \
18628 661: ASM_NOP3 ; \
18629 - .pushsection .altinstr_replacement, "ax" ; \
18630 + .pushsection .altinstr_replacement, "a" ; \
18631 662: __ASM_CLAC ; \
18632 .popsection ; \
18633 .pushsection .altinstructions, "a" ; \
18634 @@ -38,7 +67,7 @@
18635
18636 #define ASM_STAC \
18637 661: ASM_NOP3 ; \
18638 - .pushsection .altinstr_replacement, "ax" ; \
18639 + .pushsection .altinstr_replacement, "a" ; \
18640 662: __ASM_STAC ; \
18641 .popsection ; \
18642 .pushsection .altinstructions, "a" ; \
18643 @@ -56,6 +85,37 @@
18644
18645 #include <asm/alternative.h>
18646
18647 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18648 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18649 +
18650 +extern void __pax_open_userland(void);
18651 +static __always_inline unsigned long pax_open_userland(void)
18652 +{
18653 +
18654 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18655 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18656 + :
18657 + : [open] "i" (__pax_open_userland)
18658 + : "memory", "rax");
18659 +#endif
18660 +
18661 + return 0;
18662 +}
18663 +
18664 +extern void __pax_close_userland(void);
18665 +static __always_inline unsigned long pax_close_userland(void)
18666 +{
18667 +
18668 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18669 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18670 + :
18671 + : [close] "i" (__pax_close_userland)
18672 + : "memory", "rax");
18673 +#endif
18674 +
18675 + return 0;
18676 +}
18677 +
18678 #ifdef CONFIG_X86_SMAP
18679
18680 static __always_inline void clac(void)
18681 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18682 index 8cd27e0..7f05ec8 100644
18683 --- a/arch/x86/include/asm/smp.h
18684 +++ b/arch/x86/include/asm/smp.h
18685 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18686 /* cpus sharing the last level cache: */
18687 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18688 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18689 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18690 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18691
18692 static inline struct cpumask *cpu_sibling_mask(int cpu)
18693 {
18694 @@ -78,7 +78,7 @@ struct smp_ops {
18695
18696 void (*send_call_func_ipi)(const struct cpumask *mask);
18697 void (*send_call_func_single_ipi)(int cpu);
18698 -};
18699 +} __no_const;
18700
18701 /* Globals due to paravirt */
18702 extern void set_cpu_sibling_map(int cpu);
18703 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18704 extern int safe_smp_processor_id(void);
18705
18706 #elif defined(CONFIG_X86_64_SMP)
18707 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18708 -
18709 -#define stack_smp_processor_id() \
18710 -({ \
18711 - struct thread_info *ti; \
18712 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18713 - ti->cpu; \
18714 -})
18715 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18716 +#define stack_smp_processor_id() raw_smp_processor_id()
18717 #define safe_smp_processor_id() smp_processor_id()
18718
18719 #endif
18720 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18721 index 0f62f54..cb5d0dd 100644
18722 --- a/arch/x86/include/asm/spinlock.h
18723 +++ b/arch/x86/include/asm/spinlock.h
18724 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18725 static inline void arch_read_lock(arch_rwlock_t *rw)
18726 {
18727 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18728 +
18729 +#ifdef CONFIG_PAX_REFCOUNT
18730 + "jno 0f\n"
18731 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18732 + "int $4\n0:\n"
18733 + _ASM_EXTABLE(0b, 0b)
18734 +#endif
18735 +
18736 "jns 1f\n"
18737 "call __read_lock_failed\n\t"
18738 "1:\n"
18739 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18740 static inline void arch_write_lock(arch_rwlock_t *rw)
18741 {
18742 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18743 +
18744 +#ifdef CONFIG_PAX_REFCOUNT
18745 + "jno 0f\n"
18746 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18747 + "int $4\n0:\n"
18748 + _ASM_EXTABLE(0b, 0b)
18749 +#endif
18750 +
18751 "jz 1f\n"
18752 "call __write_lock_failed\n\t"
18753 "1:\n"
18754 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18755
18756 static inline void arch_read_unlock(arch_rwlock_t *rw)
18757 {
18758 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18759 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18760 +
18761 +#ifdef CONFIG_PAX_REFCOUNT
18762 + "jno 0f\n"
18763 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18764 + "int $4\n0:\n"
18765 + _ASM_EXTABLE(0b, 0b)
18766 +#endif
18767 +
18768 :"+m" (rw->lock) : : "memory");
18769 }
18770
18771 static inline void arch_write_unlock(arch_rwlock_t *rw)
18772 {
18773 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18774 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18775 +
18776 +#ifdef CONFIG_PAX_REFCOUNT
18777 + "jno 0f\n"
18778 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18779 + "int $4\n0:\n"
18780 + _ASM_EXTABLE(0b, 0b)
18781 +#endif
18782 +
18783 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18784 }
18785
18786 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18787 index 6a99859..03cb807 100644
18788 --- a/arch/x86/include/asm/stackprotector.h
18789 +++ b/arch/x86/include/asm/stackprotector.h
18790 @@ -47,7 +47,7 @@
18791 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18792 */
18793 #define GDT_STACK_CANARY_INIT \
18794 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18795 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18796
18797 /*
18798 * Initialize the stackprotector canary value.
18799 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18800
18801 static inline void load_stack_canary_segment(void)
18802 {
18803 -#ifdef CONFIG_X86_32
18804 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18805 asm volatile ("mov %0, %%gs" : : "r" (0));
18806 #endif
18807 }
18808 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18809 index 70bbe39..4ae2bd4 100644
18810 --- a/arch/x86/include/asm/stacktrace.h
18811 +++ b/arch/x86/include/asm/stacktrace.h
18812 @@ -11,28 +11,20 @@
18813
18814 extern int kstack_depth_to_print;
18815
18816 -struct thread_info;
18817 +struct task_struct;
18818 struct stacktrace_ops;
18819
18820 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18821 - unsigned long *stack,
18822 - unsigned long bp,
18823 - const struct stacktrace_ops *ops,
18824 - void *data,
18825 - unsigned long *end,
18826 - int *graph);
18827 +typedef unsigned long walk_stack_t(struct task_struct *task,
18828 + void *stack_start,
18829 + unsigned long *stack,
18830 + unsigned long bp,
18831 + const struct stacktrace_ops *ops,
18832 + void *data,
18833 + unsigned long *end,
18834 + int *graph);
18835
18836 -extern unsigned long
18837 -print_context_stack(struct thread_info *tinfo,
18838 - unsigned long *stack, unsigned long bp,
18839 - const struct stacktrace_ops *ops, void *data,
18840 - unsigned long *end, int *graph);
18841 -
18842 -extern unsigned long
18843 -print_context_stack_bp(struct thread_info *tinfo,
18844 - unsigned long *stack, unsigned long bp,
18845 - const struct stacktrace_ops *ops, void *data,
18846 - unsigned long *end, int *graph);
18847 +extern walk_stack_t print_context_stack;
18848 +extern walk_stack_t print_context_stack_bp;
18849
18850 /* Generic stack tracer with callbacks */
18851
18852 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18853 void (*address)(void *data, unsigned long address, int reliable);
18854 /* On negative return stop dumping */
18855 int (*stack)(void *data, char *name);
18856 - walk_stack_t walk_stack;
18857 + walk_stack_t *walk_stack;
18858 };
18859
18860 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18861 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18862 index d7f3b3b..3cc39f1 100644
18863 --- a/arch/x86/include/asm/switch_to.h
18864 +++ b/arch/x86/include/asm/switch_to.h
18865 @@ -108,7 +108,7 @@ do { \
18866 "call __switch_to\n\t" \
18867 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18868 __switch_canary \
18869 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18870 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18871 "movq %%rax,%%rdi\n\t" \
18872 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18873 "jnz ret_from_fork\n\t" \
18874 @@ -119,7 +119,7 @@ do { \
18875 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18876 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18877 [_tif_fork] "i" (_TIF_FORK), \
18878 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18879 + [thread_info] "m" (current_tinfo), \
18880 [current_task] "m" (current_task) \
18881 __switch_canary_iparam \
18882 : "memory", "cc" __EXTRA_CLOBBER)
18883 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18884 index e1940c0..ac50dd8 100644
18885 --- a/arch/x86/include/asm/thread_info.h
18886 +++ b/arch/x86/include/asm/thread_info.h
18887 @@ -10,6 +10,7 @@
18888 #include <linux/compiler.h>
18889 #include <asm/page.h>
18890 #include <asm/types.h>
18891 +#include <asm/percpu.h>
18892
18893 /*
18894 * low level task data that entry.S needs immediate access to
18895 @@ -23,7 +24,6 @@ struct exec_domain;
18896 #include <linux/atomic.h>
18897
18898 struct thread_info {
18899 - struct task_struct *task; /* main task structure */
18900 struct exec_domain *exec_domain; /* execution domain */
18901 __u32 flags; /* low level flags */
18902 __u32 status; /* thread synchronous flags */
18903 @@ -32,19 +32,13 @@ struct thread_info {
18904 mm_segment_t addr_limit;
18905 struct restart_block restart_block;
18906 void __user *sysenter_return;
18907 -#ifdef CONFIG_X86_32
18908 - unsigned long previous_esp; /* ESP of the previous stack in
18909 - case of nested (IRQ) stacks
18910 - */
18911 - __u8 supervisor_stack[0];
18912 -#endif
18913 + unsigned long lowest_stack;
18914 unsigned int sig_on_uaccess_error:1;
18915 unsigned int uaccess_err:1; /* uaccess failed */
18916 };
18917
18918 -#define INIT_THREAD_INFO(tsk) \
18919 +#define INIT_THREAD_INFO \
18920 { \
18921 - .task = &tsk, \
18922 .exec_domain = &default_exec_domain, \
18923 .flags = 0, \
18924 .cpu = 0, \
18925 @@ -55,7 +49,7 @@ struct thread_info {
18926 }, \
18927 }
18928
18929 -#define init_thread_info (init_thread_union.thread_info)
18930 +#define init_thread_info (init_thread_union.stack)
18931 #define init_stack (init_thread_union.stack)
18932
18933 #else /* !__ASSEMBLY__ */
18934 @@ -95,6 +89,7 @@ struct thread_info {
18935 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18936 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18937 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18938 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18939
18940 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18941 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18942 @@ -118,17 +113,18 @@ struct thread_info {
18943 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18944 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18945 #define _TIF_X32 (1 << TIF_X32)
18946 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18947
18948 /* work to do in syscall_trace_enter() */
18949 #define _TIF_WORK_SYSCALL_ENTRY \
18950 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18951 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18952 - _TIF_NOHZ)
18953 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18954
18955 /* work to do in syscall_trace_leave() */
18956 #define _TIF_WORK_SYSCALL_EXIT \
18957 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18958 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18959 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18960
18961 /* work to do on interrupt/exception return */
18962 #define _TIF_WORK_MASK \
18963 @@ -139,7 +135,7 @@ struct thread_info {
18964 /* work to do on any return to user space */
18965 #define _TIF_ALLWORK_MASK \
18966 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18967 - _TIF_NOHZ)
18968 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18969
18970 /* Only used for 64 bit */
18971 #define _TIF_DO_NOTIFY_MASK \
18972 @@ -153,6 +149,23 @@ struct thread_info {
18973 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18974 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18975
18976 +#ifdef __ASSEMBLY__
18977 +/* how to get the thread information struct from ASM */
18978 +#define GET_THREAD_INFO(reg) \
18979 + mov PER_CPU_VAR(current_tinfo), reg
18980 +
18981 +/* use this one if reg already contains %esp */
18982 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18983 +#else
18984 +/* how to get the thread information struct from C */
18985 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18986 +
18987 +static __always_inline struct thread_info *current_thread_info(void)
18988 +{
18989 + return this_cpu_read_stable(current_tinfo);
18990 +}
18991 +#endif
18992 +
18993 #ifdef CONFIG_X86_32
18994
18995 #define STACK_WARN (THREAD_SIZE/8)
18996 @@ -169,31 +182,10 @@ struct thread_info {
18997 sp; \
18998 })
18999
19000 -/* how to get the thread information struct from C */
19001 -static inline struct thread_info *current_thread_info(void)
19002 -{
19003 - return (struct thread_info *)
19004 - (current_stack_pointer & ~(THREAD_SIZE - 1));
19005 -}
19006 -
19007 -#else /* !__ASSEMBLY__ */
19008 -
19009 -/* how to get the thread information struct from ASM */
19010 -#define GET_THREAD_INFO(reg) \
19011 - movl $-THREAD_SIZE, reg; \
19012 - andl %esp, reg
19013 -
19014 -/* use this one if reg already contains %esp */
19015 -#define GET_THREAD_INFO_WITH_ESP(reg) \
19016 - andl $-THREAD_SIZE, reg
19017 -
19018 #endif
19019
19020 #else /* X86_32 */
19021
19022 -#include <asm/percpu.h>
19023 -#define KERNEL_STACK_OFFSET (5*8)
19024 -
19025 /*
19026 * macros/functions for gaining access to the thread information structure
19027 * preempt_count needs to be 1 initially, until the scheduler is functional.
19028 @@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19029 #ifndef __ASSEMBLY__
19030 DECLARE_PER_CPU(unsigned long, kernel_stack);
19031
19032 -static inline struct thread_info *current_thread_info(void)
19033 -{
19034 - struct thread_info *ti;
19035 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19036 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19037 - return ti;
19038 -}
19039 -
19040 -#else /* !__ASSEMBLY__ */
19041 -
19042 -/* how to get the thread information struct from ASM */
19043 -#define GET_THREAD_INFO(reg) \
19044 - movq PER_CPU_VAR(kernel_stack),reg ; \
19045 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19046 -
19047 -/*
19048 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19049 - * a certain register (to be used in assembler memory operands).
19050 - */
19051 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19052 -
19053 +/* how to get the current stack pointer from C */
19054 +register unsigned long current_stack_pointer asm("rsp") __used;
19055 #endif
19056
19057 #endif /* !X86_32 */
19058 @@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19059 extern void arch_task_cache_init(void);
19060 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19061 extern void arch_release_task_struct(struct task_struct *tsk);
19062 +
19063 +#define __HAVE_THREAD_FUNCTIONS
19064 +#define task_thread_info(task) (&(task)->tinfo)
19065 +#define task_stack_page(task) ((task)->stack)
19066 +#define setup_thread_stack(p, org) do {} while (0)
19067 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19068 +
19069 #endif
19070 #endif /* _ASM_X86_THREAD_INFO_H */
19071 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19072 index 04905bf..49203ca 100644
19073 --- a/arch/x86/include/asm/tlbflush.h
19074 +++ b/arch/x86/include/asm/tlbflush.h
19075 @@ -17,18 +17,44 @@
19076
19077 static inline void __native_flush_tlb(void)
19078 {
19079 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19080 + u64 descriptor[2];
19081 +
19082 + descriptor[0] = PCID_KERNEL;
19083 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19084 + return;
19085 + }
19086 +
19087 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19088 + if (static_cpu_has(X86_FEATURE_PCID)) {
19089 + unsigned int cpu = raw_get_cpu();
19090 +
19091 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19092 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19093 + raw_put_cpu_no_resched();
19094 + return;
19095 + }
19096 +#endif
19097 +
19098 native_write_cr3(native_read_cr3());
19099 }
19100
19101 static inline void __native_flush_tlb_global_irq_disabled(void)
19102 {
19103 - unsigned long cr4;
19104 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19105 + u64 descriptor[2];
19106
19107 - cr4 = native_read_cr4();
19108 - /* clear PGE */
19109 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19110 - /* write old PGE again and flush TLBs */
19111 - native_write_cr4(cr4);
19112 + descriptor[0] = PCID_KERNEL;
19113 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19114 + } else {
19115 + unsigned long cr4;
19116 +
19117 + cr4 = native_read_cr4();
19118 + /* clear PGE */
19119 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19120 + /* write old PGE again and flush TLBs */
19121 + native_write_cr4(cr4);
19122 + }
19123 }
19124
19125 static inline void __native_flush_tlb_global(void)
19126 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19127
19128 static inline void __native_flush_tlb_single(unsigned long addr)
19129 {
19130 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19131 + u64 descriptor[2];
19132 +
19133 + descriptor[0] = PCID_KERNEL;
19134 + descriptor[1] = addr;
19135 +
19136 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19137 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19138 + if (addr < TASK_SIZE_MAX)
19139 + descriptor[1] += pax_user_shadow_base;
19140 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19141 + }
19142 +
19143 + descriptor[0] = PCID_USER;
19144 + descriptor[1] = addr;
19145 +#endif
19146 +
19147 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19148 + return;
19149 + }
19150 +
19151 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19152 + if (static_cpu_has(X86_FEATURE_PCID)) {
19153 + unsigned int cpu = raw_get_cpu();
19154 +
19155 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19156 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19157 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19158 + raw_put_cpu_no_resched();
19159 +
19160 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19161 + addr += pax_user_shadow_base;
19162 + }
19163 +#endif
19164 +
19165 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19166 }
19167
19168 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19169 index 0d592e0..f58a222 100644
19170 --- a/arch/x86/include/asm/uaccess.h
19171 +++ b/arch/x86/include/asm/uaccess.h
19172 @@ -7,6 +7,7 @@
19173 #include <linux/compiler.h>
19174 #include <linux/thread_info.h>
19175 #include <linux/string.h>
19176 +#include <linux/spinlock.h>
19177 #include <asm/asm.h>
19178 #include <asm/page.h>
19179 #include <asm/smap.h>
19180 @@ -29,7 +30,12 @@
19181
19182 #define get_ds() (KERNEL_DS)
19183 #define get_fs() (current_thread_info()->addr_limit)
19184 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19185 +void __set_fs(mm_segment_t x);
19186 +void set_fs(mm_segment_t x);
19187 +#else
19188 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19189 +#endif
19190
19191 #define segment_eq(a, b) ((a).seg == (b).seg)
19192
19193 @@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19194 * checks that the pointer is in the user space range - after calling
19195 * this function, memory access functions may still return -EFAULT.
19196 */
19197 -#define access_ok(type, addr, size) \
19198 - likely(!__range_not_ok(addr, size, user_addr_max()))
19199 +extern int _cond_resched(void);
19200 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19201 +#define access_ok(type, addr, size) \
19202 +({ \
19203 + long __size = size; \
19204 + unsigned long __addr = (unsigned long)addr; \
19205 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19206 + unsigned long __end_ao = __addr + __size - 1; \
19207 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19208 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19209 + while(__addr_ao <= __end_ao) { \
19210 + char __c_ao; \
19211 + __addr_ao += PAGE_SIZE; \
19212 + if (__size > PAGE_SIZE) \
19213 + _cond_resched(); \
19214 + if (__get_user(__c_ao, (char __user *)__addr)) \
19215 + break; \
19216 + if (type != VERIFY_WRITE) { \
19217 + __addr = __addr_ao; \
19218 + continue; \
19219 + } \
19220 + if (__put_user(__c_ao, (char __user *)__addr)) \
19221 + break; \
19222 + __addr = __addr_ao; \
19223 + } \
19224 + } \
19225 + __ret_ao; \
19226 +})
19227
19228 /*
19229 * The exception table consists of pairs of addresses relative to the
19230 @@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19231 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19232 __chk_user_ptr(ptr); \
19233 might_fault(); \
19234 + pax_open_userland(); \
19235 asm volatile("call __get_user_%P3" \
19236 : "=a" (__ret_gu), "=r" (__val_gu) \
19237 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19238 (x) = (__typeof__(*(ptr))) __val_gu; \
19239 + pax_close_userland(); \
19240 __ret_gu; \
19241 })
19242
19243 @@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19244 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19245 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19246
19247 -
19248 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19249 +#define __copyuser_seg "gs;"
19250 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19251 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19252 +#else
19253 +#define __copyuser_seg
19254 +#define __COPYUSER_SET_ES
19255 +#define __COPYUSER_RESTORE_ES
19256 +#endif
19257
19258 #ifdef CONFIG_X86_32
19259 #define __put_user_asm_u64(x, addr, err, errret) \
19260 asm volatile(ASM_STAC "\n" \
19261 - "1: movl %%eax,0(%2)\n" \
19262 - "2: movl %%edx,4(%2)\n" \
19263 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19264 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19265 "3: " ASM_CLAC "\n" \
19266 ".section .fixup,\"ax\"\n" \
19267 "4: movl %3,%0\n" \
19268 @@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19269
19270 #define __put_user_asm_ex_u64(x, addr) \
19271 asm volatile(ASM_STAC "\n" \
19272 - "1: movl %%eax,0(%1)\n" \
19273 - "2: movl %%edx,4(%1)\n" \
19274 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19275 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19276 "3: " ASM_CLAC "\n" \
19277 _ASM_EXTABLE_EX(1b, 2b) \
19278 _ASM_EXTABLE_EX(2b, 3b) \
19279 @@ -257,7 +299,8 @@ extern void __put_user_8(void);
19280 __typeof__(*(ptr)) __pu_val; \
19281 __chk_user_ptr(ptr); \
19282 might_fault(); \
19283 - __pu_val = x; \
19284 + __pu_val = (x); \
19285 + pax_open_userland(); \
19286 switch (sizeof(*(ptr))) { \
19287 case 1: \
19288 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19289 @@ -275,6 +318,7 @@ extern void __put_user_8(void);
19290 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19291 break; \
19292 } \
19293 + pax_close_userland(); \
19294 __ret_pu; \
19295 })
19296
19297 @@ -355,8 +399,10 @@ do { \
19298 } while (0)
19299
19300 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19301 +do { \
19302 + pax_open_userland(); \
19303 asm volatile(ASM_STAC "\n" \
19304 - "1: mov"itype" %2,%"rtype"1\n" \
19305 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19306 "2: " ASM_CLAC "\n" \
19307 ".section .fixup,\"ax\"\n" \
19308 "3: mov %3,%0\n" \
19309 @@ -364,8 +410,10 @@ do { \
19310 " jmp 2b\n" \
19311 ".previous\n" \
19312 _ASM_EXTABLE(1b, 3b) \
19313 - : "=r" (err), ltype(x) \
19314 - : "m" (__m(addr)), "i" (errret), "0" (err))
19315 + : "=r" (err), ltype (x) \
19316 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19317 + pax_close_userland(); \
19318 +} while (0)
19319
19320 #define __get_user_size_ex(x, ptr, size) \
19321 do { \
19322 @@ -389,7 +437,7 @@ do { \
19323 } while (0)
19324
19325 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19326 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19327 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19328 "2:\n" \
19329 _ASM_EXTABLE_EX(1b, 2b) \
19330 : ltype(x) : "m" (__m(addr)))
19331 @@ -406,13 +454,24 @@ do { \
19332 int __gu_err; \
19333 unsigned long __gu_val; \
19334 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19335 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19336 + (x) = (__typeof__(*(ptr)))__gu_val; \
19337 __gu_err; \
19338 })
19339
19340 /* FIXME: this hack is definitely wrong -AK */
19341 struct __large_struct { unsigned long buf[100]; };
19342 -#define __m(x) (*(struct __large_struct __user *)(x))
19343 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19344 +#define ____m(x) \
19345 +({ \
19346 + unsigned long ____x = (unsigned long)(x); \
19347 + if (____x < pax_user_shadow_base) \
19348 + ____x += pax_user_shadow_base; \
19349 + (typeof(x))____x; \
19350 +})
19351 +#else
19352 +#define ____m(x) (x)
19353 +#endif
19354 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19355
19356 /*
19357 * Tell gcc we read from memory instead of writing: this is because
19358 @@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19359 * aliasing issues.
19360 */
19361 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19362 +do { \
19363 + pax_open_userland(); \
19364 asm volatile(ASM_STAC "\n" \
19365 - "1: mov"itype" %"rtype"1,%2\n" \
19366 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19367 "2: " ASM_CLAC "\n" \
19368 ".section .fixup,\"ax\"\n" \
19369 "3: mov %3,%0\n" \
19370 @@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19371 ".previous\n" \
19372 _ASM_EXTABLE(1b, 3b) \
19373 : "=r"(err) \
19374 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19375 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19376 + pax_close_userland(); \
19377 +} while (0)
19378
19379 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19380 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19381 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19382 "2:\n" \
19383 _ASM_EXTABLE_EX(1b, 2b) \
19384 : : ltype(x), "m" (__m(addr)))
19385 @@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19386 */
19387 #define uaccess_try do { \
19388 current_thread_info()->uaccess_err = 0; \
19389 + pax_open_userland(); \
19390 stac(); \
19391 barrier();
19392
19393 #define uaccess_catch(err) \
19394 clac(); \
19395 + pax_close_userland(); \
19396 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19397 } while (0)
19398
19399 @@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19400 * On error, the variable @x is set to zero.
19401 */
19402
19403 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19404 +#define __get_user(x, ptr) get_user((x), (ptr))
19405 +#else
19406 #define __get_user(x, ptr) \
19407 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19408 +#endif
19409
19410 /**
19411 * __put_user: - Write a simple value into user space, with less checking.
19412 @@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19413 * Returns zero on success, or -EFAULT on error.
19414 */
19415
19416 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19417 +#define __put_user(x, ptr) put_user((x), (ptr))
19418 +#else
19419 #define __put_user(x, ptr) \
19420 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19421 +#endif
19422
19423 #define __get_user_unaligned __get_user
19424 #define __put_user_unaligned __put_user
19425 @@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19426 #define get_user_ex(x, ptr) do { \
19427 unsigned long __gue_val; \
19428 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19429 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19430 + (x) = (__typeof__(*(ptr)))__gue_val; \
19431 } while (0)
19432
19433 #define put_user_try uaccess_try
19434 @@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19435 __typeof__(ptr) __uval = (uval); \
19436 __typeof__(*(ptr)) __old = (old); \
19437 __typeof__(*(ptr)) __new = (new); \
19438 + pax_open_userland(); \
19439 switch (size) { \
19440 case 1: \
19441 { \
19442 asm volatile("\t" ASM_STAC "\n" \
19443 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19444 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19445 "2:\t" ASM_CLAC "\n" \
19446 "\t.section .fixup, \"ax\"\n" \
19447 "3:\tmov %3, %0\n" \
19448 "\tjmp 2b\n" \
19449 "\t.previous\n" \
19450 _ASM_EXTABLE(1b, 3b) \
19451 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19452 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19453 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19454 : "memory" \
19455 ); \
19456 @@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19457 case 2: \
19458 { \
19459 asm volatile("\t" ASM_STAC "\n" \
19460 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19461 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19462 "2:\t" ASM_CLAC "\n" \
19463 "\t.section .fixup, \"ax\"\n" \
19464 "3:\tmov %3, %0\n" \
19465 "\tjmp 2b\n" \
19466 "\t.previous\n" \
19467 _ASM_EXTABLE(1b, 3b) \
19468 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19469 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19470 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19471 : "memory" \
19472 ); \
19473 @@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19474 case 4: \
19475 { \
19476 asm volatile("\t" ASM_STAC "\n" \
19477 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19478 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19479 "2:\t" ASM_CLAC "\n" \
19480 "\t.section .fixup, \"ax\"\n" \
19481 "3:\tmov %3, %0\n" \
19482 "\tjmp 2b\n" \
19483 "\t.previous\n" \
19484 _ASM_EXTABLE(1b, 3b) \
19485 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19486 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19487 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19488 : "memory" \
19489 ); \
19490 @@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19491 __cmpxchg_wrong_size(); \
19492 \
19493 asm volatile("\t" ASM_STAC "\n" \
19494 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19495 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19496 "2:\t" ASM_CLAC "\n" \
19497 "\t.section .fixup, \"ax\"\n" \
19498 "3:\tmov %3, %0\n" \
19499 "\tjmp 2b\n" \
19500 "\t.previous\n" \
19501 _ASM_EXTABLE(1b, 3b) \
19502 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19503 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19504 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19505 : "memory" \
19506 ); \
19507 @@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19508 default: \
19509 __cmpxchg_wrong_size(); \
19510 } \
19511 + pax_close_userland(); \
19512 *__uval = __old; \
19513 __ret; \
19514 })
19515 @@ -636,17 +711,6 @@ extern struct movsl_mask {
19516
19517 #define ARCH_HAS_NOCACHE_UACCESS 1
19518
19519 -#ifdef CONFIG_X86_32
19520 -# include <asm/uaccess_32.h>
19521 -#else
19522 -# include <asm/uaccess_64.h>
19523 -#endif
19524 -
19525 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19526 - unsigned n);
19527 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19528 - unsigned n);
19529 -
19530 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19531 # define copy_user_diag __compiletime_error
19532 #else
19533 @@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19534 extern void copy_user_diag("copy_from_user() buffer size is too small")
19535 copy_from_user_overflow(void);
19536 extern void copy_user_diag("copy_to_user() buffer size is too small")
19537 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19538 +copy_to_user_overflow(void);
19539
19540 #undef copy_user_diag
19541
19542 @@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19543
19544 extern void
19545 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19546 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19547 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19548 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19549
19550 #else
19551 @@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19552
19553 #endif
19554
19555 +#ifdef CONFIG_X86_32
19556 +# include <asm/uaccess_32.h>
19557 +#else
19558 +# include <asm/uaccess_64.h>
19559 +#endif
19560 +
19561 static inline unsigned long __must_check
19562 copy_from_user(void *to, const void __user *from, unsigned long n)
19563 {
19564 - int sz = __compiletime_object_size(to);
19565 + size_t sz = __compiletime_object_size(to);
19566
19567 might_fault();
19568
19569 @@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19570 * case, and do only runtime checking for non-constant sizes.
19571 */
19572
19573 - if (likely(sz < 0 || sz >= n))
19574 - n = _copy_from_user(to, from, n);
19575 - else if(__builtin_constant_p(n))
19576 - copy_from_user_overflow();
19577 - else
19578 - __copy_from_user_overflow(sz, n);
19579 + if (likely(sz != (size_t)-1 && sz < n)) {
19580 + if(__builtin_constant_p(n))
19581 + copy_from_user_overflow();
19582 + else
19583 + __copy_from_user_overflow(sz, n);
19584 + } if (access_ok(VERIFY_READ, from, n))
19585 + n = __copy_from_user(to, from, n);
19586 + else if ((long)n > 0)
19587 + memset(to, 0, n);
19588
19589 return n;
19590 }
19591 @@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19592 static inline unsigned long __must_check
19593 copy_to_user(void __user *to, const void *from, unsigned long n)
19594 {
19595 - int sz = __compiletime_object_size(from);
19596 + size_t sz = __compiletime_object_size(from);
19597
19598 might_fault();
19599
19600 /* See the comment in copy_from_user() above. */
19601 - if (likely(sz < 0 || sz >= n))
19602 - n = _copy_to_user(to, from, n);
19603 - else if(__builtin_constant_p(n))
19604 - copy_to_user_overflow();
19605 - else
19606 - __copy_to_user_overflow(sz, n);
19607 + if (likely(sz != (size_t)-1 && sz < n)) {
19608 + if(__builtin_constant_p(n))
19609 + copy_to_user_overflow();
19610 + else
19611 + __copy_to_user_overflow(sz, n);
19612 + } else if (access_ok(VERIFY_WRITE, to, n))
19613 + n = __copy_to_user(to, from, n);
19614
19615 return n;
19616 }
19617 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19618 index 3c03a5d..1071638 100644
19619 --- a/arch/x86/include/asm/uaccess_32.h
19620 +++ b/arch/x86/include/asm/uaccess_32.h
19621 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19622 static __always_inline unsigned long __must_check
19623 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19624 {
19625 + if ((long)n < 0)
19626 + return n;
19627 +
19628 + check_object_size(from, n, true);
19629 +
19630 if (__builtin_constant_p(n)) {
19631 unsigned long ret;
19632
19633 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19634 __copy_to_user(void __user *to, const void *from, unsigned long n)
19635 {
19636 might_fault();
19637 +
19638 return __copy_to_user_inatomic(to, from, n);
19639 }
19640
19641 static __always_inline unsigned long
19642 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19643 {
19644 + if ((long)n < 0)
19645 + return n;
19646 +
19647 /* Avoid zeroing the tail if the copy fails..
19648 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19649 * but as the zeroing behaviour is only significant when n is not
19650 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19651 __copy_from_user(void *to, const void __user *from, unsigned long n)
19652 {
19653 might_fault();
19654 +
19655 + if ((long)n < 0)
19656 + return n;
19657 +
19658 + check_object_size(to, n, false);
19659 +
19660 if (__builtin_constant_p(n)) {
19661 unsigned long ret;
19662
19663 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19664 const void __user *from, unsigned long n)
19665 {
19666 might_fault();
19667 +
19668 + if ((long)n < 0)
19669 + return n;
19670 +
19671 if (__builtin_constant_p(n)) {
19672 unsigned long ret;
19673
19674 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19675 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19676 unsigned long n)
19677 {
19678 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19679 + if ((long)n < 0)
19680 + return n;
19681 +
19682 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19683 }
19684
19685 #endif /* _ASM_X86_UACCESS_32_H */
19686 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19687 index 12a26b9..206c200 100644
19688 --- a/arch/x86/include/asm/uaccess_64.h
19689 +++ b/arch/x86/include/asm/uaccess_64.h
19690 @@ -10,6 +10,9 @@
19691 #include <asm/alternative.h>
19692 #include <asm/cpufeature.h>
19693 #include <asm/page.h>
19694 +#include <asm/pgtable.h>
19695 +
19696 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19697
19698 /*
19699 * Copy To/From Userspace
19700 @@ -17,14 +20,14 @@
19701
19702 /* Handles exceptions in both to and from, but doesn't do access_ok */
19703 __must_check unsigned long
19704 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19705 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19706 __must_check unsigned long
19707 -copy_user_generic_string(void *to, const void *from, unsigned len);
19708 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19709 __must_check unsigned long
19710 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19711 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19712
19713 static __always_inline __must_check unsigned long
19714 -copy_user_generic(void *to, const void *from, unsigned len)
19715 +copy_user_generic(void *to, const void *from, unsigned long len)
19716 {
19717 unsigned ret;
19718
19719 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19720 }
19721
19722 __must_check unsigned long
19723 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19724 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19725
19726 static __always_inline __must_check
19727 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19728 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19729 {
19730 - int ret = 0;
19731 + size_t sz = __compiletime_object_size(dst);
19732 + unsigned ret = 0;
19733 +
19734 + if (size > INT_MAX)
19735 + return size;
19736 +
19737 + check_object_size(dst, size, false);
19738 +
19739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19740 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19741 + return size;
19742 +#endif
19743 +
19744 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19745 + if(__builtin_constant_p(size))
19746 + copy_from_user_overflow();
19747 + else
19748 + __copy_from_user_overflow(sz, size);
19749 + return size;
19750 + }
19751
19752 if (!__builtin_constant_p(size))
19753 - return copy_user_generic(dst, (__force void *)src, size);
19754 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19755 switch (size) {
19756 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19757 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19758 ret, "b", "b", "=q", 1);
19759 return ret;
19760 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19761 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19762 ret, "w", "w", "=r", 2);
19763 return ret;
19764 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19765 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19766 ret, "l", "k", "=r", 4);
19767 return ret;
19768 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19769 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19770 ret, "q", "", "=r", 8);
19771 return ret;
19772 case 10:
19773 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19774 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19775 ret, "q", "", "=r", 10);
19776 if (unlikely(ret))
19777 return ret;
19778 __get_user_asm(*(u16 *)(8 + (char *)dst),
19779 - (u16 __user *)(8 + (char __user *)src),
19780 + (const u16 __user *)(8 + (const char __user *)src),
19781 ret, "w", "w", "=r", 2);
19782 return ret;
19783 case 16:
19784 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19785 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19786 ret, "q", "", "=r", 16);
19787 if (unlikely(ret))
19788 return ret;
19789 __get_user_asm(*(u64 *)(8 + (char *)dst),
19790 - (u64 __user *)(8 + (char __user *)src),
19791 + (const u64 __user *)(8 + (const char __user *)src),
19792 ret, "q", "", "=r", 8);
19793 return ret;
19794 default:
19795 - return copy_user_generic(dst, (__force void *)src, size);
19796 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19797 }
19798 }
19799
19800 static __always_inline __must_check
19801 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19802 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19803 {
19804 might_fault();
19805 return __copy_from_user_nocheck(dst, src, size);
19806 }
19807
19808 static __always_inline __must_check
19809 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19810 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19811 {
19812 - int ret = 0;
19813 + size_t sz = __compiletime_object_size(src);
19814 + unsigned ret = 0;
19815 +
19816 + if (size > INT_MAX)
19817 + return size;
19818 +
19819 + check_object_size(src, size, true);
19820 +
19821 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19822 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19823 + return size;
19824 +#endif
19825 +
19826 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19827 + if(__builtin_constant_p(size))
19828 + copy_to_user_overflow();
19829 + else
19830 + __copy_to_user_overflow(sz, size);
19831 + return size;
19832 + }
19833
19834 if (!__builtin_constant_p(size))
19835 - return copy_user_generic((__force void *)dst, src, size);
19836 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19837 switch (size) {
19838 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19839 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19840 ret, "b", "b", "iq", 1);
19841 return ret;
19842 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19843 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19844 ret, "w", "w", "ir", 2);
19845 return ret;
19846 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19847 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19848 ret, "l", "k", "ir", 4);
19849 return ret;
19850 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19851 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19852 ret, "q", "", "er", 8);
19853 return ret;
19854 case 10:
19855 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19856 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19857 ret, "q", "", "er", 10);
19858 if (unlikely(ret))
19859 return ret;
19860 asm("":::"memory");
19861 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19862 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19863 ret, "w", "w", "ir", 2);
19864 return ret;
19865 case 16:
19866 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19867 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19868 ret, "q", "", "er", 16);
19869 if (unlikely(ret))
19870 return ret;
19871 asm("":::"memory");
19872 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19873 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19874 ret, "q", "", "er", 8);
19875 return ret;
19876 default:
19877 - return copy_user_generic((__force void *)dst, src, size);
19878 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19879 }
19880 }
19881
19882 static __always_inline __must_check
19883 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19884 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19885 {
19886 might_fault();
19887 return __copy_to_user_nocheck(dst, src, size);
19888 }
19889
19890 static __always_inline __must_check
19891 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19892 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19893 {
19894 - int ret = 0;
19895 + unsigned ret = 0;
19896
19897 might_fault();
19898 +
19899 + if (size > INT_MAX)
19900 + return size;
19901 +
19902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19903 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19904 + return size;
19905 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19906 + return size;
19907 +#endif
19908 +
19909 if (!__builtin_constant_p(size))
19910 - return copy_user_generic((__force void *)dst,
19911 - (__force void *)src, size);
19912 + return copy_user_generic((__force_kernel void *)____m(dst),
19913 + (__force_kernel const void *)____m(src), size);
19914 switch (size) {
19915 case 1: {
19916 u8 tmp;
19917 - __get_user_asm(tmp, (u8 __user *)src,
19918 + __get_user_asm(tmp, (const u8 __user *)src,
19919 ret, "b", "b", "=q", 1);
19920 if (likely(!ret))
19921 __put_user_asm(tmp, (u8 __user *)dst,
19922 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19923 }
19924 case 2: {
19925 u16 tmp;
19926 - __get_user_asm(tmp, (u16 __user *)src,
19927 + __get_user_asm(tmp, (const u16 __user *)src,
19928 ret, "w", "w", "=r", 2);
19929 if (likely(!ret))
19930 __put_user_asm(tmp, (u16 __user *)dst,
19931 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19932
19933 case 4: {
19934 u32 tmp;
19935 - __get_user_asm(tmp, (u32 __user *)src,
19936 + __get_user_asm(tmp, (const u32 __user *)src,
19937 ret, "l", "k", "=r", 4);
19938 if (likely(!ret))
19939 __put_user_asm(tmp, (u32 __user *)dst,
19940 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19941 }
19942 case 8: {
19943 u64 tmp;
19944 - __get_user_asm(tmp, (u64 __user *)src,
19945 + __get_user_asm(tmp, (const u64 __user *)src,
19946 ret, "q", "", "=r", 8);
19947 if (likely(!ret))
19948 __put_user_asm(tmp, (u64 __user *)dst,
19949 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19950 return ret;
19951 }
19952 default:
19953 - return copy_user_generic((__force void *)dst,
19954 - (__force void *)src, size);
19955 + return copy_user_generic((__force_kernel void *)____m(dst),
19956 + (__force_kernel const void *)____m(src), size);
19957 }
19958 }
19959
19960 -static __must_check __always_inline int
19961 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19962 +static __must_check __always_inline unsigned long
19963 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19964 {
19965 return __copy_from_user_nocheck(dst, src, size);
19966 }
19967
19968 -static __must_check __always_inline int
19969 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19970 +static __must_check __always_inline unsigned long
19971 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19972 {
19973 return __copy_to_user_nocheck(dst, src, size);
19974 }
19975
19976 -extern long __copy_user_nocache(void *dst, const void __user *src,
19977 - unsigned size, int zerorest);
19978 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19979 + unsigned long size, int zerorest);
19980
19981 -static inline int
19982 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19983 +static inline unsigned long
19984 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19985 {
19986 might_fault();
19987 +
19988 + if (size > INT_MAX)
19989 + return size;
19990 +
19991 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19992 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19993 + return size;
19994 +#endif
19995 +
19996 return __copy_user_nocache(dst, src, size, 1);
19997 }
19998
19999 -static inline int
20000 +static inline unsigned long
20001 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20002 - unsigned size)
20003 + unsigned long size)
20004 {
20005 + if (size > INT_MAX)
20006 + return size;
20007 +
20008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20009 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20010 + return size;
20011 +#endif
20012 +
20013 return __copy_user_nocache(dst, src, size, 0);
20014 }
20015
20016 unsigned long
20017 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20018 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20019
20020 #endif /* _ASM_X86_UACCESS_64_H */
20021 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20022 index 5b238981..77fdd78 100644
20023 --- a/arch/x86/include/asm/word-at-a-time.h
20024 +++ b/arch/x86/include/asm/word-at-a-time.h
20025 @@ -11,7 +11,7 @@
20026 * and shift, for example.
20027 */
20028 struct word_at_a_time {
20029 - const unsigned long one_bits, high_bits;
20030 + unsigned long one_bits, high_bits;
20031 };
20032
20033 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20034 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20035 index e45e4da..44e8572 100644
20036 --- a/arch/x86/include/asm/x86_init.h
20037 +++ b/arch/x86/include/asm/x86_init.h
20038 @@ -129,7 +129,7 @@ struct x86_init_ops {
20039 struct x86_init_timers timers;
20040 struct x86_init_iommu iommu;
20041 struct x86_init_pci pci;
20042 -};
20043 +} __no_const;
20044
20045 /**
20046 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20047 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20048 void (*setup_percpu_clockev)(void);
20049 void (*early_percpu_clock_init)(void);
20050 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20051 -};
20052 +} __no_const;
20053
20054 struct timespec;
20055
20056 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20057 void (*save_sched_clock_state)(void);
20058 void (*restore_sched_clock_state)(void);
20059 void (*apic_post_init)(void);
20060 -};
20061 +} __no_const;
20062
20063 struct pci_dev;
20064 struct msi_msg;
20065 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20066 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20067 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20068 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20069 -};
20070 +} __no_const;
20071
20072 struct IO_APIC_route_entry;
20073 struct io_apic_irq_attr;
20074 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20075 unsigned int destination, int vector,
20076 struct io_apic_irq_attr *attr);
20077 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20078 -};
20079 +} __no_const;
20080
20081 extern struct x86_init_ops x86_init;
20082 extern struct x86_cpuinit_ops x86_cpuinit;
20083 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20084 index 3e276eb..2eb3c30 100644
20085 --- a/arch/x86/include/asm/xen/page.h
20086 +++ b/arch/x86/include/asm/xen/page.h
20087 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20088 extern struct page *m2p_find_override(unsigned long mfn);
20089 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20090
20091 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20092 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20093 {
20094 unsigned long mfn;
20095
20096 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20097 index 5547389..da68716 100644
20098 --- a/arch/x86/include/asm/xsave.h
20099 +++ b/arch/x86/include/asm/xsave.h
20100 @@ -76,8 +76,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20101 if (unlikely(err))
20102 return -EFAULT;
20103
20104 + pax_open_userland();
20105 __asm__ __volatile__(ASM_STAC "\n"
20106 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20107 + "1:"
20108 + __copyuser_seg
20109 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20110 "2: " ASM_CLAC "\n"
20111 ".section .fixup,\"ax\"\n"
20112 "3: movl $-1,%[err]\n"
20113 @@ -87,18 +90,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20114 : [err] "=r" (err)
20115 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20116 : "memory");
20117 + pax_close_userland();
20118 return err;
20119 }
20120
20121 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20122 {
20123 int err;
20124 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20125 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20126 u32 lmask = mask;
20127 u32 hmask = mask >> 32;
20128
20129 + pax_open_userland();
20130 __asm__ __volatile__(ASM_STAC "\n"
20131 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20132 + "1:"
20133 + __copyuser_seg
20134 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20135 "2: " ASM_CLAC "\n"
20136 ".section .fixup,\"ax\"\n"
20137 "3: movl $-1,%[err]\n"
20138 @@ -108,6 +115,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20139 : [err] "=r" (err)
20140 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20141 : "memory"); /* memory required? */
20142 + pax_close_userland();
20143 return err;
20144 }
20145
20146 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20147 index bbae024..e1528f9 100644
20148 --- a/arch/x86/include/uapi/asm/e820.h
20149 +++ b/arch/x86/include/uapi/asm/e820.h
20150 @@ -63,7 +63,7 @@ struct e820map {
20151 #define ISA_START_ADDRESS 0xa0000
20152 #define ISA_END_ADDRESS 0x100000
20153
20154 -#define BIOS_BEGIN 0x000a0000
20155 +#define BIOS_BEGIN 0x000c0000
20156 #define BIOS_END 0x00100000
20157
20158 #define BIOS_ROM_BASE 0xffe00000
20159 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20160 index 7b0a55a..ad115bf 100644
20161 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20162 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20163 @@ -49,7 +49,6 @@
20164 #define EFLAGS 144
20165 #define RSP 152
20166 #define SS 160
20167 -#define ARGOFFSET R11
20168 #endif /* __ASSEMBLY__ */
20169
20170 /* top of stack page */
20171 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20172 index cb648c8..91cb07e 100644
20173 --- a/arch/x86/kernel/Makefile
20174 +++ b/arch/x86/kernel/Makefile
20175 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20176 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20177 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20178 obj-y += probe_roms.o
20179 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20180 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20181 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20182 obj-y += syscall_$(BITS).o
20183 obj-$(CONFIG_X86_64) += vsyscall_64.o
20184 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20185 index 1dac942..19c8b0c 100644
20186 --- a/arch/x86/kernel/acpi/boot.c
20187 +++ b/arch/x86/kernel/acpi/boot.c
20188 @@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20189 * If your system is blacklisted here, but you find that acpi=force
20190 * works for you, please contact linux-acpi@vger.kernel.org
20191 */
20192 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20193 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20194 /*
20195 * Boxes that need ACPI disabled
20196 */
20197 @@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20198 };
20199
20200 /* second table for DMI checks that should run after early-quirks */
20201 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20202 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20203 /*
20204 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20205 * which includes some code which overrides all temperature
20206 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20207 index 3a2ae4c..9db31d6 100644
20208 --- a/arch/x86/kernel/acpi/sleep.c
20209 +++ b/arch/x86/kernel/acpi/sleep.c
20210 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20211 #else /* CONFIG_64BIT */
20212 #ifdef CONFIG_SMP
20213 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20214 +
20215 + pax_open_kernel();
20216 early_gdt_descr.address =
20217 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20218 + pax_close_kernel();
20219 +
20220 initial_gs = per_cpu_offset(smp_processor_id());
20221 #endif
20222 initial_code = (unsigned long)wakeup_long64;
20223 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20224 index 665c6b7..eae4d56 100644
20225 --- a/arch/x86/kernel/acpi/wakeup_32.S
20226 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20227 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20228 # and restore the stack ... but you need gdt for this to work
20229 movl saved_context_esp, %esp
20230
20231 - movl %cs:saved_magic, %eax
20232 - cmpl $0x12345678, %eax
20233 + cmpl $0x12345678, saved_magic
20234 jne bogus_magic
20235
20236 # jump to place where we left off
20237 - movl saved_eip, %eax
20238 - jmp *%eax
20239 + jmp *(saved_eip)
20240
20241 bogus_magic:
20242 jmp bogus_magic
20243 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20244 index df94598..f3b29bf 100644
20245 --- a/arch/x86/kernel/alternative.c
20246 +++ b/arch/x86/kernel/alternative.c
20247 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20248 */
20249 for (a = start; a < end; a++) {
20250 instr = (u8 *)&a->instr_offset + a->instr_offset;
20251 +
20252 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20253 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20254 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20255 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20256 +#endif
20257 +
20258 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20259 BUG_ON(a->replacementlen > a->instrlen);
20260 BUG_ON(a->instrlen > sizeof(insnbuf));
20261 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20262 for (poff = start; poff < end; poff++) {
20263 u8 *ptr = (u8 *)poff + *poff;
20264
20265 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20266 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20267 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20268 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20269 +#endif
20270 +
20271 if (!*poff || ptr < text || ptr >= text_end)
20272 continue;
20273 /* turn DS segment override prefix into lock prefix */
20274 - if (*ptr == 0x3e)
20275 + if (*ktla_ktva(ptr) == 0x3e)
20276 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20277 }
20278 mutex_unlock(&text_mutex);
20279 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20280 for (poff = start; poff < end; poff++) {
20281 u8 *ptr = (u8 *)poff + *poff;
20282
20283 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20284 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20285 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20286 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20287 +#endif
20288 +
20289 if (!*poff || ptr < text || ptr >= text_end)
20290 continue;
20291 /* turn lock prefix into DS segment override prefix */
20292 - if (*ptr == 0xf0)
20293 + if (*ktla_ktva(ptr) == 0xf0)
20294 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20295 }
20296 mutex_unlock(&text_mutex);
20297 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20298
20299 BUG_ON(p->len > MAX_PATCH_LEN);
20300 /* prep the buffer with the original instructions */
20301 - memcpy(insnbuf, p->instr, p->len);
20302 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20303 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20304 (unsigned long)p->instr, p->len);
20305
20306 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20307 if (!uniproc_patched || num_possible_cpus() == 1)
20308 free_init_pages("SMP alternatives",
20309 (unsigned long)__smp_locks,
20310 - (unsigned long)__smp_locks_end);
20311 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20312 #endif
20313
20314 apply_paravirt(__parainstructions, __parainstructions_end);
20315 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20316 * instructions. And on the local CPU you need to be protected again NMI or MCE
20317 * handlers seeing an inconsistent instruction while you patch.
20318 */
20319 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20320 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20321 size_t len)
20322 {
20323 unsigned long flags;
20324 local_irq_save(flags);
20325 - memcpy(addr, opcode, len);
20326 +
20327 + pax_open_kernel();
20328 + memcpy(ktla_ktva(addr), opcode, len);
20329 sync_core();
20330 + pax_close_kernel();
20331 +
20332 local_irq_restore(flags);
20333 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20334 that causes hangs on some VIA CPUs. */
20335 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20336 */
20337 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20338 {
20339 - unsigned long flags;
20340 - char *vaddr;
20341 + unsigned char *vaddr = ktla_ktva(addr);
20342 struct page *pages[2];
20343 - int i;
20344 + size_t i;
20345
20346 if (!core_kernel_text((unsigned long)addr)) {
20347 - pages[0] = vmalloc_to_page(addr);
20348 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20349 + pages[0] = vmalloc_to_page(vaddr);
20350 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20351 } else {
20352 - pages[0] = virt_to_page(addr);
20353 + pages[0] = virt_to_page(vaddr);
20354 WARN_ON(!PageReserved(pages[0]));
20355 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20356 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20357 }
20358 BUG_ON(!pages[0]);
20359 - local_irq_save(flags);
20360 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20361 - if (pages[1])
20362 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20363 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20364 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20365 - clear_fixmap(FIX_TEXT_POKE0);
20366 - if (pages[1])
20367 - clear_fixmap(FIX_TEXT_POKE1);
20368 - local_flush_tlb();
20369 - sync_core();
20370 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20371 - that causes hangs on some VIA CPUs. */
20372 + text_poke_early(addr, opcode, len);
20373 for (i = 0; i < len; i++)
20374 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20375 - local_irq_restore(flags);
20376 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20377 return addr;
20378 }
20379
20380 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20381 if (likely(!bp_patching_in_progress))
20382 return 0;
20383
20384 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20385 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20386 return 0;
20387
20388 /* set up the specified breakpoint handler */
20389 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20390 */
20391 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20392 {
20393 - unsigned char int3 = 0xcc;
20394 + const unsigned char int3 = 0xcc;
20395
20396 bp_int3_handler = handler;
20397 bp_int3_addr = (u8 *)addr + sizeof(int3);
20398 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20399 index 7f26c9a..694544e 100644
20400 --- a/arch/x86/kernel/apic/apic.c
20401 +++ b/arch/x86/kernel/apic/apic.c
20402 @@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20403 /*
20404 * Debug level, exported for io_apic.c
20405 */
20406 -unsigned int apic_verbosity;
20407 +int apic_verbosity;
20408
20409 int pic_mode;
20410
20411 @@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20412 apic_write(APIC_ESR, 0);
20413 v = apic_read(APIC_ESR);
20414 ack_APIC_irq();
20415 - atomic_inc(&irq_err_count);
20416 + atomic_inc_unchecked(&irq_err_count);
20417
20418 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20419 smp_processor_id(), v);
20420 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20421 index 2c621a6..fa2b1ae 100644
20422 --- a/arch/x86/kernel/apic/apic_flat_64.c
20423 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20424 @@ -154,7 +154,7 @@ static int flat_probe(void)
20425 return 1;
20426 }
20427
20428 -static struct apic apic_flat = {
20429 +static struct apic apic_flat __read_only = {
20430 .name = "flat",
20431 .probe = flat_probe,
20432 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20433 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20434 return 0;
20435 }
20436
20437 -static struct apic apic_physflat = {
20438 +static struct apic apic_physflat __read_only = {
20439
20440 .name = "physical flat",
20441 .probe = physflat_probe,
20442 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20443 index 191ce75..2db6d63 100644
20444 --- a/arch/x86/kernel/apic/apic_noop.c
20445 +++ b/arch/x86/kernel/apic/apic_noop.c
20446 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20447 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20448 }
20449
20450 -struct apic apic_noop = {
20451 +struct apic apic_noop __read_only = {
20452 .name = "noop",
20453 .probe = noop_probe,
20454 .acpi_madt_oem_check = NULL,
20455 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20456 index d50e364..543bee3 100644
20457 --- a/arch/x86/kernel/apic/bigsmp_32.c
20458 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20459 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20460 return dmi_bigsmp;
20461 }
20462
20463 -static struct apic apic_bigsmp = {
20464 +static struct apic apic_bigsmp __read_only = {
20465
20466 .name = "bigsmp",
20467 .probe = probe_bigsmp,
20468 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20469 index c552247..587a316 100644
20470 --- a/arch/x86/kernel/apic/es7000_32.c
20471 +++ b/arch/x86/kernel/apic/es7000_32.c
20472 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20473 return ret && es7000_apic_is_cluster();
20474 }
20475
20476 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20477 -static struct apic __refdata apic_es7000_cluster = {
20478 +static struct apic apic_es7000_cluster __read_only = {
20479
20480 .name = "es7000",
20481 .probe = probe_es7000,
20482 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20483 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20484 };
20485
20486 -static struct apic __refdata apic_es7000 = {
20487 +static struct apic apic_es7000 __read_only = {
20488
20489 .name = "es7000",
20490 .probe = probe_es7000,
20491 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20492 index 6ad4658..38a7b5c 100644
20493 --- a/arch/x86/kernel/apic/io_apic.c
20494 +++ b/arch/x86/kernel/apic/io_apic.c
20495 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20496 }
20497 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20498
20499 -void lock_vector_lock(void)
20500 +void lock_vector_lock(void) __acquires(vector_lock)
20501 {
20502 /* Used to the online set of cpus does not change
20503 * during assign_irq_vector.
20504 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20505 raw_spin_lock(&vector_lock);
20506 }
20507
20508 -void unlock_vector_lock(void)
20509 +void unlock_vector_lock(void) __releases(vector_lock)
20510 {
20511 raw_spin_unlock(&vector_lock);
20512 }
20513 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20514 ack_APIC_irq();
20515 }
20516
20517 -atomic_t irq_mis_count;
20518 +atomic_unchecked_t irq_mis_count;
20519
20520 #ifdef CONFIG_GENERIC_PENDING_IRQ
20521 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20522 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20523 * at the cpu.
20524 */
20525 if (!(v & (1 << (i & 0x1f)))) {
20526 - atomic_inc(&irq_mis_count);
20527 + atomic_inc_unchecked(&irq_mis_count);
20528
20529 eoi_ioapic_irq(irq, cfg);
20530 }
20531 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20532 index 1e42e8f..daacf44 100644
20533 --- a/arch/x86/kernel/apic/numaq_32.c
20534 +++ b/arch/x86/kernel/apic/numaq_32.c
20535 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20536 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20537 }
20538
20539 -/* Use __refdata to keep false positive warning calm. */
20540 -static struct apic __refdata apic_numaq = {
20541 +static struct apic apic_numaq __read_only = {
20542
20543 .name = "NUMAQ",
20544 .probe = probe_numaq,
20545 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20546 index eb35ef9..f184a21 100644
20547 --- a/arch/x86/kernel/apic/probe_32.c
20548 +++ b/arch/x86/kernel/apic/probe_32.c
20549 @@ -72,7 +72,7 @@ static int probe_default(void)
20550 return 1;
20551 }
20552
20553 -static struct apic apic_default = {
20554 +static struct apic apic_default __read_only = {
20555
20556 .name = "default",
20557 .probe = probe_default,
20558 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20559 index 00146f9..5e299b8 100644
20560 --- a/arch/x86/kernel/apic/summit_32.c
20561 +++ b/arch/x86/kernel/apic/summit_32.c
20562 @@ -485,7 +485,7 @@ void setup_summit(void)
20563 }
20564 #endif
20565
20566 -static struct apic apic_summit = {
20567 +static struct apic apic_summit __read_only = {
20568
20569 .name = "summit",
20570 .probe = probe_summit,
20571 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20572 index cac85ee..01fa741 100644
20573 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20574 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20575 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20576 return notifier_from_errno(err);
20577 }
20578
20579 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20580 +static struct notifier_block x2apic_cpu_notifier = {
20581 .notifier_call = update_clusterinfo,
20582 };
20583
20584 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20585 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20586 }
20587
20588 -static struct apic apic_x2apic_cluster = {
20589 +static struct apic apic_x2apic_cluster __read_only = {
20590
20591 .name = "cluster x2apic",
20592 .probe = x2apic_cluster_probe,
20593 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20594 index de231e3..1d1b2ee 100644
20595 --- a/arch/x86/kernel/apic/x2apic_phys.c
20596 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20597 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20598 return apic == &apic_x2apic_phys;
20599 }
20600
20601 -static struct apic apic_x2apic_phys = {
20602 +static struct apic apic_x2apic_phys __read_only = {
20603
20604 .name = "physical x2apic",
20605 .probe = x2apic_phys_probe,
20606 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20607 index d263b13..963258b 100644
20608 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20609 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20610 @@ -350,7 +350,7 @@ static int uv_probe(void)
20611 return apic == &apic_x2apic_uv_x;
20612 }
20613
20614 -static struct apic __refdata apic_x2apic_uv_x = {
20615 +static struct apic apic_x2apic_uv_x __read_only = {
20616
20617 .name = "UV large system",
20618 .probe = uv_probe,
20619 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20620 index 3ab0343..814c4787 100644
20621 --- a/arch/x86/kernel/apm_32.c
20622 +++ b/arch/x86/kernel/apm_32.c
20623 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20624 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20625 * even though they are called in protected mode.
20626 */
20627 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20628 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20629 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20630
20631 static const char driver_version[] = "1.16ac"; /* no spaces */
20632 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20633 BUG_ON(cpu != 0);
20634 gdt = get_cpu_gdt_table(cpu);
20635 save_desc_40 = gdt[0x40 / 8];
20636 +
20637 + pax_open_kernel();
20638 gdt[0x40 / 8] = bad_bios_desc;
20639 + pax_close_kernel();
20640
20641 apm_irq_save(flags);
20642 APM_DO_SAVE_SEGS;
20643 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20644 &call->esi);
20645 APM_DO_RESTORE_SEGS;
20646 apm_irq_restore(flags);
20647 +
20648 + pax_open_kernel();
20649 gdt[0x40 / 8] = save_desc_40;
20650 + pax_close_kernel();
20651 +
20652 put_cpu();
20653
20654 return call->eax & 0xff;
20655 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20656 BUG_ON(cpu != 0);
20657 gdt = get_cpu_gdt_table(cpu);
20658 save_desc_40 = gdt[0x40 / 8];
20659 +
20660 + pax_open_kernel();
20661 gdt[0x40 / 8] = bad_bios_desc;
20662 + pax_close_kernel();
20663
20664 apm_irq_save(flags);
20665 APM_DO_SAVE_SEGS;
20666 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20667 &call->eax);
20668 APM_DO_RESTORE_SEGS;
20669 apm_irq_restore(flags);
20670 +
20671 + pax_open_kernel();
20672 gdt[0x40 / 8] = save_desc_40;
20673 + pax_close_kernel();
20674 +
20675 put_cpu();
20676 return error;
20677 }
20678 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20679 * code to that CPU.
20680 */
20681 gdt = get_cpu_gdt_table(0);
20682 +
20683 + pax_open_kernel();
20684 set_desc_base(&gdt[APM_CS >> 3],
20685 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20686 set_desc_base(&gdt[APM_CS_16 >> 3],
20687 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20688 set_desc_base(&gdt[APM_DS >> 3],
20689 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20690 + pax_close_kernel();
20691
20692 proc_create("apm", 0, NULL, &apm_file_ops);
20693
20694 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20695 index 9f6b934..cf5ffb3 100644
20696 --- a/arch/x86/kernel/asm-offsets.c
20697 +++ b/arch/x86/kernel/asm-offsets.c
20698 @@ -32,6 +32,8 @@ void common(void) {
20699 OFFSET(TI_flags, thread_info, flags);
20700 OFFSET(TI_status, thread_info, status);
20701 OFFSET(TI_addr_limit, thread_info, addr_limit);
20702 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20703 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20704
20705 BLANK();
20706 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20707 @@ -52,8 +54,26 @@ void common(void) {
20708 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20709 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20710 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20711 +
20712 +#ifdef CONFIG_PAX_KERNEXEC
20713 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20714 #endif
20715
20716 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20717 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20718 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20719 +#ifdef CONFIG_X86_64
20720 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20721 +#endif
20722 +#endif
20723 +
20724 +#endif
20725 +
20726 + BLANK();
20727 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20728 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20729 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20730 +
20731 #ifdef CONFIG_XEN
20732 BLANK();
20733 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20734 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20735 index e7c798b..2b2019b 100644
20736 --- a/arch/x86/kernel/asm-offsets_64.c
20737 +++ b/arch/x86/kernel/asm-offsets_64.c
20738 @@ -77,6 +77,7 @@ int main(void)
20739 BLANK();
20740 #undef ENTRY
20741
20742 + DEFINE(TSS_size, sizeof(struct tss_struct));
20743 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20744 BLANK();
20745
20746 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20747 index 7fd54f0..0691410 100644
20748 --- a/arch/x86/kernel/cpu/Makefile
20749 +++ b/arch/x86/kernel/cpu/Makefile
20750 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20751 CFLAGS_REMOVE_perf_event.o = -pg
20752 endif
20753
20754 -# Make sure load_percpu_segment has no stackprotector
20755 -nostackp := $(call cc-option, -fno-stack-protector)
20756 -CFLAGS_common.o := $(nostackp)
20757 -
20758 obj-y := intel_cacheinfo.o scattered.o topology.o
20759 obj-y += proc.o capflags.o powerflags.o common.o
20760 obj-y += rdrand.o
20761 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20762 index c67ffa6..f41fbbf 100644
20763 --- a/arch/x86/kernel/cpu/amd.c
20764 +++ b/arch/x86/kernel/cpu/amd.c
20765 @@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20766 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20767 {
20768 /* AMD errata T13 (order #21922) */
20769 - if ((c->x86 == 6)) {
20770 + if (c->x86 == 6) {
20771 /* Duron Rev A0 */
20772 if (c->x86_model == 3 && c->x86_mask == 0)
20773 size = 64;
20774 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20775 index 8e28bf2..bf5c0d2 100644
20776 --- a/arch/x86/kernel/cpu/common.c
20777 +++ b/arch/x86/kernel/cpu/common.c
20778 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20779
20780 static const struct cpu_dev *this_cpu = &default_cpu;
20781
20782 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20783 -#ifdef CONFIG_X86_64
20784 - /*
20785 - * We need valid kernel segments for data and code in long mode too
20786 - * IRET will check the segment types kkeil 2000/10/28
20787 - * Also sysret mandates a special GDT layout
20788 - *
20789 - * TLS descriptors are currently at a different place compared to i386.
20790 - * Hopefully nobody expects them at a fixed place (Wine?)
20791 - */
20792 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20793 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20794 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20795 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20796 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20797 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20798 -#else
20799 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20800 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20801 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20802 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20803 - /*
20804 - * Segments used for calling PnP BIOS have byte granularity.
20805 - * They code segments and data segments have fixed 64k limits,
20806 - * the transfer segment sizes are set at run time.
20807 - */
20808 - /* 32-bit code */
20809 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20810 - /* 16-bit code */
20811 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20812 - /* 16-bit data */
20813 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20814 - /* 16-bit data */
20815 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20816 - /* 16-bit data */
20817 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20818 - /*
20819 - * The APM segments have byte granularity and their bases
20820 - * are set at run time. All have 64k limits.
20821 - */
20822 - /* 32-bit code */
20823 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20824 - /* 16-bit code */
20825 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20826 - /* data */
20827 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20828 -
20829 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20830 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20831 - GDT_STACK_CANARY_INIT
20832 -#endif
20833 -} };
20834 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20835 -
20836 static int __init x86_xsave_setup(char *s)
20837 {
20838 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20839 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20840 }
20841 }
20842
20843 +#ifdef CONFIG_X86_64
20844 +static __init int setup_disable_pcid(char *arg)
20845 +{
20846 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20847 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20848 +
20849 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20850 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20851 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20852 +#endif
20853 +
20854 + return 1;
20855 +}
20856 +__setup("nopcid", setup_disable_pcid);
20857 +
20858 +static void setup_pcid(struct cpuinfo_x86 *c)
20859 +{
20860 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20861 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20862 +
20863 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20864 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20865 + pax_open_kernel();
20866 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20867 + pax_close_kernel();
20868 + printk("PAX: slow and weak UDEREF enabled\n");
20869 + } else
20870 + printk("PAX: UDEREF disabled\n");
20871 +#endif
20872 +
20873 + return;
20874 + }
20875 +
20876 + printk("PAX: PCID detected\n");
20877 + set_in_cr4(X86_CR4_PCIDE);
20878 +
20879 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20880 + pax_open_kernel();
20881 + clone_pgd_mask = ~(pgdval_t)0UL;
20882 + pax_close_kernel();
20883 + if (pax_user_shadow_base)
20884 + printk("PAX: weak UDEREF enabled\n");
20885 + else {
20886 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20887 + printk("PAX: strong UDEREF enabled\n");
20888 + }
20889 +#endif
20890 +
20891 + if (cpu_has(c, X86_FEATURE_INVPCID))
20892 + printk("PAX: INVPCID detected\n");
20893 +}
20894 +#endif
20895 +
20896 /*
20897 * Some CPU features depend on higher CPUID levels, which may not always
20898 * be available due to CPUID level capping or broken virtualization
20899 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20900 {
20901 struct desc_ptr gdt_descr;
20902
20903 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20904 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20905 gdt_descr.size = GDT_SIZE - 1;
20906 load_gdt(&gdt_descr);
20907 /* Reload the per-cpu base */
20908 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20909 setup_smep(c);
20910 setup_smap(c);
20911
20912 +#ifdef CONFIG_X86_64
20913 + setup_pcid(c);
20914 +#endif
20915 +
20916 /*
20917 * The vendor-specific functions might have changed features.
20918 * Now we do "generic changes."
20919 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20920 /* Filter out anything that depends on CPUID levels we don't have */
20921 filter_cpuid_features(c, true);
20922
20923 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20924 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20925 +#endif
20926 +
20927 /* If the model name is still unset, do table lookup. */
20928 if (!c->x86_model_id[0]) {
20929 const char *p;
20930 @@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
20931 }
20932 __setup("clearcpuid=", setup_disablecpuid);
20933
20934 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20935 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20936 +
20937 #ifdef CONFIG_X86_64
20938 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20939 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20940 - (unsigned long) debug_idt_table };
20941 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20942 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20943
20944 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20945 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20946 @@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20947 EXPORT_PER_CPU_SYMBOL(current_task);
20948
20949 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20950 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20951 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20952 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20953
20954 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20955 @@ -1245,7 +1254,7 @@ void cpu_init(void)
20956 load_ucode_ap();
20957
20958 cpu = stack_smp_processor_id();
20959 - t = &per_cpu(init_tss, cpu);
20960 + t = init_tss + cpu;
20961 oist = &per_cpu(orig_ist, cpu);
20962
20963 #ifdef CONFIG_NUMA
20964 @@ -1280,7 +1289,6 @@ void cpu_init(void)
20965 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20966 barrier();
20967
20968 - x86_configure_nx();
20969 enable_x2apic();
20970
20971 /*
20972 @@ -1332,7 +1340,7 @@ void cpu_init(void)
20973 {
20974 int cpu = smp_processor_id();
20975 struct task_struct *curr = current;
20976 - struct tss_struct *t = &per_cpu(init_tss, cpu);
20977 + struct tss_struct *t = init_tss + cpu;
20978 struct thread_struct *thread = &curr->thread;
20979
20980 show_ucode_info_early();
20981 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20982 index 0641113..06f5ba4 100644
20983 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20984 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20985 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20986 };
20987
20988 #ifdef CONFIG_AMD_NB
20989 +static struct attribute *default_attrs_amd_nb[] = {
20990 + &type.attr,
20991 + &level.attr,
20992 + &coherency_line_size.attr,
20993 + &physical_line_partition.attr,
20994 + &ways_of_associativity.attr,
20995 + &number_of_sets.attr,
20996 + &size.attr,
20997 + &shared_cpu_map.attr,
20998 + &shared_cpu_list.attr,
20999 + NULL,
21000 + NULL,
21001 + NULL,
21002 + NULL
21003 +};
21004 +
21005 static struct attribute **amd_l3_attrs(void)
21006 {
21007 static struct attribute **attrs;
21008 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21009
21010 n = ARRAY_SIZE(default_attrs);
21011
21012 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21013 - n += 2;
21014 -
21015 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21016 - n += 1;
21017 -
21018 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21019 - if (attrs == NULL)
21020 - return attrs = default_attrs;
21021 -
21022 - for (n = 0; default_attrs[n]; n++)
21023 - attrs[n] = default_attrs[n];
21024 + attrs = default_attrs_amd_nb;
21025
21026 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21027 attrs[n++] = &cache_disable_0.attr;
21028 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21029 .default_attrs = default_attrs,
21030 };
21031
21032 +#ifdef CONFIG_AMD_NB
21033 +static struct kobj_type ktype_cache_amd_nb = {
21034 + .sysfs_ops = &sysfs_ops,
21035 + .default_attrs = default_attrs_amd_nb,
21036 +};
21037 +#endif
21038 +
21039 static struct kobj_type ktype_percpu_entry = {
21040 .sysfs_ops = &sysfs_ops,
21041 };
21042 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21043 return retval;
21044 }
21045
21046 +#ifdef CONFIG_AMD_NB
21047 + amd_l3_attrs();
21048 +#endif
21049 +
21050 for (i = 0; i < num_cache_leaves; i++) {
21051 + struct kobj_type *ktype;
21052 +
21053 this_object = INDEX_KOBJECT_PTR(cpu, i);
21054 this_object->cpu = cpu;
21055 this_object->index = i;
21056
21057 this_leaf = CPUID4_INFO_IDX(cpu, i);
21058
21059 - ktype_cache.default_attrs = default_attrs;
21060 + ktype = &ktype_cache;
21061 #ifdef CONFIG_AMD_NB
21062 if (this_leaf->base.nb)
21063 - ktype_cache.default_attrs = amd_l3_attrs();
21064 + ktype = &ktype_cache_amd_nb;
21065 #endif
21066 retval = kobject_init_and_add(&(this_object->kobj),
21067 - &ktype_cache,
21068 + ktype,
21069 per_cpu(ici_cache_kobject, cpu),
21070 "index%1lu", i);
21071 if (unlikely(retval)) {
21072 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21073 index 4d5419b..95f11bb 100644
21074 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21075 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21076 @@ -45,6 +45,7 @@
21077 #include <asm/processor.h>
21078 #include <asm/mce.h>
21079 #include <asm/msr.h>
21080 +#include <asm/local.h>
21081
21082 #include "mce-internal.h"
21083
21084 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21085 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21086 m->cs, m->ip);
21087
21088 - if (m->cs == __KERNEL_CS)
21089 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21090 print_symbol("{%s}", m->ip);
21091 pr_cont("\n");
21092 }
21093 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21094
21095 #define PANIC_TIMEOUT 5 /* 5 seconds */
21096
21097 -static atomic_t mce_paniced;
21098 +static atomic_unchecked_t mce_paniced;
21099
21100 static int fake_panic;
21101 -static atomic_t mce_fake_paniced;
21102 +static atomic_unchecked_t mce_fake_paniced;
21103
21104 /* Panic in progress. Enable interrupts and wait for final IPI */
21105 static void wait_for_panic(void)
21106 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21107 /*
21108 * Make sure only one CPU runs in machine check panic
21109 */
21110 - if (atomic_inc_return(&mce_paniced) > 1)
21111 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21112 wait_for_panic();
21113 barrier();
21114
21115 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21116 console_verbose();
21117 } else {
21118 /* Don't log too much for fake panic */
21119 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21120 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21121 return;
21122 }
21123 /* First print corrected ones that are still unlogged */
21124 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21125 if (!fake_panic) {
21126 if (panic_timeout == 0)
21127 panic_timeout = mca_cfg.panic_timeout;
21128 - panic(msg);
21129 + panic("%s", msg);
21130 } else
21131 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21132 }
21133 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21134 * might have been modified by someone else.
21135 */
21136 rmb();
21137 - if (atomic_read(&mce_paniced))
21138 + if (atomic_read_unchecked(&mce_paniced))
21139 wait_for_panic();
21140 if (!mca_cfg.monarch_timeout)
21141 goto out;
21142 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21143 }
21144
21145 /* Call the installed machine check handler for this CPU setup. */
21146 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21147 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21148 unexpected_machine_check;
21149
21150 /*
21151 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21152 return;
21153 }
21154
21155 + pax_open_kernel();
21156 machine_check_vector = do_machine_check;
21157 + pax_close_kernel();
21158
21159 __mcheck_cpu_init_generic();
21160 __mcheck_cpu_init_vendor(c);
21161 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21162 */
21163
21164 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21165 -static int mce_chrdev_open_count; /* #times opened */
21166 +static local_t mce_chrdev_open_count; /* #times opened */
21167 static int mce_chrdev_open_exclu; /* already open exclusive? */
21168
21169 static int mce_chrdev_open(struct inode *inode, struct file *file)
21170 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21171 spin_lock(&mce_chrdev_state_lock);
21172
21173 if (mce_chrdev_open_exclu ||
21174 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21175 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21176 spin_unlock(&mce_chrdev_state_lock);
21177
21178 return -EBUSY;
21179 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21180
21181 if (file->f_flags & O_EXCL)
21182 mce_chrdev_open_exclu = 1;
21183 - mce_chrdev_open_count++;
21184 + local_inc(&mce_chrdev_open_count);
21185
21186 spin_unlock(&mce_chrdev_state_lock);
21187
21188 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21189 {
21190 spin_lock(&mce_chrdev_state_lock);
21191
21192 - mce_chrdev_open_count--;
21193 + local_dec(&mce_chrdev_open_count);
21194 mce_chrdev_open_exclu = 0;
21195
21196 spin_unlock(&mce_chrdev_state_lock);
21197 @@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21198
21199 for (i = 0; i < mca_cfg.banks; i++) {
21200 struct mce_bank *b = &mce_banks[i];
21201 - struct device_attribute *a = &b->attr;
21202 + device_attribute_no_const *a = &b->attr;
21203
21204 sysfs_attr_init(&a->attr);
21205 a->attr.name = b->attrname;
21206 @@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21207 static void mce_reset(void)
21208 {
21209 cpu_missing = 0;
21210 - atomic_set(&mce_fake_paniced, 0);
21211 + atomic_set_unchecked(&mce_fake_paniced, 0);
21212 atomic_set(&mce_executing, 0);
21213 atomic_set(&mce_callin, 0);
21214 atomic_set(&global_nwo, 0);
21215 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21216 index a304298..49b6d06 100644
21217 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21218 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21219 @@ -10,6 +10,7 @@
21220 #include <asm/processor.h>
21221 #include <asm/mce.h>
21222 #include <asm/msr.h>
21223 +#include <asm/pgtable.h>
21224
21225 /* By default disabled */
21226 int mce_p5_enabled __read_mostly;
21227 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21228 if (!cpu_has(c, X86_FEATURE_MCE))
21229 return;
21230
21231 + pax_open_kernel();
21232 machine_check_vector = pentium_machine_check;
21233 + pax_close_kernel();
21234 /* Make sure the vector pointer is visible before we enable MCEs: */
21235 wmb();
21236
21237 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21238 index 7dc5564..1273569 100644
21239 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21240 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21241 @@ -9,6 +9,7 @@
21242 #include <asm/processor.h>
21243 #include <asm/mce.h>
21244 #include <asm/msr.h>
21245 +#include <asm/pgtable.h>
21246
21247 /* Machine check handler for WinChip C6: */
21248 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21249 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21250 {
21251 u32 lo, hi;
21252
21253 + pax_open_kernel();
21254 machine_check_vector = winchip_machine_check;
21255 + pax_close_kernel();
21256 /* Make sure the vector pointer is visible before we enable MCEs: */
21257 wmb();
21258
21259 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21260 index 15c9876..0a43909 100644
21261 --- a/arch/x86/kernel/cpu/microcode/core.c
21262 +++ b/arch/x86/kernel/cpu/microcode/core.c
21263 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21264 return NOTIFY_OK;
21265 }
21266
21267 -static struct notifier_block __refdata mc_cpu_notifier = {
21268 +static struct notifier_block mc_cpu_notifier = {
21269 .notifier_call = mc_cpu_callback,
21270 };
21271
21272 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21273 index a276fa7..e66810f 100644
21274 --- a/arch/x86/kernel/cpu/microcode/intel.c
21275 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21276 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21277
21278 static int get_ucode_user(void *to, const void *from, size_t n)
21279 {
21280 - return copy_from_user(to, from, n);
21281 + return copy_from_user(to, (const void __force_user *)from, n);
21282 }
21283
21284 static enum ucode_state
21285 request_microcode_user(int cpu, const void __user *buf, size_t size)
21286 {
21287 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21288 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21289 }
21290
21291 static void microcode_fini_cpu(int cpu)
21292 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21293 index f961de9..8a9d332 100644
21294 --- a/arch/x86/kernel/cpu/mtrr/main.c
21295 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21296 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21297 u64 size_or_mask, size_and_mask;
21298 static bool mtrr_aps_delayed_init;
21299
21300 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21301 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21302
21303 const struct mtrr_ops *mtrr_if;
21304
21305 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21306 index df5e41f..816c719 100644
21307 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21308 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21309 @@ -25,7 +25,7 @@ struct mtrr_ops {
21310 int (*validate_add_page)(unsigned long base, unsigned long size,
21311 unsigned int type);
21312 int (*have_wrcomb)(void);
21313 -};
21314 +} __do_const;
21315
21316 extern int generic_get_free_region(unsigned long base, unsigned long size,
21317 int replace_reg);
21318 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21319 index 79f9f84..38ace52 100644
21320 --- a/arch/x86/kernel/cpu/perf_event.c
21321 +++ b/arch/x86/kernel/cpu/perf_event.c
21322 @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21323 pr_info("no hardware sampling interrupt available.\n");
21324 }
21325
21326 -static struct attribute_group x86_pmu_format_group = {
21327 +static attribute_group_no_const x86_pmu_format_group = {
21328 .name = "format",
21329 .attrs = NULL,
21330 };
21331 @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21332 NULL,
21333 };
21334
21335 -static struct attribute_group x86_pmu_events_group = {
21336 +static attribute_group_no_const x86_pmu_events_group = {
21337 .name = "events",
21338 .attrs = events_attr,
21339 };
21340 @@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21341 if (idx > GDT_ENTRIES)
21342 return 0;
21343
21344 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21345 + desc = get_cpu_gdt_table(smp_processor_id());
21346 }
21347
21348 return get_desc_base(desc + idx);
21349 @@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21350 break;
21351
21352 perf_callchain_store(entry, frame.return_address);
21353 - fp = frame.next_frame;
21354 + fp = (const void __force_user *)frame.next_frame;
21355 }
21356 }
21357
21358 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21359 index 639d128..e92d7e5 100644
21360 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21361 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21362 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21363 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21364 {
21365 struct attribute **attrs;
21366 - struct attribute_group *attr_group;
21367 + attribute_group_no_const *attr_group;
21368 int i = 0, j;
21369
21370 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21371 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21372 index aa333d9..f9db700 100644
21373 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21374 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21375 @@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21376 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21377
21378 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21379 - u64 capabilities;
21380 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21381
21382 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21383 - x86_pmu.intel_cap.capabilities = capabilities;
21384 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21385 + x86_pmu.intel_cap.capabilities = capabilities;
21386 }
21387
21388 intel_ds_init();
21389 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21390 index 5ad35ad..e0a3960 100644
21391 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21392 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21393 @@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21394 NULL,
21395 };
21396
21397 -static struct attribute_group rapl_pmu_events_group = {
21398 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21399 .name = "events",
21400 .attrs = NULL, /* patched at runtime */
21401 };
21402 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21403 index 047f540..afdeba0 100644
21404 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21405 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21406 @@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21407 static int __init uncore_type_init(struct intel_uncore_type *type)
21408 {
21409 struct intel_uncore_pmu *pmus;
21410 - struct attribute_group *attr_group;
21411 + attribute_group_no_const *attr_group;
21412 struct attribute **attrs;
21413 int i, j;
21414
21415 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21416 index a80ab71..4089da5 100644
21417 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21418 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21419 @@ -498,7 +498,7 @@ struct intel_uncore_box {
21420 struct uncore_event_desc {
21421 struct kobj_attribute attr;
21422 const char *config;
21423 -};
21424 +} __do_const;
21425
21426 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21427 { \
21428 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21429 index 7d9481c..99c7e4b 100644
21430 --- a/arch/x86/kernel/cpuid.c
21431 +++ b/arch/x86/kernel/cpuid.c
21432 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21433 return notifier_from_errno(err);
21434 }
21435
21436 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21437 +static struct notifier_block cpuid_class_cpu_notifier =
21438 {
21439 .notifier_call = cpuid_class_cpu_callback,
21440 };
21441 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21442 index a57902e..ebaae2a 100644
21443 --- a/arch/x86/kernel/crash.c
21444 +++ b/arch/x86/kernel/crash.c
21445 @@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21446 {
21447 #ifdef CONFIG_X86_32
21448 struct pt_regs fixed_regs;
21449 -#endif
21450
21451 -#ifdef CONFIG_X86_32
21452 - if (!user_mode_vm(regs)) {
21453 + if (!user_mode(regs)) {
21454 crash_fixup_ss_esp(&fixed_regs, regs);
21455 regs = &fixed_regs;
21456 }
21457 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21458 index afa64ad..dce67dd 100644
21459 --- a/arch/x86/kernel/crash_dump_64.c
21460 +++ b/arch/x86/kernel/crash_dump_64.c
21461 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21462 return -ENOMEM;
21463
21464 if (userbuf) {
21465 - if (copy_to_user(buf, vaddr + offset, csize)) {
21466 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21467 iounmap(vaddr);
21468 return -EFAULT;
21469 }
21470 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21471 index f6dfd93..892ade4 100644
21472 --- a/arch/x86/kernel/doublefault.c
21473 +++ b/arch/x86/kernel/doublefault.c
21474 @@ -12,7 +12,7 @@
21475
21476 #define DOUBLEFAULT_STACKSIZE (1024)
21477 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21478 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21479 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21480
21481 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21482
21483 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21484 unsigned long gdt, tss;
21485
21486 native_store_gdt(&gdt_desc);
21487 - gdt = gdt_desc.address;
21488 + gdt = (unsigned long)gdt_desc.address;
21489
21490 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21491
21492 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21493 /* 0x2 bit is always set */
21494 .flags = X86_EFLAGS_SF | 0x2,
21495 .sp = STACK_START,
21496 - .es = __USER_DS,
21497 + .es = __KERNEL_DS,
21498 .cs = __KERNEL_CS,
21499 .ss = __KERNEL_DS,
21500 - .ds = __USER_DS,
21501 + .ds = __KERNEL_DS,
21502 .fs = __KERNEL_PERCPU,
21503
21504 .__cr3 = __pa_nodebug(swapper_pg_dir),
21505 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21506 index d9c12d3..7858b62 100644
21507 --- a/arch/x86/kernel/dumpstack.c
21508 +++ b/arch/x86/kernel/dumpstack.c
21509 @@ -2,6 +2,9 @@
21510 * Copyright (C) 1991, 1992 Linus Torvalds
21511 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21512 */
21513 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21514 +#define __INCLUDED_BY_HIDESYM 1
21515 +#endif
21516 #include <linux/kallsyms.h>
21517 #include <linux/kprobes.h>
21518 #include <linux/uaccess.h>
21519 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21520 static void
21521 print_ftrace_graph_addr(unsigned long addr, void *data,
21522 const struct stacktrace_ops *ops,
21523 - struct thread_info *tinfo, int *graph)
21524 + struct task_struct *task, int *graph)
21525 {
21526 - struct task_struct *task;
21527 unsigned long ret_addr;
21528 int index;
21529
21530 if (addr != (unsigned long)return_to_handler)
21531 return;
21532
21533 - task = tinfo->task;
21534 index = task->curr_ret_stack;
21535
21536 if (!task->ret_stack || index < *graph)
21537 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21538 static inline void
21539 print_ftrace_graph_addr(unsigned long addr, void *data,
21540 const struct stacktrace_ops *ops,
21541 - struct thread_info *tinfo, int *graph)
21542 + struct task_struct *task, int *graph)
21543 { }
21544 #endif
21545
21546 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21547 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21548 */
21549
21550 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21551 - void *p, unsigned int size, void *end)
21552 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21553 {
21554 - void *t = tinfo;
21555 if (end) {
21556 if (p < end && p >= (end-THREAD_SIZE))
21557 return 1;
21558 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21559 }
21560
21561 unsigned long
21562 -print_context_stack(struct thread_info *tinfo,
21563 +print_context_stack(struct task_struct *task, void *stack_start,
21564 unsigned long *stack, unsigned long bp,
21565 const struct stacktrace_ops *ops, void *data,
21566 unsigned long *end, int *graph)
21567 {
21568 struct stack_frame *frame = (struct stack_frame *)bp;
21569
21570 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21571 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21572 unsigned long addr;
21573
21574 addr = *stack;
21575 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21576 } else {
21577 ops->address(data, addr, 0);
21578 }
21579 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21580 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21581 }
21582 stack++;
21583 }
21584 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21585 EXPORT_SYMBOL_GPL(print_context_stack);
21586
21587 unsigned long
21588 -print_context_stack_bp(struct thread_info *tinfo,
21589 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21590 unsigned long *stack, unsigned long bp,
21591 const struct stacktrace_ops *ops, void *data,
21592 unsigned long *end, int *graph)
21593 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21594 struct stack_frame *frame = (struct stack_frame *)bp;
21595 unsigned long *ret_addr = &frame->return_address;
21596
21597 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21598 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21599 unsigned long addr = *ret_addr;
21600
21601 if (!__kernel_text_address(addr))
21602 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21603 ops->address(data, addr, 1);
21604 frame = frame->next_frame;
21605 ret_addr = &frame->return_address;
21606 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21607 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21608 }
21609
21610 return (unsigned long)frame;
21611 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21612 static void print_trace_address(void *data, unsigned long addr, int reliable)
21613 {
21614 touch_nmi_watchdog();
21615 - printk(data);
21616 + printk("%s", (char *)data);
21617 printk_stack_address(addr, reliable);
21618 }
21619
21620 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21621 }
21622 EXPORT_SYMBOL_GPL(oops_begin);
21623
21624 +extern void gr_handle_kernel_exploit(void);
21625 +
21626 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21627 {
21628 if (regs && kexec_should_crash(current))
21629 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21630 panic("Fatal exception in interrupt");
21631 if (panic_on_oops)
21632 panic("Fatal exception");
21633 - do_exit(signr);
21634 +
21635 + gr_handle_kernel_exploit();
21636 +
21637 + do_group_exit(signr);
21638 }
21639
21640 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21641 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21642 print_modules();
21643 show_regs(regs);
21644 #ifdef CONFIG_X86_32
21645 - if (user_mode_vm(regs)) {
21646 + if (user_mode(regs)) {
21647 sp = regs->sp;
21648 ss = regs->ss & 0xffff;
21649 } else {
21650 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21651 unsigned long flags = oops_begin();
21652 int sig = SIGSEGV;
21653
21654 - if (!user_mode_vm(regs))
21655 + if (!user_mode(regs))
21656 report_bug(regs->ip, regs);
21657
21658 if (__die(str, regs, err))
21659 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21660 index f2a1770..540657f 100644
21661 --- a/arch/x86/kernel/dumpstack_32.c
21662 +++ b/arch/x86/kernel/dumpstack_32.c
21663 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21664 bp = stack_frame(task, regs);
21665
21666 for (;;) {
21667 - struct thread_info *context;
21668 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21669
21670 - context = (struct thread_info *)
21671 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21672 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21673 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21674
21675 - stack = (unsigned long *)context->previous_esp;
21676 - if (!stack)
21677 + if (stack_start == task_stack_page(task))
21678 break;
21679 + stack = *(unsigned long **)stack_start;
21680 if (ops->stack(data, "IRQ") < 0)
21681 break;
21682 touch_nmi_watchdog();
21683 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21684 int i;
21685
21686 show_regs_print_info(KERN_EMERG);
21687 - __show_regs(regs, !user_mode_vm(regs));
21688 + __show_regs(regs, !user_mode(regs));
21689
21690 /*
21691 * When in-kernel, we also print out the stack and code at the
21692 * time of the fault..
21693 */
21694 - if (!user_mode_vm(regs)) {
21695 + if (!user_mode(regs)) {
21696 unsigned int code_prologue = code_bytes * 43 / 64;
21697 unsigned int code_len = code_bytes;
21698 unsigned char c;
21699 u8 *ip;
21700 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21701
21702 pr_emerg("Stack:\n");
21703 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21704
21705 pr_emerg("Code:");
21706
21707 - ip = (u8 *)regs->ip - code_prologue;
21708 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21709 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21710 /* try starting at IP */
21711 - ip = (u8 *)regs->ip;
21712 + ip = (u8 *)regs->ip + cs_base;
21713 code_len = code_len - code_prologue + 1;
21714 }
21715 for (i = 0; i < code_len; i++, ip++) {
21716 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21717 pr_cont(" Bad EIP value.");
21718 break;
21719 }
21720 - if (ip == (u8 *)regs->ip)
21721 + if (ip == (u8 *)regs->ip + cs_base)
21722 pr_cont(" <%02x>", c);
21723 else
21724 pr_cont(" %02x", c);
21725 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21726 {
21727 unsigned short ud2;
21728
21729 + ip = ktla_ktva(ip);
21730 if (ip < PAGE_OFFSET)
21731 return 0;
21732 if (probe_kernel_address((unsigned short *)ip, ud2))
21733 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21734
21735 return ud2 == 0x0b0f;
21736 }
21737 +
21738 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21739 +void pax_check_alloca(unsigned long size)
21740 +{
21741 + unsigned long sp = (unsigned long)&sp, stack_left;
21742 +
21743 + /* all kernel stacks are of the same size */
21744 + stack_left = sp & (THREAD_SIZE - 1);
21745 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21746 +}
21747 +EXPORT_SYMBOL(pax_check_alloca);
21748 +#endif
21749 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21750 index addb207..99635fa 100644
21751 --- a/arch/x86/kernel/dumpstack_64.c
21752 +++ b/arch/x86/kernel/dumpstack_64.c
21753 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21754 unsigned long *irq_stack_end =
21755 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21756 unsigned used = 0;
21757 - struct thread_info *tinfo;
21758 int graph = 0;
21759 unsigned long dummy;
21760 + void *stack_start;
21761
21762 if (!task)
21763 task = current;
21764 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21765 * current stack address. If the stacks consist of nested
21766 * exceptions
21767 */
21768 - tinfo = task_thread_info(task);
21769 for (;;) {
21770 char *id;
21771 unsigned long *estack_end;
21772 +
21773 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21774 &used, &id);
21775
21776 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21777 if (ops->stack(data, id) < 0)
21778 break;
21779
21780 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21781 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21782 data, estack_end, &graph);
21783 ops->stack(data, "<EOE>");
21784 /*
21785 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21786 * second-to-last pointer (index -2 to end) in the
21787 * exception stack:
21788 */
21789 + if ((u16)estack_end[-1] != __KERNEL_DS)
21790 + goto out;
21791 stack = (unsigned long *) estack_end[-2];
21792 continue;
21793 }
21794 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21795 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21796 if (ops->stack(data, "IRQ") < 0)
21797 break;
21798 - bp = ops->walk_stack(tinfo, stack, bp,
21799 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21800 ops, data, irq_stack_end, &graph);
21801 /*
21802 * We link to the next stack (which would be
21803 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21804 /*
21805 * This handles the process stack:
21806 */
21807 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21808 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21809 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21810 +out:
21811 put_cpu();
21812 }
21813 EXPORT_SYMBOL(dump_trace);
21814 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21815
21816 return ud2 == 0x0b0f;
21817 }
21818 +
21819 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21820 +void pax_check_alloca(unsigned long size)
21821 +{
21822 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21823 + unsigned cpu, used;
21824 + char *id;
21825 +
21826 + /* check the process stack first */
21827 + stack_start = (unsigned long)task_stack_page(current);
21828 + stack_end = stack_start + THREAD_SIZE;
21829 + if (likely(stack_start <= sp && sp < stack_end)) {
21830 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21831 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21832 + return;
21833 + }
21834 +
21835 + cpu = get_cpu();
21836 +
21837 + /* check the irq stacks */
21838 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21839 + stack_start = stack_end - IRQ_STACK_SIZE;
21840 + if (stack_start <= sp && sp < stack_end) {
21841 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21842 + put_cpu();
21843 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21844 + return;
21845 + }
21846 +
21847 + /* check the exception stacks */
21848 + used = 0;
21849 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21850 + stack_start = stack_end - EXCEPTION_STKSZ;
21851 + if (stack_end && stack_start <= sp && sp < stack_end) {
21852 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21853 + put_cpu();
21854 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21855 + return;
21856 + }
21857 +
21858 + put_cpu();
21859 +
21860 + /* unknown stack */
21861 + BUG();
21862 +}
21863 +EXPORT_SYMBOL(pax_check_alloca);
21864 +#endif
21865 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21866 index 988c00a..4f673b6 100644
21867 --- a/arch/x86/kernel/e820.c
21868 +++ b/arch/x86/kernel/e820.c
21869 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21870
21871 static void early_panic(char *msg)
21872 {
21873 - early_printk(msg);
21874 - panic(msg);
21875 + early_printk("%s", msg);
21876 + panic("%s", msg);
21877 }
21878
21879 static int userdef __initdata;
21880 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21881 index 01d1c18..8073693 100644
21882 --- a/arch/x86/kernel/early_printk.c
21883 +++ b/arch/x86/kernel/early_printk.c
21884 @@ -7,6 +7,7 @@
21885 #include <linux/pci_regs.h>
21886 #include <linux/pci_ids.h>
21887 #include <linux/errno.h>
21888 +#include <linux/sched.h>
21889 #include <asm/io.h>
21890 #include <asm/processor.h>
21891 #include <asm/fcntl.h>
21892 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21893 index a2a4f46..6cab058 100644
21894 --- a/arch/x86/kernel/entry_32.S
21895 +++ b/arch/x86/kernel/entry_32.S
21896 @@ -177,13 +177,153 @@
21897 /*CFI_REL_OFFSET gs, PT_GS*/
21898 .endm
21899 .macro SET_KERNEL_GS reg
21900 +
21901 +#ifdef CONFIG_CC_STACKPROTECTOR
21902 movl $(__KERNEL_STACK_CANARY), \reg
21903 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21904 + movl $(__USER_DS), \reg
21905 +#else
21906 + xorl \reg, \reg
21907 +#endif
21908 +
21909 movl \reg, %gs
21910 .endm
21911
21912 #endif /* CONFIG_X86_32_LAZY_GS */
21913
21914 -.macro SAVE_ALL
21915 +.macro pax_enter_kernel
21916 +#ifdef CONFIG_PAX_KERNEXEC
21917 + call pax_enter_kernel
21918 +#endif
21919 +.endm
21920 +
21921 +.macro pax_exit_kernel
21922 +#ifdef CONFIG_PAX_KERNEXEC
21923 + call pax_exit_kernel
21924 +#endif
21925 +.endm
21926 +
21927 +#ifdef CONFIG_PAX_KERNEXEC
21928 +ENTRY(pax_enter_kernel)
21929 +#ifdef CONFIG_PARAVIRT
21930 + pushl %eax
21931 + pushl %ecx
21932 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21933 + mov %eax, %esi
21934 +#else
21935 + mov %cr0, %esi
21936 +#endif
21937 + bts $16, %esi
21938 + jnc 1f
21939 + mov %cs, %esi
21940 + cmp $__KERNEL_CS, %esi
21941 + jz 3f
21942 + ljmp $__KERNEL_CS, $3f
21943 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21944 +2:
21945 +#ifdef CONFIG_PARAVIRT
21946 + mov %esi, %eax
21947 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21948 +#else
21949 + mov %esi, %cr0
21950 +#endif
21951 +3:
21952 +#ifdef CONFIG_PARAVIRT
21953 + popl %ecx
21954 + popl %eax
21955 +#endif
21956 + ret
21957 +ENDPROC(pax_enter_kernel)
21958 +
21959 +ENTRY(pax_exit_kernel)
21960 +#ifdef CONFIG_PARAVIRT
21961 + pushl %eax
21962 + pushl %ecx
21963 +#endif
21964 + mov %cs, %esi
21965 + cmp $__KERNEXEC_KERNEL_CS, %esi
21966 + jnz 2f
21967 +#ifdef CONFIG_PARAVIRT
21968 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21969 + mov %eax, %esi
21970 +#else
21971 + mov %cr0, %esi
21972 +#endif
21973 + btr $16, %esi
21974 + ljmp $__KERNEL_CS, $1f
21975 +1:
21976 +#ifdef CONFIG_PARAVIRT
21977 + mov %esi, %eax
21978 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21979 +#else
21980 + mov %esi, %cr0
21981 +#endif
21982 +2:
21983 +#ifdef CONFIG_PARAVIRT
21984 + popl %ecx
21985 + popl %eax
21986 +#endif
21987 + ret
21988 +ENDPROC(pax_exit_kernel)
21989 +#endif
21990 +
21991 + .macro pax_erase_kstack
21992 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21993 + call pax_erase_kstack
21994 +#endif
21995 + .endm
21996 +
21997 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21998 +/*
21999 + * ebp: thread_info
22000 + */
22001 +ENTRY(pax_erase_kstack)
22002 + pushl %edi
22003 + pushl %ecx
22004 + pushl %eax
22005 +
22006 + mov TI_lowest_stack(%ebp), %edi
22007 + mov $-0xBEEF, %eax
22008 + std
22009 +
22010 +1: mov %edi, %ecx
22011 + and $THREAD_SIZE_asm - 1, %ecx
22012 + shr $2, %ecx
22013 + repne scasl
22014 + jecxz 2f
22015 +
22016 + cmp $2*16, %ecx
22017 + jc 2f
22018 +
22019 + mov $2*16, %ecx
22020 + repe scasl
22021 + jecxz 2f
22022 + jne 1b
22023 +
22024 +2: cld
22025 + mov %esp, %ecx
22026 + sub %edi, %ecx
22027 +
22028 + cmp $THREAD_SIZE_asm, %ecx
22029 + jb 3f
22030 + ud2
22031 +3:
22032 +
22033 + shr $2, %ecx
22034 + rep stosl
22035 +
22036 + mov TI_task_thread_sp0(%ebp), %edi
22037 + sub $128, %edi
22038 + mov %edi, TI_lowest_stack(%ebp)
22039 +
22040 + popl %eax
22041 + popl %ecx
22042 + popl %edi
22043 + ret
22044 +ENDPROC(pax_erase_kstack)
22045 +#endif
22046 +
22047 +.macro __SAVE_ALL _DS
22048 cld
22049 PUSH_GS
22050 pushl_cfi %fs
22051 @@ -206,7 +346,7 @@
22052 CFI_REL_OFFSET ecx, 0
22053 pushl_cfi %ebx
22054 CFI_REL_OFFSET ebx, 0
22055 - movl $(__USER_DS), %edx
22056 + movl $\_DS, %edx
22057 movl %edx, %ds
22058 movl %edx, %es
22059 movl $(__KERNEL_PERCPU), %edx
22060 @@ -214,6 +354,15 @@
22061 SET_KERNEL_GS %edx
22062 .endm
22063
22064 +.macro SAVE_ALL
22065 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22066 + __SAVE_ALL __KERNEL_DS
22067 + pax_enter_kernel
22068 +#else
22069 + __SAVE_ALL __USER_DS
22070 +#endif
22071 +.endm
22072 +
22073 .macro RESTORE_INT_REGS
22074 popl_cfi %ebx
22075 CFI_RESTORE ebx
22076 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22077 popfl_cfi
22078 jmp syscall_exit
22079 CFI_ENDPROC
22080 -END(ret_from_fork)
22081 +ENDPROC(ret_from_fork)
22082
22083 ENTRY(ret_from_kernel_thread)
22084 CFI_STARTPROC
22085 @@ -344,7 +493,15 @@ ret_from_intr:
22086 andl $SEGMENT_RPL_MASK, %eax
22087 #endif
22088 cmpl $USER_RPL, %eax
22089 +
22090 +#ifdef CONFIG_PAX_KERNEXEC
22091 + jae resume_userspace
22092 +
22093 + pax_exit_kernel
22094 + jmp resume_kernel
22095 +#else
22096 jb resume_kernel # not returning to v8086 or userspace
22097 +#endif
22098
22099 ENTRY(resume_userspace)
22100 LOCKDEP_SYS_EXIT
22101 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22102 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22103 # int/exception return?
22104 jne work_pending
22105 - jmp restore_all
22106 -END(ret_from_exception)
22107 + jmp restore_all_pax
22108 +ENDPROC(ret_from_exception)
22109
22110 #ifdef CONFIG_PREEMPT
22111 ENTRY(resume_kernel)
22112 @@ -369,7 +526,7 @@ need_resched:
22113 jz restore_all
22114 call preempt_schedule_irq
22115 jmp need_resched
22116 -END(resume_kernel)
22117 +ENDPROC(resume_kernel)
22118 #endif
22119 CFI_ENDPROC
22120 /*
22121 @@ -403,30 +560,45 @@ sysenter_past_esp:
22122 /*CFI_REL_OFFSET cs, 0*/
22123 /*
22124 * Push current_thread_info()->sysenter_return to the stack.
22125 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22126 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22127 */
22128 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22129 + pushl_cfi $0
22130 CFI_REL_OFFSET eip, 0
22131
22132 pushl_cfi %eax
22133 SAVE_ALL
22134 + GET_THREAD_INFO(%ebp)
22135 + movl TI_sysenter_return(%ebp),%ebp
22136 + movl %ebp,PT_EIP(%esp)
22137 ENABLE_INTERRUPTS(CLBR_NONE)
22138
22139 /*
22140 * Load the potential sixth argument from user stack.
22141 * Careful about security.
22142 */
22143 + movl PT_OLDESP(%esp),%ebp
22144 +
22145 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22146 + mov PT_OLDSS(%esp),%ds
22147 +1: movl %ds:(%ebp),%ebp
22148 + push %ss
22149 + pop %ds
22150 +#else
22151 cmpl $__PAGE_OFFSET-3,%ebp
22152 jae syscall_fault
22153 ASM_STAC
22154 1: movl (%ebp),%ebp
22155 ASM_CLAC
22156 +#endif
22157 +
22158 movl %ebp,PT_EBP(%esp)
22159 _ASM_EXTABLE(1b,syscall_fault)
22160
22161 GET_THREAD_INFO(%ebp)
22162
22163 +#ifdef CONFIG_PAX_RANDKSTACK
22164 + pax_erase_kstack
22165 +#endif
22166 +
22167 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22168 jnz sysenter_audit
22169 sysenter_do_call:
22170 @@ -441,12 +613,24 @@ sysenter_do_call:
22171 testl $_TIF_ALLWORK_MASK, %ecx
22172 jne sysexit_audit
22173 sysenter_exit:
22174 +
22175 +#ifdef CONFIG_PAX_RANDKSTACK
22176 + pushl_cfi %eax
22177 + movl %esp, %eax
22178 + call pax_randomize_kstack
22179 + popl_cfi %eax
22180 +#endif
22181 +
22182 + pax_erase_kstack
22183 +
22184 /* if something modifies registers it must also disable sysexit */
22185 movl PT_EIP(%esp), %edx
22186 movl PT_OLDESP(%esp), %ecx
22187 xorl %ebp,%ebp
22188 TRACE_IRQS_ON
22189 1: mov PT_FS(%esp), %fs
22190 +2: mov PT_DS(%esp), %ds
22191 +3: mov PT_ES(%esp), %es
22192 PTGS_TO_GS
22193 ENABLE_INTERRUPTS_SYSEXIT
22194
22195 @@ -463,6 +647,9 @@ sysenter_audit:
22196 movl %eax,%edx /* 2nd arg: syscall number */
22197 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22198 call __audit_syscall_entry
22199 +
22200 + pax_erase_kstack
22201 +
22202 pushl_cfi %ebx
22203 movl PT_EAX(%esp),%eax /* reload syscall number */
22204 jmp sysenter_do_call
22205 @@ -488,10 +675,16 @@ sysexit_audit:
22206
22207 CFI_ENDPROC
22208 .pushsection .fixup,"ax"
22209 -2: movl $0,PT_FS(%esp)
22210 +4: movl $0,PT_FS(%esp)
22211 + jmp 1b
22212 +5: movl $0,PT_DS(%esp)
22213 + jmp 1b
22214 +6: movl $0,PT_ES(%esp)
22215 jmp 1b
22216 .popsection
22217 - _ASM_EXTABLE(1b,2b)
22218 + _ASM_EXTABLE(1b,4b)
22219 + _ASM_EXTABLE(2b,5b)
22220 + _ASM_EXTABLE(3b,6b)
22221 PTGS_TO_GS_EX
22222 ENDPROC(ia32_sysenter_target)
22223
22224 @@ -506,6 +699,11 @@ ENTRY(system_call)
22225 pushl_cfi %eax # save orig_eax
22226 SAVE_ALL
22227 GET_THREAD_INFO(%ebp)
22228 +
22229 +#ifdef CONFIG_PAX_RANDKSTACK
22230 + pax_erase_kstack
22231 +#endif
22232 +
22233 # system call tracing in operation / emulation
22234 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22235 jnz syscall_trace_entry
22236 @@ -524,6 +722,15 @@ syscall_exit:
22237 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22238 jne syscall_exit_work
22239
22240 +restore_all_pax:
22241 +
22242 +#ifdef CONFIG_PAX_RANDKSTACK
22243 + movl %esp, %eax
22244 + call pax_randomize_kstack
22245 +#endif
22246 +
22247 + pax_erase_kstack
22248 +
22249 restore_all:
22250 TRACE_IRQS_IRET
22251 restore_all_notrace:
22252 @@ -580,14 +787,34 @@ ldt_ss:
22253 * compensating for the offset by changing to the ESPFIX segment with
22254 * a base address that matches for the difference.
22255 */
22256 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22257 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22258 mov %esp, %edx /* load kernel esp */
22259 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22260 mov %dx, %ax /* eax: new kernel esp */
22261 sub %eax, %edx /* offset (low word is 0) */
22262 +#ifdef CONFIG_SMP
22263 + movl PER_CPU_VAR(cpu_number), %ebx
22264 + shll $PAGE_SHIFT_asm, %ebx
22265 + addl $cpu_gdt_table, %ebx
22266 +#else
22267 + movl $cpu_gdt_table, %ebx
22268 +#endif
22269 shr $16, %edx
22270 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22271 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22272 +
22273 +#ifdef CONFIG_PAX_KERNEXEC
22274 + mov %cr0, %esi
22275 + btr $16, %esi
22276 + mov %esi, %cr0
22277 +#endif
22278 +
22279 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22280 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22281 +
22282 +#ifdef CONFIG_PAX_KERNEXEC
22283 + bts $16, %esi
22284 + mov %esi, %cr0
22285 +#endif
22286 +
22287 pushl_cfi $__ESPFIX_SS
22288 pushl_cfi %eax /* new kernel esp */
22289 /* Disable interrupts, but do not irqtrace this section: we
22290 @@ -616,20 +843,18 @@ work_resched:
22291 movl TI_flags(%ebp), %ecx
22292 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22293 # than syscall tracing?
22294 - jz restore_all
22295 + jz restore_all_pax
22296 testb $_TIF_NEED_RESCHED, %cl
22297 jnz work_resched
22298
22299 work_notifysig: # deal with pending signals and
22300 # notify-resume requests
22301 + movl %esp, %eax
22302 #ifdef CONFIG_VM86
22303 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22304 - movl %esp, %eax
22305 jne work_notifysig_v86 # returning to kernel-space or
22306 # vm86-space
22307 1:
22308 -#else
22309 - movl %esp, %eax
22310 #endif
22311 TRACE_IRQS_ON
22312 ENABLE_INTERRUPTS(CLBR_NONE)
22313 @@ -650,7 +875,7 @@ work_notifysig_v86:
22314 movl %eax, %esp
22315 jmp 1b
22316 #endif
22317 -END(work_pending)
22318 +ENDPROC(work_pending)
22319
22320 # perform syscall exit tracing
22321 ALIGN
22322 @@ -658,11 +883,14 @@ syscall_trace_entry:
22323 movl $-ENOSYS,PT_EAX(%esp)
22324 movl %esp, %eax
22325 call syscall_trace_enter
22326 +
22327 + pax_erase_kstack
22328 +
22329 /* What it returned is what we'll actually use. */
22330 cmpl $(NR_syscalls), %eax
22331 jnae syscall_call
22332 jmp syscall_exit
22333 -END(syscall_trace_entry)
22334 +ENDPROC(syscall_trace_entry)
22335
22336 # perform syscall exit tracing
22337 ALIGN
22338 @@ -675,21 +903,25 @@ syscall_exit_work:
22339 movl %esp, %eax
22340 call syscall_trace_leave
22341 jmp resume_userspace
22342 -END(syscall_exit_work)
22343 +ENDPROC(syscall_exit_work)
22344 CFI_ENDPROC
22345
22346 RING0_INT_FRAME # can't unwind into user space anyway
22347 syscall_fault:
22348 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22349 + push %ss
22350 + pop %ds
22351 +#endif
22352 ASM_CLAC
22353 GET_THREAD_INFO(%ebp)
22354 movl $-EFAULT,PT_EAX(%esp)
22355 jmp resume_userspace
22356 -END(syscall_fault)
22357 +ENDPROC(syscall_fault)
22358
22359 syscall_badsys:
22360 movl $-ENOSYS,PT_EAX(%esp)
22361 jmp resume_userspace
22362 -END(syscall_badsys)
22363 +ENDPROC(syscall_badsys)
22364 CFI_ENDPROC
22365 /*
22366 * End of kprobes section
22367 @@ -705,8 +937,15 @@ END(syscall_badsys)
22368 * normal stack and adjusts ESP with the matching offset.
22369 */
22370 /* fixup the stack */
22371 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22372 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22373 +#ifdef CONFIG_SMP
22374 + movl PER_CPU_VAR(cpu_number), %ebx
22375 + shll $PAGE_SHIFT_asm, %ebx
22376 + addl $cpu_gdt_table, %ebx
22377 +#else
22378 + movl $cpu_gdt_table, %ebx
22379 +#endif
22380 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22381 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22382 shl $16, %eax
22383 addl %esp, %eax /* the adjusted stack pointer */
22384 pushl_cfi $__KERNEL_DS
22385 @@ -759,7 +998,7 @@ vector=vector+1
22386 .endr
22387 2: jmp common_interrupt
22388 .endr
22389 -END(irq_entries_start)
22390 +ENDPROC(irq_entries_start)
22391
22392 .previous
22393 END(interrupt)
22394 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22395 pushl_cfi $do_coprocessor_error
22396 jmp error_code
22397 CFI_ENDPROC
22398 -END(coprocessor_error)
22399 +ENDPROC(coprocessor_error)
22400
22401 ENTRY(simd_coprocessor_error)
22402 RING0_INT_FRAME
22403 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22404 .section .altinstructions,"a"
22405 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22406 .previous
22407 -.section .altinstr_replacement,"ax"
22408 +.section .altinstr_replacement,"a"
22409 663: pushl $do_simd_coprocessor_error
22410 664:
22411 .previous
22412 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22413 #endif
22414 jmp error_code
22415 CFI_ENDPROC
22416 -END(simd_coprocessor_error)
22417 +ENDPROC(simd_coprocessor_error)
22418
22419 ENTRY(device_not_available)
22420 RING0_INT_FRAME
22421 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22422 pushl_cfi $do_device_not_available
22423 jmp error_code
22424 CFI_ENDPROC
22425 -END(device_not_available)
22426 +ENDPROC(device_not_available)
22427
22428 #ifdef CONFIG_PARAVIRT
22429 ENTRY(native_iret)
22430 iret
22431 _ASM_EXTABLE(native_iret, iret_exc)
22432 -END(native_iret)
22433 +ENDPROC(native_iret)
22434
22435 ENTRY(native_irq_enable_sysexit)
22436 sti
22437 sysexit
22438 -END(native_irq_enable_sysexit)
22439 +ENDPROC(native_irq_enable_sysexit)
22440 #endif
22441
22442 ENTRY(overflow)
22443 @@ -872,7 +1111,7 @@ ENTRY(overflow)
22444 pushl_cfi $do_overflow
22445 jmp error_code
22446 CFI_ENDPROC
22447 -END(overflow)
22448 +ENDPROC(overflow)
22449
22450 ENTRY(bounds)
22451 RING0_INT_FRAME
22452 @@ -881,7 +1120,7 @@ ENTRY(bounds)
22453 pushl_cfi $do_bounds
22454 jmp error_code
22455 CFI_ENDPROC
22456 -END(bounds)
22457 +ENDPROC(bounds)
22458
22459 ENTRY(invalid_op)
22460 RING0_INT_FRAME
22461 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22462 pushl_cfi $do_invalid_op
22463 jmp error_code
22464 CFI_ENDPROC
22465 -END(invalid_op)
22466 +ENDPROC(invalid_op)
22467
22468 ENTRY(coprocessor_segment_overrun)
22469 RING0_INT_FRAME
22470 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22471 pushl_cfi $do_coprocessor_segment_overrun
22472 jmp error_code
22473 CFI_ENDPROC
22474 -END(coprocessor_segment_overrun)
22475 +ENDPROC(coprocessor_segment_overrun)
22476
22477 ENTRY(invalid_TSS)
22478 RING0_EC_FRAME
22479 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22480 pushl_cfi $do_invalid_TSS
22481 jmp error_code
22482 CFI_ENDPROC
22483 -END(invalid_TSS)
22484 +ENDPROC(invalid_TSS)
22485
22486 ENTRY(segment_not_present)
22487 RING0_EC_FRAME
22488 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22489 pushl_cfi $do_segment_not_present
22490 jmp error_code
22491 CFI_ENDPROC
22492 -END(segment_not_present)
22493 +ENDPROC(segment_not_present)
22494
22495 ENTRY(stack_segment)
22496 RING0_EC_FRAME
22497 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22498 pushl_cfi $do_stack_segment
22499 jmp error_code
22500 CFI_ENDPROC
22501 -END(stack_segment)
22502 +ENDPROC(stack_segment)
22503
22504 ENTRY(alignment_check)
22505 RING0_EC_FRAME
22506 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22507 pushl_cfi $do_alignment_check
22508 jmp error_code
22509 CFI_ENDPROC
22510 -END(alignment_check)
22511 +ENDPROC(alignment_check)
22512
22513 ENTRY(divide_error)
22514 RING0_INT_FRAME
22515 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22516 pushl_cfi $do_divide_error
22517 jmp error_code
22518 CFI_ENDPROC
22519 -END(divide_error)
22520 +ENDPROC(divide_error)
22521
22522 #ifdef CONFIG_X86_MCE
22523 ENTRY(machine_check)
22524 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22525 pushl_cfi machine_check_vector
22526 jmp error_code
22527 CFI_ENDPROC
22528 -END(machine_check)
22529 +ENDPROC(machine_check)
22530 #endif
22531
22532 ENTRY(spurious_interrupt_bug)
22533 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22534 pushl_cfi $do_spurious_interrupt_bug
22535 jmp error_code
22536 CFI_ENDPROC
22537 -END(spurious_interrupt_bug)
22538 +ENDPROC(spurious_interrupt_bug)
22539 /*
22540 * End of kprobes section
22541 */
22542 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22543
22544 ENTRY(mcount)
22545 ret
22546 -END(mcount)
22547 +ENDPROC(mcount)
22548
22549 ENTRY(ftrace_caller)
22550 cmpl $0, function_trace_stop
22551 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22552 .globl ftrace_stub
22553 ftrace_stub:
22554 ret
22555 -END(ftrace_caller)
22556 +ENDPROC(ftrace_caller)
22557
22558 ENTRY(ftrace_regs_caller)
22559 pushf /* push flags before compare (in cs location) */
22560 @@ -1207,7 +1446,7 @@ trace:
22561 popl %ecx
22562 popl %eax
22563 jmp ftrace_stub
22564 -END(mcount)
22565 +ENDPROC(mcount)
22566 #endif /* CONFIG_DYNAMIC_FTRACE */
22567 #endif /* CONFIG_FUNCTION_TRACER */
22568
22569 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22570 popl %ecx
22571 popl %eax
22572 ret
22573 -END(ftrace_graph_caller)
22574 +ENDPROC(ftrace_graph_caller)
22575
22576 .globl return_to_handler
22577 return_to_handler:
22578 @@ -1291,15 +1530,18 @@ error_code:
22579 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22580 REG_TO_PTGS %ecx
22581 SET_KERNEL_GS %ecx
22582 - movl $(__USER_DS), %ecx
22583 + movl $(__KERNEL_DS), %ecx
22584 movl %ecx, %ds
22585 movl %ecx, %es
22586 +
22587 + pax_enter_kernel
22588 +
22589 TRACE_IRQS_OFF
22590 movl %esp,%eax # pt_regs pointer
22591 call *%edi
22592 jmp ret_from_exception
22593 CFI_ENDPROC
22594 -END(page_fault)
22595 +ENDPROC(page_fault)
22596
22597 /*
22598 * Debug traps and NMI can happen at the one SYSENTER instruction
22599 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22600 call do_debug
22601 jmp ret_from_exception
22602 CFI_ENDPROC
22603 -END(debug)
22604 +ENDPROC(debug)
22605
22606 /*
22607 * NMI is doubly nasty. It can happen _while_ we're handling
22608 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22609 xorl %edx,%edx # zero error code
22610 movl %esp,%eax # pt_regs pointer
22611 call do_nmi
22612 +
22613 + pax_exit_kernel
22614 +
22615 jmp restore_all_notrace
22616 CFI_ENDPROC
22617
22618 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22619 FIXUP_ESPFIX_STACK # %eax == %esp
22620 xorl %edx,%edx # zero error code
22621 call do_nmi
22622 +
22623 + pax_exit_kernel
22624 +
22625 RESTORE_REGS
22626 lss 12+4(%esp), %esp # back to espfix stack
22627 CFI_ADJUST_CFA_OFFSET -24
22628 jmp irq_return
22629 CFI_ENDPROC
22630 -END(nmi)
22631 +ENDPROC(nmi)
22632
22633 ENTRY(int3)
22634 RING0_INT_FRAME
22635 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22636 call do_int3
22637 jmp ret_from_exception
22638 CFI_ENDPROC
22639 -END(int3)
22640 +ENDPROC(int3)
22641
22642 ENTRY(general_protection)
22643 RING0_EC_FRAME
22644 pushl_cfi $do_general_protection
22645 jmp error_code
22646 CFI_ENDPROC
22647 -END(general_protection)
22648 +ENDPROC(general_protection)
22649
22650 #ifdef CONFIG_KVM_GUEST
22651 ENTRY(async_page_fault)
22652 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22653 pushl_cfi $do_async_page_fault
22654 jmp error_code
22655 CFI_ENDPROC
22656 -END(async_page_fault)
22657 +ENDPROC(async_page_fault)
22658 #endif
22659
22660 /*
22661 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22662 index 1e96c36..3ff710a 100644
22663 --- a/arch/x86/kernel/entry_64.S
22664 +++ b/arch/x86/kernel/entry_64.S
22665 @@ -59,6 +59,8 @@
22666 #include <asm/context_tracking.h>
22667 #include <asm/smap.h>
22668 #include <linux/err.h>
22669 +#include <asm/pgtable.h>
22670 +#include <asm/alternative-asm.h>
22671
22672 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22673 #include <linux/elf-em.h>
22674 @@ -80,8 +82,9 @@
22675 #ifdef CONFIG_DYNAMIC_FTRACE
22676
22677 ENTRY(function_hook)
22678 + pax_force_retaddr
22679 retq
22680 -END(function_hook)
22681 +ENDPROC(function_hook)
22682
22683 /* skip is set if stack has been adjusted */
22684 .macro ftrace_caller_setup skip=0
22685 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22686 #endif
22687
22688 GLOBAL(ftrace_stub)
22689 + pax_force_retaddr
22690 retq
22691 -END(ftrace_caller)
22692 +ENDPROC(ftrace_caller)
22693
22694 ENTRY(ftrace_regs_caller)
22695 /* Save the current flags before compare (in SS location)*/
22696 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22697 popfq
22698 jmp ftrace_stub
22699
22700 -END(ftrace_regs_caller)
22701 +ENDPROC(ftrace_regs_caller)
22702
22703
22704 #else /* ! CONFIG_DYNAMIC_FTRACE */
22705 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22706 #endif
22707
22708 GLOBAL(ftrace_stub)
22709 + pax_force_retaddr
22710 retq
22711
22712 trace:
22713 @@ -225,12 +230,13 @@ trace:
22714 #endif
22715 subq $MCOUNT_INSN_SIZE, %rdi
22716
22717 + pax_force_fptr ftrace_trace_function
22718 call *ftrace_trace_function
22719
22720 MCOUNT_RESTORE_FRAME
22721
22722 jmp ftrace_stub
22723 -END(function_hook)
22724 +ENDPROC(function_hook)
22725 #endif /* CONFIG_DYNAMIC_FTRACE */
22726 #endif /* CONFIG_FUNCTION_TRACER */
22727
22728 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22729
22730 MCOUNT_RESTORE_FRAME
22731
22732 + pax_force_retaddr
22733 retq
22734 -END(ftrace_graph_caller)
22735 +ENDPROC(ftrace_graph_caller)
22736
22737 GLOBAL(return_to_handler)
22738 subq $24, %rsp
22739 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22740 movq 8(%rsp), %rdx
22741 movq (%rsp), %rax
22742 addq $24, %rsp
22743 + pax_force_fptr %rdi
22744 jmp *%rdi
22745 +ENDPROC(return_to_handler)
22746 #endif
22747
22748
22749 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22750 ENDPROC(native_usergs_sysret64)
22751 #endif /* CONFIG_PARAVIRT */
22752
22753 + .macro ljmpq sel, off
22754 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22755 + .byte 0x48; ljmp *1234f(%rip)
22756 + .pushsection .rodata
22757 + .align 16
22758 + 1234: .quad \off; .word \sel
22759 + .popsection
22760 +#else
22761 + pushq $\sel
22762 + pushq $\off
22763 + lretq
22764 +#endif
22765 + .endm
22766 +
22767 + .macro pax_enter_kernel
22768 + pax_set_fptr_mask
22769 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22770 + call pax_enter_kernel
22771 +#endif
22772 + .endm
22773 +
22774 + .macro pax_exit_kernel
22775 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22776 + call pax_exit_kernel
22777 +#endif
22778 +
22779 + .endm
22780 +
22781 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22782 +ENTRY(pax_enter_kernel)
22783 + pushq %rdi
22784 +
22785 +#ifdef CONFIG_PARAVIRT
22786 + PV_SAVE_REGS(CLBR_RDI)
22787 +#endif
22788 +
22789 +#ifdef CONFIG_PAX_KERNEXEC
22790 + GET_CR0_INTO_RDI
22791 + bts $16,%rdi
22792 + jnc 3f
22793 + mov %cs,%edi
22794 + cmp $__KERNEL_CS,%edi
22795 + jnz 2f
22796 +1:
22797 +#endif
22798 +
22799 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22800 + 661: jmp 111f
22801 + .pushsection .altinstr_replacement, "a"
22802 + 662: ASM_NOP2
22803 + .popsection
22804 + .pushsection .altinstructions, "a"
22805 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22806 + .popsection
22807 + GET_CR3_INTO_RDI
22808 + cmp $0,%dil
22809 + jnz 112f
22810 + mov $__KERNEL_DS,%edi
22811 + mov %edi,%ss
22812 + jmp 111f
22813 +112: cmp $1,%dil
22814 + jz 113f
22815 + ud2
22816 +113: sub $4097,%rdi
22817 + bts $63,%rdi
22818 + SET_RDI_INTO_CR3
22819 + mov $__UDEREF_KERNEL_DS,%edi
22820 + mov %edi,%ss
22821 +111:
22822 +#endif
22823 +
22824 +#ifdef CONFIG_PARAVIRT
22825 + PV_RESTORE_REGS(CLBR_RDI)
22826 +#endif
22827 +
22828 + popq %rdi
22829 + pax_force_retaddr
22830 + retq
22831 +
22832 +#ifdef CONFIG_PAX_KERNEXEC
22833 +2: ljmpq __KERNEL_CS,1b
22834 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22835 +4: SET_RDI_INTO_CR0
22836 + jmp 1b
22837 +#endif
22838 +ENDPROC(pax_enter_kernel)
22839 +
22840 +ENTRY(pax_exit_kernel)
22841 + pushq %rdi
22842 +
22843 +#ifdef CONFIG_PARAVIRT
22844 + PV_SAVE_REGS(CLBR_RDI)
22845 +#endif
22846 +
22847 +#ifdef CONFIG_PAX_KERNEXEC
22848 + mov %cs,%rdi
22849 + cmp $__KERNEXEC_KERNEL_CS,%edi
22850 + jz 2f
22851 + GET_CR0_INTO_RDI
22852 + bts $16,%rdi
22853 + jnc 4f
22854 +1:
22855 +#endif
22856 +
22857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22858 + 661: jmp 111f
22859 + .pushsection .altinstr_replacement, "a"
22860 + 662: ASM_NOP2
22861 + .popsection
22862 + .pushsection .altinstructions, "a"
22863 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22864 + .popsection
22865 + mov %ss,%edi
22866 + cmp $__UDEREF_KERNEL_DS,%edi
22867 + jnz 111f
22868 + GET_CR3_INTO_RDI
22869 + cmp $0,%dil
22870 + jz 112f
22871 + ud2
22872 +112: add $4097,%rdi
22873 + bts $63,%rdi
22874 + SET_RDI_INTO_CR3
22875 + mov $__KERNEL_DS,%edi
22876 + mov %edi,%ss
22877 +111:
22878 +#endif
22879 +
22880 +#ifdef CONFIG_PARAVIRT
22881 + PV_RESTORE_REGS(CLBR_RDI);
22882 +#endif
22883 +
22884 + popq %rdi
22885 + pax_force_retaddr
22886 + retq
22887 +
22888 +#ifdef CONFIG_PAX_KERNEXEC
22889 +2: GET_CR0_INTO_RDI
22890 + btr $16,%rdi
22891 + jnc 4f
22892 + ljmpq __KERNEL_CS,3f
22893 +3: SET_RDI_INTO_CR0
22894 + jmp 1b
22895 +4: ud2
22896 + jmp 4b
22897 +#endif
22898 +ENDPROC(pax_exit_kernel)
22899 +#endif
22900 +
22901 + .macro pax_enter_kernel_user
22902 + pax_set_fptr_mask
22903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22904 + call pax_enter_kernel_user
22905 +#endif
22906 + .endm
22907 +
22908 + .macro pax_exit_kernel_user
22909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22910 + call pax_exit_kernel_user
22911 +#endif
22912 +#ifdef CONFIG_PAX_RANDKSTACK
22913 + pushq %rax
22914 + pushq %r11
22915 + call pax_randomize_kstack
22916 + popq %r11
22917 + popq %rax
22918 +#endif
22919 + .endm
22920 +
22921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22922 +ENTRY(pax_enter_kernel_user)
22923 + pushq %rdi
22924 + pushq %rbx
22925 +
22926 +#ifdef CONFIG_PARAVIRT
22927 + PV_SAVE_REGS(CLBR_RDI)
22928 +#endif
22929 +
22930 + 661: jmp 111f
22931 + .pushsection .altinstr_replacement, "a"
22932 + 662: ASM_NOP2
22933 + .popsection
22934 + .pushsection .altinstructions, "a"
22935 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22936 + .popsection
22937 + GET_CR3_INTO_RDI
22938 + cmp $1,%dil
22939 + jnz 4f
22940 + sub $4097,%rdi
22941 + bts $63,%rdi
22942 + SET_RDI_INTO_CR3
22943 + jmp 3f
22944 +111:
22945 +
22946 + GET_CR3_INTO_RDI
22947 + mov %rdi,%rbx
22948 + add $__START_KERNEL_map,%rbx
22949 + sub phys_base(%rip),%rbx
22950 +
22951 +#ifdef CONFIG_PARAVIRT
22952 + cmpl $0, pv_info+PARAVIRT_enabled
22953 + jz 1f
22954 + pushq %rdi
22955 + i = 0
22956 + .rept USER_PGD_PTRS
22957 + mov i*8(%rbx),%rsi
22958 + mov $0,%sil
22959 + lea i*8(%rbx),%rdi
22960 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22961 + i = i + 1
22962 + .endr
22963 + popq %rdi
22964 + jmp 2f
22965 +1:
22966 +#endif
22967 +
22968 + i = 0
22969 + .rept USER_PGD_PTRS
22970 + movb $0,i*8(%rbx)
22971 + i = i + 1
22972 + .endr
22973 +
22974 +2: SET_RDI_INTO_CR3
22975 +
22976 +#ifdef CONFIG_PAX_KERNEXEC
22977 + GET_CR0_INTO_RDI
22978 + bts $16,%rdi
22979 + SET_RDI_INTO_CR0
22980 +#endif
22981 +
22982 +3:
22983 +
22984 +#ifdef CONFIG_PARAVIRT
22985 + PV_RESTORE_REGS(CLBR_RDI)
22986 +#endif
22987 +
22988 + popq %rbx
22989 + popq %rdi
22990 + pax_force_retaddr
22991 + retq
22992 +4: ud2
22993 +ENDPROC(pax_enter_kernel_user)
22994 +
22995 +ENTRY(pax_exit_kernel_user)
22996 + pushq %rdi
22997 + pushq %rbx
22998 +
22999 +#ifdef CONFIG_PARAVIRT
23000 + PV_SAVE_REGS(CLBR_RDI)
23001 +#endif
23002 +
23003 + GET_CR3_INTO_RDI
23004 + 661: jmp 1f
23005 + .pushsection .altinstr_replacement, "a"
23006 + 662: ASM_NOP2
23007 + .popsection
23008 + .pushsection .altinstructions, "a"
23009 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23010 + .popsection
23011 + cmp $0,%dil
23012 + jnz 3f
23013 + add $4097,%rdi
23014 + bts $63,%rdi
23015 + SET_RDI_INTO_CR3
23016 + jmp 2f
23017 +1:
23018 +
23019 + mov %rdi,%rbx
23020 +
23021 +#ifdef CONFIG_PAX_KERNEXEC
23022 + GET_CR0_INTO_RDI
23023 + btr $16,%rdi
23024 + jnc 3f
23025 + SET_RDI_INTO_CR0
23026 +#endif
23027 +
23028 + add $__START_KERNEL_map,%rbx
23029 + sub phys_base(%rip),%rbx
23030 +
23031 +#ifdef CONFIG_PARAVIRT
23032 + cmpl $0, pv_info+PARAVIRT_enabled
23033 + jz 1f
23034 + i = 0
23035 + .rept USER_PGD_PTRS
23036 + mov i*8(%rbx),%rsi
23037 + mov $0x67,%sil
23038 + lea i*8(%rbx),%rdi
23039 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23040 + i = i + 1
23041 + .endr
23042 + jmp 2f
23043 +1:
23044 +#endif
23045 +
23046 + i = 0
23047 + .rept USER_PGD_PTRS
23048 + movb $0x67,i*8(%rbx)
23049 + i = i + 1
23050 + .endr
23051 +2:
23052 +
23053 +#ifdef CONFIG_PARAVIRT
23054 + PV_RESTORE_REGS(CLBR_RDI)
23055 +#endif
23056 +
23057 + popq %rbx
23058 + popq %rdi
23059 + pax_force_retaddr
23060 + retq
23061 +3: ud2
23062 +ENDPROC(pax_exit_kernel_user)
23063 +#endif
23064 +
23065 + .macro pax_enter_kernel_nmi
23066 + pax_set_fptr_mask
23067 +
23068 +#ifdef CONFIG_PAX_KERNEXEC
23069 + GET_CR0_INTO_RDI
23070 + bts $16,%rdi
23071 + jc 110f
23072 + SET_RDI_INTO_CR0
23073 + or $2,%ebx
23074 +110:
23075 +#endif
23076 +
23077 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23078 + 661: jmp 111f
23079 + .pushsection .altinstr_replacement, "a"
23080 + 662: ASM_NOP2
23081 + .popsection
23082 + .pushsection .altinstructions, "a"
23083 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23084 + .popsection
23085 + GET_CR3_INTO_RDI
23086 + cmp $0,%dil
23087 + jz 111f
23088 + sub $4097,%rdi
23089 + or $4,%ebx
23090 + bts $63,%rdi
23091 + SET_RDI_INTO_CR3
23092 + mov $__UDEREF_KERNEL_DS,%edi
23093 + mov %edi,%ss
23094 +111:
23095 +#endif
23096 + .endm
23097 +
23098 + .macro pax_exit_kernel_nmi
23099 +#ifdef CONFIG_PAX_KERNEXEC
23100 + btr $1,%ebx
23101 + jnc 110f
23102 + GET_CR0_INTO_RDI
23103 + btr $16,%rdi
23104 + SET_RDI_INTO_CR0
23105 +110:
23106 +#endif
23107 +
23108 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23109 + btr $2,%ebx
23110 + jnc 111f
23111 + GET_CR3_INTO_RDI
23112 + add $4097,%rdi
23113 + bts $63,%rdi
23114 + SET_RDI_INTO_CR3
23115 + mov $__KERNEL_DS,%edi
23116 + mov %edi,%ss
23117 +111:
23118 +#endif
23119 + .endm
23120 +
23121 + .macro pax_erase_kstack
23122 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23123 + call pax_erase_kstack
23124 +#endif
23125 + .endm
23126 +
23127 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23128 +ENTRY(pax_erase_kstack)
23129 + pushq %rdi
23130 + pushq %rcx
23131 + pushq %rax
23132 + pushq %r11
23133 +
23134 + GET_THREAD_INFO(%r11)
23135 + mov TI_lowest_stack(%r11), %rdi
23136 + mov $-0xBEEF, %rax
23137 + std
23138 +
23139 +1: mov %edi, %ecx
23140 + and $THREAD_SIZE_asm - 1, %ecx
23141 + shr $3, %ecx
23142 + repne scasq
23143 + jecxz 2f
23144 +
23145 + cmp $2*8, %ecx
23146 + jc 2f
23147 +
23148 + mov $2*8, %ecx
23149 + repe scasq
23150 + jecxz 2f
23151 + jne 1b
23152 +
23153 +2: cld
23154 + mov %esp, %ecx
23155 + sub %edi, %ecx
23156 +
23157 + cmp $THREAD_SIZE_asm, %rcx
23158 + jb 3f
23159 + ud2
23160 +3:
23161 +
23162 + shr $3, %ecx
23163 + rep stosq
23164 +
23165 + mov TI_task_thread_sp0(%r11), %rdi
23166 + sub $256, %rdi
23167 + mov %rdi, TI_lowest_stack(%r11)
23168 +
23169 + popq %r11
23170 + popq %rax
23171 + popq %rcx
23172 + popq %rdi
23173 + pax_force_retaddr
23174 + ret
23175 +ENDPROC(pax_erase_kstack)
23176 +#endif
23177
23178 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23179 #ifdef CONFIG_TRACE_IRQFLAGS
23180 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23181 .endm
23182
23183 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23184 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23185 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23186 jnc 1f
23187 TRACE_IRQS_ON_DEBUG
23188 1:
23189 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23190 movq \tmp,R11+\offset(%rsp)
23191 .endm
23192
23193 - .macro FAKE_STACK_FRAME child_rip
23194 - /* push in order ss, rsp, eflags, cs, rip */
23195 - xorl %eax, %eax
23196 - pushq_cfi $__KERNEL_DS /* ss */
23197 - /*CFI_REL_OFFSET ss,0*/
23198 - pushq_cfi %rax /* rsp */
23199 - CFI_REL_OFFSET rsp,0
23200 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23201 - /*CFI_REL_OFFSET rflags,0*/
23202 - pushq_cfi $__KERNEL_CS /* cs */
23203 - /*CFI_REL_OFFSET cs,0*/
23204 - pushq_cfi \child_rip /* rip */
23205 - CFI_REL_OFFSET rip,0
23206 - pushq_cfi %rax /* orig rax */
23207 - .endm
23208 -
23209 - .macro UNFAKE_STACK_FRAME
23210 - addq $8*6, %rsp
23211 - CFI_ADJUST_CFA_OFFSET -(6*8)
23212 - .endm
23213 -
23214 /*
23215 * initial frame state for interrupts (and exceptions without error code)
23216 */
23217 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23218 /* save partial stack frame */
23219 .macro SAVE_ARGS_IRQ
23220 cld
23221 - /* start from rbp in pt_regs and jump over */
23222 - movq_cfi rdi, (RDI-RBP)
23223 - movq_cfi rsi, (RSI-RBP)
23224 - movq_cfi rdx, (RDX-RBP)
23225 - movq_cfi rcx, (RCX-RBP)
23226 - movq_cfi rax, (RAX-RBP)
23227 - movq_cfi r8, (R8-RBP)
23228 - movq_cfi r9, (R9-RBP)
23229 - movq_cfi r10, (R10-RBP)
23230 - movq_cfi r11, (R11-RBP)
23231 + /* start from r15 in pt_regs and jump over */
23232 + movq_cfi rdi, RDI
23233 + movq_cfi rsi, RSI
23234 + movq_cfi rdx, RDX
23235 + movq_cfi rcx, RCX
23236 + movq_cfi rax, RAX
23237 + movq_cfi r8, R8
23238 + movq_cfi r9, R9
23239 + movq_cfi r10, R10
23240 + movq_cfi r11, R11
23241 + movq_cfi r12, R12
23242
23243 /* Save rbp so that we can unwind from get_irq_regs() */
23244 - movq_cfi rbp, 0
23245 + movq_cfi rbp, RBP
23246
23247 /* Save previous stack value */
23248 movq %rsp, %rsi
23249
23250 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23251 - testl $3, CS-RBP(%rsi)
23252 + movq %rsp,%rdi /* arg1 for handler */
23253 + testb $3, CS(%rsi)
23254 je 1f
23255 SWAPGS
23256 /*
23257 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23258 0x06 /* DW_OP_deref */, \
23259 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23260 0x22 /* DW_OP_plus */
23261 +
23262 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23263 + testb $3, CS(%rdi)
23264 + jnz 1f
23265 + pax_enter_kernel
23266 + jmp 2f
23267 +1: pax_enter_kernel_user
23268 +2:
23269 +#else
23270 + pax_enter_kernel
23271 +#endif
23272 +
23273 /* We entered an interrupt context - irqs are off: */
23274 TRACE_IRQS_OFF
23275 .endm
23276 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23277 js 1f /* negative -> in kernel */
23278 SWAPGS
23279 xorl %ebx,%ebx
23280 -1: ret
23281 +1:
23282 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23283 + testb $3, CS+8(%rsp)
23284 + jnz 1f
23285 + pax_enter_kernel
23286 + jmp 2f
23287 +1: pax_enter_kernel_user
23288 +2:
23289 +#else
23290 + pax_enter_kernel
23291 +#endif
23292 + pax_force_retaddr
23293 + ret
23294 CFI_ENDPROC
23295 -END(save_paranoid)
23296 +ENDPROC(save_paranoid)
23297 +
23298 +ENTRY(save_paranoid_nmi)
23299 + XCPT_FRAME 1 RDI+8
23300 + cld
23301 + movq_cfi rdi, RDI+8
23302 + movq_cfi rsi, RSI+8
23303 + movq_cfi rdx, RDX+8
23304 + movq_cfi rcx, RCX+8
23305 + movq_cfi rax, RAX+8
23306 + movq_cfi r8, R8+8
23307 + movq_cfi r9, R9+8
23308 + movq_cfi r10, R10+8
23309 + movq_cfi r11, R11+8
23310 + movq_cfi rbx, RBX+8
23311 + movq_cfi rbp, RBP+8
23312 + movq_cfi r12, R12+8
23313 + movq_cfi r13, R13+8
23314 + movq_cfi r14, R14+8
23315 + movq_cfi r15, R15+8
23316 + movl $1,%ebx
23317 + movl $MSR_GS_BASE,%ecx
23318 + rdmsr
23319 + testl %edx,%edx
23320 + js 1f /* negative -> in kernel */
23321 + SWAPGS
23322 + xorl %ebx,%ebx
23323 +1: pax_enter_kernel_nmi
23324 + pax_force_retaddr
23325 + ret
23326 + CFI_ENDPROC
23327 +ENDPROC(save_paranoid_nmi)
23328 .popsection
23329
23330 /*
23331 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23332
23333 RESTORE_REST
23334
23335 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23336 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23337 jz 1f
23338
23339 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23340 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23341 jmp ret_from_sys_call # go to the SYSRET fastpath
23342
23343 1:
23344 - subq $REST_SKIP, %rsp # leave space for volatiles
23345 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23346 movq %rbp, %rdi
23347 call *%rbx
23348 movl $0, RAX(%rsp)
23349 RESTORE_REST
23350 jmp int_ret_from_sys_call
23351 CFI_ENDPROC
23352 -END(ret_from_fork)
23353 +ENDPROC(ret_from_fork)
23354
23355 /*
23356 * System call entry. Up to 6 arguments in registers are supported.
23357 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23358 ENTRY(system_call)
23359 CFI_STARTPROC simple
23360 CFI_SIGNAL_FRAME
23361 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23362 + CFI_DEF_CFA rsp,0
23363 CFI_REGISTER rip,rcx
23364 /*CFI_REGISTER rflags,r11*/
23365 SWAPGS_UNSAFE_STACK
23366 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23367
23368 movq %rsp,PER_CPU_VAR(old_rsp)
23369 movq PER_CPU_VAR(kernel_stack),%rsp
23370 + SAVE_ARGS 8*6,0
23371 + pax_enter_kernel_user
23372 +
23373 +#ifdef CONFIG_PAX_RANDKSTACK
23374 + pax_erase_kstack
23375 +#endif
23376 +
23377 /*
23378 * No need to follow this irqs off/on section - it's straight
23379 * and short:
23380 */
23381 ENABLE_INTERRUPTS(CLBR_NONE)
23382 - SAVE_ARGS 8,0
23383 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23384 movq %rcx,RIP-ARGOFFSET(%rsp)
23385 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23386 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23387 + GET_THREAD_INFO(%rcx)
23388 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23389 jnz tracesys
23390 system_call_fastpath:
23391 #if __SYSCALL_MASK == ~0
23392 @@ -639,10 +1112,13 @@ sysret_check:
23393 LOCKDEP_SYS_EXIT
23394 DISABLE_INTERRUPTS(CLBR_NONE)
23395 TRACE_IRQS_OFF
23396 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23397 + GET_THREAD_INFO(%rcx)
23398 + movl TI_flags(%rcx),%edx
23399 andl %edi,%edx
23400 jnz sysret_careful
23401 CFI_REMEMBER_STATE
23402 + pax_exit_kernel_user
23403 + pax_erase_kstack
23404 /*
23405 * sysretq will re-enable interrupts:
23406 */
23407 @@ -701,6 +1177,9 @@ auditsys:
23408 movq %rax,%rsi /* 2nd arg: syscall number */
23409 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23410 call __audit_syscall_entry
23411 +
23412 + pax_erase_kstack
23413 +
23414 LOAD_ARGS 0 /* reload call-clobbered registers */
23415 jmp system_call_fastpath
23416
23417 @@ -722,7 +1201,7 @@ sysret_audit:
23418 /* Do syscall tracing */
23419 tracesys:
23420 #ifdef CONFIG_AUDITSYSCALL
23421 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23422 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23423 jz auditsys
23424 #endif
23425 SAVE_REST
23426 @@ -730,12 +1209,15 @@ tracesys:
23427 FIXUP_TOP_OF_STACK %rdi
23428 movq %rsp,%rdi
23429 call syscall_trace_enter
23430 +
23431 + pax_erase_kstack
23432 +
23433 /*
23434 * Reload arg registers from stack in case ptrace changed them.
23435 * We don't reload %rax because syscall_trace_enter() returned
23436 * the value it wants us to use in the table lookup.
23437 */
23438 - LOAD_ARGS ARGOFFSET, 1
23439 + LOAD_ARGS 1
23440 RESTORE_REST
23441 #if __SYSCALL_MASK == ~0
23442 cmpq $__NR_syscall_max,%rax
23443 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23444 andl %edi,%edx
23445 jnz int_careful
23446 andl $~TS_COMPAT,TI_status(%rcx)
23447 - jmp retint_swapgs
23448 + pax_exit_kernel_user
23449 + pax_erase_kstack
23450 + jmp retint_swapgs_pax
23451
23452 /* Either reschedule or signal or syscall exit tracking needed. */
23453 /* First do a reschedule test. */
23454 @@ -811,7 +1295,7 @@ int_restore_rest:
23455 TRACE_IRQS_OFF
23456 jmp int_with_check
23457 CFI_ENDPROC
23458 -END(system_call)
23459 +ENDPROC(system_call)
23460
23461 .macro FORK_LIKE func
23462 ENTRY(stub_\func)
23463 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23464 DEFAULT_FRAME 0 8 /* offset 8: return address */
23465 call sys_\func
23466 RESTORE_TOP_OF_STACK %r11, 8
23467 - ret $REST_SKIP /* pop extended registers */
23468 + pax_force_retaddr
23469 + ret
23470 CFI_ENDPROC
23471 -END(stub_\func)
23472 +ENDPROC(stub_\func)
23473 .endm
23474
23475 .macro FIXED_FRAME label,func
23476 @@ -836,9 +1321,10 @@ ENTRY(\label)
23477 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23478 call \func
23479 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23480 + pax_force_retaddr
23481 ret
23482 CFI_ENDPROC
23483 -END(\label)
23484 +ENDPROC(\label)
23485 .endm
23486
23487 FORK_LIKE clone
23488 @@ -846,19 +1332,6 @@ END(\label)
23489 FORK_LIKE vfork
23490 FIXED_FRAME stub_iopl, sys_iopl
23491
23492 -ENTRY(ptregscall_common)
23493 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23494 - RESTORE_TOP_OF_STACK %r11, 8
23495 - movq_cfi_restore R15+8, r15
23496 - movq_cfi_restore R14+8, r14
23497 - movq_cfi_restore R13+8, r13
23498 - movq_cfi_restore R12+8, r12
23499 - movq_cfi_restore RBP+8, rbp
23500 - movq_cfi_restore RBX+8, rbx
23501 - ret $REST_SKIP /* pop extended registers */
23502 - CFI_ENDPROC
23503 -END(ptregscall_common)
23504 -
23505 ENTRY(stub_execve)
23506 CFI_STARTPROC
23507 addq $8, %rsp
23508 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23509 RESTORE_REST
23510 jmp int_ret_from_sys_call
23511 CFI_ENDPROC
23512 -END(stub_execve)
23513 +ENDPROC(stub_execve)
23514
23515 /*
23516 * sigreturn is special because it needs to restore all registers on return.
23517 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23518 RESTORE_REST
23519 jmp int_ret_from_sys_call
23520 CFI_ENDPROC
23521 -END(stub_rt_sigreturn)
23522 +ENDPROC(stub_rt_sigreturn)
23523
23524 #ifdef CONFIG_X86_X32_ABI
23525 ENTRY(stub_x32_rt_sigreturn)
23526 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23527 RESTORE_REST
23528 jmp int_ret_from_sys_call
23529 CFI_ENDPROC
23530 -END(stub_x32_rt_sigreturn)
23531 +ENDPROC(stub_x32_rt_sigreturn)
23532
23533 ENTRY(stub_x32_execve)
23534 CFI_STARTPROC
23535 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23536 RESTORE_REST
23537 jmp int_ret_from_sys_call
23538 CFI_ENDPROC
23539 -END(stub_x32_execve)
23540 +ENDPROC(stub_x32_execve)
23541
23542 #endif
23543
23544 @@ -952,7 +1425,7 @@ vector=vector+1
23545 2: jmp common_interrupt
23546 .endr
23547 CFI_ENDPROC
23548 -END(irq_entries_start)
23549 +ENDPROC(irq_entries_start)
23550
23551 .previous
23552 END(interrupt)
23553 @@ -969,8 +1442,8 @@ END(interrupt)
23554 /* 0(%rsp): ~(interrupt number) */
23555 .macro interrupt func
23556 /* reserve pt_regs for scratch regs and rbp */
23557 - subq $ORIG_RAX-RBP, %rsp
23558 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23559 + subq $ORIG_RAX, %rsp
23560 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23561 SAVE_ARGS_IRQ
23562 call \func
23563 .endm
23564 @@ -997,14 +1470,14 @@ ret_from_intr:
23565
23566 /* Restore saved previous stack */
23567 popq %rsi
23568 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23569 - leaq ARGOFFSET-RBP(%rsi), %rsp
23570 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23571 + movq %rsi, %rsp
23572 CFI_DEF_CFA_REGISTER rsp
23573 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23574 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23575
23576 exit_intr:
23577 GET_THREAD_INFO(%rcx)
23578 - testl $3,CS-ARGOFFSET(%rsp)
23579 + testb $3,CS-ARGOFFSET(%rsp)
23580 je retint_kernel
23581
23582 /* Interrupt came from user space */
23583 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23584 * The iretq could re-enable interrupts:
23585 */
23586 DISABLE_INTERRUPTS(CLBR_ANY)
23587 + pax_exit_kernel_user
23588 +retint_swapgs_pax:
23589 TRACE_IRQS_IRETQ
23590 SWAPGS
23591 jmp restore_args
23592
23593 retint_restore_args: /* return to kernel space */
23594 DISABLE_INTERRUPTS(CLBR_ANY)
23595 + pax_exit_kernel
23596 + pax_force_retaddr (RIP-ARGOFFSET)
23597 /*
23598 * The iretq could re-enable interrupts:
23599 */
23600 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23601 #endif
23602
23603 CFI_ENDPROC
23604 -END(common_interrupt)
23605 +ENDPROC(common_interrupt)
23606 /*
23607 * End of kprobes section
23608 */
23609 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23610 interrupt \do_sym
23611 jmp ret_from_intr
23612 CFI_ENDPROC
23613 -END(\sym)
23614 +ENDPROC(\sym)
23615 .endm
23616
23617 #ifdef CONFIG_TRACING
23618 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23619 call \do_sym
23620 jmp error_exit /* %ebx: no swapgs flag */
23621 CFI_ENDPROC
23622 -END(\sym)
23623 +ENDPROC(\sym)
23624 .endm
23625
23626 .macro paranoidzeroentry sym do_sym
23627 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23628 call \do_sym
23629 jmp paranoid_exit /* %ebx: no swapgs flag */
23630 CFI_ENDPROC
23631 -END(\sym)
23632 +ENDPROC(\sym)
23633 .endm
23634
23635 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23636 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23637 .macro paranoidzeroentry_ist sym do_sym ist
23638 ENTRY(\sym)
23639 INTR_FRAME
23640 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23641 TRACE_IRQS_OFF_DEBUG
23642 movq %rsp,%rdi /* pt_regs pointer */
23643 xorl %esi,%esi /* no error code */
23644 +#ifdef CONFIG_SMP
23645 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23646 + lea init_tss(%r13), %r13
23647 +#else
23648 + lea init_tss(%rip), %r13
23649 +#endif
23650 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23651 call \do_sym
23652 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23653 jmp paranoid_exit /* %ebx: no swapgs flag */
23654 CFI_ENDPROC
23655 -END(\sym)
23656 +ENDPROC(\sym)
23657 .endm
23658
23659 .macro errorentry sym do_sym
23660 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23661 call \do_sym
23662 jmp error_exit /* %ebx: no swapgs flag */
23663 CFI_ENDPROC
23664 -END(\sym)
23665 +ENDPROC(\sym)
23666 .endm
23667
23668 #ifdef CONFIG_TRACING
23669 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23670 call \do_sym
23671 jmp paranoid_exit /* %ebx: no swapgs flag */
23672 CFI_ENDPROC
23673 -END(\sym)
23674 +ENDPROC(\sym)
23675 .endm
23676
23677 zeroentry divide_error do_divide_error
23678 @@ -1336,9 +1819,10 @@ gs_change:
23679 2: mfence /* workaround */
23680 SWAPGS
23681 popfq_cfi
23682 + pax_force_retaddr
23683 ret
23684 CFI_ENDPROC
23685 -END(native_load_gs_index)
23686 +ENDPROC(native_load_gs_index)
23687
23688 _ASM_EXTABLE(gs_change,bad_gs)
23689 .section .fixup,"ax"
23690 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23691 CFI_DEF_CFA_REGISTER rsp
23692 CFI_ADJUST_CFA_OFFSET -8
23693 decl PER_CPU_VAR(irq_count)
23694 + pax_force_retaddr
23695 ret
23696 CFI_ENDPROC
23697 -END(do_softirq_own_stack)
23698 +ENDPROC(do_softirq_own_stack)
23699
23700 #ifdef CONFIG_XEN
23701 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23702 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23703 decl PER_CPU_VAR(irq_count)
23704 jmp error_exit
23705 CFI_ENDPROC
23706 -END(xen_do_hypervisor_callback)
23707 +ENDPROC(xen_do_hypervisor_callback)
23708
23709 /*
23710 * Hypervisor uses this for application faults while it executes.
23711 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23712 SAVE_ALL
23713 jmp error_exit
23714 CFI_ENDPROC
23715 -END(xen_failsafe_callback)
23716 +ENDPROC(xen_failsafe_callback)
23717
23718 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23719 xen_hvm_callback_vector xen_evtchn_do_upcall
23720 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23721 DEFAULT_FRAME
23722 DISABLE_INTERRUPTS(CLBR_NONE)
23723 TRACE_IRQS_OFF_DEBUG
23724 - testl %ebx,%ebx /* swapgs needed? */
23725 + testl $1,%ebx /* swapgs needed? */
23726 jnz paranoid_restore
23727 - testl $3,CS(%rsp)
23728 + testb $3,CS(%rsp)
23729 jnz paranoid_userspace
23730 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23731 + pax_exit_kernel
23732 + TRACE_IRQS_IRETQ 0
23733 + SWAPGS_UNSAFE_STACK
23734 + RESTORE_ALL 8
23735 + pax_force_retaddr_bts
23736 + jmp irq_return
23737 +#endif
23738 paranoid_swapgs:
23739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23740 + pax_exit_kernel_user
23741 +#else
23742 + pax_exit_kernel
23743 +#endif
23744 TRACE_IRQS_IRETQ 0
23745 SWAPGS_UNSAFE_STACK
23746 RESTORE_ALL 8
23747 jmp irq_return
23748 paranoid_restore:
23749 + pax_exit_kernel
23750 TRACE_IRQS_IRETQ_DEBUG 0
23751 RESTORE_ALL 8
23752 + pax_force_retaddr_bts
23753 jmp irq_return
23754 paranoid_userspace:
23755 GET_THREAD_INFO(%rcx)
23756 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23757 TRACE_IRQS_OFF
23758 jmp paranoid_userspace
23759 CFI_ENDPROC
23760 -END(paranoid_exit)
23761 +ENDPROC(paranoid_exit)
23762
23763 /*
23764 * Exception entry point. This expects an error code/orig_rax on the stack.
23765 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23766 movq_cfi r14, R14+8
23767 movq_cfi r15, R15+8
23768 xorl %ebx,%ebx
23769 - testl $3,CS+8(%rsp)
23770 + testb $3,CS+8(%rsp)
23771 je error_kernelspace
23772 error_swapgs:
23773 SWAPGS
23774 error_sti:
23775 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23776 + testb $3, CS+8(%rsp)
23777 + jnz 1f
23778 + pax_enter_kernel
23779 + jmp 2f
23780 +1: pax_enter_kernel_user
23781 +2:
23782 +#else
23783 + pax_enter_kernel
23784 +#endif
23785 TRACE_IRQS_OFF
23786 + pax_force_retaddr
23787 ret
23788
23789 /*
23790 @@ -1616,7 +2127,7 @@ bstep_iret:
23791 movq %rcx,RIP+8(%rsp)
23792 jmp error_swapgs
23793 CFI_ENDPROC
23794 -END(error_entry)
23795 +ENDPROC(error_entry)
23796
23797
23798 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23799 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23800 DISABLE_INTERRUPTS(CLBR_NONE)
23801 TRACE_IRQS_OFF
23802 GET_THREAD_INFO(%rcx)
23803 - testl %eax,%eax
23804 + testl $1,%eax
23805 jne retint_kernel
23806 LOCKDEP_SYS_EXIT_IRQ
23807 movl TI_flags(%rcx),%edx
23808 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23809 jnz retint_careful
23810 jmp retint_swapgs
23811 CFI_ENDPROC
23812 -END(error_exit)
23813 +ENDPROC(error_exit)
23814
23815 /*
23816 * Test if a given stack is an NMI stack or not.
23817 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23818 * If %cs was not the kernel segment, then the NMI triggered in user
23819 * space, which means it is definitely not nested.
23820 */
23821 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23822 + je 1f
23823 cmpl $__KERNEL_CS, 16(%rsp)
23824 jne first_nmi
23825 -
23826 +1:
23827 /*
23828 * Check the special variable on the stack to see if NMIs are
23829 * executing.
23830 @@ -1730,8 +2243,7 @@ nested_nmi:
23831
23832 1:
23833 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23834 - leaq -1*8(%rsp), %rdx
23835 - movq %rdx, %rsp
23836 + subq $8, %rsp
23837 CFI_ADJUST_CFA_OFFSET 1*8
23838 leaq -10*8(%rsp), %rdx
23839 pushq_cfi $__KERNEL_DS
23840 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23841 CFI_RESTORE rdx
23842
23843 /* No need to check faults here */
23844 +# pax_force_retaddr_bts
23845 INTERRUPT_RETURN
23846
23847 CFI_RESTORE_STATE
23848 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23849 subq $ORIG_RAX-R15, %rsp
23850 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23851 /*
23852 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23853 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23854 * as we should not be calling schedule in NMI context.
23855 * Even with normal interrupts enabled. An NMI should not be
23856 * setting NEED_RESCHED or anything that normal interrupts and
23857 * exceptions might do.
23858 */
23859 - call save_paranoid
23860 + call save_paranoid_nmi
23861 DEFAULT_FRAME 0
23862
23863 /*
23864 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23865 * NMI itself takes a page fault, the page fault that was preempted
23866 * will read the information from the NMI page fault and not the
23867 * origin fault. Save it off and restore it if it changes.
23868 - * Use the r12 callee-saved register.
23869 + * Use the r13 callee-saved register.
23870 */
23871 - movq %cr2, %r12
23872 + movq %cr2, %r13
23873
23874 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23875 movq %rsp,%rdi
23876 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23877
23878 /* Did the NMI take a page fault? Restore cr2 if it did */
23879 movq %cr2, %rcx
23880 - cmpq %rcx, %r12
23881 + cmpq %rcx, %r13
23882 je 1f
23883 - movq %r12, %cr2
23884 + movq %r13, %cr2
23885 1:
23886
23887 - testl %ebx,%ebx /* swapgs needed? */
23888 + testl $1,%ebx /* swapgs needed? */
23889 jnz nmi_restore
23890 nmi_swapgs:
23891 SWAPGS_UNSAFE_STACK
23892 nmi_restore:
23893 + pax_exit_kernel_nmi
23894 /* Pop the extra iret frame at once */
23895 RESTORE_ALL 6*8
23896 + testb $3, 8(%rsp)
23897 + jnz 1f
23898 + pax_force_retaddr_bts
23899 +1:
23900
23901 /* Clear the NMI executing stack variable */
23902 movq $0, 5*8(%rsp)
23903 jmp irq_return
23904 CFI_ENDPROC
23905 -END(nmi)
23906 +ENDPROC(nmi)
23907
23908 ENTRY(ignore_sysret)
23909 CFI_STARTPROC
23910 mov $-ENOSYS,%eax
23911 sysret
23912 CFI_ENDPROC
23913 -END(ignore_sysret)
23914 +ENDPROC(ignore_sysret)
23915
23916 /*
23917 * End of kprobes section
23918 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23919 index e625319..b9abb9d 100644
23920 --- a/arch/x86/kernel/ftrace.c
23921 +++ b/arch/x86/kernel/ftrace.c
23922 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23923 {
23924 unsigned char replaced[MCOUNT_INSN_SIZE];
23925
23926 + ip = ktla_ktva(ip);
23927 +
23928 /*
23929 * Note: Due to modules and __init, code can
23930 * disappear and change, we need to protect against faulting
23931 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23932 unsigned char old[MCOUNT_INSN_SIZE];
23933 int ret;
23934
23935 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23936 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23937
23938 ftrace_update_func = ip;
23939 /* Make sure the breakpoints see the ftrace_update_func update */
23940 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23941 * kernel identity mapping to modify code.
23942 */
23943 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23944 - ip = (unsigned long)__va(__pa_symbol(ip));
23945 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23946
23947 return probe_kernel_write((void *)ip, val, size);
23948 }
23949 @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23950 unsigned char replaced[MCOUNT_INSN_SIZE];
23951 unsigned char brk = BREAKPOINT_INSTRUCTION;
23952
23953 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23954 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23955 return -EFAULT;
23956
23957 /* Make sure it is what we expect it to be */
23958 @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23959 return ret;
23960
23961 fail_update:
23962 - probe_kernel_write((void *)ip, &old_code[0], 1);
23963 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23964 goto out;
23965 }
23966
23967 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23968 index 85126cc..1bbce17 100644
23969 --- a/arch/x86/kernel/head64.c
23970 +++ b/arch/x86/kernel/head64.c
23971 @@ -67,12 +67,12 @@ again:
23972 pgd = *pgd_p;
23973
23974 /*
23975 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23976 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23977 + * The use of __early_va rather than __va here is critical:
23978 + * __va would point us back into the dynamic
23979 * range and we might end up looping forever...
23980 */
23981 if (pgd)
23982 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23983 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23984 else {
23985 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23986 reset_early_page_tables();
23987 @@ -82,13 +82,13 @@ again:
23988 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23989 for (i = 0; i < PTRS_PER_PUD; i++)
23990 pud_p[i] = 0;
23991 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23992 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23993 }
23994 pud_p += pud_index(address);
23995 pud = *pud_p;
23996
23997 if (pud)
23998 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23999 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24000 else {
24001 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24002 reset_early_page_tables();
24003 @@ -98,7 +98,7 @@ again:
24004 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24005 for (i = 0; i < PTRS_PER_PMD; i++)
24006 pmd_p[i] = 0;
24007 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24008 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24009 }
24010 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24011 pmd_p[pmd_index(address)] = pmd;
24012 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24013 if (console_loglevel == 10)
24014 early_printk("Kernel alive\n");
24015
24016 - clear_page(init_level4_pgt);
24017 /* set init_level4_pgt kernel high mapping*/
24018 init_level4_pgt[511] = early_level4_pgt[511];
24019
24020 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24021 index f36bd42..56ee1534 100644
24022 --- a/arch/x86/kernel/head_32.S
24023 +++ b/arch/x86/kernel/head_32.S
24024 @@ -26,6 +26,12 @@
24025 /* Physical address */
24026 #define pa(X) ((X) - __PAGE_OFFSET)
24027
24028 +#ifdef CONFIG_PAX_KERNEXEC
24029 +#define ta(X) (X)
24030 +#else
24031 +#define ta(X) ((X) - __PAGE_OFFSET)
24032 +#endif
24033 +
24034 /*
24035 * References to members of the new_cpu_data structure.
24036 */
24037 @@ -55,11 +61,7 @@
24038 * and small than max_low_pfn, otherwise will waste some page table entries
24039 */
24040
24041 -#if PTRS_PER_PMD > 1
24042 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24043 -#else
24044 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24045 -#endif
24046 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24047
24048 /* Number of possible pages in the lowmem region */
24049 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24050 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24051 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24052
24053 /*
24054 + * Real beginning of normal "text" segment
24055 + */
24056 +ENTRY(stext)
24057 +ENTRY(_stext)
24058 +
24059 +/*
24060 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24061 * %esi points to the real-mode code as a 32-bit pointer.
24062 * CS and DS must be 4 GB flat segments, but we don't depend on
24063 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24064 * can.
24065 */
24066 __HEAD
24067 +
24068 +#ifdef CONFIG_PAX_KERNEXEC
24069 + jmp startup_32
24070 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24071 +.fill PAGE_SIZE-5,1,0xcc
24072 +#endif
24073 +
24074 ENTRY(startup_32)
24075 movl pa(stack_start),%ecx
24076
24077 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24078 2:
24079 leal -__PAGE_OFFSET(%ecx),%esp
24080
24081 +#ifdef CONFIG_SMP
24082 + movl $pa(cpu_gdt_table),%edi
24083 + movl $__per_cpu_load,%eax
24084 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24085 + rorl $16,%eax
24086 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24087 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24088 + movl $__per_cpu_end - 1,%eax
24089 + subl $__per_cpu_start,%eax
24090 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24091 +#endif
24092 +
24093 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24094 + movl $NR_CPUS,%ecx
24095 + movl $pa(cpu_gdt_table),%edi
24096 +1:
24097 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24098 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24099 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24100 + addl $PAGE_SIZE_asm,%edi
24101 + loop 1b
24102 +#endif
24103 +
24104 +#ifdef CONFIG_PAX_KERNEXEC
24105 + movl $pa(boot_gdt),%edi
24106 + movl $__LOAD_PHYSICAL_ADDR,%eax
24107 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24108 + rorl $16,%eax
24109 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24110 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24111 + rorl $16,%eax
24112 +
24113 + ljmp $(__BOOT_CS),$1f
24114 +1:
24115 +
24116 + movl $NR_CPUS,%ecx
24117 + movl $pa(cpu_gdt_table),%edi
24118 + addl $__PAGE_OFFSET,%eax
24119 +1:
24120 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24121 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24122 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24123 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24124 + rorl $16,%eax
24125 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24126 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24127 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24128 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24129 + rorl $16,%eax
24130 + addl $PAGE_SIZE_asm,%edi
24131 + loop 1b
24132 +#endif
24133 +
24134 /*
24135 * Clear BSS first so that there are no surprises...
24136 */
24137 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24138 movl %eax, pa(max_pfn_mapped)
24139
24140 /* Do early initialization of the fixmap area */
24141 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24142 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24143 +#ifdef CONFIG_COMPAT_VDSO
24144 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24145 +#else
24146 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24147 +#endif
24148 #else /* Not PAE */
24149
24150 page_pde_offset = (__PAGE_OFFSET >> 20);
24151 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24152 movl %eax, pa(max_pfn_mapped)
24153
24154 /* Do early initialization of the fixmap area */
24155 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24156 - movl %eax,pa(initial_page_table+0xffc)
24157 +#ifdef CONFIG_COMPAT_VDSO
24158 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24159 +#else
24160 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24161 +#endif
24162 #endif
24163
24164 #ifdef CONFIG_PARAVIRT
24165 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24166 cmpl $num_subarch_entries, %eax
24167 jae bad_subarch
24168
24169 - movl pa(subarch_entries)(,%eax,4), %eax
24170 - subl $__PAGE_OFFSET, %eax
24171 - jmp *%eax
24172 + jmp *pa(subarch_entries)(,%eax,4)
24173
24174 bad_subarch:
24175 WEAK(lguest_entry)
24176 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24177 __INITDATA
24178
24179 subarch_entries:
24180 - .long default_entry /* normal x86/PC */
24181 - .long lguest_entry /* lguest hypervisor */
24182 - .long xen_entry /* Xen hypervisor */
24183 - .long default_entry /* Moorestown MID */
24184 + .long ta(default_entry) /* normal x86/PC */
24185 + .long ta(lguest_entry) /* lguest hypervisor */
24186 + .long ta(xen_entry) /* Xen hypervisor */
24187 + .long ta(default_entry) /* Moorestown MID */
24188 num_subarch_entries = (. - subarch_entries) / 4
24189 .previous
24190 #else
24191 @@ -354,6 +426,7 @@ default_entry:
24192 movl pa(mmu_cr4_features),%eax
24193 movl %eax,%cr4
24194
24195 +#ifdef CONFIG_X86_PAE
24196 testb $X86_CR4_PAE, %al # check if PAE is enabled
24197 jz enable_paging
24198
24199 @@ -382,6 +455,9 @@ default_entry:
24200 /* Make changes effective */
24201 wrmsr
24202
24203 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24204 +#endif
24205 +
24206 enable_paging:
24207
24208 /*
24209 @@ -449,14 +525,20 @@ is486:
24210 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24211 movl %eax,%ss # after changing gdt.
24212
24213 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24214 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24215 movl %eax,%ds
24216 movl %eax,%es
24217
24218 movl $(__KERNEL_PERCPU), %eax
24219 movl %eax,%fs # set this cpu's percpu
24220
24221 +#ifdef CONFIG_CC_STACKPROTECTOR
24222 movl $(__KERNEL_STACK_CANARY),%eax
24223 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24224 + movl $(__USER_DS),%eax
24225 +#else
24226 + xorl %eax,%eax
24227 +#endif
24228 movl %eax,%gs
24229
24230 xorl %eax,%eax # Clear LDT
24231 @@ -512,8 +594,11 @@ setup_once:
24232 * relocation. Manually set base address in stack canary
24233 * segment descriptor.
24234 */
24235 - movl $gdt_page,%eax
24236 + movl $cpu_gdt_table,%eax
24237 movl $stack_canary,%ecx
24238 +#ifdef CONFIG_SMP
24239 + addl $__per_cpu_load,%ecx
24240 +#endif
24241 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24242 shrl $16, %ecx
24243 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24244 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24245 cmpl $2,(%esp) # X86_TRAP_NMI
24246 je is_nmi # Ignore NMI
24247
24248 - cmpl $2,%ss:early_recursion_flag
24249 + cmpl $1,%ss:early_recursion_flag
24250 je hlt_loop
24251 incl %ss:early_recursion_flag
24252
24253 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24254 pushl (20+6*4)(%esp) /* trapno */
24255 pushl $fault_msg
24256 call printk
24257 -#endif
24258 call dump_stack
24259 +#endif
24260 hlt_loop:
24261 hlt
24262 jmp hlt_loop
24263 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24264 /* This is the default interrupt "handler" :-) */
24265 ALIGN
24266 ignore_int:
24267 - cld
24268 #ifdef CONFIG_PRINTK
24269 + cmpl $2,%ss:early_recursion_flag
24270 + je hlt_loop
24271 + incl %ss:early_recursion_flag
24272 + cld
24273 pushl %eax
24274 pushl %ecx
24275 pushl %edx
24276 @@ -617,9 +705,6 @@ ignore_int:
24277 movl $(__KERNEL_DS),%eax
24278 movl %eax,%ds
24279 movl %eax,%es
24280 - cmpl $2,early_recursion_flag
24281 - je hlt_loop
24282 - incl early_recursion_flag
24283 pushl 16(%esp)
24284 pushl 24(%esp)
24285 pushl 32(%esp)
24286 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24287 /*
24288 * BSS section
24289 */
24290 -__PAGE_ALIGNED_BSS
24291 - .align PAGE_SIZE
24292 #ifdef CONFIG_X86_PAE
24293 +.section .initial_pg_pmd,"a",@progbits
24294 initial_pg_pmd:
24295 .fill 1024*KPMDS,4,0
24296 #else
24297 +.section .initial_page_table,"a",@progbits
24298 ENTRY(initial_page_table)
24299 .fill 1024,4,0
24300 #endif
24301 +.section .initial_pg_fixmap,"a",@progbits
24302 initial_pg_fixmap:
24303 .fill 1024,4,0
24304 +.section .empty_zero_page,"a",@progbits
24305 ENTRY(empty_zero_page)
24306 .fill 4096,1,0
24307 +.section .swapper_pg_dir,"a",@progbits
24308 ENTRY(swapper_pg_dir)
24309 +#ifdef CONFIG_X86_PAE
24310 + .fill 4,8,0
24311 +#else
24312 .fill 1024,4,0
24313 +#endif
24314
24315 /*
24316 * This starts the data section.
24317 */
24318 #ifdef CONFIG_X86_PAE
24319 -__PAGE_ALIGNED_DATA
24320 - /* Page-aligned for the benefit of paravirt? */
24321 - .align PAGE_SIZE
24322 +.section .initial_page_table,"a",@progbits
24323 ENTRY(initial_page_table)
24324 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24325 # if KPMDS == 3
24326 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24327 # error "Kernel PMDs should be 1, 2 or 3"
24328 # endif
24329 .align PAGE_SIZE /* needs to be page-sized too */
24330 +
24331 +#ifdef CONFIG_PAX_PER_CPU_PGD
24332 +ENTRY(cpu_pgd)
24333 + .rept 2*NR_CPUS
24334 + .fill 4,8,0
24335 + .endr
24336 +#endif
24337 +
24338 #endif
24339
24340 .data
24341 .balign 4
24342 ENTRY(stack_start)
24343 - .long init_thread_union+THREAD_SIZE
24344 + .long init_thread_union+THREAD_SIZE-8
24345
24346 __INITRODATA
24347 int_msg:
24348 @@ -727,7 +825,7 @@ fault_msg:
24349 * segment size, and 32-bit linear address value:
24350 */
24351
24352 - .data
24353 +.section .rodata,"a",@progbits
24354 .globl boot_gdt_descr
24355 .globl idt_descr
24356
24357 @@ -736,7 +834,7 @@ fault_msg:
24358 .word 0 # 32 bit align gdt_desc.address
24359 boot_gdt_descr:
24360 .word __BOOT_DS+7
24361 - .long boot_gdt - __PAGE_OFFSET
24362 + .long pa(boot_gdt)
24363
24364 .word 0 # 32-bit align idt_desc.address
24365 idt_descr:
24366 @@ -747,7 +845,7 @@ idt_descr:
24367 .word 0 # 32 bit align gdt_desc.address
24368 ENTRY(early_gdt_descr)
24369 .word GDT_ENTRIES*8-1
24370 - .long gdt_page /* Overwritten for secondary CPUs */
24371 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24372
24373 /*
24374 * The boot_gdt must mirror the equivalent in setup.S and is
24375 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24376 .align L1_CACHE_BYTES
24377 ENTRY(boot_gdt)
24378 .fill GDT_ENTRY_BOOT_CS,8,0
24379 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24380 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24381 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24382 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24383 +
24384 + .align PAGE_SIZE_asm
24385 +ENTRY(cpu_gdt_table)
24386 + .rept NR_CPUS
24387 + .quad 0x0000000000000000 /* NULL descriptor */
24388 + .quad 0x0000000000000000 /* 0x0b reserved */
24389 + .quad 0x0000000000000000 /* 0x13 reserved */
24390 + .quad 0x0000000000000000 /* 0x1b reserved */
24391 +
24392 +#ifdef CONFIG_PAX_KERNEXEC
24393 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24394 +#else
24395 + .quad 0x0000000000000000 /* 0x20 unused */
24396 +#endif
24397 +
24398 + .quad 0x0000000000000000 /* 0x28 unused */
24399 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24400 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24401 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24402 + .quad 0x0000000000000000 /* 0x4b reserved */
24403 + .quad 0x0000000000000000 /* 0x53 reserved */
24404 + .quad 0x0000000000000000 /* 0x5b reserved */
24405 +
24406 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24407 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24408 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24409 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24410 +
24411 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24412 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24413 +
24414 + /*
24415 + * Segments used for calling PnP BIOS have byte granularity.
24416 + * The code segments and data segments have fixed 64k limits,
24417 + * the transfer segment sizes are set at run time.
24418 + */
24419 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24420 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24421 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24422 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24423 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24424 +
24425 + /*
24426 + * The APM segments have byte granularity and their bases
24427 + * are set at run time. All have 64k limits.
24428 + */
24429 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24430 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24431 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24432 +
24433 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24434 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24435 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24436 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24437 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24438 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24439 +
24440 + /* Be sure this is zeroed to avoid false validations in Xen */
24441 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24442 + .endr
24443 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24444 index a468c0a..c7dec74 100644
24445 --- a/arch/x86/kernel/head_64.S
24446 +++ b/arch/x86/kernel/head_64.S
24447 @@ -20,6 +20,8 @@
24448 #include <asm/processor-flags.h>
24449 #include <asm/percpu.h>
24450 #include <asm/nops.h>
24451 +#include <asm/cpufeature.h>
24452 +#include <asm/alternative-asm.h>
24453
24454 #ifdef CONFIG_PARAVIRT
24455 #include <asm/asm-offsets.h>
24456 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24457 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24458 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24459 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24460 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24461 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24462 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24463 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24464 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24465 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24466
24467 .text
24468 __HEAD
24469 @@ -89,11 +97,24 @@ startup_64:
24470 * Fixup the physical addresses in the page table
24471 */
24472 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24473 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24474 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24475 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24476 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24477 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24478
24479 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24480 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24481 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24482 +#ifndef CONFIG_XEN
24483 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24484 +#endif
24485 +
24486 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24487 +
24488 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24489 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24490
24491 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24492 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24493
24494 /*
24495 * Set up the identity mapping for the switchover. These
24496 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24497 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24498 1:
24499
24500 - /* Enable PAE mode and PGE */
24501 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24502 + /* Enable PAE mode and PSE/PGE */
24503 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24504 movq %rcx, %cr4
24505
24506 /* Setup early boot stage 4 level pagetables. */
24507 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24508 movl $MSR_EFER, %ecx
24509 rdmsr
24510 btsl $_EFER_SCE, %eax /* Enable System Call */
24511 - btl $20,%edi /* No Execute supported? */
24512 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24513 jnc 1f
24514 btsl $_EFER_NX, %eax
24515 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24516 +#ifndef CONFIG_EFI
24517 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24518 +#endif
24519 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24520 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24521 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24522 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24523 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24524 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24525 1: wrmsr /* Make changes effective */
24526
24527 /* Setup cr0 */
24528 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24529 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24530 * address given in m16:64.
24531 */
24532 + pax_set_fptr_mask
24533 movq initial_code(%rip),%rax
24534 pushq $0 # fake return address to stop unwinder
24535 pushq $__KERNEL_CS # set correct cs
24536 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24537 .quad INIT_PER_CPU_VAR(irq_stack_union)
24538
24539 GLOBAL(stack_start)
24540 - .quad init_thread_union+THREAD_SIZE-8
24541 + .quad init_thread_union+THREAD_SIZE-16
24542 .word 0
24543 __FINITDATA
24544
24545 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24546 call dump_stack
24547 #ifdef CONFIG_KALLSYMS
24548 leaq early_idt_ripmsg(%rip),%rdi
24549 - movq 40(%rsp),%rsi # %rip again
24550 + movq 88(%rsp),%rsi # %rip again
24551 call __print_symbol
24552 #endif
24553 #endif /* EARLY_PRINTK */
24554 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24555 early_recursion_flag:
24556 .long 0
24557
24558 + .section .rodata,"a",@progbits
24559 #ifdef CONFIG_EARLY_PRINTK
24560 early_idt_msg:
24561 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24562 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24563 NEXT_PAGE(early_dynamic_pgts)
24564 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24565
24566 - .data
24567 + .section .rodata,"a",@progbits
24568
24569 -#ifndef CONFIG_XEN
24570 NEXT_PAGE(init_level4_pgt)
24571 - .fill 512,8,0
24572 -#else
24573 -NEXT_PAGE(init_level4_pgt)
24574 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24575 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24576 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24577 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24578 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24579 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24580 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24581 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24582 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24583 .org init_level4_pgt + L4_START_KERNEL*8, 0
24584 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24585 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24586
24587 +#ifdef CONFIG_PAX_PER_CPU_PGD
24588 +NEXT_PAGE(cpu_pgd)
24589 + .rept 2*NR_CPUS
24590 + .fill 512,8,0
24591 + .endr
24592 +#endif
24593 +
24594 NEXT_PAGE(level3_ident_pgt)
24595 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24596 +#ifdef CONFIG_XEN
24597 .fill 511, 8, 0
24598 +#else
24599 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24600 + .fill 510,8,0
24601 +#endif
24602 +
24603 +NEXT_PAGE(level3_vmalloc_start_pgt)
24604 + .fill 512,8,0
24605 +
24606 +NEXT_PAGE(level3_vmalloc_end_pgt)
24607 + .fill 512,8,0
24608 +
24609 +NEXT_PAGE(level3_vmemmap_pgt)
24610 + .fill L3_VMEMMAP_START,8,0
24611 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24612 +
24613 NEXT_PAGE(level2_ident_pgt)
24614 - /* Since I easily can, map the first 1G.
24615 + /* Since I easily can, map the first 2G.
24616 * Don't set NX because code runs from these pages.
24617 */
24618 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24619 -#endif
24620 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24621
24622 NEXT_PAGE(level3_kernel_pgt)
24623 .fill L3_START_KERNEL,8,0
24624 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24625 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24626 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24627
24628 +NEXT_PAGE(level2_vmemmap_pgt)
24629 + .fill 512,8,0
24630 +
24631 NEXT_PAGE(level2_kernel_pgt)
24632 /*
24633 * 512 MB kernel mapping. We spend a full page on this pagetable
24634 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24635 NEXT_PAGE(level2_fixmap_pgt)
24636 .fill 506,8,0
24637 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24638 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24639 - .fill 5,8,0
24640 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24641 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24642 + .fill 4,8,0
24643
24644 NEXT_PAGE(level1_fixmap_pgt)
24645 .fill 512,8,0
24646
24647 +NEXT_PAGE(level1_vsyscall_pgt)
24648 + .fill 512,8,0
24649 +
24650 #undef PMDS
24651
24652 - .data
24653 + .align PAGE_SIZE
24654 +ENTRY(cpu_gdt_table)
24655 + .rept NR_CPUS
24656 + .quad 0x0000000000000000 /* NULL descriptor */
24657 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24658 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24659 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24660 + .quad 0x00cffb000000ffff /* __USER32_CS */
24661 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24662 + .quad 0x00affb000000ffff /* __USER_CS */
24663 +
24664 +#ifdef CONFIG_PAX_KERNEXEC
24665 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24666 +#else
24667 + .quad 0x0 /* unused */
24668 +#endif
24669 +
24670 + .quad 0,0 /* TSS */
24671 + .quad 0,0 /* LDT */
24672 + .quad 0,0,0 /* three TLS descriptors */
24673 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24674 + /* asm/segment.h:GDT_ENTRIES must match this */
24675 +
24676 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24677 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24678 +#else
24679 + .quad 0x0 /* unused */
24680 +#endif
24681 +
24682 + /* zero the remaining page */
24683 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24684 + .endr
24685 +
24686 .align 16
24687 .globl early_gdt_descr
24688 early_gdt_descr:
24689 .word GDT_ENTRIES*8-1
24690 early_gdt_descr_base:
24691 - .quad INIT_PER_CPU_VAR(gdt_page)
24692 + .quad cpu_gdt_table
24693
24694 ENTRY(phys_base)
24695 /* This must match the first entry in level2_kernel_pgt */
24696 .quad 0x0000000000000000
24697
24698 #include "../../x86/xen/xen-head.S"
24699 -
24700 - __PAGE_ALIGNED_BSS
24701 +
24702 + .section .rodata,"a",@progbits
24703 NEXT_PAGE(empty_zero_page)
24704 .skip PAGE_SIZE
24705 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24706 index 05fd74f..c3548b1 100644
24707 --- a/arch/x86/kernel/i386_ksyms_32.c
24708 +++ b/arch/x86/kernel/i386_ksyms_32.c
24709 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24710 EXPORT_SYMBOL(cmpxchg8b_emu);
24711 #endif
24712
24713 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24714 +
24715 /* Networking helper routines. */
24716 EXPORT_SYMBOL(csum_partial_copy_generic);
24717 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24718 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24719
24720 EXPORT_SYMBOL(__get_user_1);
24721 EXPORT_SYMBOL(__get_user_2);
24722 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24723 EXPORT_SYMBOL(___preempt_schedule_context);
24724 #endif
24725 #endif
24726 +
24727 +#ifdef CONFIG_PAX_KERNEXEC
24728 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24729 +#endif
24730 +
24731 +#ifdef CONFIG_PAX_PER_CPU_PGD
24732 +EXPORT_SYMBOL(cpu_pgd);
24733 +#endif
24734 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24735 index d5dd808..b6432cf 100644
24736 --- a/arch/x86/kernel/i387.c
24737 +++ b/arch/x86/kernel/i387.c
24738 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24739 static inline bool interrupted_user_mode(void)
24740 {
24741 struct pt_regs *regs = get_irq_regs();
24742 - return regs && user_mode_vm(regs);
24743 + return regs && user_mode(regs);
24744 }
24745
24746 /*
24747 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24748 index 2e977b5..5f2c273 100644
24749 --- a/arch/x86/kernel/i8259.c
24750 +++ b/arch/x86/kernel/i8259.c
24751 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24752 static void make_8259A_irq(unsigned int irq)
24753 {
24754 disable_irq_nosync(irq);
24755 - io_apic_irqs &= ~(1<<irq);
24756 + io_apic_irqs &= ~(1UL<<irq);
24757 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24758 i8259A_chip.name);
24759 enable_irq(irq);
24760 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24761 "spurious 8259A interrupt: IRQ%d.\n", irq);
24762 spurious_irq_mask |= irqmask;
24763 }
24764 - atomic_inc(&irq_err_count);
24765 + atomic_inc_unchecked(&irq_err_count);
24766 /*
24767 * Theoretically we do not have to handle this IRQ,
24768 * but in Linux this does not cause problems and is
24769 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24770 /* (slave's support for AEOI in flat mode is to be investigated) */
24771 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24772
24773 + pax_open_kernel();
24774 if (auto_eoi)
24775 /*
24776 * In AEOI mode we just have to mask the interrupt
24777 * when acking.
24778 */
24779 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24780 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24781 else
24782 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24783 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24784 + pax_close_kernel();
24785
24786 udelay(100); /* wait for 8259A to initialize */
24787
24788 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24789 index a979b5b..1d6db75 100644
24790 --- a/arch/x86/kernel/io_delay.c
24791 +++ b/arch/x86/kernel/io_delay.c
24792 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24793 * Quirk table for systems that misbehave (lock up, etc.) if port
24794 * 0x80 is used:
24795 */
24796 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24797 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24798 {
24799 .callback = dmi_io_delay_0xed_port,
24800 .ident = "Compaq Presario V6000",
24801 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24802 index 4ddaf66..49d5c18 100644
24803 --- a/arch/x86/kernel/ioport.c
24804 +++ b/arch/x86/kernel/ioport.c
24805 @@ -6,6 +6,7 @@
24806 #include <linux/sched.h>
24807 #include <linux/kernel.h>
24808 #include <linux/capability.h>
24809 +#include <linux/security.h>
24810 #include <linux/errno.h>
24811 #include <linux/types.h>
24812 #include <linux/ioport.h>
24813 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24814 return -EINVAL;
24815 if (turn_on && !capable(CAP_SYS_RAWIO))
24816 return -EPERM;
24817 +#ifdef CONFIG_GRKERNSEC_IO
24818 + if (turn_on && grsec_disable_privio) {
24819 + gr_handle_ioperm();
24820 + return -ENODEV;
24821 + }
24822 +#endif
24823
24824 /*
24825 * If it's the first ioperm() call in this thread's lifetime, set the
24826 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24827 * because the ->io_bitmap_max value must match the bitmap
24828 * contents:
24829 */
24830 - tss = &per_cpu(init_tss, get_cpu());
24831 + tss = init_tss + get_cpu();
24832
24833 if (turn_on)
24834 bitmap_clear(t->io_bitmap_ptr, from, num);
24835 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24836 if (level > old) {
24837 if (!capable(CAP_SYS_RAWIO))
24838 return -EPERM;
24839 +#ifdef CONFIG_GRKERNSEC_IO
24840 + if (grsec_disable_privio) {
24841 + gr_handle_iopl();
24842 + return -ENODEV;
24843 + }
24844 +#endif
24845 }
24846 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24847 t->iopl = level << 12;
24848 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24849 index d99f31d..1c0f466 100644
24850 --- a/arch/x86/kernel/irq.c
24851 +++ b/arch/x86/kernel/irq.c
24852 @@ -21,7 +21,7 @@
24853 #define CREATE_TRACE_POINTS
24854 #include <asm/trace/irq_vectors.h>
24855
24856 -atomic_t irq_err_count;
24857 +atomic_unchecked_t irq_err_count;
24858
24859 /* Function pointer for generic interrupt vector handling */
24860 void (*x86_platform_ipi_callback)(void) = NULL;
24861 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24862 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24863 seq_printf(p, " Machine check polls\n");
24864 #endif
24865 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24866 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24867 #if defined(CONFIG_X86_IO_APIC)
24868 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24869 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24870 #endif
24871 return 0;
24872 }
24873 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24874
24875 u64 arch_irq_stat(void)
24876 {
24877 - u64 sum = atomic_read(&irq_err_count);
24878 + u64 sum = atomic_read_unchecked(&irq_err_count);
24879 return sum;
24880 }
24881
24882 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24883 index d7fcbed..1f747f7 100644
24884 --- a/arch/x86/kernel/irq_32.c
24885 +++ b/arch/x86/kernel/irq_32.c
24886 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24887 __asm__ __volatile__("andl %%esp,%0" :
24888 "=r" (sp) : "0" (THREAD_SIZE - 1));
24889
24890 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24891 + return sp < STACK_WARN;
24892 }
24893
24894 static void print_stack_overflow(void)
24895 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24896 * per-CPU IRQ handling contexts (thread information and stack)
24897 */
24898 union irq_ctx {
24899 - struct thread_info tinfo;
24900 - u32 stack[THREAD_SIZE/sizeof(u32)];
24901 + unsigned long previous_esp;
24902 + u32 stack[THREAD_SIZE/sizeof(u32)];
24903 } __attribute__((aligned(THREAD_SIZE)));
24904
24905 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24906 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24907 static inline int
24908 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24909 {
24910 - union irq_ctx *curctx, *irqctx;
24911 + union irq_ctx *irqctx;
24912 u32 *isp, arg1, arg2;
24913
24914 - curctx = (union irq_ctx *) current_thread_info();
24915 irqctx = __this_cpu_read(hardirq_ctx);
24916
24917 /*
24918 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24919 * handler) we can't do that and just have to keep using the
24920 * current stack (which is the irq stack already after all)
24921 */
24922 - if (unlikely(curctx == irqctx))
24923 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24924 return 0;
24925
24926 /* build the stack frame on the IRQ stack */
24927 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24928 - irqctx->tinfo.task = curctx->tinfo.task;
24929 - irqctx->tinfo.previous_esp = current_stack_pointer;
24930 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24931 + irqctx->previous_esp = current_stack_pointer;
24932 +
24933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24934 + __set_fs(MAKE_MM_SEG(0));
24935 +#endif
24936
24937 if (unlikely(overflow))
24938 call_on_stack(print_stack_overflow, isp);
24939 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24940 : "0" (irq), "1" (desc), "2" (isp),
24941 "D" (desc->handle_irq)
24942 : "memory", "cc", "ecx");
24943 +
24944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24945 + __set_fs(current_thread_info()->addr_limit);
24946 +#endif
24947 +
24948 return 1;
24949 }
24950
24951 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24952 */
24953 void irq_ctx_init(int cpu)
24954 {
24955 - union irq_ctx *irqctx;
24956 -
24957 if (per_cpu(hardirq_ctx, cpu))
24958 return;
24959
24960 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24961 - THREADINFO_GFP,
24962 - THREAD_SIZE_ORDER));
24963 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24964 - irqctx->tinfo.cpu = cpu;
24965 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24966 -
24967 - per_cpu(hardirq_ctx, cpu) = irqctx;
24968 -
24969 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24970 - THREADINFO_GFP,
24971 - THREAD_SIZE_ORDER));
24972 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24973 - irqctx->tinfo.cpu = cpu;
24974 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24975 -
24976 - per_cpu(softirq_ctx, cpu) = irqctx;
24977 -
24978 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24979 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24980 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24981 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24982 }
24983
24984 void do_softirq_own_stack(void)
24985 {
24986 - struct thread_info *curctx;
24987 union irq_ctx *irqctx;
24988 u32 *isp;
24989
24990 - curctx = current_thread_info();
24991 irqctx = __this_cpu_read(softirq_ctx);
24992 - irqctx->tinfo.task = curctx->task;
24993 - irqctx->tinfo.previous_esp = current_stack_pointer;
24994 + irqctx->previous_esp = current_stack_pointer;
24995
24996 /* build the stack frame on the softirq stack */
24997 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24998 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24999 +
25000 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25001 + __set_fs(MAKE_MM_SEG(0));
25002 +#endif
25003
25004 call_on_stack(__do_softirq, isp);
25005 +
25006 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25007 + __set_fs(current_thread_info()->addr_limit);
25008 +#endif
25009 +
25010 }
25011
25012 bool handle_irq(unsigned irq, struct pt_regs *regs)
25013 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25014 if (unlikely(!desc))
25015 return false;
25016
25017 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25018 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25019 if (unlikely(overflow))
25020 print_stack_overflow();
25021 desc->handle_irq(irq, desc);
25022 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25023 index 4d1c746..232961d 100644
25024 --- a/arch/x86/kernel/irq_64.c
25025 +++ b/arch/x86/kernel/irq_64.c
25026 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25027 u64 estack_top, estack_bottom;
25028 u64 curbase = (u64)task_stack_page(current);
25029
25030 - if (user_mode_vm(regs))
25031 + if (user_mode(regs))
25032 return;
25033
25034 if (regs->sp >= curbase + sizeof(struct thread_info) +
25035 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25036 index 26d5a55..a01160a 100644
25037 --- a/arch/x86/kernel/jump_label.c
25038 +++ b/arch/x86/kernel/jump_label.c
25039 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25040 * Jump label is enabled for the first time.
25041 * So we expect a default_nop...
25042 */
25043 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25044 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25045 != 0))
25046 bug_at((void *)entry->code, __LINE__);
25047 } else {
25048 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25049 * ...otherwise expect an ideal_nop. Otherwise
25050 * something went horribly wrong.
25051 */
25052 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25053 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25054 != 0))
25055 bug_at((void *)entry->code, __LINE__);
25056 }
25057 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25058 * are converting the default nop to the ideal nop.
25059 */
25060 if (init) {
25061 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25062 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25063 bug_at((void *)entry->code, __LINE__);
25064 } else {
25065 code.jump = 0xe9;
25066 code.offset = entry->target -
25067 (entry->code + JUMP_LABEL_NOP_SIZE);
25068 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25069 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25070 bug_at((void *)entry->code, __LINE__);
25071 }
25072 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25073 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25074 index 7ec1d5f..5a7d130 100644
25075 --- a/arch/x86/kernel/kgdb.c
25076 +++ b/arch/x86/kernel/kgdb.c
25077 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25078 #ifdef CONFIG_X86_32
25079 switch (regno) {
25080 case GDB_SS:
25081 - if (!user_mode_vm(regs))
25082 + if (!user_mode(regs))
25083 *(unsigned long *)mem = __KERNEL_DS;
25084 break;
25085 case GDB_SP:
25086 - if (!user_mode_vm(regs))
25087 + if (!user_mode(regs))
25088 *(unsigned long *)mem = kernel_stack_pointer(regs);
25089 break;
25090 case GDB_GS:
25091 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25092 bp->attr.bp_addr = breakinfo[breakno].addr;
25093 bp->attr.bp_len = breakinfo[breakno].len;
25094 bp->attr.bp_type = breakinfo[breakno].type;
25095 - info->address = breakinfo[breakno].addr;
25096 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25097 + info->address = ktla_ktva(breakinfo[breakno].addr);
25098 + else
25099 + info->address = breakinfo[breakno].addr;
25100 info->len = breakinfo[breakno].len;
25101 info->type = breakinfo[breakno].type;
25102 val = arch_install_hw_breakpoint(bp);
25103 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25104 case 'k':
25105 /* clear the trace bit */
25106 linux_regs->flags &= ~X86_EFLAGS_TF;
25107 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25108 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25109
25110 /* set the trace bit if we're stepping */
25111 if (remcomInBuffer[0] == 's') {
25112 linux_regs->flags |= X86_EFLAGS_TF;
25113 - atomic_set(&kgdb_cpu_doing_single_step,
25114 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25115 raw_smp_processor_id());
25116 }
25117
25118 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25119
25120 switch (cmd) {
25121 case DIE_DEBUG:
25122 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25123 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25124 if (user_mode(regs))
25125 return single_step_cont(regs, args);
25126 break;
25127 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25128 #endif /* CONFIG_DEBUG_RODATA */
25129
25130 bpt->type = BP_BREAKPOINT;
25131 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25132 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25133 BREAK_INSTR_SIZE);
25134 if (err)
25135 return err;
25136 - err = probe_kernel_write((char *)bpt->bpt_addr,
25137 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25138 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25139 #ifdef CONFIG_DEBUG_RODATA
25140 if (!err)
25141 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25142 return -EBUSY;
25143 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25144 BREAK_INSTR_SIZE);
25145 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25146 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25147 if (err)
25148 return err;
25149 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25150 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25151 if (mutex_is_locked(&text_mutex))
25152 goto knl_write;
25153 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25154 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25155 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25156 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25157 goto knl_write;
25158 return err;
25159 knl_write:
25160 #endif /* CONFIG_DEBUG_RODATA */
25161 - return probe_kernel_write((char *)bpt->bpt_addr,
25162 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25163 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25164 }
25165
25166 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25167 index 79a3f96..6ba030a 100644
25168 --- a/arch/x86/kernel/kprobes/core.c
25169 +++ b/arch/x86/kernel/kprobes/core.c
25170 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25171 s32 raddr;
25172 } __packed *insn;
25173
25174 - insn = (struct __arch_relative_insn *)from;
25175 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25176 +
25177 + pax_open_kernel();
25178 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25179 insn->op = op;
25180 + pax_close_kernel();
25181 }
25182
25183 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25184 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25185 kprobe_opcode_t opcode;
25186 kprobe_opcode_t *orig_opcodes = opcodes;
25187
25188 - if (search_exception_tables((unsigned long)opcodes))
25189 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25190 return 0; /* Page fault may occur on this address. */
25191
25192 retry:
25193 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25194 * for the first byte, we can recover the original instruction
25195 * from it and kp->opcode.
25196 */
25197 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25198 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25199 buf[0] = kp->opcode;
25200 - return (unsigned long)buf;
25201 + return ktva_ktla((unsigned long)buf);
25202 }
25203
25204 /*
25205 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25206 /* Another subsystem puts a breakpoint, failed to recover */
25207 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25208 return 0;
25209 + pax_open_kernel();
25210 memcpy(dest, insn.kaddr, insn.length);
25211 + pax_close_kernel();
25212
25213 #ifdef CONFIG_X86_64
25214 if (insn_rip_relative(&insn)) {
25215 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25216 return 0;
25217 }
25218 disp = (u8 *) dest + insn_offset_displacement(&insn);
25219 + pax_open_kernel();
25220 *(s32 *) disp = (s32) newdisp;
25221 + pax_close_kernel();
25222 }
25223 #endif
25224 return insn.length;
25225 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25226 * nor set current_kprobe, because it doesn't use single
25227 * stepping.
25228 */
25229 - regs->ip = (unsigned long)p->ainsn.insn;
25230 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25231 preempt_enable_no_resched();
25232 return;
25233 }
25234 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25235 regs->flags &= ~X86_EFLAGS_IF;
25236 /* single step inline if the instruction is an int3 */
25237 if (p->opcode == BREAKPOINT_INSTRUCTION)
25238 - regs->ip = (unsigned long)p->addr;
25239 + regs->ip = ktla_ktva((unsigned long)p->addr);
25240 else
25241 - regs->ip = (unsigned long)p->ainsn.insn;
25242 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25243 }
25244
25245 /*
25246 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25247 setup_singlestep(p, regs, kcb, 0);
25248 return 1;
25249 }
25250 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25251 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25252 /*
25253 * The breakpoint instruction was removed right
25254 * after we hit it. Another cpu has removed
25255 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25256 " movq %rax, 152(%rsp)\n"
25257 RESTORE_REGS_STRING
25258 " popfq\n"
25259 +#ifdef KERNEXEC_PLUGIN
25260 + " btsq $63,(%rsp)\n"
25261 +#endif
25262 #else
25263 " pushf\n"
25264 SAVE_REGS_STRING
25265 @@ -779,7 +789,7 @@ static void __kprobes
25266 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25267 {
25268 unsigned long *tos = stack_addr(regs);
25269 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25270 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25271 unsigned long orig_ip = (unsigned long)p->addr;
25272 kprobe_opcode_t *insn = p->ainsn.insn;
25273
25274 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25275 struct die_args *args = data;
25276 int ret = NOTIFY_DONE;
25277
25278 - if (args->regs && user_mode_vm(args->regs))
25279 + if (args->regs && user_mode(args->regs))
25280 return ret;
25281
25282 switch (val) {
25283 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25284 index 898160b..758cde8 100644
25285 --- a/arch/x86/kernel/kprobes/opt.c
25286 +++ b/arch/x86/kernel/kprobes/opt.c
25287 @@ -79,6 +79,7 @@ found:
25288 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25289 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25290 {
25291 + pax_open_kernel();
25292 #ifdef CONFIG_X86_64
25293 *addr++ = 0x48;
25294 *addr++ = 0xbf;
25295 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25296 *addr++ = 0xb8;
25297 #endif
25298 *(unsigned long *)addr = val;
25299 + pax_close_kernel();
25300 }
25301
25302 asm (
25303 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25304 * Verify if the address gap is in 2GB range, because this uses
25305 * a relative jump.
25306 */
25307 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25308 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25309 if (abs(rel) > 0x7fffffff)
25310 return -ERANGE;
25311
25312 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25313 op->optinsn.size = ret;
25314
25315 /* Copy arch-dep-instance from template */
25316 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25317 + pax_open_kernel();
25318 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25319 + pax_close_kernel();
25320
25321 /* Set probe information */
25322 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25323
25324 /* Set probe function call */
25325 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25326 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25327
25328 /* Set returning jmp instruction at the tail of out-of-line buffer */
25329 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25330 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25331 (u8 *)op->kp.addr + op->optinsn.size);
25332
25333 flush_icache_range((unsigned long) buf,
25334 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25335 WARN_ON(kprobe_disabled(&op->kp));
25336
25337 /* Backup instructions which will be replaced by jump address */
25338 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25339 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25340 RELATIVE_ADDR_SIZE);
25341
25342 insn_buf[0] = RELATIVEJUMP_OPCODE;
25343 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25344 /* This kprobe is really able to run optimized path. */
25345 op = container_of(p, struct optimized_kprobe, kp);
25346 /* Detour through copied instructions */
25347 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25348 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25349 if (!reenter)
25350 reset_current_kprobe();
25351 preempt_enable_no_resched();
25352 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25353 index c2bedae..25e7ab6 100644
25354 --- a/arch/x86/kernel/ksysfs.c
25355 +++ b/arch/x86/kernel/ksysfs.c
25356 @@ -184,7 +184,7 @@ out:
25357
25358 static struct kobj_attribute type_attr = __ATTR_RO(type);
25359
25360 -static struct bin_attribute data_attr = {
25361 +static bin_attribute_no_const data_attr __read_only = {
25362 .attr = {
25363 .name = "data",
25364 .mode = S_IRUGO,
25365 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25366 index ebc9873..37b8776 100644
25367 --- a/arch/x86/kernel/ldt.c
25368 +++ b/arch/x86/kernel/ldt.c
25369 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25370 if (reload) {
25371 #ifdef CONFIG_SMP
25372 preempt_disable();
25373 - load_LDT(pc);
25374 + load_LDT_nolock(pc);
25375 if (!cpumask_equal(mm_cpumask(current->mm),
25376 cpumask_of(smp_processor_id())))
25377 smp_call_function(flush_ldt, current->mm, 1);
25378 preempt_enable();
25379 #else
25380 - load_LDT(pc);
25381 + load_LDT_nolock(pc);
25382 #endif
25383 }
25384 if (oldsize) {
25385 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25386 return err;
25387
25388 for (i = 0; i < old->size; i++)
25389 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25390 + write_ldt_entry(new->ldt, i, old->ldt + i);
25391 return 0;
25392 }
25393
25394 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25395 retval = copy_ldt(&mm->context, &old_mm->context);
25396 mutex_unlock(&old_mm->context.lock);
25397 }
25398 +
25399 + if (tsk == current) {
25400 + mm->context.vdso = 0;
25401 +
25402 +#ifdef CONFIG_X86_32
25403 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25404 + mm->context.user_cs_base = 0UL;
25405 + mm->context.user_cs_limit = ~0UL;
25406 +
25407 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25408 + cpus_clear(mm->context.cpu_user_cs_mask);
25409 +#endif
25410 +
25411 +#endif
25412 +#endif
25413 +
25414 + }
25415 +
25416 return retval;
25417 }
25418
25419 @@ -229,6 +247,24 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25420 }
25421 }
25422
25423 +#ifdef CONFIG_PAX_SEGMEXEC
25424 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25425 + error = -EINVAL;
25426 + goto out_unlock;
25427 + }
25428 +#endif
25429 +
25430 + /*
25431 + * On x86-64 we do not support 16-bit segments due to
25432 + * IRET leaking the high bits of the kernel stack address.
25433 + */
25434 +#ifdef CONFIG_X86_64
25435 + if (!ldt_info.seg_32bit) {
25436 + error = -EINVAL;
25437 + goto out_unlock;
25438 + }
25439 +#endif
25440 +
25441 fill_ldt(&ldt, &ldt_info);
25442 if (oldmode)
25443 ldt.avl = 0;
25444 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25445 index 1667b1d..16492c5 100644
25446 --- a/arch/x86/kernel/machine_kexec_32.c
25447 +++ b/arch/x86/kernel/machine_kexec_32.c
25448 @@ -25,7 +25,7 @@
25449 #include <asm/cacheflush.h>
25450 #include <asm/debugreg.h>
25451
25452 -static void set_idt(void *newidt, __u16 limit)
25453 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25454 {
25455 struct desc_ptr curidt;
25456
25457 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25458 }
25459
25460
25461 -static void set_gdt(void *newgdt, __u16 limit)
25462 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25463 {
25464 struct desc_ptr curgdt;
25465
25466 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25467 }
25468
25469 control_page = page_address(image->control_code_page);
25470 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25471 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25472
25473 relocate_kernel_ptr = control_page;
25474 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25475 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25476 index 18be189..4a9fe40 100644
25477 --- a/arch/x86/kernel/module.c
25478 +++ b/arch/x86/kernel/module.c
25479 @@ -43,15 +43,60 @@ do { \
25480 } while (0)
25481 #endif
25482
25483 -void *module_alloc(unsigned long size)
25484 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25485 {
25486 - if (PAGE_ALIGN(size) > MODULES_LEN)
25487 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25488 return NULL;
25489 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25490 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25491 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25492 NUMA_NO_NODE, __builtin_return_address(0));
25493 }
25494
25495 +void *module_alloc(unsigned long size)
25496 +{
25497 +
25498 +#ifdef CONFIG_PAX_KERNEXEC
25499 + return __module_alloc(size, PAGE_KERNEL);
25500 +#else
25501 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25502 +#endif
25503 +
25504 +}
25505 +
25506 +#ifdef CONFIG_PAX_KERNEXEC
25507 +#ifdef CONFIG_X86_32
25508 +void *module_alloc_exec(unsigned long size)
25509 +{
25510 + struct vm_struct *area;
25511 +
25512 + if (size == 0)
25513 + return NULL;
25514 +
25515 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25516 + return area ? area->addr : NULL;
25517 +}
25518 +EXPORT_SYMBOL(module_alloc_exec);
25519 +
25520 +void module_free_exec(struct module *mod, void *module_region)
25521 +{
25522 + vunmap(module_region);
25523 +}
25524 +EXPORT_SYMBOL(module_free_exec);
25525 +#else
25526 +void module_free_exec(struct module *mod, void *module_region)
25527 +{
25528 + module_free(mod, module_region);
25529 +}
25530 +EXPORT_SYMBOL(module_free_exec);
25531 +
25532 +void *module_alloc_exec(unsigned long size)
25533 +{
25534 + return __module_alloc(size, PAGE_KERNEL_RX);
25535 +}
25536 +EXPORT_SYMBOL(module_alloc_exec);
25537 +#endif
25538 +#endif
25539 +
25540 #ifdef CONFIG_X86_32
25541 int apply_relocate(Elf32_Shdr *sechdrs,
25542 const char *strtab,
25543 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25544 unsigned int i;
25545 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25546 Elf32_Sym *sym;
25547 - uint32_t *location;
25548 + uint32_t *plocation, location;
25549
25550 DEBUGP("Applying relocate section %u to %u\n",
25551 relsec, sechdrs[relsec].sh_info);
25552 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25553 /* This is where to make the change */
25554 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25555 - + rel[i].r_offset;
25556 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25557 + location = (uint32_t)plocation;
25558 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25559 + plocation = ktla_ktva((void *)plocation);
25560 /* This is the symbol it is referring to. Note that all
25561 undefined symbols have been resolved. */
25562 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25563 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25564 switch (ELF32_R_TYPE(rel[i].r_info)) {
25565 case R_386_32:
25566 /* We add the value into the location given */
25567 - *location += sym->st_value;
25568 + pax_open_kernel();
25569 + *plocation += sym->st_value;
25570 + pax_close_kernel();
25571 break;
25572 case R_386_PC32:
25573 /* Add the value, subtract its position */
25574 - *location += sym->st_value - (uint32_t)location;
25575 + pax_open_kernel();
25576 + *plocation += sym->st_value - location;
25577 + pax_close_kernel();
25578 break;
25579 default:
25580 pr_err("%s: Unknown relocation: %u\n",
25581 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25582 case R_X86_64_NONE:
25583 break;
25584 case R_X86_64_64:
25585 + pax_open_kernel();
25586 *(u64 *)loc = val;
25587 + pax_close_kernel();
25588 break;
25589 case R_X86_64_32:
25590 + pax_open_kernel();
25591 *(u32 *)loc = val;
25592 + pax_close_kernel();
25593 if (val != *(u32 *)loc)
25594 goto overflow;
25595 break;
25596 case R_X86_64_32S:
25597 + pax_open_kernel();
25598 *(s32 *)loc = val;
25599 + pax_close_kernel();
25600 if ((s64)val != *(s32 *)loc)
25601 goto overflow;
25602 break;
25603 case R_X86_64_PC32:
25604 val -= (u64)loc;
25605 + pax_open_kernel();
25606 *(u32 *)loc = val;
25607 + pax_close_kernel();
25608 +
25609 #if 0
25610 if ((s64)val != *(s32 *)loc)
25611 goto overflow;
25612 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25613 index 05266b5..3432443 100644
25614 --- a/arch/x86/kernel/msr.c
25615 +++ b/arch/x86/kernel/msr.c
25616 @@ -37,6 +37,7 @@
25617 #include <linux/notifier.h>
25618 #include <linux/uaccess.h>
25619 #include <linux/gfp.h>
25620 +#include <linux/grsecurity.h>
25621
25622 #include <asm/processor.h>
25623 #include <asm/msr.h>
25624 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25625 int err = 0;
25626 ssize_t bytes = 0;
25627
25628 +#ifdef CONFIG_GRKERNSEC_KMEM
25629 + gr_handle_msr_write();
25630 + return -EPERM;
25631 +#endif
25632 +
25633 if (count % 8)
25634 return -EINVAL; /* Invalid chunk size */
25635
25636 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25637 err = -EBADF;
25638 break;
25639 }
25640 +#ifdef CONFIG_GRKERNSEC_KMEM
25641 + gr_handle_msr_write();
25642 + return -EPERM;
25643 +#endif
25644 if (copy_from_user(&regs, uregs, sizeof regs)) {
25645 err = -EFAULT;
25646 break;
25647 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25648 return notifier_from_errno(err);
25649 }
25650
25651 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25652 +static struct notifier_block msr_class_cpu_notifier = {
25653 .notifier_call = msr_class_cpu_callback,
25654 };
25655
25656 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25657 index 6fcb49c..5b3f4ff 100644
25658 --- a/arch/x86/kernel/nmi.c
25659 +++ b/arch/x86/kernel/nmi.c
25660 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25661 return handled;
25662 }
25663
25664 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25665 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25666 {
25667 struct nmi_desc *desc = nmi_to_desc(type);
25668 unsigned long flags;
25669 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25670 * event confuses some handlers (kdump uses this flag)
25671 */
25672 if (action->flags & NMI_FLAG_FIRST)
25673 - list_add_rcu(&action->list, &desc->head);
25674 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25675 else
25676 - list_add_tail_rcu(&action->list, &desc->head);
25677 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25678
25679 spin_unlock_irqrestore(&desc->lock, flags);
25680 return 0;
25681 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25682 if (!strcmp(n->name, name)) {
25683 WARN(in_nmi(),
25684 "Trying to free NMI (%s) from NMI context!\n", n->name);
25685 - list_del_rcu(&n->list);
25686 + pax_list_del_rcu((struct list_head *)&n->list);
25687 break;
25688 }
25689 }
25690 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25691 dotraplinkage notrace __kprobes void
25692 do_nmi(struct pt_regs *regs, long error_code)
25693 {
25694 +
25695 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25696 + if (!user_mode(regs)) {
25697 + unsigned long cs = regs->cs & 0xFFFF;
25698 + unsigned long ip = ktva_ktla(regs->ip);
25699 +
25700 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25701 + regs->ip = ip;
25702 + }
25703 +#endif
25704 +
25705 nmi_nesting_preprocess(regs);
25706
25707 nmi_enter();
25708 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25709 index 6d9582e..f746287 100644
25710 --- a/arch/x86/kernel/nmi_selftest.c
25711 +++ b/arch/x86/kernel/nmi_selftest.c
25712 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25713 {
25714 /* trap all the unknown NMIs we may generate */
25715 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25716 - __initdata);
25717 + __initconst);
25718 }
25719
25720 static void __init cleanup_nmi_testsuite(void)
25721 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25722 unsigned long timeout;
25723
25724 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25725 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25726 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25727 nmi_fail = FAILURE;
25728 return;
25729 }
25730 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25731 index bbb6c73..24a58ef 100644
25732 --- a/arch/x86/kernel/paravirt-spinlocks.c
25733 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25734 @@ -8,7 +8,7 @@
25735
25736 #include <asm/paravirt.h>
25737
25738 -struct pv_lock_ops pv_lock_ops = {
25739 +struct pv_lock_ops pv_lock_ops __read_only = {
25740 #ifdef CONFIG_SMP
25741 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25742 .unlock_kick = paravirt_nop,
25743 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25744 index 1b10af8..0b58cbc 100644
25745 --- a/arch/x86/kernel/paravirt.c
25746 +++ b/arch/x86/kernel/paravirt.c
25747 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25748 {
25749 return x;
25750 }
25751 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25752 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25753 +#endif
25754
25755 void __init default_banner(void)
25756 {
25757 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25758 if (opfunc == NULL)
25759 /* If there's no function, patch it with a ud2a (BUG) */
25760 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25761 - else if (opfunc == _paravirt_nop)
25762 + else if (opfunc == (void *)_paravirt_nop)
25763 /* If the operation is a nop, then nop the callsite */
25764 ret = paravirt_patch_nop();
25765
25766 /* identity functions just return their single argument */
25767 - else if (opfunc == _paravirt_ident_32)
25768 + else if (opfunc == (void *)_paravirt_ident_32)
25769 ret = paravirt_patch_ident_32(insnbuf, len);
25770 - else if (opfunc == _paravirt_ident_64)
25771 + else if (opfunc == (void *)_paravirt_ident_64)
25772 ret = paravirt_patch_ident_64(insnbuf, len);
25773 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25774 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25775 + ret = paravirt_patch_ident_64(insnbuf, len);
25776 +#endif
25777
25778 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25779 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25780 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25781 if (insn_len > len || start == NULL)
25782 insn_len = len;
25783 else
25784 - memcpy(insnbuf, start, insn_len);
25785 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25786
25787 return insn_len;
25788 }
25789 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25790 return this_cpu_read(paravirt_lazy_mode);
25791 }
25792
25793 -struct pv_info pv_info = {
25794 +struct pv_info pv_info __read_only = {
25795 .name = "bare hardware",
25796 .paravirt_enabled = 0,
25797 .kernel_rpl = 0,
25798 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25799 #endif
25800 };
25801
25802 -struct pv_init_ops pv_init_ops = {
25803 +struct pv_init_ops pv_init_ops __read_only = {
25804 .patch = native_patch,
25805 };
25806
25807 -struct pv_time_ops pv_time_ops = {
25808 +struct pv_time_ops pv_time_ops __read_only = {
25809 .sched_clock = native_sched_clock,
25810 .steal_clock = native_steal_clock,
25811 };
25812
25813 -__visible struct pv_irq_ops pv_irq_ops = {
25814 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25815 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25816 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25817 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25818 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25819 #endif
25820 };
25821
25822 -__visible struct pv_cpu_ops pv_cpu_ops = {
25823 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25824 .cpuid = native_cpuid,
25825 .get_debugreg = native_get_debugreg,
25826 .set_debugreg = native_set_debugreg,
25827 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25828 .end_context_switch = paravirt_nop,
25829 };
25830
25831 -struct pv_apic_ops pv_apic_ops = {
25832 +struct pv_apic_ops pv_apic_ops __read_only= {
25833 #ifdef CONFIG_X86_LOCAL_APIC
25834 .startup_ipi_hook = paravirt_nop,
25835 #endif
25836 };
25837
25838 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25839 +#ifdef CONFIG_X86_32
25840 +#ifdef CONFIG_X86_PAE
25841 +/* 64-bit pagetable entries */
25842 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25843 +#else
25844 /* 32-bit pagetable entries */
25845 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25846 +#endif
25847 #else
25848 /* 64-bit pagetable entries */
25849 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25850 #endif
25851
25852 -struct pv_mmu_ops pv_mmu_ops = {
25853 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25854
25855 .read_cr2 = native_read_cr2,
25856 .write_cr2 = native_write_cr2,
25857 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25858 .make_pud = PTE_IDENT,
25859
25860 .set_pgd = native_set_pgd,
25861 + .set_pgd_batched = native_set_pgd_batched,
25862 #endif
25863 #endif /* PAGETABLE_LEVELS >= 3 */
25864
25865 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25866 },
25867
25868 .set_fixmap = native_set_fixmap,
25869 +
25870 +#ifdef CONFIG_PAX_KERNEXEC
25871 + .pax_open_kernel = native_pax_open_kernel,
25872 + .pax_close_kernel = native_pax_close_kernel,
25873 +#endif
25874 +
25875 };
25876
25877 EXPORT_SYMBOL_GPL(pv_time_ops);
25878 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25879 index 299d493..2ccb0ee 100644
25880 --- a/arch/x86/kernel/pci-calgary_64.c
25881 +++ b/arch/x86/kernel/pci-calgary_64.c
25882 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25883 tce_space = be64_to_cpu(readq(target));
25884 tce_space = tce_space & TAR_SW_BITS;
25885
25886 - tce_space = tce_space & (~specified_table_size);
25887 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25888 info->tce_space = (u64 *)__va(tce_space);
25889 }
25890 }
25891 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25892 index 35ccf75..7a15747 100644
25893 --- a/arch/x86/kernel/pci-iommu_table.c
25894 +++ b/arch/x86/kernel/pci-iommu_table.c
25895 @@ -2,7 +2,7 @@
25896 #include <asm/iommu_table.h>
25897 #include <linux/string.h>
25898 #include <linux/kallsyms.h>
25899 -
25900 +#include <linux/sched.h>
25901
25902 #define DEBUG 1
25903
25904 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25905 index 6c483ba..d10ce2f 100644
25906 --- a/arch/x86/kernel/pci-swiotlb.c
25907 +++ b/arch/x86/kernel/pci-swiotlb.c
25908 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25909 void *vaddr, dma_addr_t dma_addr,
25910 struct dma_attrs *attrs)
25911 {
25912 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25913 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25914 }
25915
25916 static struct dma_map_ops swiotlb_dma_ops = {
25917 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25918 index ca7f0d5..8996469 100644
25919 --- a/arch/x86/kernel/preempt.S
25920 +++ b/arch/x86/kernel/preempt.S
25921 @@ -3,12 +3,14 @@
25922 #include <asm/dwarf2.h>
25923 #include <asm/asm.h>
25924 #include <asm/calling.h>
25925 +#include <asm/alternative-asm.h>
25926
25927 ENTRY(___preempt_schedule)
25928 CFI_STARTPROC
25929 SAVE_ALL
25930 call preempt_schedule
25931 RESTORE_ALL
25932 + pax_force_retaddr
25933 ret
25934 CFI_ENDPROC
25935
25936 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25937 SAVE_ALL
25938 call preempt_schedule_context
25939 RESTORE_ALL
25940 + pax_force_retaddr
25941 ret
25942 CFI_ENDPROC
25943
25944 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25945 index 3fb8d95..254dc51 100644
25946 --- a/arch/x86/kernel/process.c
25947 +++ b/arch/x86/kernel/process.c
25948 @@ -36,7 +36,8 @@
25949 * section. Since TSS's are completely CPU-local, we want them
25950 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25951 */
25952 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25953 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25954 +EXPORT_SYMBOL(init_tss);
25955
25956 #ifdef CONFIG_X86_64
25957 static DEFINE_PER_CPU(unsigned char, is_idle);
25958 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25959 task_xstate_cachep =
25960 kmem_cache_create("task_xstate", xstate_size,
25961 __alignof__(union thread_xstate),
25962 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25963 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25964 }
25965
25966 /*
25967 @@ -105,7 +106,7 @@ void exit_thread(void)
25968 unsigned long *bp = t->io_bitmap_ptr;
25969
25970 if (bp) {
25971 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25972 + struct tss_struct *tss = init_tss + get_cpu();
25973
25974 t->io_bitmap_ptr = NULL;
25975 clear_thread_flag(TIF_IO_BITMAP);
25976 @@ -125,6 +126,9 @@ void flush_thread(void)
25977 {
25978 struct task_struct *tsk = current;
25979
25980 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25981 + loadsegment(gs, 0);
25982 +#endif
25983 flush_ptrace_hw_breakpoint(tsk);
25984 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25985 drop_init_fpu(tsk);
25986 @@ -271,7 +275,7 @@ static void __exit_idle(void)
25987 void exit_idle(void)
25988 {
25989 /* idle loop has pid 0 */
25990 - if (current->pid)
25991 + if (task_pid_nr(current))
25992 return;
25993 __exit_idle();
25994 }
25995 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25996 return ret;
25997 }
25998 #endif
25999 -void stop_this_cpu(void *dummy)
26000 +__noreturn void stop_this_cpu(void *dummy)
26001 {
26002 local_irq_disable();
26003 /*
26004 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26005 }
26006 early_param("idle", idle_setup);
26007
26008 -unsigned long arch_align_stack(unsigned long sp)
26009 +#ifdef CONFIG_PAX_RANDKSTACK
26010 +void pax_randomize_kstack(struct pt_regs *regs)
26011 {
26012 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26013 - sp -= get_random_int() % 8192;
26014 - return sp & ~0xf;
26015 -}
26016 + struct thread_struct *thread = &current->thread;
26017 + unsigned long time;
26018
26019 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26020 -{
26021 - unsigned long range_end = mm->brk + 0x02000000;
26022 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26023 -}
26024 + if (!randomize_va_space)
26025 + return;
26026 +
26027 + if (v8086_mode(regs))
26028 + return;
26029
26030 + rdtscl(time);
26031 +
26032 + /* P4 seems to return a 0 LSB, ignore it */
26033 +#ifdef CONFIG_MPENTIUM4
26034 + time &= 0x3EUL;
26035 + time <<= 2;
26036 +#elif defined(CONFIG_X86_64)
26037 + time &= 0xFUL;
26038 + time <<= 4;
26039 +#else
26040 + time &= 0x1FUL;
26041 + time <<= 3;
26042 +#endif
26043 +
26044 + thread->sp0 ^= time;
26045 + load_sp0(init_tss + smp_processor_id(), thread);
26046 +
26047 +#ifdef CONFIG_X86_64
26048 + this_cpu_write(kernel_stack, thread->sp0);
26049 +#endif
26050 +}
26051 +#endif
26052 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26053 index 0de43e9..056b840 100644
26054 --- a/arch/x86/kernel/process_32.c
26055 +++ b/arch/x86/kernel/process_32.c
26056 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26057 unsigned long thread_saved_pc(struct task_struct *tsk)
26058 {
26059 return ((unsigned long *)tsk->thread.sp)[3];
26060 +//XXX return tsk->thread.eip;
26061 }
26062
26063 void __show_regs(struct pt_regs *regs, int all)
26064 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26065 unsigned long sp;
26066 unsigned short ss, gs;
26067
26068 - if (user_mode_vm(regs)) {
26069 + if (user_mode(regs)) {
26070 sp = regs->sp;
26071 ss = regs->ss & 0xffff;
26072 - gs = get_user_gs(regs);
26073 } else {
26074 sp = kernel_stack_pointer(regs);
26075 savesegment(ss, ss);
26076 - savesegment(gs, gs);
26077 }
26078 + gs = get_user_gs(regs);
26079
26080 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26081 (u16)regs->cs, regs->ip, regs->flags,
26082 - smp_processor_id());
26083 + raw_smp_processor_id());
26084 print_symbol("EIP is at %s\n", regs->ip);
26085
26086 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26087 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26088 int copy_thread(unsigned long clone_flags, unsigned long sp,
26089 unsigned long arg, struct task_struct *p)
26090 {
26091 - struct pt_regs *childregs = task_pt_regs(p);
26092 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26093 struct task_struct *tsk;
26094 int err;
26095
26096 p->thread.sp = (unsigned long) childregs;
26097 p->thread.sp0 = (unsigned long) (childregs+1);
26098 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26099
26100 if (unlikely(p->flags & PF_KTHREAD)) {
26101 /* kernel thread */
26102 memset(childregs, 0, sizeof(struct pt_regs));
26103 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26104 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26105 - childregs->ds = __USER_DS;
26106 - childregs->es = __USER_DS;
26107 + savesegment(gs, childregs->gs);
26108 + childregs->ds = __KERNEL_DS;
26109 + childregs->es = __KERNEL_DS;
26110 childregs->fs = __KERNEL_PERCPU;
26111 childregs->bx = sp; /* function */
26112 childregs->bp = arg;
26113 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26114 struct thread_struct *prev = &prev_p->thread,
26115 *next = &next_p->thread;
26116 int cpu = smp_processor_id();
26117 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26118 + struct tss_struct *tss = init_tss + cpu;
26119 fpu_switch_t fpu;
26120
26121 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26122 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26123 */
26124 lazy_save_gs(prev->gs);
26125
26126 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26127 + __set_fs(task_thread_info(next_p)->addr_limit);
26128 +#endif
26129 +
26130 /*
26131 * Load the per-thread Thread-Local Storage descriptor.
26132 */
26133 @@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26134 */
26135 arch_end_context_switch(next_p);
26136
26137 + this_cpu_write(current_task, next_p);
26138 + this_cpu_write(current_tinfo, &next_p->tinfo);
26139 +
26140 /*
26141 * Restore %gs if needed (which is common)
26142 */
26143 @@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26144
26145 switch_fpu_finish(next_p, fpu);
26146
26147 - this_cpu_write(current_task, next_p);
26148 -
26149 return prev_p;
26150 }
26151
26152 @@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26153 } while (count++ < 16);
26154 return 0;
26155 }
26156 -
26157 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26158 index 9c0280f..5bbb1c0 100644
26159 --- a/arch/x86/kernel/process_64.c
26160 +++ b/arch/x86/kernel/process_64.c
26161 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26162 struct pt_regs *childregs;
26163 struct task_struct *me = current;
26164
26165 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26166 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26167 childregs = task_pt_regs(p);
26168 p->thread.sp = (unsigned long) childregs;
26169 p->thread.usersp = me->thread.usersp;
26170 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26171 set_tsk_thread_flag(p, TIF_FORK);
26172 p->thread.fpu_counter = 0;
26173 p->thread.io_bitmap_ptr = NULL;
26174 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26175 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26176 savesegment(es, p->thread.es);
26177 savesegment(ds, p->thread.ds);
26178 + savesegment(ss, p->thread.ss);
26179 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26180 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26181
26182 if (unlikely(p->flags & PF_KTHREAD)) {
26183 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26184 struct thread_struct *prev = &prev_p->thread;
26185 struct thread_struct *next = &next_p->thread;
26186 int cpu = smp_processor_id();
26187 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26188 + struct tss_struct *tss = init_tss + cpu;
26189 unsigned fsindex, gsindex;
26190 fpu_switch_t fpu;
26191
26192 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26193 if (unlikely(next->ds | prev->ds))
26194 loadsegment(ds, next->ds);
26195
26196 + savesegment(ss, prev->ss);
26197 + if (unlikely(next->ss != prev->ss))
26198 + loadsegment(ss, next->ss);
26199
26200 /* We must save %fs and %gs before load_TLS() because
26201 * %fs and %gs may be cleared by load_TLS().
26202 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26203 prev->usersp = this_cpu_read(old_rsp);
26204 this_cpu_write(old_rsp, next->usersp);
26205 this_cpu_write(current_task, next_p);
26206 + this_cpu_write(current_tinfo, &next_p->tinfo);
26207
26208 /*
26209 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26210 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26211 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26212 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26213
26214 - this_cpu_write(kernel_stack,
26215 - (unsigned long)task_stack_page(next_p) +
26216 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26217 + this_cpu_write(kernel_stack, next->sp0);
26218
26219 /*
26220 * Now maybe reload the debug registers and handle I/O bitmaps
26221 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26222 if (!p || p == current || p->state == TASK_RUNNING)
26223 return 0;
26224 stack = (unsigned long)task_stack_page(p);
26225 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26226 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26227 return 0;
26228 fp = *(u64 *)(p->thread.sp);
26229 do {
26230 - if (fp < (unsigned long)stack ||
26231 - fp >= (unsigned long)stack+THREAD_SIZE)
26232 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26233 return 0;
26234 ip = *(u64 *)(fp+8);
26235 if (!in_sched_functions(ip))
26236 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26237 index 7461f50..1334029 100644
26238 --- a/arch/x86/kernel/ptrace.c
26239 +++ b/arch/x86/kernel/ptrace.c
26240 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26241 {
26242 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26243 unsigned long sp = (unsigned long)&regs->sp;
26244 - struct thread_info *tinfo;
26245
26246 - if (context == (sp & ~(THREAD_SIZE - 1)))
26247 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26248 return sp;
26249
26250 - tinfo = (struct thread_info *)context;
26251 - if (tinfo->previous_esp)
26252 - return tinfo->previous_esp;
26253 + sp = *(unsigned long *)context;
26254 + if (sp)
26255 + return sp;
26256
26257 return (unsigned long)regs;
26258 }
26259 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26260 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26261 {
26262 int i;
26263 - int dr7 = 0;
26264 + unsigned long dr7 = 0;
26265 struct arch_hw_breakpoint *info;
26266
26267 for (i = 0; i < HBP_NUM; i++) {
26268 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26269 unsigned long addr, unsigned long data)
26270 {
26271 int ret;
26272 - unsigned long __user *datap = (unsigned long __user *)data;
26273 + unsigned long __user *datap = (__force unsigned long __user *)data;
26274
26275 switch (request) {
26276 /* read the word at location addr in the USER area. */
26277 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26278 if ((int) addr < 0)
26279 return -EIO;
26280 ret = do_get_thread_area(child, addr,
26281 - (struct user_desc __user *)data);
26282 + (__force struct user_desc __user *) data);
26283 break;
26284
26285 case PTRACE_SET_THREAD_AREA:
26286 if ((int) addr < 0)
26287 return -EIO;
26288 ret = do_set_thread_area(child, addr,
26289 - (struct user_desc __user *)data, 0);
26290 + (__force struct user_desc __user *) data, 0);
26291 break;
26292 #endif
26293
26294 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26295
26296 #ifdef CONFIG_X86_64
26297
26298 -static struct user_regset x86_64_regsets[] __read_mostly = {
26299 +static user_regset_no_const x86_64_regsets[] __read_only = {
26300 [REGSET_GENERAL] = {
26301 .core_note_type = NT_PRSTATUS,
26302 .n = sizeof(struct user_regs_struct) / sizeof(long),
26303 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26304 #endif /* CONFIG_X86_64 */
26305
26306 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26307 -static struct user_regset x86_32_regsets[] __read_mostly = {
26308 +static user_regset_no_const x86_32_regsets[] __read_only = {
26309 [REGSET_GENERAL] = {
26310 .core_note_type = NT_PRSTATUS,
26311 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26312 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26313 */
26314 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26315
26316 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26317 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26318 {
26319 #ifdef CONFIG_X86_64
26320 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26321 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26322 memset(info, 0, sizeof(*info));
26323 info->si_signo = SIGTRAP;
26324 info->si_code = si_code;
26325 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26326 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26327 }
26328
26329 void user_single_step_siginfo(struct task_struct *tsk,
26330 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26331 # define IS_IA32 0
26332 #endif
26333
26334 +#ifdef CONFIG_GRKERNSEC_SETXID
26335 +extern void gr_delayed_cred_worker(void);
26336 +#endif
26337 +
26338 /*
26339 * We must return the syscall number to actually look up in the table.
26340 * This can be -1L to skip running any syscall at all.
26341 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26342
26343 user_exit();
26344
26345 +#ifdef CONFIG_GRKERNSEC_SETXID
26346 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26347 + gr_delayed_cred_worker();
26348 +#endif
26349 +
26350 /*
26351 * If we stepped into a sysenter/syscall insn, it trapped in
26352 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26353 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26354 */
26355 user_exit();
26356
26357 +#ifdef CONFIG_GRKERNSEC_SETXID
26358 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26359 + gr_delayed_cred_worker();
26360 +#endif
26361 +
26362 audit_syscall_exit(regs);
26363
26364 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26365 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26366 index 2f355d2..e75ed0a 100644
26367 --- a/arch/x86/kernel/pvclock.c
26368 +++ b/arch/x86/kernel/pvclock.c
26369 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26370 reset_hung_task_detector();
26371 }
26372
26373 -static atomic64_t last_value = ATOMIC64_INIT(0);
26374 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26375
26376 void pvclock_resume(void)
26377 {
26378 - atomic64_set(&last_value, 0);
26379 + atomic64_set_unchecked(&last_value, 0);
26380 }
26381
26382 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26383 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26384 * updating at the same time, and one of them could be slightly behind,
26385 * making the assumption that last_value always go forward fail to hold.
26386 */
26387 - last = atomic64_read(&last_value);
26388 + last = atomic64_read_unchecked(&last_value);
26389 do {
26390 if (ret < last)
26391 return last;
26392 - last = atomic64_cmpxchg(&last_value, last, ret);
26393 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26394 } while (unlikely(last != ret));
26395
26396 return ret;
26397 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26398 index c752cb4..866c432 100644
26399 --- a/arch/x86/kernel/reboot.c
26400 +++ b/arch/x86/kernel/reboot.c
26401 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26402
26403 void __noreturn machine_real_restart(unsigned int type)
26404 {
26405 +
26406 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26407 + struct desc_struct *gdt;
26408 +#endif
26409 +
26410 local_irq_disable();
26411
26412 /*
26413 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26414
26415 /* Jump to the identity-mapped low memory code */
26416 #ifdef CONFIG_X86_32
26417 - asm volatile("jmpl *%0" : :
26418 +
26419 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26420 + gdt = get_cpu_gdt_table(smp_processor_id());
26421 + pax_open_kernel();
26422 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26423 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26424 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26425 + loadsegment(ds, __KERNEL_DS);
26426 + loadsegment(es, __KERNEL_DS);
26427 + loadsegment(ss, __KERNEL_DS);
26428 +#endif
26429 +#ifdef CONFIG_PAX_KERNEXEC
26430 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26431 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26432 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26433 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26434 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26435 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26436 +#endif
26437 + pax_close_kernel();
26438 +#endif
26439 +
26440 + asm volatile("ljmpl *%0" : :
26441 "rm" (real_mode_header->machine_real_restart_asm),
26442 "a" (type));
26443 #else
26444 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26445 * try to force a triple fault and then cycle between hitting the keyboard
26446 * controller and doing that
26447 */
26448 -static void native_machine_emergency_restart(void)
26449 +static void __noreturn native_machine_emergency_restart(void)
26450 {
26451 int i;
26452 int attempt = 0;
26453 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26454 #endif
26455 }
26456
26457 -static void __machine_emergency_restart(int emergency)
26458 +static void __noreturn __machine_emergency_restart(int emergency)
26459 {
26460 reboot_emergency = emergency;
26461 machine_ops.emergency_restart();
26462 }
26463
26464 -static void native_machine_restart(char *__unused)
26465 +static void __noreturn native_machine_restart(char *__unused)
26466 {
26467 pr_notice("machine restart\n");
26468
26469 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26470 __machine_emergency_restart(0);
26471 }
26472
26473 -static void native_machine_halt(void)
26474 +static void __noreturn native_machine_halt(void)
26475 {
26476 /* Stop other cpus and apics */
26477 machine_shutdown();
26478 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
26479 stop_this_cpu(NULL);
26480 }
26481
26482 -static void native_machine_power_off(void)
26483 +static void __noreturn native_machine_power_off(void)
26484 {
26485 if (pm_power_off) {
26486 if (!reboot_force)
26487 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26488 }
26489 /* A fallback in case there is no PM info available */
26490 tboot_shutdown(TB_SHUTDOWN_HALT);
26491 + unreachable();
26492 }
26493
26494 -struct machine_ops machine_ops = {
26495 +struct machine_ops machine_ops __read_only = {
26496 .power_off = native_machine_power_off,
26497 .shutdown = native_machine_shutdown,
26498 .emergency_restart = native_machine_emergency_restart,
26499 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26500 index c8e41e9..64049ef 100644
26501 --- a/arch/x86/kernel/reboot_fixups_32.c
26502 +++ b/arch/x86/kernel/reboot_fixups_32.c
26503 @@ -57,7 +57,7 @@ struct device_fixup {
26504 unsigned int vendor;
26505 unsigned int device;
26506 void (*reboot_fixup)(struct pci_dev *);
26507 -};
26508 +} __do_const;
26509
26510 /*
26511 * PCI ids solely used for fixups_table go here
26512 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26513 index 3fd2c69..a444264 100644
26514 --- a/arch/x86/kernel/relocate_kernel_64.S
26515 +++ b/arch/x86/kernel/relocate_kernel_64.S
26516 @@ -96,8 +96,7 @@ relocate_kernel:
26517
26518 /* jump to identity mapped page */
26519 addq $(identity_mapped - relocate_kernel), %r8
26520 - pushq %r8
26521 - ret
26522 + jmp *%r8
26523
26524 identity_mapped:
26525 /* set return address to 0 if not preserving context */
26526 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26527 index ce72964..be8aea7 100644
26528 --- a/arch/x86/kernel/setup.c
26529 +++ b/arch/x86/kernel/setup.c
26530 @@ -110,6 +110,7 @@
26531 #include <asm/mce.h>
26532 #include <asm/alternative.h>
26533 #include <asm/prom.h>
26534 +#include <asm/boot.h>
26535
26536 /*
26537 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26538 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26539 #endif
26540
26541
26542 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26543 -__visible unsigned long mmu_cr4_features;
26544 +#ifdef CONFIG_X86_64
26545 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26546 +#elif defined(CONFIG_X86_PAE)
26547 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26548 #else
26549 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26550 +__visible unsigned long mmu_cr4_features __read_only;
26551 #endif
26552
26553 +void set_in_cr4(unsigned long mask)
26554 +{
26555 + unsigned long cr4 = read_cr4();
26556 +
26557 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26558 + return;
26559 +
26560 + pax_open_kernel();
26561 + mmu_cr4_features |= mask;
26562 + pax_close_kernel();
26563 +
26564 + if (trampoline_cr4_features)
26565 + *trampoline_cr4_features = mmu_cr4_features;
26566 + cr4 |= mask;
26567 + write_cr4(cr4);
26568 +}
26569 +EXPORT_SYMBOL(set_in_cr4);
26570 +
26571 +void clear_in_cr4(unsigned long mask)
26572 +{
26573 + unsigned long cr4 = read_cr4();
26574 +
26575 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26576 + return;
26577 +
26578 + pax_open_kernel();
26579 + mmu_cr4_features &= ~mask;
26580 + pax_close_kernel();
26581 +
26582 + if (trampoline_cr4_features)
26583 + *trampoline_cr4_features = mmu_cr4_features;
26584 + cr4 &= ~mask;
26585 + write_cr4(cr4);
26586 +}
26587 +EXPORT_SYMBOL(clear_in_cr4);
26588 +
26589 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26590 int bootloader_type, bootloader_version;
26591
26592 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26593 * area (640->1Mb) as ram even though it is not.
26594 * take them out.
26595 */
26596 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26597 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26598
26599 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26600 }
26601 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26602 /* called before trim_bios_range() to spare extra sanitize */
26603 static void __init e820_add_kernel_range(void)
26604 {
26605 - u64 start = __pa_symbol(_text);
26606 + u64 start = __pa_symbol(ktla_ktva(_text));
26607 u64 size = __pa_symbol(_end) - start;
26608
26609 /*
26610 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26611
26612 void __init setup_arch(char **cmdline_p)
26613 {
26614 +#ifdef CONFIG_X86_32
26615 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26616 +#else
26617 memblock_reserve(__pa_symbol(_text),
26618 (unsigned long)__bss_stop - (unsigned long)_text);
26619 +#endif
26620
26621 early_reserve_initrd();
26622
26623 @@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
26624
26625 if (!boot_params.hdr.root_flags)
26626 root_mountflags &= ~MS_RDONLY;
26627 - init_mm.start_code = (unsigned long) _text;
26628 - init_mm.end_code = (unsigned long) _etext;
26629 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26630 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26631 init_mm.end_data = (unsigned long) _edata;
26632 init_mm.brk = _brk_end;
26633
26634 - code_resource.start = __pa_symbol(_text);
26635 - code_resource.end = __pa_symbol(_etext)-1;
26636 - data_resource.start = __pa_symbol(_etext);
26637 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26638 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26639 + data_resource.start = __pa_symbol(_sdata);
26640 data_resource.end = __pa_symbol(_edata)-1;
26641 bss_resource.start = __pa_symbol(__bss_start);
26642 bss_resource.end = __pa_symbol(__bss_stop)-1;
26643 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26644 index 5cdff03..80fa283 100644
26645 --- a/arch/x86/kernel/setup_percpu.c
26646 +++ b/arch/x86/kernel/setup_percpu.c
26647 @@ -21,19 +21,17 @@
26648 #include <asm/cpu.h>
26649 #include <asm/stackprotector.h>
26650
26651 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26652 +#ifdef CONFIG_SMP
26653 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26654 EXPORT_PER_CPU_SYMBOL(cpu_number);
26655 +#endif
26656
26657 -#ifdef CONFIG_X86_64
26658 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26659 -#else
26660 -#define BOOT_PERCPU_OFFSET 0
26661 -#endif
26662
26663 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26664 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26665
26666 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26667 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26668 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26669 };
26670 EXPORT_SYMBOL(__per_cpu_offset);
26671 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26672 {
26673 #ifdef CONFIG_NEED_MULTIPLE_NODES
26674 pg_data_t *last = NULL;
26675 - unsigned int cpu;
26676 + int cpu;
26677
26678 for_each_possible_cpu(cpu) {
26679 int node = early_cpu_to_node(cpu);
26680 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26681 {
26682 #ifdef CONFIG_X86_32
26683 struct desc_struct gdt;
26684 + unsigned long base = per_cpu_offset(cpu);
26685
26686 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26687 - 0x2 | DESCTYPE_S, 0x8);
26688 - gdt.s = 1;
26689 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26690 + 0x83 | DESCTYPE_S, 0xC);
26691 write_gdt_entry(get_cpu_gdt_table(cpu),
26692 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26693 #endif
26694 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26695 /* alrighty, percpu areas up and running */
26696 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26697 for_each_possible_cpu(cpu) {
26698 +#ifdef CONFIG_CC_STACKPROTECTOR
26699 +#ifdef CONFIG_X86_32
26700 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26701 +#endif
26702 +#endif
26703 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26704 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26705 per_cpu(cpu_number, cpu) = cpu;
26706 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26707 */
26708 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26709 #endif
26710 +#ifdef CONFIG_CC_STACKPROTECTOR
26711 +#ifdef CONFIG_X86_32
26712 + if (!cpu)
26713 + per_cpu(stack_canary.canary, cpu) = canary;
26714 +#endif
26715 +#endif
26716 /*
26717 * Up to this point, the boot CPU has been using .init.data
26718 * area. Reload any changed state for the boot CPU.
26719 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26720 index 9e5de68..16c53cb 100644
26721 --- a/arch/x86/kernel/signal.c
26722 +++ b/arch/x86/kernel/signal.c
26723 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26724 * Align the stack pointer according to the i386 ABI,
26725 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26726 */
26727 - sp = ((sp + 4) & -16ul) - 4;
26728 + sp = ((sp - 12) & -16ul) - 4;
26729 #else /* !CONFIG_X86_32 */
26730 sp = round_down(sp, 16) - 8;
26731 #endif
26732 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26733 }
26734
26735 if (current->mm->context.vdso)
26736 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26737 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26738 else
26739 - restorer = &frame->retcode;
26740 + restorer = (void __user *)&frame->retcode;
26741 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26742 restorer = ksig->ka.sa.sa_restorer;
26743
26744 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26745 * reasons and because gdb uses it as a signature to notice
26746 * signal handler stack frames.
26747 */
26748 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26749 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26750
26751 if (err)
26752 return -EFAULT;
26753 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26754 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26755
26756 /* Set up to return from userspace. */
26757 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26758 + if (current->mm->context.vdso)
26759 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26760 + else
26761 + restorer = (void __user *)&frame->retcode;
26762 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26763 restorer = ksig->ka.sa.sa_restorer;
26764 put_user_ex(restorer, &frame->pretcode);
26765 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26766 * reasons and because gdb uses it as a signature to notice
26767 * signal handler stack frames.
26768 */
26769 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26770 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26771 } put_user_catch(err);
26772
26773 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26774 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26775 {
26776 int usig = signr_convert(ksig->sig);
26777 sigset_t *set = sigmask_to_save();
26778 - compat_sigset_t *cset = (compat_sigset_t *) set;
26779 + sigset_t sigcopy;
26780 + compat_sigset_t *cset;
26781 +
26782 + sigcopy = *set;
26783 +
26784 + cset = (compat_sigset_t *) &sigcopy;
26785
26786 /* Set up the stack frame */
26787 if (is_ia32_frame()) {
26788 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26789 } else if (is_x32_frame()) {
26790 return x32_setup_rt_frame(ksig, cset, regs);
26791 } else {
26792 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26793 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26794 }
26795 }
26796
26797 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26798 index 7c3a5a6..f0a8961 100644
26799 --- a/arch/x86/kernel/smp.c
26800 +++ b/arch/x86/kernel/smp.c
26801 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26802
26803 __setup("nonmi_ipi", nonmi_ipi_setup);
26804
26805 -struct smp_ops smp_ops = {
26806 +struct smp_ops smp_ops __read_only = {
26807 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26808 .smp_prepare_cpus = native_smp_prepare_cpus,
26809 .smp_cpus_done = native_smp_cpus_done,
26810 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26811 index a32da80..30c97f1 100644
26812 --- a/arch/x86/kernel/smpboot.c
26813 +++ b/arch/x86/kernel/smpboot.c
26814 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26815
26816 enable_start_cpu0 = 0;
26817
26818 -#ifdef CONFIG_X86_32
26819 - /* switch away from the initial page table */
26820 - load_cr3(swapper_pg_dir);
26821 - __flush_tlb_all();
26822 -#endif
26823 -
26824 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26825 barrier();
26826 +
26827 + /* switch away from the initial page table */
26828 +#ifdef CONFIG_PAX_PER_CPU_PGD
26829 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26830 + __flush_tlb_all();
26831 +#elif defined(CONFIG_X86_32)
26832 + load_cr3(swapper_pg_dir);
26833 + __flush_tlb_all();
26834 +#endif
26835 +
26836 /*
26837 * Check TSC synchronization with the BP:
26838 */
26839 @@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26840 alternatives_enable_smp();
26841
26842 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26843 - (THREAD_SIZE + task_stack_page(idle))) - 1);
26844 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26845 per_cpu(current_task, cpu) = idle;
26846 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26847
26848 #ifdef CONFIG_X86_32
26849 /* Stack for startup_32 can be just as for start_secondary onwards */
26850 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26851 #else
26852 clear_tsk_thread_flag(idle, TIF_FORK);
26853 initial_gs = per_cpu_offset(cpu);
26854 - per_cpu(kernel_stack, cpu) =
26855 - (unsigned long)task_stack_page(idle) -
26856 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26857 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26858 #endif
26859 +
26860 + pax_open_kernel();
26861 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26862 + pax_close_kernel();
26863 +
26864 initial_code = (unsigned long)start_secondary;
26865 stack_start = idle->thread.sp;
26866
26867 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26868 /* the FPU context is blank, nobody can own it */
26869 __cpu_disable_lazy_restore(cpu);
26870
26871 +#ifdef CONFIG_PAX_PER_CPU_PGD
26872 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26873 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26874 + KERNEL_PGD_PTRS);
26875 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26876 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26877 + KERNEL_PGD_PTRS);
26878 +#endif
26879 +
26880 err = do_boot_cpu(apicid, cpu, tidle);
26881 if (err) {
26882 pr_debug("do_boot_cpu failed %d\n", err);
26883 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26884 index 9b4d51d..5d28b58 100644
26885 --- a/arch/x86/kernel/step.c
26886 +++ b/arch/x86/kernel/step.c
26887 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26888 struct desc_struct *desc;
26889 unsigned long base;
26890
26891 - seg &= ~7UL;
26892 + seg >>= 3;
26893
26894 mutex_lock(&child->mm->context.lock);
26895 - if (unlikely((seg >> 3) >= child->mm->context.size))
26896 + if (unlikely(seg >= child->mm->context.size))
26897 addr = -1L; /* bogus selector, access would fault */
26898 else {
26899 desc = child->mm->context.ldt + seg;
26900 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26901 addr += base;
26902 }
26903 mutex_unlock(&child->mm->context.lock);
26904 - }
26905 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26906 + addr = ktla_ktva(addr);
26907
26908 return addr;
26909 }
26910 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26911 unsigned char opcode[15];
26912 unsigned long addr = convert_ip_to_linear(child, regs);
26913
26914 + if (addr == -EINVAL)
26915 + return 0;
26916 +
26917 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26918 for (i = 0; i < copied; i++) {
26919 switch (opcode[i]) {
26920 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26921 new file mode 100644
26922 index 0000000..5877189
26923 --- /dev/null
26924 +++ b/arch/x86/kernel/sys_i386_32.c
26925 @@ -0,0 +1,189 @@
26926 +/*
26927 + * This file contains various random system calls that
26928 + * have a non-standard calling sequence on the Linux/i386
26929 + * platform.
26930 + */
26931 +
26932 +#include <linux/errno.h>
26933 +#include <linux/sched.h>
26934 +#include <linux/mm.h>
26935 +#include <linux/fs.h>
26936 +#include <linux/smp.h>
26937 +#include <linux/sem.h>
26938 +#include <linux/msg.h>
26939 +#include <linux/shm.h>
26940 +#include <linux/stat.h>
26941 +#include <linux/syscalls.h>
26942 +#include <linux/mman.h>
26943 +#include <linux/file.h>
26944 +#include <linux/utsname.h>
26945 +#include <linux/ipc.h>
26946 +#include <linux/elf.h>
26947 +
26948 +#include <linux/uaccess.h>
26949 +#include <linux/unistd.h>
26950 +
26951 +#include <asm/syscalls.h>
26952 +
26953 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26954 +{
26955 + unsigned long pax_task_size = TASK_SIZE;
26956 +
26957 +#ifdef CONFIG_PAX_SEGMEXEC
26958 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26959 + pax_task_size = SEGMEXEC_TASK_SIZE;
26960 +#endif
26961 +
26962 + if (flags & MAP_FIXED)
26963 + if (len > pax_task_size || addr > pax_task_size - len)
26964 + return -EINVAL;
26965 +
26966 + return 0;
26967 +}
26968 +
26969 +/*
26970 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26971 + */
26972 +static unsigned long get_align_mask(void)
26973 +{
26974 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26975 + return 0;
26976 +
26977 + if (!(current->flags & PF_RANDOMIZE))
26978 + return 0;
26979 +
26980 + return va_align.mask;
26981 +}
26982 +
26983 +unsigned long
26984 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
26985 + unsigned long len, unsigned long pgoff, unsigned long flags)
26986 +{
26987 + struct mm_struct *mm = current->mm;
26988 + struct vm_area_struct *vma;
26989 + unsigned long pax_task_size = TASK_SIZE;
26990 + struct vm_unmapped_area_info info;
26991 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26992 +
26993 +#ifdef CONFIG_PAX_SEGMEXEC
26994 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26995 + pax_task_size = SEGMEXEC_TASK_SIZE;
26996 +#endif
26997 +
26998 + pax_task_size -= PAGE_SIZE;
26999 +
27000 + if (len > pax_task_size)
27001 + return -ENOMEM;
27002 +
27003 + if (flags & MAP_FIXED)
27004 + return addr;
27005 +
27006 +#ifdef CONFIG_PAX_RANDMMAP
27007 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27008 +#endif
27009 +
27010 + if (addr) {
27011 + addr = PAGE_ALIGN(addr);
27012 + if (pax_task_size - len >= addr) {
27013 + vma = find_vma(mm, addr);
27014 + if (check_heap_stack_gap(vma, addr, len, offset))
27015 + return addr;
27016 + }
27017 + }
27018 +
27019 + info.flags = 0;
27020 + info.length = len;
27021 + info.align_mask = filp ? get_align_mask() : 0;
27022 + info.align_offset = pgoff << PAGE_SHIFT;
27023 + info.threadstack_offset = offset;
27024 +
27025 +#ifdef CONFIG_PAX_PAGEEXEC
27026 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27027 + info.low_limit = 0x00110000UL;
27028 + info.high_limit = mm->start_code;
27029 +
27030 +#ifdef CONFIG_PAX_RANDMMAP
27031 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27032 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27033 +#endif
27034 +
27035 + if (info.low_limit < info.high_limit) {
27036 + addr = vm_unmapped_area(&info);
27037 + if (!IS_ERR_VALUE(addr))
27038 + return addr;
27039 + }
27040 + } else
27041 +#endif
27042 +
27043 + info.low_limit = mm->mmap_base;
27044 + info.high_limit = pax_task_size;
27045 +
27046 + return vm_unmapped_area(&info);
27047 +}
27048 +
27049 +unsigned long
27050 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27051 + const unsigned long len, const unsigned long pgoff,
27052 + const unsigned long flags)
27053 +{
27054 + struct vm_area_struct *vma;
27055 + struct mm_struct *mm = current->mm;
27056 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27057 + struct vm_unmapped_area_info info;
27058 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27059 +
27060 +#ifdef CONFIG_PAX_SEGMEXEC
27061 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27062 + pax_task_size = SEGMEXEC_TASK_SIZE;
27063 +#endif
27064 +
27065 + pax_task_size -= PAGE_SIZE;
27066 +
27067 + /* requested length too big for entire address space */
27068 + if (len > pax_task_size)
27069 + return -ENOMEM;
27070 +
27071 + if (flags & MAP_FIXED)
27072 + return addr;
27073 +
27074 +#ifdef CONFIG_PAX_PAGEEXEC
27075 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27076 + goto bottomup;
27077 +#endif
27078 +
27079 +#ifdef CONFIG_PAX_RANDMMAP
27080 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27081 +#endif
27082 +
27083 + /* requesting a specific address */
27084 + if (addr) {
27085 + addr = PAGE_ALIGN(addr);
27086 + if (pax_task_size - len >= addr) {
27087 + vma = find_vma(mm, addr);
27088 + if (check_heap_stack_gap(vma, addr, len, offset))
27089 + return addr;
27090 + }
27091 + }
27092 +
27093 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27094 + info.length = len;
27095 + info.low_limit = PAGE_SIZE;
27096 + info.high_limit = mm->mmap_base;
27097 + info.align_mask = filp ? get_align_mask() : 0;
27098 + info.align_offset = pgoff << PAGE_SHIFT;
27099 + info.threadstack_offset = offset;
27100 +
27101 + addr = vm_unmapped_area(&info);
27102 + if (!(addr & ~PAGE_MASK))
27103 + return addr;
27104 + VM_BUG_ON(addr != -ENOMEM);
27105 +
27106 +bottomup:
27107 + /*
27108 + * A failed mmap() very likely causes application failure,
27109 + * so fall back to the bottom-up function here. This scenario
27110 + * can happen with large stack limits and large mmap()
27111 + * allocations.
27112 + */
27113 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27114 +}
27115 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27116 index 30277e2..5664a29 100644
27117 --- a/arch/x86/kernel/sys_x86_64.c
27118 +++ b/arch/x86/kernel/sys_x86_64.c
27119 @@ -81,8 +81,8 @@ out:
27120 return error;
27121 }
27122
27123 -static void find_start_end(unsigned long flags, unsigned long *begin,
27124 - unsigned long *end)
27125 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27126 + unsigned long *begin, unsigned long *end)
27127 {
27128 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27129 unsigned long new_begin;
27130 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27131 *begin = new_begin;
27132 }
27133 } else {
27134 - *begin = current->mm->mmap_legacy_base;
27135 + *begin = mm->mmap_legacy_base;
27136 *end = TASK_SIZE;
27137 }
27138 }
27139 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27140 struct vm_area_struct *vma;
27141 struct vm_unmapped_area_info info;
27142 unsigned long begin, end;
27143 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27144
27145 if (flags & MAP_FIXED)
27146 return addr;
27147
27148 - find_start_end(flags, &begin, &end);
27149 + find_start_end(mm, flags, &begin, &end);
27150
27151 if (len > end)
27152 return -ENOMEM;
27153
27154 +#ifdef CONFIG_PAX_RANDMMAP
27155 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27156 +#endif
27157 +
27158 if (addr) {
27159 addr = PAGE_ALIGN(addr);
27160 vma = find_vma(mm, addr);
27161 - if (end - len >= addr &&
27162 - (!vma || addr + len <= vma->vm_start))
27163 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27164 return addr;
27165 }
27166
27167 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27168 info.high_limit = end;
27169 info.align_mask = filp ? get_align_mask() : 0;
27170 info.align_offset = pgoff << PAGE_SHIFT;
27171 + info.threadstack_offset = offset;
27172 return vm_unmapped_area(&info);
27173 }
27174
27175 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27176 struct mm_struct *mm = current->mm;
27177 unsigned long addr = addr0;
27178 struct vm_unmapped_area_info info;
27179 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27180
27181 /* requested length too big for entire address space */
27182 if (len > TASK_SIZE)
27183 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27184 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27185 goto bottomup;
27186
27187 +#ifdef CONFIG_PAX_RANDMMAP
27188 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27189 +#endif
27190 +
27191 /* requesting a specific address */
27192 if (addr) {
27193 addr = PAGE_ALIGN(addr);
27194 vma = find_vma(mm, addr);
27195 - if (TASK_SIZE - len >= addr &&
27196 - (!vma || addr + len <= vma->vm_start))
27197 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27198 return addr;
27199 }
27200
27201 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27202 info.high_limit = mm->mmap_base;
27203 info.align_mask = filp ? get_align_mask() : 0;
27204 info.align_offset = pgoff << PAGE_SHIFT;
27205 + info.threadstack_offset = offset;
27206 addr = vm_unmapped_area(&info);
27207 if (!(addr & ~PAGE_MASK))
27208 return addr;
27209 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27210 index 91a4496..bb87552 100644
27211 --- a/arch/x86/kernel/tboot.c
27212 +++ b/arch/x86/kernel/tboot.c
27213 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27214
27215 void tboot_shutdown(u32 shutdown_type)
27216 {
27217 - void (*shutdown)(void);
27218 + void (* __noreturn shutdown)(void);
27219
27220 if (!tboot_enabled())
27221 return;
27222 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27223
27224 switch_to_tboot_pt();
27225
27226 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27227 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27228 shutdown();
27229
27230 /* should not reach here */
27231 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27232 return -ENODEV;
27233 }
27234
27235 -static atomic_t ap_wfs_count;
27236 +static atomic_unchecked_t ap_wfs_count;
27237
27238 static int tboot_wait_for_aps(int num_aps)
27239 {
27240 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27241 {
27242 switch (action) {
27243 case CPU_DYING:
27244 - atomic_inc(&ap_wfs_count);
27245 + atomic_inc_unchecked(&ap_wfs_count);
27246 if (num_online_cpus() == 1)
27247 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27248 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27249 return NOTIFY_BAD;
27250 break;
27251 }
27252 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27253
27254 tboot_create_trampoline();
27255
27256 - atomic_set(&ap_wfs_count, 0);
27257 + atomic_set_unchecked(&ap_wfs_count, 0);
27258 register_hotcpu_notifier(&tboot_cpu_notifier);
27259
27260 #ifdef CONFIG_DEBUG_FS
27261 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27262 index 24d3c91..d06b473 100644
27263 --- a/arch/x86/kernel/time.c
27264 +++ b/arch/x86/kernel/time.c
27265 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27266 {
27267 unsigned long pc = instruction_pointer(regs);
27268
27269 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27270 + if (!user_mode(regs) && in_lock_functions(pc)) {
27271 #ifdef CONFIG_FRAME_POINTER
27272 - return *(unsigned long *)(regs->bp + sizeof(long));
27273 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27274 #else
27275 unsigned long *sp =
27276 (unsigned long *)kernel_stack_pointer(regs);
27277 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27278 * or above a saved flags. Eflags has bits 22-31 zero,
27279 * kernel addresses don't.
27280 */
27281 +
27282 +#ifdef CONFIG_PAX_KERNEXEC
27283 + return ktla_ktva(sp[0]);
27284 +#else
27285 if (sp[0] >> 22)
27286 return sp[0];
27287 if (sp[1] >> 22)
27288 return sp[1];
27289 #endif
27290 +
27291 +#endif
27292 }
27293 return pc;
27294 }
27295 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27296 index f7fec09..9991981 100644
27297 --- a/arch/x86/kernel/tls.c
27298 +++ b/arch/x86/kernel/tls.c
27299 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27300 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27301 return -EINVAL;
27302
27303 +#ifdef CONFIG_PAX_SEGMEXEC
27304 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27305 + return -EINVAL;
27306 +#endif
27307 +
27308 set_tls_desc(p, idx, &info, 1);
27309
27310 return 0;
27311 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27312
27313 if (kbuf)
27314 info = kbuf;
27315 - else if (__copy_from_user(infobuf, ubuf, count))
27316 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27317 return -EFAULT;
27318 else
27319 info = infobuf;
27320 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27321 index 1c113db..287b42e 100644
27322 --- a/arch/x86/kernel/tracepoint.c
27323 +++ b/arch/x86/kernel/tracepoint.c
27324 @@ -9,11 +9,11 @@
27325 #include <linux/atomic.h>
27326
27327 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27328 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27329 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27330 (unsigned long) trace_idt_table };
27331
27332 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27333 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27334 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27335
27336 static int trace_irq_vector_refcount;
27337 static DEFINE_MUTEX(irq_vector_mutex);
27338 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27339 index 57409f6..e2c17e1 100644
27340 --- a/arch/x86/kernel/traps.c
27341 +++ b/arch/x86/kernel/traps.c
27342 @@ -66,7 +66,7 @@
27343 #include <asm/proto.h>
27344
27345 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27346 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27347 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27348 #else
27349 #include <asm/processor-flags.h>
27350 #include <asm/setup.h>
27351 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27352 #endif
27353
27354 /* Must be page-aligned because the real IDT is used in a fixmap. */
27355 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27356 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27357
27358 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27359 EXPORT_SYMBOL_GPL(used_vectors);
27360 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27361 }
27362
27363 static int __kprobes
27364 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27365 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27366 struct pt_regs *regs, long error_code)
27367 {
27368 #ifdef CONFIG_X86_32
27369 - if (regs->flags & X86_VM_MASK) {
27370 + if (v8086_mode(regs)) {
27371 /*
27372 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27373 * On nmi (interrupt 2), do_trap should not be called.
27374 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27375 return -1;
27376 }
27377 #endif
27378 - if (!user_mode(regs)) {
27379 + if (!user_mode_novm(regs)) {
27380 if (!fixup_exception(regs)) {
27381 tsk->thread.error_code = error_code;
27382 tsk->thread.trap_nr = trapnr;
27383 +
27384 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27385 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27386 + str = "PAX: suspicious stack segment fault";
27387 +#endif
27388 +
27389 die(str, regs, error_code);
27390 }
27391 +
27392 +#ifdef CONFIG_PAX_REFCOUNT
27393 + if (trapnr == X86_TRAP_OF)
27394 + pax_report_refcount_overflow(regs);
27395 +#endif
27396 +
27397 return 0;
27398 }
27399
27400 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27401 }
27402
27403 static void __kprobes
27404 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27405 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27406 long error_code, siginfo_t *info)
27407 {
27408 struct task_struct *tsk = current;
27409 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27410 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27411 printk_ratelimit()) {
27412 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27413 - tsk->comm, tsk->pid, str,
27414 + tsk->comm, task_pid_nr(tsk), str,
27415 regs->ip, regs->sp, error_code);
27416 print_vma_addr(" in ", regs->ip);
27417 pr_cont("\n");
27418 @@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27419 conditional_sti(regs);
27420
27421 #ifdef CONFIG_X86_32
27422 - if (regs->flags & X86_VM_MASK) {
27423 + if (v8086_mode(regs)) {
27424 local_irq_enable();
27425 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27426 goto exit;
27427 @@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27428 #endif
27429
27430 tsk = current;
27431 - if (!user_mode(regs)) {
27432 + if (!user_mode_novm(regs)) {
27433 if (fixup_exception(regs))
27434 goto exit;
27435
27436 tsk->thread.error_code = error_code;
27437 tsk->thread.trap_nr = X86_TRAP_GP;
27438 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27439 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27440 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27441 +
27442 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27443 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27444 + die("PAX: suspicious general protection fault", regs, error_code);
27445 + else
27446 +#endif
27447 +
27448 die("general protection fault", regs, error_code);
27449 + }
27450 goto exit;
27451 }
27452
27453 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27454 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27455 + struct mm_struct *mm = tsk->mm;
27456 + unsigned long limit;
27457 +
27458 + down_write(&mm->mmap_sem);
27459 + limit = mm->context.user_cs_limit;
27460 + if (limit < TASK_SIZE) {
27461 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27462 + up_write(&mm->mmap_sem);
27463 + return;
27464 + }
27465 + up_write(&mm->mmap_sem);
27466 + }
27467 +#endif
27468 +
27469 tsk->thread.error_code = error_code;
27470 tsk->thread.trap_nr = X86_TRAP_GP;
27471
27472 @@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27473 /* It's safe to allow irq's after DR6 has been saved */
27474 preempt_conditional_sti(regs);
27475
27476 - if (regs->flags & X86_VM_MASK) {
27477 + if (v8086_mode(regs)) {
27478 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27479 X86_TRAP_DB);
27480 preempt_conditional_cli(regs);
27481 @@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27482 * We already checked v86 mode above, so we can check for kernel mode
27483 * by just checking the CPL of CS.
27484 */
27485 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27486 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27487 tsk->thread.debugreg6 &= ~DR_STEP;
27488 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27489 regs->flags &= ~X86_EFLAGS_TF;
27490 @@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27491 return;
27492 conditional_sti(regs);
27493
27494 - if (!user_mode_vm(regs))
27495 + if (!user_mode(regs))
27496 {
27497 if (!fixup_exception(regs)) {
27498 task->thread.error_code = error_code;
27499 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27500 index cfbe99f..a6e8fa7 100644
27501 --- a/arch/x86/kernel/tsc.c
27502 +++ b/arch/x86/kernel/tsc.c
27503 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27504 */
27505 smp_wmb();
27506
27507 - ACCESS_ONCE(c2n->head) = data;
27508 + ACCESS_ONCE_RW(c2n->head) = data;
27509 }
27510
27511 /*
27512 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27513 index 2ed8459..7cf329f 100644
27514 --- a/arch/x86/kernel/uprobes.c
27515 +++ b/arch/x86/kernel/uprobes.c
27516 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27517 int ret = NOTIFY_DONE;
27518
27519 /* We are only interested in userspace traps */
27520 - if (regs && !user_mode_vm(regs))
27521 + if (regs && !user_mode(regs))
27522 return NOTIFY_DONE;
27523
27524 switch (val) {
27525 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27526
27527 if (ncopied != rasize) {
27528 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27529 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27530 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27531
27532 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27533 }
27534 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27535 index b9242ba..50c5edd 100644
27536 --- a/arch/x86/kernel/verify_cpu.S
27537 +++ b/arch/x86/kernel/verify_cpu.S
27538 @@ -20,6 +20,7 @@
27539 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27540 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27541 * arch/x86/kernel/head_32.S: processor startup
27542 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27543 *
27544 * verify_cpu, returns the status of longmode and SSE in register %eax.
27545 * 0: Success 1: Failure
27546 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27547 index e8edcf5..27f9344 100644
27548 --- a/arch/x86/kernel/vm86_32.c
27549 +++ b/arch/x86/kernel/vm86_32.c
27550 @@ -44,6 +44,7 @@
27551 #include <linux/ptrace.h>
27552 #include <linux/audit.h>
27553 #include <linux/stddef.h>
27554 +#include <linux/grsecurity.h>
27555
27556 #include <asm/uaccess.h>
27557 #include <asm/io.h>
27558 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27559 do_exit(SIGSEGV);
27560 }
27561
27562 - tss = &per_cpu(init_tss, get_cpu());
27563 + tss = init_tss + get_cpu();
27564 current->thread.sp0 = current->thread.saved_sp0;
27565 current->thread.sysenter_cs = __KERNEL_CS;
27566 load_sp0(tss, &current->thread);
27567 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27568
27569 if (tsk->thread.saved_sp0)
27570 return -EPERM;
27571 +
27572 +#ifdef CONFIG_GRKERNSEC_VM86
27573 + if (!capable(CAP_SYS_RAWIO)) {
27574 + gr_handle_vm86();
27575 + return -EPERM;
27576 + }
27577 +#endif
27578 +
27579 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27580 offsetof(struct kernel_vm86_struct, vm86plus) -
27581 sizeof(info.regs));
27582 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27583 int tmp;
27584 struct vm86plus_struct __user *v86;
27585
27586 +#ifdef CONFIG_GRKERNSEC_VM86
27587 + if (!capable(CAP_SYS_RAWIO)) {
27588 + gr_handle_vm86();
27589 + return -EPERM;
27590 + }
27591 +#endif
27592 +
27593 tsk = current;
27594 switch (cmd) {
27595 case VM86_REQUEST_IRQ:
27596 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27597 tsk->thread.saved_fs = info->regs32->fs;
27598 tsk->thread.saved_gs = get_user_gs(info->regs32);
27599
27600 - tss = &per_cpu(init_tss, get_cpu());
27601 + tss = init_tss + get_cpu();
27602 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27603 if (cpu_has_sep)
27604 tsk->thread.sysenter_cs = 0;
27605 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27606 goto cannot_handle;
27607 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27608 goto cannot_handle;
27609 - intr_ptr = (unsigned long __user *) (i << 2);
27610 + intr_ptr = (__force unsigned long __user *) (i << 2);
27611 if (get_user(segoffs, intr_ptr))
27612 goto cannot_handle;
27613 if ((segoffs >> 16) == BIOSSEG)
27614 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27615 index da6b35a..977e9cf 100644
27616 --- a/arch/x86/kernel/vmlinux.lds.S
27617 +++ b/arch/x86/kernel/vmlinux.lds.S
27618 @@ -26,6 +26,13 @@
27619 #include <asm/page_types.h>
27620 #include <asm/cache.h>
27621 #include <asm/boot.h>
27622 +#include <asm/segment.h>
27623 +
27624 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27625 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27626 +#else
27627 +#define __KERNEL_TEXT_OFFSET 0
27628 +#endif
27629
27630 #undef i386 /* in case the preprocessor is a 32bit one */
27631
27632 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27633
27634 PHDRS {
27635 text PT_LOAD FLAGS(5); /* R_E */
27636 +#ifdef CONFIG_X86_32
27637 + module PT_LOAD FLAGS(5); /* R_E */
27638 +#endif
27639 +#ifdef CONFIG_XEN
27640 + rodata PT_LOAD FLAGS(5); /* R_E */
27641 +#else
27642 + rodata PT_LOAD FLAGS(4); /* R__ */
27643 +#endif
27644 data PT_LOAD FLAGS(6); /* RW_ */
27645 -#ifdef CONFIG_X86_64
27646 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27647 #ifdef CONFIG_SMP
27648 percpu PT_LOAD FLAGS(6); /* RW_ */
27649 #endif
27650 + text.init PT_LOAD FLAGS(5); /* R_E */
27651 + text.exit PT_LOAD FLAGS(5); /* R_E */
27652 init PT_LOAD FLAGS(7); /* RWE */
27653 -#endif
27654 note PT_NOTE FLAGS(0); /* ___ */
27655 }
27656
27657 SECTIONS
27658 {
27659 #ifdef CONFIG_X86_32
27660 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27661 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27662 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27663 #else
27664 - . = __START_KERNEL;
27665 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27666 + . = __START_KERNEL;
27667 #endif
27668
27669 /* Text and read-only data */
27670 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27671 - _text = .;
27672 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27673 /* bootstrapping code */
27674 +#ifdef CONFIG_X86_32
27675 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27676 +#else
27677 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27678 +#endif
27679 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27680 + _text = .;
27681 HEAD_TEXT
27682 . = ALIGN(8);
27683 _stext = .;
27684 @@ -104,13 +124,47 @@ SECTIONS
27685 IRQENTRY_TEXT
27686 *(.fixup)
27687 *(.gnu.warning)
27688 - /* End of text section */
27689 - _etext = .;
27690 } :text = 0x9090
27691
27692 - NOTES :text :note
27693 + . += __KERNEL_TEXT_OFFSET;
27694
27695 - EXCEPTION_TABLE(16) :text = 0x9090
27696 +#ifdef CONFIG_X86_32
27697 + . = ALIGN(PAGE_SIZE);
27698 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27699 +
27700 +#ifdef CONFIG_PAX_KERNEXEC
27701 + MODULES_EXEC_VADDR = .;
27702 + BYTE(0)
27703 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27704 + . = ALIGN(HPAGE_SIZE) - 1;
27705 + MODULES_EXEC_END = .;
27706 +#endif
27707 +
27708 + } :module
27709 +#endif
27710 +
27711 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27712 + /* End of text section */
27713 + BYTE(0)
27714 + _etext = . - __KERNEL_TEXT_OFFSET;
27715 + }
27716 +
27717 +#ifdef CONFIG_X86_32
27718 + . = ALIGN(PAGE_SIZE);
27719 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27720 + . = ALIGN(PAGE_SIZE);
27721 + *(.empty_zero_page)
27722 + *(.initial_pg_fixmap)
27723 + *(.initial_pg_pmd)
27724 + *(.initial_page_table)
27725 + *(.swapper_pg_dir)
27726 + } :rodata
27727 +#endif
27728 +
27729 + . = ALIGN(PAGE_SIZE);
27730 + NOTES :rodata :note
27731 +
27732 + EXCEPTION_TABLE(16) :rodata
27733
27734 #if defined(CONFIG_DEBUG_RODATA)
27735 /* .text should occupy whole number of pages */
27736 @@ -122,16 +176,20 @@ SECTIONS
27737
27738 /* Data */
27739 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27740 +
27741 +#ifdef CONFIG_PAX_KERNEXEC
27742 + . = ALIGN(HPAGE_SIZE);
27743 +#else
27744 + . = ALIGN(PAGE_SIZE);
27745 +#endif
27746 +
27747 /* Start of data section */
27748 _sdata = .;
27749
27750 /* init_task */
27751 INIT_TASK_DATA(THREAD_SIZE)
27752
27753 -#ifdef CONFIG_X86_32
27754 - /* 32 bit has nosave before _edata */
27755 NOSAVE_DATA
27756 -#endif
27757
27758 PAGE_ALIGNED_DATA(PAGE_SIZE)
27759
27760 @@ -172,12 +230,19 @@ SECTIONS
27761 #endif /* CONFIG_X86_64 */
27762
27763 /* Init code and data - will be freed after init */
27764 - . = ALIGN(PAGE_SIZE);
27765 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27766 + BYTE(0)
27767 +
27768 +#ifdef CONFIG_PAX_KERNEXEC
27769 + . = ALIGN(HPAGE_SIZE);
27770 +#else
27771 + . = ALIGN(PAGE_SIZE);
27772 +#endif
27773 +
27774 __init_begin = .; /* paired with __init_end */
27775 - }
27776 + } :init.begin
27777
27778 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27779 +#ifdef CONFIG_SMP
27780 /*
27781 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27782 * output PHDR, so the next output section - .init.text - should
27783 @@ -186,12 +251,27 @@ SECTIONS
27784 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27785 #endif
27786
27787 - INIT_TEXT_SECTION(PAGE_SIZE)
27788 -#ifdef CONFIG_X86_64
27789 - :init
27790 -#endif
27791 + . = ALIGN(PAGE_SIZE);
27792 + init_begin = .;
27793 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27794 + VMLINUX_SYMBOL(_sinittext) = .;
27795 + INIT_TEXT
27796 + VMLINUX_SYMBOL(_einittext) = .;
27797 + . = ALIGN(PAGE_SIZE);
27798 + } :text.init
27799
27800 - INIT_DATA_SECTION(16)
27801 + /*
27802 + * .exit.text is discard at runtime, not link time, to deal with
27803 + * references from .altinstructions and .eh_frame
27804 + */
27805 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27806 + EXIT_TEXT
27807 + . = ALIGN(16);
27808 + } :text.exit
27809 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27810 +
27811 + . = ALIGN(PAGE_SIZE);
27812 + INIT_DATA_SECTION(16) :init
27813
27814 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27815 __x86_cpu_dev_start = .;
27816 @@ -262,19 +342,12 @@ SECTIONS
27817 }
27818
27819 . = ALIGN(8);
27820 - /*
27821 - * .exit.text is discard at runtime, not link time, to deal with
27822 - * references from .altinstructions and .eh_frame
27823 - */
27824 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27825 - EXIT_TEXT
27826 - }
27827
27828 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27829 EXIT_DATA
27830 }
27831
27832 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27833 +#ifndef CONFIG_SMP
27834 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27835 #endif
27836
27837 @@ -293,16 +366,10 @@ SECTIONS
27838 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27839 __smp_locks = .;
27840 *(.smp_locks)
27841 - . = ALIGN(PAGE_SIZE);
27842 __smp_locks_end = .;
27843 + . = ALIGN(PAGE_SIZE);
27844 }
27845
27846 -#ifdef CONFIG_X86_64
27847 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27848 - NOSAVE_DATA
27849 - }
27850 -#endif
27851 -
27852 /* BSS */
27853 . = ALIGN(PAGE_SIZE);
27854 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27855 @@ -318,6 +385,7 @@ SECTIONS
27856 __brk_base = .;
27857 . += 64 * 1024; /* 64k alignment slop space */
27858 *(.brk_reservation) /* areas brk users have reserved */
27859 + . = ALIGN(HPAGE_SIZE);
27860 __brk_limit = .;
27861 }
27862
27863 @@ -344,13 +412,12 @@ SECTIONS
27864 * for the boot processor.
27865 */
27866 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27867 -INIT_PER_CPU(gdt_page);
27868 INIT_PER_CPU(irq_stack_union);
27869
27870 /*
27871 * Build-time check on the image size:
27872 */
27873 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27874 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27875 "kernel image bigger than KERNEL_IMAGE_SIZE");
27876
27877 #ifdef CONFIG_SMP
27878 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27879 index 1f96f93..d5c8f7a 100644
27880 --- a/arch/x86/kernel/vsyscall_64.c
27881 +++ b/arch/x86/kernel/vsyscall_64.c
27882 @@ -56,15 +56,13 @@
27883 DEFINE_VVAR(int, vgetcpu_mode);
27884 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27885
27886 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27887 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27888
27889 static int __init vsyscall_setup(char *str)
27890 {
27891 if (str) {
27892 if (!strcmp("emulate", str))
27893 vsyscall_mode = EMULATE;
27894 - else if (!strcmp("native", str))
27895 - vsyscall_mode = NATIVE;
27896 else if (!strcmp("none", str))
27897 vsyscall_mode = NONE;
27898 else
27899 @@ -323,8 +321,7 @@ do_ret:
27900 return true;
27901
27902 sigsegv:
27903 - force_sig(SIGSEGV, current);
27904 - return true;
27905 + do_group_exit(SIGKILL);
27906 }
27907
27908 /*
27909 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27910 extern char __vvar_page;
27911 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27912
27913 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27914 - vsyscall_mode == NATIVE
27915 - ? PAGE_KERNEL_VSYSCALL
27916 - : PAGE_KERNEL_VVAR);
27917 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27918 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27919 (unsigned long)VSYSCALL_START);
27920
27921 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27922 index 04068192..4d75aa6 100644
27923 --- a/arch/x86/kernel/x8664_ksyms_64.c
27924 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27925 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27926 EXPORT_SYMBOL(copy_user_generic_unrolled);
27927 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27928 EXPORT_SYMBOL(__copy_user_nocache);
27929 -EXPORT_SYMBOL(_copy_from_user);
27930 -EXPORT_SYMBOL(_copy_to_user);
27931
27932 EXPORT_SYMBOL(copy_page);
27933 EXPORT_SYMBOL(clear_page);
27934 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27935 EXPORT_SYMBOL(___preempt_schedule_context);
27936 #endif
27937 #endif
27938 +
27939 +#ifdef CONFIG_PAX_PER_CPU_PGD
27940 +EXPORT_SYMBOL(cpu_pgd);
27941 +#endif
27942 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27943 index e48b674..a451dd9 100644
27944 --- a/arch/x86/kernel/x86_init.c
27945 +++ b/arch/x86/kernel/x86_init.c
27946 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27947 static void default_nmi_init(void) { };
27948 static int default_i8042_detect(void) { return 1; };
27949
27950 -struct x86_platform_ops x86_platform = {
27951 +struct x86_platform_ops x86_platform __read_only = {
27952 .calibrate_tsc = native_calibrate_tsc,
27953 .get_wallclock = mach_get_cmos_time,
27954 .set_wallclock = mach_set_rtc_mmss,
27955 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27956 EXPORT_SYMBOL_GPL(x86_platform);
27957
27958 #if defined(CONFIG_PCI_MSI)
27959 -struct x86_msi_ops x86_msi = {
27960 +struct x86_msi_ops x86_msi __read_only = {
27961 .setup_msi_irqs = native_setup_msi_irqs,
27962 .compose_msi_msg = native_compose_msi_msg,
27963 .teardown_msi_irq = native_teardown_msi_irq,
27964 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27965 }
27966 #endif
27967
27968 -struct x86_io_apic_ops x86_io_apic_ops = {
27969 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27970 .init = native_io_apic_init_mappings,
27971 .read = native_io_apic_read,
27972 .write = native_io_apic_write,
27973 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27974 index a4b451c..8dfe1ad 100644
27975 --- a/arch/x86/kernel/xsave.c
27976 +++ b/arch/x86/kernel/xsave.c
27977 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27978
27979 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27980 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27981 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27982 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27983
27984 if (!use_xsave())
27985 return err;
27986
27987 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27988 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27989
27990 /*
27991 * Read the xstate_bv which we copied (directly from the cpu or
27992 * from the state in task struct) to the user buffers.
27993 */
27994 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27995 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27996
27997 /*
27998 * For legacy compatible, we always set FP/SSE bits in the bit
27999 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28000 */
28001 xstate_bv |= XSTATE_FPSSE;
28002
28003 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28004 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28005
28006 return err;
28007 }
28008 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28009 {
28010 int err;
28011
28012 + buf = (struct xsave_struct __user *)____m(buf);
28013 if (use_xsave())
28014 err = xsave_user(buf);
28015 else if (use_fxsr())
28016 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28017 */
28018 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28019 {
28020 + buf = (void __user *)____m(buf);
28021 if (use_xsave()) {
28022 if ((unsigned long)buf % 64 || fx_only) {
28023 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28024 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28025 index c697625..a032162 100644
28026 --- a/arch/x86/kvm/cpuid.c
28027 +++ b/arch/x86/kvm/cpuid.c
28028 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28029 struct kvm_cpuid2 *cpuid,
28030 struct kvm_cpuid_entry2 __user *entries)
28031 {
28032 - int r;
28033 + int r, i;
28034
28035 r = -E2BIG;
28036 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28037 goto out;
28038 r = -EFAULT;
28039 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28040 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28041 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28042 goto out;
28043 + for (i = 0; i < cpuid->nent; ++i) {
28044 + struct kvm_cpuid_entry2 cpuid_entry;
28045 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28046 + goto out;
28047 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28048 + }
28049 vcpu->arch.cpuid_nent = cpuid->nent;
28050 kvm_apic_set_version(vcpu);
28051 kvm_x86_ops->cpuid_update(vcpu);
28052 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28053 struct kvm_cpuid2 *cpuid,
28054 struct kvm_cpuid_entry2 __user *entries)
28055 {
28056 - int r;
28057 + int r, i;
28058
28059 r = -E2BIG;
28060 if (cpuid->nent < vcpu->arch.cpuid_nent)
28061 goto out;
28062 r = -EFAULT;
28063 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28064 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28065 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28066 goto out;
28067 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28068 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28069 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28070 + goto out;
28071 + }
28072 return 0;
28073
28074 out:
28075 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28076 index 9736529..ab4f54c 100644
28077 --- a/arch/x86/kvm/lapic.c
28078 +++ b/arch/x86/kvm/lapic.c
28079 @@ -55,7 +55,7 @@
28080 #define APIC_BUS_CYCLE_NS 1
28081
28082 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28083 -#define apic_debug(fmt, arg...)
28084 +#define apic_debug(fmt, arg...) do {} while (0)
28085
28086 #define APIC_LVT_NUM 6
28087 /* 14 is the version for Xeon and Pentium 8.4.8*/
28088 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28089 index cba218a..1cc1bed 100644
28090 --- a/arch/x86/kvm/paging_tmpl.h
28091 +++ b/arch/x86/kvm/paging_tmpl.h
28092 @@ -331,7 +331,7 @@ retry_walk:
28093 if (unlikely(kvm_is_error_hva(host_addr)))
28094 goto error;
28095
28096 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28097 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28098 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28099 goto error;
28100 walker->ptep_user[walker->level - 1] = ptep_user;
28101 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28102 index 2de1bc0..22251ee 100644
28103 --- a/arch/x86/kvm/svm.c
28104 +++ b/arch/x86/kvm/svm.c
28105 @@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28106 int cpu = raw_smp_processor_id();
28107
28108 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28109 +
28110 + pax_open_kernel();
28111 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28112 + pax_close_kernel();
28113 +
28114 load_TR_desc();
28115 }
28116
28117 @@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28118 #endif
28119 #endif
28120
28121 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28122 + __set_fs(current_thread_info()->addr_limit);
28123 +#endif
28124 +
28125 reload_tss(vcpu);
28126
28127 local_irq_disable();
28128 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28129 index 3927528..fc19971 100644
28130 --- a/arch/x86/kvm/vmx.c
28131 +++ b/arch/x86/kvm/vmx.c
28132 @@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28133 #endif
28134 }
28135
28136 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28137 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28138 {
28139 vmcs_writel(field, vmcs_readl(field) & ~mask);
28140 }
28141
28142 -static void vmcs_set_bits(unsigned long field, u32 mask)
28143 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28144 {
28145 vmcs_writel(field, vmcs_readl(field) | mask);
28146 }
28147 @@ -1585,7 +1585,11 @@ static void reload_tss(void)
28148 struct desc_struct *descs;
28149
28150 descs = (void *)gdt->address;
28151 +
28152 + pax_open_kernel();
28153 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28154 + pax_close_kernel();
28155 +
28156 load_TR_desc();
28157 }
28158
28159 @@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28160 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28161 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28162
28163 +#ifdef CONFIG_PAX_PER_CPU_PGD
28164 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28165 +#endif
28166 +
28167 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28168 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28169 vmx->loaded_vmcs->cpu = cpu;
28170 @@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28171 * reads and returns guest's timestamp counter "register"
28172 * guest_tsc = host_tsc + tsc_offset -- 21.3
28173 */
28174 -static u64 guest_read_tsc(void)
28175 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28176 {
28177 u64 host_tsc, tsc_offset;
28178
28179 @@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28180 if (!cpu_has_vmx_flexpriority())
28181 flexpriority_enabled = 0;
28182
28183 - if (!cpu_has_vmx_tpr_shadow())
28184 - kvm_x86_ops->update_cr8_intercept = NULL;
28185 + if (!cpu_has_vmx_tpr_shadow()) {
28186 + pax_open_kernel();
28187 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28188 + pax_close_kernel();
28189 + }
28190
28191 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28192 kvm_disable_largepages();
28193 @@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28194 if (!cpu_has_vmx_apicv())
28195 enable_apicv = 0;
28196
28197 + pax_open_kernel();
28198 if (enable_apicv)
28199 - kvm_x86_ops->update_cr8_intercept = NULL;
28200 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28201 else {
28202 - kvm_x86_ops->hwapic_irr_update = NULL;
28203 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28204 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28205 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28206 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28207 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28208 }
28209 + pax_close_kernel();
28210
28211 if (nested)
28212 nested_vmx_setup_ctls_msrs();
28213 @@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28214
28215 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28216 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28217 +
28218 +#ifndef CONFIG_PAX_PER_CPU_PGD
28219 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28220 +#endif
28221
28222 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28223 #ifdef CONFIG_X86_64
28224 @@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28225 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28226 vmx->host_idt_base = dt.address;
28227
28228 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28229 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28230
28231 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28232 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28233 @@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28234 "jmp 2f \n\t"
28235 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28236 "2: "
28237 +
28238 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28239 + "ljmp %[cs],$3f\n\t"
28240 + "3: "
28241 +#endif
28242 +
28243 /* Save guest registers, load host registers, keep flags */
28244 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28245 "pop %0 \n\t"
28246 @@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28247 #endif
28248 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28249 [wordsize]"i"(sizeof(ulong))
28250 +
28251 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28252 + ,[cs]"i"(__KERNEL_CS)
28253 +#endif
28254 +
28255 : "cc", "memory"
28256 #ifdef CONFIG_X86_64
28257 , "rax", "rbx", "rdi", "rsi"
28258 @@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28259 if (debugctlmsr)
28260 update_debugctlmsr(debugctlmsr);
28261
28262 -#ifndef CONFIG_X86_64
28263 +#ifdef CONFIG_X86_32
28264 /*
28265 * The sysexit path does not restore ds/es, so we must set them to
28266 * a reasonable value ourselves.
28267 @@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28268 * may be executed in interrupt context, which saves and restore segments
28269 * around it, nullifying its effect.
28270 */
28271 - loadsegment(ds, __USER_DS);
28272 - loadsegment(es, __USER_DS);
28273 + loadsegment(ds, __KERNEL_DS);
28274 + loadsegment(es, __KERNEL_DS);
28275 + loadsegment(ss, __KERNEL_DS);
28276 +
28277 +#ifdef CONFIG_PAX_KERNEXEC
28278 + loadsegment(fs, __KERNEL_PERCPU);
28279 +#endif
28280 +
28281 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28282 + __set_fs(current_thread_info()->addr_limit);
28283 +#endif
28284 +
28285 #endif
28286
28287 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28288 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28289 index 2b85784..ad70e19 100644
28290 --- a/arch/x86/kvm/x86.c
28291 +++ b/arch/x86/kvm/x86.c
28292 @@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28293 {
28294 struct kvm *kvm = vcpu->kvm;
28295 int lm = is_long_mode(vcpu);
28296 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28297 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28298 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28299 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28300 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28301 : kvm->arch.xen_hvm_config.blob_size_32;
28302 u32 page_num = data & ~PAGE_MASK;
28303 @@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28304 if (n < msr_list.nmsrs)
28305 goto out;
28306 r = -EFAULT;
28307 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28308 + goto out;
28309 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28310 num_msrs_to_save * sizeof(u32)))
28311 goto out;
28312 @@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28313 };
28314 #endif
28315
28316 -int kvm_arch_init(void *opaque)
28317 +int kvm_arch_init(const void *opaque)
28318 {
28319 int r;
28320 struct kvm_x86_ops *ops = opaque;
28321 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28322 index ad1fb5f..fe30b66 100644
28323 --- a/arch/x86/lguest/boot.c
28324 +++ b/arch/x86/lguest/boot.c
28325 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28326 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28327 * Launcher to reboot us.
28328 */
28329 -static void lguest_restart(char *reason)
28330 +static __noreturn void lguest_restart(char *reason)
28331 {
28332 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28333 + BUG();
28334 }
28335
28336 /*G:050
28337 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28338 index 00933d5..3a64af9 100644
28339 --- a/arch/x86/lib/atomic64_386_32.S
28340 +++ b/arch/x86/lib/atomic64_386_32.S
28341 @@ -48,6 +48,10 @@ BEGIN(read)
28342 movl (v), %eax
28343 movl 4(v), %edx
28344 RET_ENDP
28345 +BEGIN(read_unchecked)
28346 + movl (v), %eax
28347 + movl 4(v), %edx
28348 +RET_ENDP
28349 #undef v
28350
28351 #define v %esi
28352 @@ -55,6 +59,10 @@ BEGIN(set)
28353 movl %ebx, (v)
28354 movl %ecx, 4(v)
28355 RET_ENDP
28356 +BEGIN(set_unchecked)
28357 + movl %ebx, (v)
28358 + movl %ecx, 4(v)
28359 +RET_ENDP
28360 #undef v
28361
28362 #define v %esi
28363 @@ -70,6 +78,20 @@ RET_ENDP
28364 BEGIN(add)
28365 addl %eax, (v)
28366 adcl %edx, 4(v)
28367 +
28368 +#ifdef CONFIG_PAX_REFCOUNT
28369 + jno 0f
28370 + subl %eax, (v)
28371 + sbbl %edx, 4(v)
28372 + int $4
28373 +0:
28374 + _ASM_EXTABLE(0b, 0b)
28375 +#endif
28376 +
28377 +RET_ENDP
28378 +BEGIN(add_unchecked)
28379 + addl %eax, (v)
28380 + adcl %edx, 4(v)
28381 RET_ENDP
28382 #undef v
28383
28384 @@ -77,6 +99,24 @@ RET_ENDP
28385 BEGIN(add_return)
28386 addl (v), %eax
28387 adcl 4(v), %edx
28388 +
28389 +#ifdef CONFIG_PAX_REFCOUNT
28390 + into
28391 +1234:
28392 + _ASM_EXTABLE(1234b, 2f)
28393 +#endif
28394 +
28395 + movl %eax, (v)
28396 + movl %edx, 4(v)
28397 +
28398 +#ifdef CONFIG_PAX_REFCOUNT
28399 +2:
28400 +#endif
28401 +
28402 +RET_ENDP
28403 +BEGIN(add_return_unchecked)
28404 + addl (v), %eax
28405 + adcl 4(v), %edx
28406 movl %eax, (v)
28407 movl %edx, 4(v)
28408 RET_ENDP
28409 @@ -86,6 +126,20 @@ RET_ENDP
28410 BEGIN(sub)
28411 subl %eax, (v)
28412 sbbl %edx, 4(v)
28413 +
28414 +#ifdef CONFIG_PAX_REFCOUNT
28415 + jno 0f
28416 + addl %eax, (v)
28417 + adcl %edx, 4(v)
28418 + int $4
28419 +0:
28420 + _ASM_EXTABLE(0b, 0b)
28421 +#endif
28422 +
28423 +RET_ENDP
28424 +BEGIN(sub_unchecked)
28425 + subl %eax, (v)
28426 + sbbl %edx, 4(v)
28427 RET_ENDP
28428 #undef v
28429
28430 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28431 sbbl $0, %edx
28432 addl (v), %eax
28433 adcl 4(v), %edx
28434 +
28435 +#ifdef CONFIG_PAX_REFCOUNT
28436 + into
28437 +1234:
28438 + _ASM_EXTABLE(1234b, 2f)
28439 +#endif
28440 +
28441 + movl %eax, (v)
28442 + movl %edx, 4(v)
28443 +
28444 +#ifdef CONFIG_PAX_REFCOUNT
28445 +2:
28446 +#endif
28447 +
28448 +RET_ENDP
28449 +BEGIN(sub_return_unchecked)
28450 + negl %edx
28451 + negl %eax
28452 + sbbl $0, %edx
28453 + addl (v), %eax
28454 + adcl 4(v), %edx
28455 movl %eax, (v)
28456 movl %edx, 4(v)
28457 RET_ENDP
28458 @@ -105,6 +180,20 @@ RET_ENDP
28459 BEGIN(inc)
28460 addl $1, (v)
28461 adcl $0, 4(v)
28462 +
28463 +#ifdef CONFIG_PAX_REFCOUNT
28464 + jno 0f
28465 + subl $1, (v)
28466 + sbbl $0, 4(v)
28467 + int $4
28468 +0:
28469 + _ASM_EXTABLE(0b, 0b)
28470 +#endif
28471 +
28472 +RET_ENDP
28473 +BEGIN(inc_unchecked)
28474 + addl $1, (v)
28475 + adcl $0, 4(v)
28476 RET_ENDP
28477 #undef v
28478
28479 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28480 movl 4(v), %edx
28481 addl $1, %eax
28482 adcl $0, %edx
28483 +
28484 +#ifdef CONFIG_PAX_REFCOUNT
28485 + into
28486 +1234:
28487 + _ASM_EXTABLE(1234b, 2f)
28488 +#endif
28489 +
28490 + movl %eax, (v)
28491 + movl %edx, 4(v)
28492 +
28493 +#ifdef CONFIG_PAX_REFCOUNT
28494 +2:
28495 +#endif
28496 +
28497 +RET_ENDP
28498 +BEGIN(inc_return_unchecked)
28499 + movl (v), %eax
28500 + movl 4(v), %edx
28501 + addl $1, %eax
28502 + adcl $0, %edx
28503 movl %eax, (v)
28504 movl %edx, 4(v)
28505 RET_ENDP
28506 @@ -123,6 +232,20 @@ RET_ENDP
28507 BEGIN(dec)
28508 subl $1, (v)
28509 sbbl $0, 4(v)
28510 +
28511 +#ifdef CONFIG_PAX_REFCOUNT
28512 + jno 0f
28513 + addl $1, (v)
28514 + adcl $0, 4(v)
28515 + int $4
28516 +0:
28517 + _ASM_EXTABLE(0b, 0b)
28518 +#endif
28519 +
28520 +RET_ENDP
28521 +BEGIN(dec_unchecked)
28522 + subl $1, (v)
28523 + sbbl $0, 4(v)
28524 RET_ENDP
28525 #undef v
28526
28527 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28528 movl 4(v), %edx
28529 subl $1, %eax
28530 sbbl $0, %edx
28531 +
28532 +#ifdef CONFIG_PAX_REFCOUNT
28533 + into
28534 +1234:
28535 + _ASM_EXTABLE(1234b, 2f)
28536 +#endif
28537 +
28538 + movl %eax, (v)
28539 + movl %edx, 4(v)
28540 +
28541 +#ifdef CONFIG_PAX_REFCOUNT
28542 +2:
28543 +#endif
28544 +
28545 +RET_ENDP
28546 +BEGIN(dec_return_unchecked)
28547 + movl (v), %eax
28548 + movl 4(v), %edx
28549 + subl $1, %eax
28550 + sbbl $0, %edx
28551 movl %eax, (v)
28552 movl %edx, 4(v)
28553 RET_ENDP
28554 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28555 adcl %edx, %edi
28556 addl (v), %eax
28557 adcl 4(v), %edx
28558 +
28559 +#ifdef CONFIG_PAX_REFCOUNT
28560 + into
28561 +1234:
28562 + _ASM_EXTABLE(1234b, 2f)
28563 +#endif
28564 +
28565 cmpl %eax, %ecx
28566 je 3f
28567 1:
28568 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28569 1:
28570 addl $1, %eax
28571 adcl $0, %edx
28572 +
28573 +#ifdef CONFIG_PAX_REFCOUNT
28574 + into
28575 +1234:
28576 + _ASM_EXTABLE(1234b, 2f)
28577 +#endif
28578 +
28579 movl %eax, (v)
28580 movl %edx, 4(v)
28581 movl $1, %eax
28582 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28583 movl 4(v), %edx
28584 subl $1, %eax
28585 sbbl $0, %edx
28586 +
28587 +#ifdef CONFIG_PAX_REFCOUNT
28588 + into
28589 +1234:
28590 + _ASM_EXTABLE(1234b, 1f)
28591 +#endif
28592 +
28593 js 1f
28594 movl %eax, (v)
28595 movl %edx, 4(v)
28596 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28597 index f5cc9eb..51fa319 100644
28598 --- a/arch/x86/lib/atomic64_cx8_32.S
28599 +++ b/arch/x86/lib/atomic64_cx8_32.S
28600 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28601 CFI_STARTPROC
28602
28603 read64 %ecx
28604 + pax_force_retaddr
28605 ret
28606 CFI_ENDPROC
28607 ENDPROC(atomic64_read_cx8)
28608
28609 +ENTRY(atomic64_read_unchecked_cx8)
28610 + CFI_STARTPROC
28611 +
28612 + read64 %ecx
28613 + pax_force_retaddr
28614 + ret
28615 + CFI_ENDPROC
28616 +ENDPROC(atomic64_read_unchecked_cx8)
28617 +
28618 ENTRY(atomic64_set_cx8)
28619 CFI_STARTPROC
28620
28621 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28622 cmpxchg8b (%esi)
28623 jne 1b
28624
28625 + pax_force_retaddr
28626 ret
28627 CFI_ENDPROC
28628 ENDPROC(atomic64_set_cx8)
28629
28630 +ENTRY(atomic64_set_unchecked_cx8)
28631 + CFI_STARTPROC
28632 +
28633 +1:
28634 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28635 + * are atomic on 586 and newer */
28636 + cmpxchg8b (%esi)
28637 + jne 1b
28638 +
28639 + pax_force_retaddr
28640 + ret
28641 + CFI_ENDPROC
28642 +ENDPROC(atomic64_set_unchecked_cx8)
28643 +
28644 ENTRY(atomic64_xchg_cx8)
28645 CFI_STARTPROC
28646
28647 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28648 cmpxchg8b (%esi)
28649 jne 1b
28650
28651 + pax_force_retaddr
28652 ret
28653 CFI_ENDPROC
28654 ENDPROC(atomic64_xchg_cx8)
28655
28656 -.macro addsub_return func ins insc
28657 -ENTRY(atomic64_\func\()_return_cx8)
28658 +.macro addsub_return func ins insc unchecked=""
28659 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28660 CFI_STARTPROC
28661 SAVE ebp
28662 SAVE ebx
28663 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28664 movl %edx, %ecx
28665 \ins\()l %esi, %ebx
28666 \insc\()l %edi, %ecx
28667 +
28668 +.ifb \unchecked
28669 +#ifdef CONFIG_PAX_REFCOUNT
28670 + into
28671 +2:
28672 + _ASM_EXTABLE(2b, 3f)
28673 +#endif
28674 +.endif
28675 +
28676 LOCK_PREFIX
28677 cmpxchg8b (%ebp)
28678 jne 1b
28679 -
28680 -10:
28681 movl %ebx, %eax
28682 movl %ecx, %edx
28683 +
28684 +.ifb \unchecked
28685 +#ifdef CONFIG_PAX_REFCOUNT
28686 +3:
28687 +#endif
28688 +.endif
28689 +
28690 RESTORE edi
28691 RESTORE esi
28692 RESTORE ebx
28693 RESTORE ebp
28694 + pax_force_retaddr
28695 ret
28696 CFI_ENDPROC
28697 -ENDPROC(atomic64_\func\()_return_cx8)
28698 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28699 .endm
28700
28701 addsub_return add add adc
28702 addsub_return sub sub sbb
28703 +addsub_return add add adc _unchecked
28704 +addsub_return sub sub sbb _unchecked
28705
28706 -.macro incdec_return func ins insc
28707 -ENTRY(atomic64_\func\()_return_cx8)
28708 +.macro incdec_return func ins insc unchecked=""
28709 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28710 CFI_STARTPROC
28711 SAVE ebx
28712
28713 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28714 movl %edx, %ecx
28715 \ins\()l $1, %ebx
28716 \insc\()l $0, %ecx
28717 +
28718 +.ifb \unchecked
28719 +#ifdef CONFIG_PAX_REFCOUNT
28720 + into
28721 +2:
28722 + _ASM_EXTABLE(2b, 3f)
28723 +#endif
28724 +.endif
28725 +
28726 LOCK_PREFIX
28727 cmpxchg8b (%esi)
28728 jne 1b
28729
28730 -10:
28731 movl %ebx, %eax
28732 movl %ecx, %edx
28733 +
28734 +.ifb \unchecked
28735 +#ifdef CONFIG_PAX_REFCOUNT
28736 +3:
28737 +#endif
28738 +.endif
28739 +
28740 RESTORE ebx
28741 + pax_force_retaddr
28742 ret
28743 CFI_ENDPROC
28744 -ENDPROC(atomic64_\func\()_return_cx8)
28745 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28746 .endm
28747
28748 incdec_return inc add adc
28749 incdec_return dec sub sbb
28750 +incdec_return inc add adc _unchecked
28751 +incdec_return dec sub sbb _unchecked
28752
28753 ENTRY(atomic64_dec_if_positive_cx8)
28754 CFI_STARTPROC
28755 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28756 movl %edx, %ecx
28757 subl $1, %ebx
28758 sbb $0, %ecx
28759 +
28760 +#ifdef CONFIG_PAX_REFCOUNT
28761 + into
28762 +1234:
28763 + _ASM_EXTABLE(1234b, 2f)
28764 +#endif
28765 +
28766 js 2f
28767 LOCK_PREFIX
28768 cmpxchg8b (%esi)
28769 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28770 movl %ebx, %eax
28771 movl %ecx, %edx
28772 RESTORE ebx
28773 + pax_force_retaddr
28774 ret
28775 CFI_ENDPROC
28776 ENDPROC(atomic64_dec_if_positive_cx8)
28777 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28778 movl %edx, %ecx
28779 addl %ebp, %ebx
28780 adcl %edi, %ecx
28781 +
28782 +#ifdef CONFIG_PAX_REFCOUNT
28783 + into
28784 +1234:
28785 + _ASM_EXTABLE(1234b, 3f)
28786 +#endif
28787 +
28788 LOCK_PREFIX
28789 cmpxchg8b (%esi)
28790 jne 1b
28791 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28792 CFI_ADJUST_CFA_OFFSET -8
28793 RESTORE ebx
28794 RESTORE ebp
28795 + pax_force_retaddr
28796 ret
28797 4:
28798 cmpl %edx, 4(%esp)
28799 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28800 xorl %ecx, %ecx
28801 addl $1, %ebx
28802 adcl %edx, %ecx
28803 +
28804 +#ifdef CONFIG_PAX_REFCOUNT
28805 + into
28806 +1234:
28807 + _ASM_EXTABLE(1234b, 3f)
28808 +#endif
28809 +
28810 LOCK_PREFIX
28811 cmpxchg8b (%esi)
28812 jne 1b
28813 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28814 movl $1, %eax
28815 3:
28816 RESTORE ebx
28817 + pax_force_retaddr
28818 ret
28819 CFI_ENDPROC
28820 ENDPROC(atomic64_inc_not_zero_cx8)
28821 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28822 index e78b8ee..7e173a8 100644
28823 --- a/arch/x86/lib/checksum_32.S
28824 +++ b/arch/x86/lib/checksum_32.S
28825 @@ -29,7 +29,8 @@
28826 #include <asm/dwarf2.h>
28827 #include <asm/errno.h>
28828 #include <asm/asm.h>
28829 -
28830 +#include <asm/segment.h>
28831 +
28832 /*
28833 * computes a partial checksum, e.g. for TCP/UDP fragments
28834 */
28835 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28836
28837 #define ARGBASE 16
28838 #define FP 12
28839 -
28840 -ENTRY(csum_partial_copy_generic)
28841 +
28842 +ENTRY(csum_partial_copy_generic_to_user)
28843 CFI_STARTPROC
28844 +
28845 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28846 + pushl_cfi %gs
28847 + popl_cfi %es
28848 + jmp csum_partial_copy_generic
28849 +#endif
28850 +
28851 +ENTRY(csum_partial_copy_generic_from_user)
28852 +
28853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28854 + pushl_cfi %gs
28855 + popl_cfi %ds
28856 +#endif
28857 +
28858 +ENTRY(csum_partial_copy_generic)
28859 subl $4,%esp
28860 CFI_ADJUST_CFA_OFFSET 4
28861 pushl_cfi %edi
28862 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28863 jmp 4f
28864 SRC(1: movw (%esi), %bx )
28865 addl $2, %esi
28866 -DST( movw %bx, (%edi) )
28867 +DST( movw %bx, %es:(%edi) )
28868 addl $2, %edi
28869 addw %bx, %ax
28870 adcl $0, %eax
28871 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28872 SRC(1: movl (%esi), %ebx )
28873 SRC( movl 4(%esi), %edx )
28874 adcl %ebx, %eax
28875 -DST( movl %ebx, (%edi) )
28876 +DST( movl %ebx, %es:(%edi) )
28877 adcl %edx, %eax
28878 -DST( movl %edx, 4(%edi) )
28879 +DST( movl %edx, %es:4(%edi) )
28880
28881 SRC( movl 8(%esi), %ebx )
28882 SRC( movl 12(%esi), %edx )
28883 adcl %ebx, %eax
28884 -DST( movl %ebx, 8(%edi) )
28885 +DST( movl %ebx, %es:8(%edi) )
28886 adcl %edx, %eax
28887 -DST( movl %edx, 12(%edi) )
28888 +DST( movl %edx, %es:12(%edi) )
28889
28890 SRC( movl 16(%esi), %ebx )
28891 SRC( movl 20(%esi), %edx )
28892 adcl %ebx, %eax
28893 -DST( movl %ebx, 16(%edi) )
28894 +DST( movl %ebx, %es:16(%edi) )
28895 adcl %edx, %eax
28896 -DST( movl %edx, 20(%edi) )
28897 +DST( movl %edx, %es:20(%edi) )
28898
28899 SRC( movl 24(%esi), %ebx )
28900 SRC( movl 28(%esi), %edx )
28901 adcl %ebx, %eax
28902 -DST( movl %ebx, 24(%edi) )
28903 +DST( movl %ebx, %es:24(%edi) )
28904 adcl %edx, %eax
28905 -DST( movl %edx, 28(%edi) )
28906 +DST( movl %edx, %es:28(%edi) )
28907
28908 lea 32(%esi), %esi
28909 lea 32(%edi), %edi
28910 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28911 shrl $2, %edx # This clears CF
28912 SRC(3: movl (%esi), %ebx )
28913 adcl %ebx, %eax
28914 -DST( movl %ebx, (%edi) )
28915 +DST( movl %ebx, %es:(%edi) )
28916 lea 4(%esi), %esi
28917 lea 4(%edi), %edi
28918 dec %edx
28919 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28920 jb 5f
28921 SRC( movw (%esi), %cx )
28922 leal 2(%esi), %esi
28923 -DST( movw %cx, (%edi) )
28924 +DST( movw %cx, %es:(%edi) )
28925 leal 2(%edi), %edi
28926 je 6f
28927 shll $16,%ecx
28928 SRC(5: movb (%esi), %cl )
28929 -DST( movb %cl, (%edi) )
28930 +DST( movb %cl, %es:(%edi) )
28931 6: addl %ecx, %eax
28932 adcl $0, %eax
28933 7:
28934 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28935
28936 6001:
28937 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28938 - movl $-EFAULT, (%ebx)
28939 + movl $-EFAULT, %ss:(%ebx)
28940
28941 # zero the complete destination - computing the rest
28942 # is too much work
28943 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28944
28945 6002:
28946 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28947 - movl $-EFAULT,(%ebx)
28948 + movl $-EFAULT,%ss:(%ebx)
28949 jmp 5000b
28950
28951 .previous
28952
28953 + pushl_cfi %ss
28954 + popl_cfi %ds
28955 + pushl_cfi %ss
28956 + popl_cfi %es
28957 popl_cfi %ebx
28958 CFI_RESTORE ebx
28959 popl_cfi %esi
28960 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28961 popl_cfi %ecx # equivalent to addl $4,%esp
28962 ret
28963 CFI_ENDPROC
28964 -ENDPROC(csum_partial_copy_generic)
28965 +ENDPROC(csum_partial_copy_generic_to_user)
28966
28967 #else
28968
28969 /* Version for PentiumII/PPro */
28970
28971 #define ROUND1(x) \
28972 + nop; nop; nop; \
28973 SRC(movl x(%esi), %ebx ) ; \
28974 addl %ebx, %eax ; \
28975 - DST(movl %ebx, x(%edi) ) ;
28976 + DST(movl %ebx, %es:x(%edi)) ;
28977
28978 #define ROUND(x) \
28979 + nop; nop; nop; \
28980 SRC(movl x(%esi), %ebx ) ; \
28981 adcl %ebx, %eax ; \
28982 - DST(movl %ebx, x(%edi) ) ;
28983 + DST(movl %ebx, %es:x(%edi)) ;
28984
28985 #define ARGBASE 12
28986 -
28987 -ENTRY(csum_partial_copy_generic)
28988 +
28989 +ENTRY(csum_partial_copy_generic_to_user)
28990 CFI_STARTPROC
28991 +
28992 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28993 + pushl_cfi %gs
28994 + popl_cfi %es
28995 + jmp csum_partial_copy_generic
28996 +#endif
28997 +
28998 +ENTRY(csum_partial_copy_generic_from_user)
28999 +
29000 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29001 + pushl_cfi %gs
29002 + popl_cfi %ds
29003 +#endif
29004 +
29005 +ENTRY(csum_partial_copy_generic)
29006 pushl_cfi %ebx
29007 CFI_REL_OFFSET ebx, 0
29008 pushl_cfi %edi
29009 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29010 subl %ebx, %edi
29011 lea -1(%esi),%edx
29012 andl $-32,%edx
29013 - lea 3f(%ebx,%ebx), %ebx
29014 + lea 3f(%ebx,%ebx,2), %ebx
29015 testl %esi, %esi
29016 jmp *%ebx
29017 1: addl $64,%esi
29018 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29019 jb 5f
29020 SRC( movw (%esi), %dx )
29021 leal 2(%esi), %esi
29022 -DST( movw %dx, (%edi) )
29023 +DST( movw %dx, %es:(%edi) )
29024 leal 2(%edi), %edi
29025 je 6f
29026 shll $16,%edx
29027 5:
29028 SRC( movb (%esi), %dl )
29029 -DST( movb %dl, (%edi) )
29030 +DST( movb %dl, %es:(%edi) )
29031 6: addl %edx, %eax
29032 adcl $0, %eax
29033 7:
29034 .section .fixup, "ax"
29035 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29036 - movl $-EFAULT, (%ebx)
29037 + movl $-EFAULT, %ss:(%ebx)
29038 # zero the complete destination (computing the rest is too much work)
29039 movl ARGBASE+8(%esp),%edi # dst
29040 movl ARGBASE+12(%esp),%ecx # len
29041 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29042 rep; stosb
29043 jmp 7b
29044 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29045 - movl $-EFAULT, (%ebx)
29046 + movl $-EFAULT, %ss:(%ebx)
29047 jmp 7b
29048 .previous
29049
29050 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29051 + pushl_cfi %ss
29052 + popl_cfi %ds
29053 + pushl_cfi %ss
29054 + popl_cfi %es
29055 +#endif
29056 +
29057 popl_cfi %esi
29058 CFI_RESTORE esi
29059 popl_cfi %edi
29060 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29061 CFI_RESTORE ebx
29062 ret
29063 CFI_ENDPROC
29064 -ENDPROC(csum_partial_copy_generic)
29065 +ENDPROC(csum_partial_copy_generic_to_user)
29066
29067 #undef ROUND
29068 #undef ROUND1
29069 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29070 index f2145cf..cea889d 100644
29071 --- a/arch/x86/lib/clear_page_64.S
29072 +++ b/arch/x86/lib/clear_page_64.S
29073 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29074 movl $4096/8,%ecx
29075 xorl %eax,%eax
29076 rep stosq
29077 + pax_force_retaddr
29078 ret
29079 CFI_ENDPROC
29080 ENDPROC(clear_page_c)
29081 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29082 movl $4096,%ecx
29083 xorl %eax,%eax
29084 rep stosb
29085 + pax_force_retaddr
29086 ret
29087 CFI_ENDPROC
29088 ENDPROC(clear_page_c_e)
29089 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29090 leaq 64(%rdi),%rdi
29091 jnz .Lloop
29092 nop
29093 + pax_force_retaddr
29094 ret
29095 CFI_ENDPROC
29096 .Lclear_page_end:
29097 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29098
29099 #include <asm/cpufeature.h>
29100
29101 - .section .altinstr_replacement,"ax"
29102 + .section .altinstr_replacement,"a"
29103 1: .byte 0xeb /* jmp <disp8> */
29104 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29105 2: .byte 0xeb /* jmp <disp8> */
29106 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29107 index 1e572c5..2a162cd 100644
29108 --- a/arch/x86/lib/cmpxchg16b_emu.S
29109 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29110 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29111
29112 popf
29113 mov $1, %al
29114 + pax_force_retaddr
29115 ret
29116
29117 not_same:
29118 popf
29119 xor %al,%al
29120 + pax_force_retaddr
29121 ret
29122
29123 CFI_ENDPROC
29124 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29125 index 176cca6..e0d658e 100644
29126 --- a/arch/x86/lib/copy_page_64.S
29127 +++ b/arch/x86/lib/copy_page_64.S
29128 @@ -9,6 +9,7 @@ copy_page_rep:
29129 CFI_STARTPROC
29130 movl $4096/8, %ecx
29131 rep movsq
29132 + pax_force_retaddr
29133 ret
29134 CFI_ENDPROC
29135 ENDPROC(copy_page_rep)
29136 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29137 CFI_ADJUST_CFA_OFFSET 2*8
29138 movq %rbx, (%rsp)
29139 CFI_REL_OFFSET rbx, 0
29140 - movq %r12, 1*8(%rsp)
29141 - CFI_REL_OFFSET r12, 1*8
29142 + movq %r13, 1*8(%rsp)
29143 + CFI_REL_OFFSET r13, 1*8
29144
29145 movl $(4096/64)-5, %ecx
29146 .p2align 4
29147 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29148 movq 0x8*4(%rsi), %r9
29149 movq 0x8*5(%rsi), %r10
29150 movq 0x8*6(%rsi), %r11
29151 - movq 0x8*7(%rsi), %r12
29152 + movq 0x8*7(%rsi), %r13
29153
29154 prefetcht0 5*64(%rsi)
29155
29156 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29157 movq %r9, 0x8*4(%rdi)
29158 movq %r10, 0x8*5(%rdi)
29159 movq %r11, 0x8*6(%rdi)
29160 - movq %r12, 0x8*7(%rdi)
29161 + movq %r13, 0x8*7(%rdi)
29162
29163 leaq 64 (%rsi), %rsi
29164 leaq 64 (%rdi), %rdi
29165 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29166 movq 0x8*4(%rsi), %r9
29167 movq 0x8*5(%rsi), %r10
29168 movq 0x8*6(%rsi), %r11
29169 - movq 0x8*7(%rsi), %r12
29170 + movq 0x8*7(%rsi), %r13
29171
29172 movq %rax, 0x8*0(%rdi)
29173 movq %rbx, 0x8*1(%rdi)
29174 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29175 movq %r9, 0x8*4(%rdi)
29176 movq %r10, 0x8*5(%rdi)
29177 movq %r11, 0x8*6(%rdi)
29178 - movq %r12, 0x8*7(%rdi)
29179 + movq %r13, 0x8*7(%rdi)
29180
29181 leaq 64(%rdi), %rdi
29182 leaq 64(%rsi), %rsi
29183 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29184
29185 movq (%rsp), %rbx
29186 CFI_RESTORE rbx
29187 - movq 1*8(%rsp), %r12
29188 - CFI_RESTORE r12
29189 + movq 1*8(%rsp), %r13
29190 + CFI_RESTORE r13
29191 addq $2*8, %rsp
29192 CFI_ADJUST_CFA_OFFSET -2*8
29193 + pax_force_retaddr
29194 ret
29195 .Lcopy_page_end:
29196 CFI_ENDPROC
29197 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29198
29199 #include <asm/cpufeature.h>
29200
29201 - .section .altinstr_replacement,"ax"
29202 + .section .altinstr_replacement,"a"
29203 1: .byte 0xeb /* jmp <disp8> */
29204 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29205 2:
29206 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29207 index dee945d..a84067b 100644
29208 --- a/arch/x86/lib/copy_user_64.S
29209 +++ b/arch/x86/lib/copy_user_64.S
29210 @@ -18,31 +18,7 @@
29211 #include <asm/alternative-asm.h>
29212 #include <asm/asm.h>
29213 #include <asm/smap.h>
29214 -
29215 -/*
29216 - * By placing feature2 after feature1 in altinstructions section, we logically
29217 - * implement:
29218 - * If CPU has feature2, jmp to alt2 is used
29219 - * else if CPU has feature1, jmp to alt1 is used
29220 - * else jmp to orig is used.
29221 - */
29222 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29223 -0:
29224 - .byte 0xe9 /* 32bit jump */
29225 - .long \orig-1f /* by default jump to orig */
29226 -1:
29227 - .section .altinstr_replacement,"ax"
29228 -2: .byte 0xe9 /* near jump with 32bit immediate */
29229 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29230 -3: .byte 0xe9 /* near jump with 32bit immediate */
29231 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29232 - .previous
29233 -
29234 - .section .altinstructions,"a"
29235 - altinstruction_entry 0b,2b,\feature1,5,5
29236 - altinstruction_entry 0b,3b,\feature2,5,5
29237 - .previous
29238 - .endm
29239 +#include <asm/pgtable.h>
29240
29241 .macro ALIGN_DESTINATION
29242 #ifdef FIX_ALIGNMENT
29243 @@ -70,52 +46,6 @@
29244 #endif
29245 .endm
29246
29247 -/* Standard copy_to_user with segment limit checking */
29248 -ENTRY(_copy_to_user)
29249 - CFI_STARTPROC
29250 - GET_THREAD_INFO(%rax)
29251 - movq %rdi,%rcx
29252 - addq %rdx,%rcx
29253 - jc bad_to_user
29254 - cmpq TI_addr_limit(%rax),%rcx
29255 - ja bad_to_user
29256 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29257 - copy_user_generic_unrolled,copy_user_generic_string, \
29258 - copy_user_enhanced_fast_string
29259 - CFI_ENDPROC
29260 -ENDPROC(_copy_to_user)
29261 -
29262 -/* Standard copy_from_user with segment limit checking */
29263 -ENTRY(_copy_from_user)
29264 - CFI_STARTPROC
29265 - GET_THREAD_INFO(%rax)
29266 - movq %rsi,%rcx
29267 - addq %rdx,%rcx
29268 - jc bad_from_user
29269 - cmpq TI_addr_limit(%rax),%rcx
29270 - ja bad_from_user
29271 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29272 - copy_user_generic_unrolled,copy_user_generic_string, \
29273 - copy_user_enhanced_fast_string
29274 - CFI_ENDPROC
29275 -ENDPROC(_copy_from_user)
29276 -
29277 - .section .fixup,"ax"
29278 - /* must zero dest */
29279 -ENTRY(bad_from_user)
29280 -bad_from_user:
29281 - CFI_STARTPROC
29282 - movl %edx,%ecx
29283 - xorl %eax,%eax
29284 - rep
29285 - stosb
29286 -bad_to_user:
29287 - movl %edx,%eax
29288 - ret
29289 - CFI_ENDPROC
29290 -ENDPROC(bad_from_user)
29291 - .previous
29292 -
29293 /*
29294 * copy_user_generic_unrolled - memory copy with exception handling.
29295 * This version is for CPUs like P4 that don't have efficient micro
29296 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29297 */
29298 ENTRY(copy_user_generic_unrolled)
29299 CFI_STARTPROC
29300 + ASM_PAX_OPEN_USERLAND
29301 ASM_STAC
29302 cmpl $8,%edx
29303 jb 20f /* less then 8 bytes, go to byte copy loop */
29304 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29305 jnz 21b
29306 23: xor %eax,%eax
29307 ASM_CLAC
29308 + ASM_PAX_CLOSE_USERLAND
29309 + pax_force_retaddr
29310 ret
29311
29312 .section .fixup,"ax"
29313 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29314 */
29315 ENTRY(copy_user_generic_string)
29316 CFI_STARTPROC
29317 + ASM_PAX_OPEN_USERLAND
29318 ASM_STAC
29319 cmpl $8,%edx
29320 jb 2f /* less than 8 bytes, go to byte copy loop */
29321 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29322 movsb
29323 xorl %eax,%eax
29324 ASM_CLAC
29325 + ASM_PAX_CLOSE_USERLAND
29326 + pax_force_retaddr
29327 ret
29328
29329 .section .fixup,"ax"
29330 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29331 */
29332 ENTRY(copy_user_enhanced_fast_string)
29333 CFI_STARTPROC
29334 + ASM_PAX_OPEN_USERLAND
29335 ASM_STAC
29336 movl %edx,%ecx
29337 1: rep
29338 movsb
29339 xorl %eax,%eax
29340 ASM_CLAC
29341 + ASM_PAX_CLOSE_USERLAND
29342 + pax_force_retaddr
29343 ret
29344
29345 .section .fixup,"ax"
29346 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29347 index 6a4f43c..c70fb52 100644
29348 --- a/arch/x86/lib/copy_user_nocache_64.S
29349 +++ b/arch/x86/lib/copy_user_nocache_64.S
29350 @@ -8,6 +8,7 @@
29351
29352 #include <linux/linkage.h>
29353 #include <asm/dwarf2.h>
29354 +#include <asm/alternative-asm.h>
29355
29356 #define FIX_ALIGNMENT 1
29357
29358 @@ -16,6 +17,7 @@
29359 #include <asm/thread_info.h>
29360 #include <asm/asm.h>
29361 #include <asm/smap.h>
29362 +#include <asm/pgtable.h>
29363
29364 .macro ALIGN_DESTINATION
29365 #ifdef FIX_ALIGNMENT
29366 @@ -49,6 +51,16 @@
29367 */
29368 ENTRY(__copy_user_nocache)
29369 CFI_STARTPROC
29370 +
29371 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29372 + mov pax_user_shadow_base,%rcx
29373 + cmp %rcx,%rsi
29374 + jae 1f
29375 + add %rcx,%rsi
29376 +1:
29377 +#endif
29378 +
29379 + ASM_PAX_OPEN_USERLAND
29380 ASM_STAC
29381 cmpl $8,%edx
29382 jb 20f /* less then 8 bytes, go to byte copy loop */
29383 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29384 jnz 21b
29385 23: xorl %eax,%eax
29386 ASM_CLAC
29387 + ASM_PAX_CLOSE_USERLAND
29388 sfence
29389 + pax_force_retaddr
29390 ret
29391
29392 .section .fixup,"ax"
29393 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29394 index 2419d5f..fe52d0e 100644
29395 --- a/arch/x86/lib/csum-copy_64.S
29396 +++ b/arch/x86/lib/csum-copy_64.S
29397 @@ -9,6 +9,7 @@
29398 #include <asm/dwarf2.h>
29399 #include <asm/errno.h>
29400 #include <asm/asm.h>
29401 +#include <asm/alternative-asm.h>
29402
29403 /*
29404 * Checksum copy with exception handling.
29405 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29406 CFI_ADJUST_CFA_OFFSET 7*8
29407 movq %rbx, 2*8(%rsp)
29408 CFI_REL_OFFSET rbx, 2*8
29409 - movq %r12, 3*8(%rsp)
29410 - CFI_REL_OFFSET r12, 3*8
29411 + movq %r15, 3*8(%rsp)
29412 + CFI_REL_OFFSET r15, 3*8
29413 movq %r14, 4*8(%rsp)
29414 CFI_REL_OFFSET r14, 4*8
29415 movq %r13, 5*8(%rsp)
29416 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29417 movl %edx, %ecx
29418
29419 xorl %r9d, %r9d
29420 - movq %rcx, %r12
29421 + movq %rcx, %r15
29422
29423 - shrq $6, %r12
29424 + shrq $6, %r15
29425 jz .Lhandle_tail /* < 64 */
29426
29427 clc
29428
29429 /* main loop. clear in 64 byte blocks */
29430 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29431 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29432 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29433 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29434 .p2align 4
29435 .Lloop:
29436 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29437 adcq %r14, %rax
29438 adcq %r13, %rax
29439
29440 - decl %r12d
29441 + decl %r15d
29442
29443 dest
29444 movq %rbx, (%rsi)
29445 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29446 .Lende:
29447 movq 2*8(%rsp), %rbx
29448 CFI_RESTORE rbx
29449 - movq 3*8(%rsp), %r12
29450 - CFI_RESTORE r12
29451 + movq 3*8(%rsp), %r15
29452 + CFI_RESTORE r15
29453 movq 4*8(%rsp), %r14
29454 CFI_RESTORE r14
29455 movq 5*8(%rsp), %r13
29456 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29457 CFI_RESTORE rbp
29458 addq $7*8, %rsp
29459 CFI_ADJUST_CFA_OFFSET -7*8
29460 + pax_force_retaddr
29461 ret
29462 CFI_RESTORE_STATE
29463
29464 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29465 index 7609e0e..b449b98 100644
29466 --- a/arch/x86/lib/csum-wrappers_64.c
29467 +++ b/arch/x86/lib/csum-wrappers_64.c
29468 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29469 len -= 2;
29470 }
29471 }
29472 + pax_open_userland();
29473 stac();
29474 - isum = csum_partial_copy_generic((__force const void *)src,
29475 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29476 dst, len, isum, errp, NULL);
29477 clac();
29478 + pax_close_userland();
29479 if (unlikely(*errp))
29480 goto out_err;
29481
29482 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29483 }
29484
29485 *errp = 0;
29486 + pax_open_userland();
29487 stac();
29488 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29489 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29490 len, isum, NULL, errp);
29491 clac();
29492 + pax_close_userland();
29493 return ret;
29494 }
29495 EXPORT_SYMBOL(csum_partial_copy_to_user);
29496 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29497 index a451235..1daa956 100644
29498 --- a/arch/x86/lib/getuser.S
29499 +++ b/arch/x86/lib/getuser.S
29500 @@ -33,17 +33,40 @@
29501 #include <asm/thread_info.h>
29502 #include <asm/asm.h>
29503 #include <asm/smap.h>
29504 +#include <asm/segment.h>
29505 +#include <asm/pgtable.h>
29506 +#include <asm/alternative-asm.h>
29507 +
29508 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29509 +#define __copyuser_seg gs;
29510 +#else
29511 +#define __copyuser_seg
29512 +#endif
29513
29514 .text
29515 ENTRY(__get_user_1)
29516 CFI_STARTPROC
29517 +
29518 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29519 GET_THREAD_INFO(%_ASM_DX)
29520 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29521 jae bad_get_user
29522 ASM_STAC
29523 -1: movzbl (%_ASM_AX),%edx
29524 +
29525 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29526 + mov pax_user_shadow_base,%_ASM_DX
29527 + cmp %_ASM_DX,%_ASM_AX
29528 + jae 1234f
29529 + add %_ASM_DX,%_ASM_AX
29530 +1234:
29531 +#endif
29532 +
29533 +#endif
29534 +
29535 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29536 xor %eax,%eax
29537 ASM_CLAC
29538 + pax_force_retaddr
29539 ret
29540 CFI_ENDPROC
29541 ENDPROC(__get_user_1)
29542 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29543 ENTRY(__get_user_2)
29544 CFI_STARTPROC
29545 add $1,%_ASM_AX
29546 +
29547 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29548 jc bad_get_user
29549 GET_THREAD_INFO(%_ASM_DX)
29550 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29551 jae bad_get_user
29552 ASM_STAC
29553 -2: movzwl -1(%_ASM_AX),%edx
29554 +
29555 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29556 + mov pax_user_shadow_base,%_ASM_DX
29557 + cmp %_ASM_DX,%_ASM_AX
29558 + jae 1234f
29559 + add %_ASM_DX,%_ASM_AX
29560 +1234:
29561 +#endif
29562 +
29563 +#endif
29564 +
29565 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29566 xor %eax,%eax
29567 ASM_CLAC
29568 + pax_force_retaddr
29569 ret
29570 CFI_ENDPROC
29571 ENDPROC(__get_user_2)
29572 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29573 ENTRY(__get_user_4)
29574 CFI_STARTPROC
29575 add $3,%_ASM_AX
29576 +
29577 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29578 jc bad_get_user
29579 GET_THREAD_INFO(%_ASM_DX)
29580 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29581 jae bad_get_user
29582 ASM_STAC
29583 -3: movl -3(%_ASM_AX),%edx
29584 +
29585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29586 + mov pax_user_shadow_base,%_ASM_DX
29587 + cmp %_ASM_DX,%_ASM_AX
29588 + jae 1234f
29589 + add %_ASM_DX,%_ASM_AX
29590 +1234:
29591 +#endif
29592 +
29593 +#endif
29594 +
29595 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29596 xor %eax,%eax
29597 ASM_CLAC
29598 + pax_force_retaddr
29599 ret
29600 CFI_ENDPROC
29601 ENDPROC(__get_user_4)
29602 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29603 GET_THREAD_INFO(%_ASM_DX)
29604 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29605 jae bad_get_user
29606 +
29607 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29608 + mov pax_user_shadow_base,%_ASM_DX
29609 + cmp %_ASM_DX,%_ASM_AX
29610 + jae 1234f
29611 + add %_ASM_DX,%_ASM_AX
29612 +1234:
29613 +#endif
29614 +
29615 ASM_STAC
29616 4: movq -7(%_ASM_AX),%rdx
29617 xor %eax,%eax
29618 ASM_CLAC
29619 + pax_force_retaddr
29620 ret
29621 #else
29622 add $7,%_ASM_AX
29623 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29624 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29625 jae bad_get_user_8
29626 ASM_STAC
29627 -4: movl -7(%_ASM_AX),%edx
29628 -5: movl -3(%_ASM_AX),%ecx
29629 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29630 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29631 xor %eax,%eax
29632 ASM_CLAC
29633 + pax_force_retaddr
29634 ret
29635 #endif
29636 CFI_ENDPROC
29637 @@ -113,6 +175,7 @@ bad_get_user:
29638 xor %edx,%edx
29639 mov $(-EFAULT),%_ASM_AX
29640 ASM_CLAC
29641 + pax_force_retaddr
29642 ret
29643 CFI_ENDPROC
29644 END(bad_get_user)
29645 @@ -124,6 +187,7 @@ bad_get_user_8:
29646 xor %ecx,%ecx
29647 mov $(-EFAULT),%_ASM_AX
29648 ASM_CLAC
29649 + pax_force_retaddr
29650 ret
29651 CFI_ENDPROC
29652 END(bad_get_user_8)
29653 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29654 index 54fcffe..7be149e 100644
29655 --- a/arch/x86/lib/insn.c
29656 +++ b/arch/x86/lib/insn.c
29657 @@ -20,8 +20,10 @@
29658
29659 #ifdef __KERNEL__
29660 #include <linux/string.h>
29661 +#include <asm/pgtable_types.h>
29662 #else
29663 #include <string.h>
29664 +#define ktla_ktva(addr) addr
29665 #endif
29666 #include <asm/inat.h>
29667 #include <asm/insn.h>
29668 @@ -53,8 +55,8 @@
29669 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29670 {
29671 memset(insn, 0, sizeof(*insn));
29672 - insn->kaddr = kaddr;
29673 - insn->next_byte = kaddr;
29674 + insn->kaddr = ktla_ktva(kaddr);
29675 + insn->next_byte = ktla_ktva(kaddr);
29676 insn->x86_64 = x86_64 ? 1 : 0;
29677 insn->opnd_bytes = 4;
29678 if (x86_64)
29679 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29680 index 05a95e7..326f2fa 100644
29681 --- a/arch/x86/lib/iomap_copy_64.S
29682 +++ b/arch/x86/lib/iomap_copy_64.S
29683 @@ -17,6 +17,7 @@
29684
29685 #include <linux/linkage.h>
29686 #include <asm/dwarf2.h>
29687 +#include <asm/alternative-asm.h>
29688
29689 /*
29690 * override generic version in lib/iomap_copy.c
29691 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29692 CFI_STARTPROC
29693 movl %edx,%ecx
29694 rep movsd
29695 + pax_force_retaddr
29696 ret
29697 CFI_ENDPROC
29698 ENDPROC(__iowrite32_copy)
29699 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29700 index 56313a3..0db417e 100644
29701 --- a/arch/x86/lib/memcpy_64.S
29702 +++ b/arch/x86/lib/memcpy_64.S
29703 @@ -24,7 +24,7 @@
29704 * This gets patched over the unrolled variant (below) via the
29705 * alternative instructions framework:
29706 */
29707 - .section .altinstr_replacement, "ax", @progbits
29708 + .section .altinstr_replacement, "a", @progbits
29709 .Lmemcpy_c:
29710 movq %rdi, %rax
29711 movq %rdx, %rcx
29712 @@ -33,6 +33,7 @@
29713 rep movsq
29714 movl %edx, %ecx
29715 rep movsb
29716 + pax_force_retaddr
29717 ret
29718 .Lmemcpy_e:
29719 .previous
29720 @@ -44,11 +45,12 @@
29721 * This gets patched over the unrolled variant (below) via the
29722 * alternative instructions framework:
29723 */
29724 - .section .altinstr_replacement, "ax", @progbits
29725 + .section .altinstr_replacement, "a", @progbits
29726 .Lmemcpy_c_e:
29727 movq %rdi, %rax
29728 movq %rdx, %rcx
29729 rep movsb
29730 + pax_force_retaddr
29731 ret
29732 .Lmemcpy_e_e:
29733 .previous
29734 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29735 movq %r9, 1*8(%rdi)
29736 movq %r10, -2*8(%rdi, %rdx)
29737 movq %r11, -1*8(%rdi, %rdx)
29738 + pax_force_retaddr
29739 retq
29740 .p2align 4
29741 .Lless_16bytes:
29742 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29743 movq -1*8(%rsi, %rdx), %r9
29744 movq %r8, 0*8(%rdi)
29745 movq %r9, -1*8(%rdi, %rdx)
29746 + pax_force_retaddr
29747 retq
29748 .p2align 4
29749 .Lless_8bytes:
29750 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29751 movl -4(%rsi, %rdx), %r8d
29752 movl %ecx, (%rdi)
29753 movl %r8d, -4(%rdi, %rdx)
29754 + pax_force_retaddr
29755 retq
29756 .p2align 4
29757 .Lless_3bytes:
29758 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29759 movb %cl, (%rdi)
29760
29761 .Lend:
29762 + pax_force_retaddr
29763 retq
29764 CFI_ENDPROC
29765 ENDPROC(memcpy)
29766 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29767 index 65268a6..dd1de11 100644
29768 --- a/arch/x86/lib/memmove_64.S
29769 +++ b/arch/x86/lib/memmove_64.S
29770 @@ -202,14 +202,16 @@ ENTRY(memmove)
29771 movb (%rsi), %r11b
29772 movb %r11b, (%rdi)
29773 13:
29774 + pax_force_retaddr
29775 retq
29776 CFI_ENDPROC
29777
29778 - .section .altinstr_replacement,"ax"
29779 + .section .altinstr_replacement,"a"
29780 .Lmemmove_begin_forward_efs:
29781 /* Forward moving data. */
29782 movq %rdx, %rcx
29783 rep movsb
29784 + pax_force_retaddr
29785 retq
29786 .Lmemmove_end_forward_efs:
29787 .previous
29788 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29789 index 2dcb380..2eb79fe 100644
29790 --- a/arch/x86/lib/memset_64.S
29791 +++ b/arch/x86/lib/memset_64.S
29792 @@ -16,7 +16,7 @@
29793 *
29794 * rax original destination
29795 */
29796 - .section .altinstr_replacement, "ax", @progbits
29797 + .section .altinstr_replacement, "a", @progbits
29798 .Lmemset_c:
29799 movq %rdi,%r9
29800 movq %rdx,%rcx
29801 @@ -30,6 +30,7 @@
29802 movl %edx,%ecx
29803 rep stosb
29804 movq %r9,%rax
29805 + pax_force_retaddr
29806 ret
29807 .Lmemset_e:
29808 .previous
29809 @@ -45,13 +46,14 @@
29810 *
29811 * rax original destination
29812 */
29813 - .section .altinstr_replacement, "ax", @progbits
29814 + .section .altinstr_replacement, "a", @progbits
29815 .Lmemset_c_e:
29816 movq %rdi,%r9
29817 movb %sil,%al
29818 movq %rdx,%rcx
29819 rep stosb
29820 movq %r9,%rax
29821 + pax_force_retaddr
29822 ret
29823 .Lmemset_e_e:
29824 .previous
29825 @@ -118,6 +120,7 @@ ENTRY(__memset)
29826
29827 .Lende:
29828 movq %r10,%rax
29829 + pax_force_retaddr
29830 ret
29831
29832 CFI_RESTORE_STATE
29833 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29834 index c9f2d9b..e7fd2c0 100644
29835 --- a/arch/x86/lib/mmx_32.c
29836 +++ b/arch/x86/lib/mmx_32.c
29837 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29838 {
29839 void *p;
29840 int i;
29841 + unsigned long cr0;
29842
29843 if (unlikely(in_interrupt()))
29844 return __memcpy(to, from, len);
29845 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29846 kernel_fpu_begin();
29847
29848 __asm__ __volatile__ (
29849 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29850 - " prefetch 64(%0)\n"
29851 - " prefetch 128(%0)\n"
29852 - " prefetch 192(%0)\n"
29853 - " prefetch 256(%0)\n"
29854 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29855 + " prefetch 64(%1)\n"
29856 + " prefetch 128(%1)\n"
29857 + " prefetch 192(%1)\n"
29858 + " prefetch 256(%1)\n"
29859 "2: \n"
29860 ".section .fixup, \"ax\"\n"
29861 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29862 + "3: \n"
29863 +
29864 +#ifdef CONFIG_PAX_KERNEXEC
29865 + " movl %%cr0, %0\n"
29866 + " movl %0, %%eax\n"
29867 + " andl $0xFFFEFFFF, %%eax\n"
29868 + " movl %%eax, %%cr0\n"
29869 +#endif
29870 +
29871 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29872 +
29873 +#ifdef CONFIG_PAX_KERNEXEC
29874 + " movl %0, %%cr0\n"
29875 +#endif
29876 +
29877 " jmp 2b\n"
29878 ".previous\n"
29879 _ASM_EXTABLE(1b, 3b)
29880 - : : "r" (from));
29881 + : "=&r" (cr0) : "r" (from) : "ax");
29882
29883 for ( ; i > 5; i--) {
29884 __asm__ __volatile__ (
29885 - "1: prefetch 320(%0)\n"
29886 - "2: movq (%0), %%mm0\n"
29887 - " movq 8(%0), %%mm1\n"
29888 - " movq 16(%0), %%mm2\n"
29889 - " movq 24(%0), %%mm3\n"
29890 - " movq %%mm0, (%1)\n"
29891 - " movq %%mm1, 8(%1)\n"
29892 - " movq %%mm2, 16(%1)\n"
29893 - " movq %%mm3, 24(%1)\n"
29894 - " movq 32(%0), %%mm0\n"
29895 - " movq 40(%0), %%mm1\n"
29896 - " movq 48(%0), %%mm2\n"
29897 - " movq 56(%0), %%mm3\n"
29898 - " movq %%mm0, 32(%1)\n"
29899 - " movq %%mm1, 40(%1)\n"
29900 - " movq %%mm2, 48(%1)\n"
29901 - " movq %%mm3, 56(%1)\n"
29902 + "1: prefetch 320(%1)\n"
29903 + "2: movq (%1), %%mm0\n"
29904 + " movq 8(%1), %%mm1\n"
29905 + " movq 16(%1), %%mm2\n"
29906 + " movq 24(%1), %%mm3\n"
29907 + " movq %%mm0, (%2)\n"
29908 + " movq %%mm1, 8(%2)\n"
29909 + " movq %%mm2, 16(%2)\n"
29910 + " movq %%mm3, 24(%2)\n"
29911 + " movq 32(%1), %%mm0\n"
29912 + " movq 40(%1), %%mm1\n"
29913 + " movq 48(%1), %%mm2\n"
29914 + " movq 56(%1), %%mm3\n"
29915 + " movq %%mm0, 32(%2)\n"
29916 + " movq %%mm1, 40(%2)\n"
29917 + " movq %%mm2, 48(%2)\n"
29918 + " movq %%mm3, 56(%2)\n"
29919 ".section .fixup, \"ax\"\n"
29920 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29921 + "3:\n"
29922 +
29923 +#ifdef CONFIG_PAX_KERNEXEC
29924 + " movl %%cr0, %0\n"
29925 + " movl %0, %%eax\n"
29926 + " andl $0xFFFEFFFF, %%eax\n"
29927 + " movl %%eax, %%cr0\n"
29928 +#endif
29929 +
29930 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29931 +
29932 +#ifdef CONFIG_PAX_KERNEXEC
29933 + " movl %0, %%cr0\n"
29934 +#endif
29935 +
29936 " jmp 2b\n"
29937 ".previous\n"
29938 _ASM_EXTABLE(1b, 3b)
29939 - : : "r" (from), "r" (to) : "memory");
29940 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29941
29942 from += 64;
29943 to += 64;
29944 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29945 static void fast_copy_page(void *to, void *from)
29946 {
29947 int i;
29948 + unsigned long cr0;
29949
29950 kernel_fpu_begin();
29951
29952 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29953 * but that is for later. -AV
29954 */
29955 __asm__ __volatile__(
29956 - "1: prefetch (%0)\n"
29957 - " prefetch 64(%0)\n"
29958 - " prefetch 128(%0)\n"
29959 - " prefetch 192(%0)\n"
29960 - " prefetch 256(%0)\n"
29961 + "1: prefetch (%1)\n"
29962 + " prefetch 64(%1)\n"
29963 + " prefetch 128(%1)\n"
29964 + " prefetch 192(%1)\n"
29965 + " prefetch 256(%1)\n"
29966 "2: \n"
29967 ".section .fixup, \"ax\"\n"
29968 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29969 + "3: \n"
29970 +
29971 +#ifdef CONFIG_PAX_KERNEXEC
29972 + " movl %%cr0, %0\n"
29973 + " movl %0, %%eax\n"
29974 + " andl $0xFFFEFFFF, %%eax\n"
29975 + " movl %%eax, %%cr0\n"
29976 +#endif
29977 +
29978 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29979 +
29980 +#ifdef CONFIG_PAX_KERNEXEC
29981 + " movl %0, %%cr0\n"
29982 +#endif
29983 +
29984 " jmp 2b\n"
29985 ".previous\n"
29986 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29987 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29988
29989 for (i = 0; i < (4096-320)/64; i++) {
29990 __asm__ __volatile__ (
29991 - "1: prefetch 320(%0)\n"
29992 - "2: movq (%0), %%mm0\n"
29993 - " movntq %%mm0, (%1)\n"
29994 - " movq 8(%0), %%mm1\n"
29995 - " movntq %%mm1, 8(%1)\n"
29996 - " movq 16(%0), %%mm2\n"
29997 - " movntq %%mm2, 16(%1)\n"
29998 - " movq 24(%0), %%mm3\n"
29999 - " movntq %%mm3, 24(%1)\n"
30000 - " movq 32(%0), %%mm4\n"
30001 - " movntq %%mm4, 32(%1)\n"
30002 - " movq 40(%0), %%mm5\n"
30003 - " movntq %%mm5, 40(%1)\n"
30004 - " movq 48(%0), %%mm6\n"
30005 - " movntq %%mm6, 48(%1)\n"
30006 - " movq 56(%0), %%mm7\n"
30007 - " movntq %%mm7, 56(%1)\n"
30008 + "1: prefetch 320(%1)\n"
30009 + "2: movq (%1), %%mm0\n"
30010 + " movntq %%mm0, (%2)\n"
30011 + " movq 8(%1), %%mm1\n"
30012 + " movntq %%mm1, 8(%2)\n"
30013 + " movq 16(%1), %%mm2\n"
30014 + " movntq %%mm2, 16(%2)\n"
30015 + " movq 24(%1), %%mm3\n"
30016 + " movntq %%mm3, 24(%2)\n"
30017 + " movq 32(%1), %%mm4\n"
30018 + " movntq %%mm4, 32(%2)\n"
30019 + " movq 40(%1), %%mm5\n"
30020 + " movntq %%mm5, 40(%2)\n"
30021 + " movq 48(%1), %%mm6\n"
30022 + " movntq %%mm6, 48(%2)\n"
30023 + " movq 56(%1), %%mm7\n"
30024 + " movntq %%mm7, 56(%2)\n"
30025 ".section .fixup, \"ax\"\n"
30026 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30027 + "3:\n"
30028 +
30029 +#ifdef CONFIG_PAX_KERNEXEC
30030 + " movl %%cr0, %0\n"
30031 + " movl %0, %%eax\n"
30032 + " andl $0xFFFEFFFF, %%eax\n"
30033 + " movl %%eax, %%cr0\n"
30034 +#endif
30035 +
30036 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30037 +
30038 +#ifdef CONFIG_PAX_KERNEXEC
30039 + " movl %0, %%cr0\n"
30040 +#endif
30041 +
30042 " jmp 2b\n"
30043 ".previous\n"
30044 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30045 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30046
30047 from += 64;
30048 to += 64;
30049 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30050 static void fast_copy_page(void *to, void *from)
30051 {
30052 int i;
30053 + unsigned long cr0;
30054
30055 kernel_fpu_begin();
30056
30057 __asm__ __volatile__ (
30058 - "1: prefetch (%0)\n"
30059 - " prefetch 64(%0)\n"
30060 - " prefetch 128(%0)\n"
30061 - " prefetch 192(%0)\n"
30062 - " prefetch 256(%0)\n"
30063 + "1: prefetch (%1)\n"
30064 + " prefetch 64(%1)\n"
30065 + " prefetch 128(%1)\n"
30066 + " prefetch 192(%1)\n"
30067 + " prefetch 256(%1)\n"
30068 "2: \n"
30069 ".section .fixup, \"ax\"\n"
30070 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30071 + "3: \n"
30072 +
30073 +#ifdef CONFIG_PAX_KERNEXEC
30074 + " movl %%cr0, %0\n"
30075 + " movl %0, %%eax\n"
30076 + " andl $0xFFFEFFFF, %%eax\n"
30077 + " movl %%eax, %%cr0\n"
30078 +#endif
30079 +
30080 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30081 +
30082 +#ifdef CONFIG_PAX_KERNEXEC
30083 + " movl %0, %%cr0\n"
30084 +#endif
30085 +
30086 " jmp 2b\n"
30087 ".previous\n"
30088 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30089 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30090
30091 for (i = 0; i < 4096/64; i++) {
30092 __asm__ __volatile__ (
30093 - "1: prefetch 320(%0)\n"
30094 - "2: movq (%0), %%mm0\n"
30095 - " movq 8(%0), %%mm1\n"
30096 - " movq 16(%0), %%mm2\n"
30097 - " movq 24(%0), %%mm3\n"
30098 - " movq %%mm0, (%1)\n"
30099 - " movq %%mm1, 8(%1)\n"
30100 - " movq %%mm2, 16(%1)\n"
30101 - " movq %%mm3, 24(%1)\n"
30102 - " movq 32(%0), %%mm0\n"
30103 - " movq 40(%0), %%mm1\n"
30104 - " movq 48(%0), %%mm2\n"
30105 - " movq 56(%0), %%mm3\n"
30106 - " movq %%mm0, 32(%1)\n"
30107 - " movq %%mm1, 40(%1)\n"
30108 - " movq %%mm2, 48(%1)\n"
30109 - " movq %%mm3, 56(%1)\n"
30110 + "1: prefetch 320(%1)\n"
30111 + "2: movq (%1), %%mm0\n"
30112 + " movq 8(%1), %%mm1\n"
30113 + " movq 16(%1), %%mm2\n"
30114 + " movq 24(%1), %%mm3\n"
30115 + " movq %%mm0, (%2)\n"
30116 + " movq %%mm1, 8(%2)\n"
30117 + " movq %%mm2, 16(%2)\n"
30118 + " movq %%mm3, 24(%2)\n"
30119 + " movq 32(%1), %%mm0\n"
30120 + " movq 40(%1), %%mm1\n"
30121 + " movq 48(%1), %%mm2\n"
30122 + " movq 56(%1), %%mm3\n"
30123 + " movq %%mm0, 32(%2)\n"
30124 + " movq %%mm1, 40(%2)\n"
30125 + " movq %%mm2, 48(%2)\n"
30126 + " movq %%mm3, 56(%2)\n"
30127 ".section .fixup, \"ax\"\n"
30128 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30129 + "3:\n"
30130 +
30131 +#ifdef CONFIG_PAX_KERNEXEC
30132 + " movl %%cr0, %0\n"
30133 + " movl %0, %%eax\n"
30134 + " andl $0xFFFEFFFF, %%eax\n"
30135 + " movl %%eax, %%cr0\n"
30136 +#endif
30137 +
30138 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30139 +
30140 +#ifdef CONFIG_PAX_KERNEXEC
30141 + " movl %0, %%cr0\n"
30142 +#endif
30143 +
30144 " jmp 2b\n"
30145 ".previous\n"
30146 _ASM_EXTABLE(1b, 3b)
30147 - : : "r" (from), "r" (to) : "memory");
30148 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30149
30150 from += 64;
30151 to += 64;
30152 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30153 index f6d13ee..d789440 100644
30154 --- a/arch/x86/lib/msr-reg.S
30155 +++ b/arch/x86/lib/msr-reg.S
30156 @@ -3,6 +3,7 @@
30157 #include <asm/dwarf2.h>
30158 #include <asm/asm.h>
30159 #include <asm/msr.h>
30160 +#include <asm/alternative-asm.h>
30161
30162 #ifdef CONFIG_X86_64
30163 /*
30164 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30165 movl %edi, 28(%r10)
30166 popq_cfi %rbp
30167 popq_cfi %rbx
30168 + pax_force_retaddr
30169 ret
30170 3:
30171 CFI_RESTORE_STATE
30172 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30173 index fc6ba17..d4d989d 100644
30174 --- a/arch/x86/lib/putuser.S
30175 +++ b/arch/x86/lib/putuser.S
30176 @@ -16,7 +16,9 @@
30177 #include <asm/errno.h>
30178 #include <asm/asm.h>
30179 #include <asm/smap.h>
30180 -
30181 +#include <asm/segment.h>
30182 +#include <asm/pgtable.h>
30183 +#include <asm/alternative-asm.h>
30184
30185 /*
30186 * __put_user_X
30187 @@ -30,57 +32,125 @@
30188 * as they get called from within inline assembly.
30189 */
30190
30191 -#define ENTER CFI_STARTPROC ; \
30192 - GET_THREAD_INFO(%_ASM_BX)
30193 -#define EXIT ASM_CLAC ; \
30194 - ret ; \
30195 +#define ENTER CFI_STARTPROC
30196 +#define EXIT ASM_CLAC ; \
30197 + pax_force_retaddr ; \
30198 + ret ; \
30199 CFI_ENDPROC
30200
30201 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30202 +#define _DEST %_ASM_CX,%_ASM_BX
30203 +#else
30204 +#define _DEST %_ASM_CX
30205 +#endif
30206 +
30207 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30208 +#define __copyuser_seg gs;
30209 +#else
30210 +#define __copyuser_seg
30211 +#endif
30212 +
30213 .text
30214 ENTRY(__put_user_1)
30215 ENTER
30216 +
30217 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30218 + GET_THREAD_INFO(%_ASM_BX)
30219 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30220 jae bad_put_user
30221 ASM_STAC
30222 -1: movb %al,(%_ASM_CX)
30223 +
30224 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30225 + mov pax_user_shadow_base,%_ASM_BX
30226 + cmp %_ASM_BX,%_ASM_CX
30227 + jb 1234f
30228 + xor %ebx,%ebx
30229 +1234:
30230 +#endif
30231 +
30232 +#endif
30233 +
30234 +1: __copyuser_seg movb %al,(_DEST)
30235 xor %eax,%eax
30236 EXIT
30237 ENDPROC(__put_user_1)
30238
30239 ENTRY(__put_user_2)
30240 ENTER
30241 +
30242 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30243 + GET_THREAD_INFO(%_ASM_BX)
30244 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30245 sub $1,%_ASM_BX
30246 cmp %_ASM_BX,%_ASM_CX
30247 jae bad_put_user
30248 ASM_STAC
30249 -2: movw %ax,(%_ASM_CX)
30250 +
30251 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30252 + mov pax_user_shadow_base,%_ASM_BX
30253 + cmp %_ASM_BX,%_ASM_CX
30254 + jb 1234f
30255 + xor %ebx,%ebx
30256 +1234:
30257 +#endif
30258 +
30259 +#endif
30260 +
30261 +2: __copyuser_seg movw %ax,(_DEST)
30262 xor %eax,%eax
30263 EXIT
30264 ENDPROC(__put_user_2)
30265
30266 ENTRY(__put_user_4)
30267 ENTER
30268 +
30269 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30270 + GET_THREAD_INFO(%_ASM_BX)
30271 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30272 sub $3,%_ASM_BX
30273 cmp %_ASM_BX,%_ASM_CX
30274 jae bad_put_user
30275 ASM_STAC
30276 -3: movl %eax,(%_ASM_CX)
30277 +
30278 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30279 + mov pax_user_shadow_base,%_ASM_BX
30280 + cmp %_ASM_BX,%_ASM_CX
30281 + jb 1234f
30282 + xor %ebx,%ebx
30283 +1234:
30284 +#endif
30285 +
30286 +#endif
30287 +
30288 +3: __copyuser_seg movl %eax,(_DEST)
30289 xor %eax,%eax
30290 EXIT
30291 ENDPROC(__put_user_4)
30292
30293 ENTRY(__put_user_8)
30294 ENTER
30295 +
30296 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30297 + GET_THREAD_INFO(%_ASM_BX)
30298 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30299 sub $7,%_ASM_BX
30300 cmp %_ASM_BX,%_ASM_CX
30301 jae bad_put_user
30302 ASM_STAC
30303 -4: mov %_ASM_AX,(%_ASM_CX)
30304 +
30305 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30306 + mov pax_user_shadow_base,%_ASM_BX
30307 + cmp %_ASM_BX,%_ASM_CX
30308 + jb 1234f
30309 + xor %ebx,%ebx
30310 +1234:
30311 +#endif
30312 +
30313 +#endif
30314 +
30315 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30316 #ifdef CONFIG_X86_32
30317 -5: movl %edx,4(%_ASM_CX)
30318 +5: __copyuser_seg movl %edx,4(_DEST)
30319 #endif
30320 xor %eax,%eax
30321 EXIT
30322 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30323 index 1cad221..de671ee 100644
30324 --- a/arch/x86/lib/rwlock.S
30325 +++ b/arch/x86/lib/rwlock.S
30326 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30327 FRAME
30328 0: LOCK_PREFIX
30329 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30330 +
30331 +#ifdef CONFIG_PAX_REFCOUNT
30332 + jno 1234f
30333 + LOCK_PREFIX
30334 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30335 + int $4
30336 +1234:
30337 + _ASM_EXTABLE(1234b, 1234b)
30338 +#endif
30339 +
30340 1: rep; nop
30341 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30342 jne 1b
30343 LOCK_PREFIX
30344 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30345 +
30346 +#ifdef CONFIG_PAX_REFCOUNT
30347 + jno 1234f
30348 + LOCK_PREFIX
30349 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30350 + int $4
30351 +1234:
30352 + _ASM_EXTABLE(1234b, 1234b)
30353 +#endif
30354 +
30355 jnz 0b
30356 ENDFRAME
30357 + pax_force_retaddr
30358 ret
30359 CFI_ENDPROC
30360 END(__write_lock_failed)
30361 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30362 FRAME
30363 0: LOCK_PREFIX
30364 READ_LOCK_SIZE(inc) (%__lock_ptr)
30365 +
30366 +#ifdef CONFIG_PAX_REFCOUNT
30367 + jno 1234f
30368 + LOCK_PREFIX
30369 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30370 + int $4
30371 +1234:
30372 + _ASM_EXTABLE(1234b, 1234b)
30373 +#endif
30374 +
30375 1: rep; nop
30376 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30377 js 1b
30378 LOCK_PREFIX
30379 READ_LOCK_SIZE(dec) (%__lock_ptr)
30380 +
30381 +#ifdef CONFIG_PAX_REFCOUNT
30382 + jno 1234f
30383 + LOCK_PREFIX
30384 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30385 + int $4
30386 +1234:
30387 + _ASM_EXTABLE(1234b, 1234b)
30388 +#endif
30389 +
30390 js 0b
30391 ENDFRAME
30392 + pax_force_retaddr
30393 ret
30394 CFI_ENDPROC
30395 END(__read_lock_failed)
30396 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30397 index 5dff5f0..cadebf4 100644
30398 --- a/arch/x86/lib/rwsem.S
30399 +++ b/arch/x86/lib/rwsem.S
30400 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30401 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30402 CFI_RESTORE __ASM_REG(dx)
30403 restore_common_regs
30404 + pax_force_retaddr
30405 ret
30406 CFI_ENDPROC
30407 ENDPROC(call_rwsem_down_read_failed)
30408 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30409 movq %rax,%rdi
30410 call rwsem_down_write_failed
30411 restore_common_regs
30412 + pax_force_retaddr
30413 ret
30414 CFI_ENDPROC
30415 ENDPROC(call_rwsem_down_write_failed)
30416 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30417 movq %rax,%rdi
30418 call rwsem_wake
30419 restore_common_regs
30420 -1: ret
30421 +1: pax_force_retaddr
30422 + ret
30423 CFI_ENDPROC
30424 ENDPROC(call_rwsem_wake)
30425
30426 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30427 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30428 CFI_RESTORE __ASM_REG(dx)
30429 restore_common_regs
30430 + pax_force_retaddr
30431 ret
30432 CFI_ENDPROC
30433 ENDPROC(call_rwsem_downgrade_wake)
30434 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30435 index a63efd6..8149fbe 100644
30436 --- a/arch/x86/lib/thunk_64.S
30437 +++ b/arch/x86/lib/thunk_64.S
30438 @@ -8,6 +8,7 @@
30439 #include <linux/linkage.h>
30440 #include <asm/dwarf2.h>
30441 #include <asm/calling.h>
30442 +#include <asm/alternative-asm.h>
30443
30444 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30445 .macro THUNK name, func, put_ret_addr_in_rdi=0
30446 @@ -15,11 +16,11 @@
30447 \name:
30448 CFI_STARTPROC
30449
30450 - /* this one pushes 9 elems, the next one would be %rIP */
30451 - SAVE_ARGS
30452 + /* this one pushes 15+1 elems, the next one would be %rIP */
30453 + SAVE_ARGS 8
30454
30455 .if \put_ret_addr_in_rdi
30456 - movq_cfi_restore 9*8, rdi
30457 + movq_cfi_restore RIP, rdi
30458 .endif
30459
30460 call \func
30461 @@ -38,8 +39,9 @@
30462
30463 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30464 CFI_STARTPROC
30465 - SAVE_ARGS
30466 + SAVE_ARGS 8
30467 restore:
30468 - RESTORE_ARGS
30469 + RESTORE_ARGS 1,8
30470 + pax_force_retaddr
30471 ret
30472 CFI_ENDPROC
30473 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30474 index e2f5e21..4b22130 100644
30475 --- a/arch/x86/lib/usercopy_32.c
30476 +++ b/arch/x86/lib/usercopy_32.c
30477 @@ -42,11 +42,13 @@ do { \
30478 int __d0; \
30479 might_fault(); \
30480 __asm__ __volatile__( \
30481 + __COPYUSER_SET_ES \
30482 ASM_STAC "\n" \
30483 "0: rep; stosl\n" \
30484 " movl %2,%0\n" \
30485 "1: rep; stosb\n" \
30486 "2: " ASM_CLAC "\n" \
30487 + __COPYUSER_RESTORE_ES \
30488 ".section .fixup,\"ax\"\n" \
30489 "3: lea 0(%2,%0,4),%0\n" \
30490 " jmp 2b\n" \
30491 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30492
30493 #ifdef CONFIG_X86_INTEL_USERCOPY
30494 static unsigned long
30495 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30496 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30497 {
30498 int d0, d1;
30499 __asm__ __volatile__(
30500 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30501 " .align 2,0x90\n"
30502 "3: movl 0(%4), %%eax\n"
30503 "4: movl 4(%4), %%edx\n"
30504 - "5: movl %%eax, 0(%3)\n"
30505 - "6: movl %%edx, 4(%3)\n"
30506 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30507 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30508 "7: movl 8(%4), %%eax\n"
30509 "8: movl 12(%4),%%edx\n"
30510 - "9: movl %%eax, 8(%3)\n"
30511 - "10: movl %%edx, 12(%3)\n"
30512 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30513 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30514 "11: movl 16(%4), %%eax\n"
30515 "12: movl 20(%4), %%edx\n"
30516 - "13: movl %%eax, 16(%3)\n"
30517 - "14: movl %%edx, 20(%3)\n"
30518 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30519 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30520 "15: movl 24(%4), %%eax\n"
30521 "16: movl 28(%4), %%edx\n"
30522 - "17: movl %%eax, 24(%3)\n"
30523 - "18: movl %%edx, 28(%3)\n"
30524 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30525 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30526 "19: movl 32(%4), %%eax\n"
30527 "20: movl 36(%4), %%edx\n"
30528 - "21: movl %%eax, 32(%3)\n"
30529 - "22: movl %%edx, 36(%3)\n"
30530 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30531 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30532 "23: movl 40(%4), %%eax\n"
30533 "24: movl 44(%4), %%edx\n"
30534 - "25: movl %%eax, 40(%3)\n"
30535 - "26: movl %%edx, 44(%3)\n"
30536 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30537 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30538 "27: movl 48(%4), %%eax\n"
30539 "28: movl 52(%4), %%edx\n"
30540 - "29: movl %%eax, 48(%3)\n"
30541 - "30: movl %%edx, 52(%3)\n"
30542 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30543 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30544 "31: movl 56(%4), %%eax\n"
30545 "32: movl 60(%4), %%edx\n"
30546 - "33: movl %%eax, 56(%3)\n"
30547 - "34: movl %%edx, 60(%3)\n"
30548 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30549 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30550 " addl $-64, %0\n"
30551 " addl $64, %4\n"
30552 " addl $64, %3\n"
30553 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30554 " shrl $2, %0\n"
30555 " andl $3, %%eax\n"
30556 " cld\n"
30557 + __COPYUSER_SET_ES
30558 "99: rep; movsl\n"
30559 "36: movl %%eax, %0\n"
30560 "37: rep; movsb\n"
30561 "100:\n"
30562 + __COPYUSER_RESTORE_ES
30563 + ".section .fixup,\"ax\"\n"
30564 + "101: lea 0(%%eax,%0,4),%0\n"
30565 + " jmp 100b\n"
30566 + ".previous\n"
30567 + _ASM_EXTABLE(1b,100b)
30568 + _ASM_EXTABLE(2b,100b)
30569 + _ASM_EXTABLE(3b,100b)
30570 + _ASM_EXTABLE(4b,100b)
30571 + _ASM_EXTABLE(5b,100b)
30572 + _ASM_EXTABLE(6b,100b)
30573 + _ASM_EXTABLE(7b,100b)
30574 + _ASM_EXTABLE(8b,100b)
30575 + _ASM_EXTABLE(9b,100b)
30576 + _ASM_EXTABLE(10b,100b)
30577 + _ASM_EXTABLE(11b,100b)
30578 + _ASM_EXTABLE(12b,100b)
30579 + _ASM_EXTABLE(13b,100b)
30580 + _ASM_EXTABLE(14b,100b)
30581 + _ASM_EXTABLE(15b,100b)
30582 + _ASM_EXTABLE(16b,100b)
30583 + _ASM_EXTABLE(17b,100b)
30584 + _ASM_EXTABLE(18b,100b)
30585 + _ASM_EXTABLE(19b,100b)
30586 + _ASM_EXTABLE(20b,100b)
30587 + _ASM_EXTABLE(21b,100b)
30588 + _ASM_EXTABLE(22b,100b)
30589 + _ASM_EXTABLE(23b,100b)
30590 + _ASM_EXTABLE(24b,100b)
30591 + _ASM_EXTABLE(25b,100b)
30592 + _ASM_EXTABLE(26b,100b)
30593 + _ASM_EXTABLE(27b,100b)
30594 + _ASM_EXTABLE(28b,100b)
30595 + _ASM_EXTABLE(29b,100b)
30596 + _ASM_EXTABLE(30b,100b)
30597 + _ASM_EXTABLE(31b,100b)
30598 + _ASM_EXTABLE(32b,100b)
30599 + _ASM_EXTABLE(33b,100b)
30600 + _ASM_EXTABLE(34b,100b)
30601 + _ASM_EXTABLE(35b,100b)
30602 + _ASM_EXTABLE(36b,100b)
30603 + _ASM_EXTABLE(37b,100b)
30604 + _ASM_EXTABLE(99b,101b)
30605 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30606 + : "1"(to), "2"(from), "0"(size)
30607 + : "eax", "edx", "memory");
30608 + return size;
30609 +}
30610 +
30611 +static unsigned long
30612 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30613 +{
30614 + int d0, d1;
30615 + __asm__ __volatile__(
30616 + " .align 2,0x90\n"
30617 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30618 + " cmpl $67, %0\n"
30619 + " jbe 3f\n"
30620 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30621 + " .align 2,0x90\n"
30622 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30623 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30624 + "5: movl %%eax, 0(%3)\n"
30625 + "6: movl %%edx, 4(%3)\n"
30626 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30627 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30628 + "9: movl %%eax, 8(%3)\n"
30629 + "10: movl %%edx, 12(%3)\n"
30630 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30631 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30632 + "13: movl %%eax, 16(%3)\n"
30633 + "14: movl %%edx, 20(%3)\n"
30634 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30635 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30636 + "17: movl %%eax, 24(%3)\n"
30637 + "18: movl %%edx, 28(%3)\n"
30638 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30639 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30640 + "21: movl %%eax, 32(%3)\n"
30641 + "22: movl %%edx, 36(%3)\n"
30642 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30643 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30644 + "25: movl %%eax, 40(%3)\n"
30645 + "26: movl %%edx, 44(%3)\n"
30646 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30647 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30648 + "29: movl %%eax, 48(%3)\n"
30649 + "30: movl %%edx, 52(%3)\n"
30650 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30651 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30652 + "33: movl %%eax, 56(%3)\n"
30653 + "34: movl %%edx, 60(%3)\n"
30654 + " addl $-64, %0\n"
30655 + " addl $64, %4\n"
30656 + " addl $64, %3\n"
30657 + " cmpl $63, %0\n"
30658 + " ja 1b\n"
30659 + "35: movl %0, %%eax\n"
30660 + " shrl $2, %0\n"
30661 + " andl $3, %%eax\n"
30662 + " cld\n"
30663 + "99: rep; "__copyuser_seg" movsl\n"
30664 + "36: movl %%eax, %0\n"
30665 + "37: rep; "__copyuser_seg" movsb\n"
30666 + "100:\n"
30667 ".section .fixup,\"ax\"\n"
30668 "101: lea 0(%%eax,%0,4),%0\n"
30669 " jmp 100b\n"
30670 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30671 int d0, d1;
30672 __asm__ __volatile__(
30673 " .align 2,0x90\n"
30674 - "0: movl 32(%4), %%eax\n"
30675 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30676 " cmpl $67, %0\n"
30677 " jbe 2f\n"
30678 - "1: movl 64(%4), %%eax\n"
30679 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30680 " .align 2,0x90\n"
30681 - "2: movl 0(%4), %%eax\n"
30682 - "21: movl 4(%4), %%edx\n"
30683 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30684 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30685 " movl %%eax, 0(%3)\n"
30686 " movl %%edx, 4(%3)\n"
30687 - "3: movl 8(%4), %%eax\n"
30688 - "31: movl 12(%4),%%edx\n"
30689 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30690 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30691 " movl %%eax, 8(%3)\n"
30692 " movl %%edx, 12(%3)\n"
30693 - "4: movl 16(%4), %%eax\n"
30694 - "41: movl 20(%4), %%edx\n"
30695 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30696 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30697 " movl %%eax, 16(%3)\n"
30698 " movl %%edx, 20(%3)\n"
30699 - "10: movl 24(%4), %%eax\n"
30700 - "51: movl 28(%4), %%edx\n"
30701 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30702 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30703 " movl %%eax, 24(%3)\n"
30704 " movl %%edx, 28(%3)\n"
30705 - "11: movl 32(%4), %%eax\n"
30706 - "61: movl 36(%4), %%edx\n"
30707 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30708 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30709 " movl %%eax, 32(%3)\n"
30710 " movl %%edx, 36(%3)\n"
30711 - "12: movl 40(%4), %%eax\n"
30712 - "71: movl 44(%4), %%edx\n"
30713 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30714 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30715 " movl %%eax, 40(%3)\n"
30716 " movl %%edx, 44(%3)\n"
30717 - "13: movl 48(%4), %%eax\n"
30718 - "81: movl 52(%4), %%edx\n"
30719 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30720 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30721 " movl %%eax, 48(%3)\n"
30722 " movl %%edx, 52(%3)\n"
30723 - "14: movl 56(%4), %%eax\n"
30724 - "91: movl 60(%4), %%edx\n"
30725 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30726 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30727 " movl %%eax, 56(%3)\n"
30728 " movl %%edx, 60(%3)\n"
30729 " addl $-64, %0\n"
30730 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30731 " shrl $2, %0\n"
30732 " andl $3, %%eax\n"
30733 " cld\n"
30734 - "6: rep; movsl\n"
30735 + "6: rep; "__copyuser_seg" movsl\n"
30736 " movl %%eax,%0\n"
30737 - "7: rep; movsb\n"
30738 + "7: rep; "__copyuser_seg" movsb\n"
30739 "8:\n"
30740 ".section .fixup,\"ax\"\n"
30741 "9: lea 0(%%eax,%0,4),%0\n"
30742 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30743
30744 __asm__ __volatile__(
30745 " .align 2,0x90\n"
30746 - "0: movl 32(%4), %%eax\n"
30747 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30748 " cmpl $67, %0\n"
30749 " jbe 2f\n"
30750 - "1: movl 64(%4), %%eax\n"
30751 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30752 " .align 2,0x90\n"
30753 - "2: movl 0(%4), %%eax\n"
30754 - "21: movl 4(%4), %%edx\n"
30755 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30756 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30757 " movnti %%eax, 0(%3)\n"
30758 " movnti %%edx, 4(%3)\n"
30759 - "3: movl 8(%4), %%eax\n"
30760 - "31: movl 12(%4),%%edx\n"
30761 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30762 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30763 " movnti %%eax, 8(%3)\n"
30764 " movnti %%edx, 12(%3)\n"
30765 - "4: movl 16(%4), %%eax\n"
30766 - "41: movl 20(%4), %%edx\n"
30767 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30768 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30769 " movnti %%eax, 16(%3)\n"
30770 " movnti %%edx, 20(%3)\n"
30771 - "10: movl 24(%4), %%eax\n"
30772 - "51: movl 28(%4), %%edx\n"
30773 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30774 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30775 " movnti %%eax, 24(%3)\n"
30776 " movnti %%edx, 28(%3)\n"
30777 - "11: movl 32(%4), %%eax\n"
30778 - "61: movl 36(%4), %%edx\n"
30779 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30780 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30781 " movnti %%eax, 32(%3)\n"
30782 " movnti %%edx, 36(%3)\n"
30783 - "12: movl 40(%4), %%eax\n"
30784 - "71: movl 44(%4), %%edx\n"
30785 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30786 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30787 " movnti %%eax, 40(%3)\n"
30788 " movnti %%edx, 44(%3)\n"
30789 - "13: movl 48(%4), %%eax\n"
30790 - "81: movl 52(%4), %%edx\n"
30791 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30792 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30793 " movnti %%eax, 48(%3)\n"
30794 " movnti %%edx, 52(%3)\n"
30795 - "14: movl 56(%4), %%eax\n"
30796 - "91: movl 60(%4), %%edx\n"
30797 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30798 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30799 " movnti %%eax, 56(%3)\n"
30800 " movnti %%edx, 60(%3)\n"
30801 " addl $-64, %0\n"
30802 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30803 " shrl $2, %0\n"
30804 " andl $3, %%eax\n"
30805 " cld\n"
30806 - "6: rep; movsl\n"
30807 + "6: rep; "__copyuser_seg" movsl\n"
30808 " movl %%eax,%0\n"
30809 - "7: rep; movsb\n"
30810 + "7: rep; "__copyuser_seg" movsb\n"
30811 "8:\n"
30812 ".section .fixup,\"ax\"\n"
30813 "9: lea 0(%%eax,%0,4),%0\n"
30814 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30815
30816 __asm__ __volatile__(
30817 " .align 2,0x90\n"
30818 - "0: movl 32(%4), %%eax\n"
30819 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30820 " cmpl $67, %0\n"
30821 " jbe 2f\n"
30822 - "1: movl 64(%4), %%eax\n"
30823 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30824 " .align 2,0x90\n"
30825 - "2: movl 0(%4), %%eax\n"
30826 - "21: movl 4(%4), %%edx\n"
30827 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30828 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30829 " movnti %%eax, 0(%3)\n"
30830 " movnti %%edx, 4(%3)\n"
30831 - "3: movl 8(%4), %%eax\n"
30832 - "31: movl 12(%4),%%edx\n"
30833 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30834 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30835 " movnti %%eax, 8(%3)\n"
30836 " movnti %%edx, 12(%3)\n"
30837 - "4: movl 16(%4), %%eax\n"
30838 - "41: movl 20(%4), %%edx\n"
30839 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30840 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30841 " movnti %%eax, 16(%3)\n"
30842 " movnti %%edx, 20(%3)\n"
30843 - "10: movl 24(%4), %%eax\n"
30844 - "51: movl 28(%4), %%edx\n"
30845 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30846 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30847 " movnti %%eax, 24(%3)\n"
30848 " movnti %%edx, 28(%3)\n"
30849 - "11: movl 32(%4), %%eax\n"
30850 - "61: movl 36(%4), %%edx\n"
30851 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30852 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30853 " movnti %%eax, 32(%3)\n"
30854 " movnti %%edx, 36(%3)\n"
30855 - "12: movl 40(%4), %%eax\n"
30856 - "71: movl 44(%4), %%edx\n"
30857 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30858 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30859 " movnti %%eax, 40(%3)\n"
30860 " movnti %%edx, 44(%3)\n"
30861 - "13: movl 48(%4), %%eax\n"
30862 - "81: movl 52(%4), %%edx\n"
30863 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30864 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30865 " movnti %%eax, 48(%3)\n"
30866 " movnti %%edx, 52(%3)\n"
30867 - "14: movl 56(%4), %%eax\n"
30868 - "91: movl 60(%4), %%edx\n"
30869 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30870 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30871 " movnti %%eax, 56(%3)\n"
30872 " movnti %%edx, 60(%3)\n"
30873 " addl $-64, %0\n"
30874 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30875 " shrl $2, %0\n"
30876 " andl $3, %%eax\n"
30877 " cld\n"
30878 - "6: rep; movsl\n"
30879 + "6: rep; "__copyuser_seg" movsl\n"
30880 " movl %%eax,%0\n"
30881 - "7: rep; movsb\n"
30882 + "7: rep; "__copyuser_seg" movsb\n"
30883 "8:\n"
30884 ".section .fixup,\"ax\"\n"
30885 "9: lea 0(%%eax,%0,4),%0\n"
30886 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30887 */
30888 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30889 unsigned long size);
30890 -unsigned long __copy_user_intel(void __user *to, const void *from,
30891 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30892 + unsigned long size);
30893 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30894 unsigned long size);
30895 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30896 const void __user *from, unsigned long size);
30897 #endif /* CONFIG_X86_INTEL_USERCOPY */
30898
30899 /* Generic arbitrary sized copy. */
30900 -#define __copy_user(to, from, size) \
30901 +#define __copy_user(to, from, size, prefix, set, restore) \
30902 do { \
30903 int __d0, __d1, __d2; \
30904 __asm__ __volatile__( \
30905 + set \
30906 " cmp $7,%0\n" \
30907 " jbe 1f\n" \
30908 " movl %1,%0\n" \
30909 " negl %0\n" \
30910 " andl $7,%0\n" \
30911 " subl %0,%3\n" \
30912 - "4: rep; movsb\n" \
30913 + "4: rep; "prefix"movsb\n" \
30914 " movl %3,%0\n" \
30915 " shrl $2,%0\n" \
30916 " andl $3,%3\n" \
30917 " .align 2,0x90\n" \
30918 - "0: rep; movsl\n" \
30919 + "0: rep; "prefix"movsl\n" \
30920 " movl %3,%0\n" \
30921 - "1: rep; movsb\n" \
30922 + "1: rep; "prefix"movsb\n" \
30923 "2:\n" \
30924 + restore \
30925 ".section .fixup,\"ax\"\n" \
30926 "5: addl %3,%0\n" \
30927 " jmp 2b\n" \
30928 @@ -538,14 +650,14 @@ do { \
30929 " negl %0\n" \
30930 " andl $7,%0\n" \
30931 " subl %0,%3\n" \
30932 - "4: rep; movsb\n" \
30933 + "4: rep; "__copyuser_seg"movsb\n" \
30934 " movl %3,%0\n" \
30935 " shrl $2,%0\n" \
30936 " andl $3,%3\n" \
30937 " .align 2,0x90\n" \
30938 - "0: rep; movsl\n" \
30939 + "0: rep; "__copyuser_seg"movsl\n" \
30940 " movl %3,%0\n" \
30941 - "1: rep; movsb\n" \
30942 + "1: rep; "__copyuser_seg"movsb\n" \
30943 "2:\n" \
30944 ".section .fixup,\"ax\"\n" \
30945 "5: addl %3,%0\n" \
30946 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30947 {
30948 stac();
30949 if (movsl_is_ok(to, from, n))
30950 - __copy_user(to, from, n);
30951 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30952 else
30953 - n = __copy_user_intel(to, from, n);
30954 + n = __generic_copy_to_user_intel(to, from, n);
30955 clac();
30956 return n;
30957 }
30958 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30959 {
30960 stac();
30961 if (movsl_is_ok(to, from, n))
30962 - __copy_user(to, from, n);
30963 + __copy_user(to, from, n, __copyuser_seg, "", "");
30964 else
30965 - n = __copy_user_intel((void __user *)to,
30966 - (const void *)from, n);
30967 + n = __generic_copy_from_user_intel(to, from, n);
30968 clac();
30969 return n;
30970 }
30971 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30972 if (n > 64 && cpu_has_xmm2)
30973 n = __copy_user_intel_nocache(to, from, n);
30974 else
30975 - __copy_user(to, from, n);
30976 + __copy_user(to, from, n, __copyuser_seg, "", "");
30977 #else
30978 - __copy_user(to, from, n);
30979 + __copy_user(to, from, n, __copyuser_seg, "", "");
30980 #endif
30981 clac();
30982 return n;
30983 }
30984 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30985
30986 -/**
30987 - * copy_to_user: - Copy a block of data into user space.
30988 - * @to: Destination address, in user space.
30989 - * @from: Source address, in kernel space.
30990 - * @n: Number of bytes to copy.
30991 - *
30992 - * Context: User context only. This function may sleep.
30993 - *
30994 - * Copy data from kernel space to user space.
30995 - *
30996 - * Returns number of bytes that could not be copied.
30997 - * On success, this will be zero.
30998 - */
30999 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31000 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31001 +void __set_fs(mm_segment_t x)
31002 {
31003 - if (access_ok(VERIFY_WRITE, to, n))
31004 - n = __copy_to_user(to, from, n);
31005 - return n;
31006 + switch (x.seg) {
31007 + case 0:
31008 + loadsegment(gs, 0);
31009 + break;
31010 + case TASK_SIZE_MAX:
31011 + loadsegment(gs, __USER_DS);
31012 + break;
31013 + case -1UL:
31014 + loadsegment(gs, __KERNEL_DS);
31015 + break;
31016 + default:
31017 + BUG();
31018 + }
31019 }
31020 -EXPORT_SYMBOL(_copy_to_user);
31021 +EXPORT_SYMBOL(__set_fs);
31022
31023 -/**
31024 - * copy_from_user: - Copy a block of data from user space.
31025 - * @to: Destination address, in kernel space.
31026 - * @from: Source address, in user space.
31027 - * @n: Number of bytes to copy.
31028 - *
31029 - * Context: User context only. This function may sleep.
31030 - *
31031 - * Copy data from user space to kernel space.
31032 - *
31033 - * Returns number of bytes that could not be copied.
31034 - * On success, this will be zero.
31035 - *
31036 - * If some data could not be copied, this function will pad the copied
31037 - * data to the requested size using zero bytes.
31038 - */
31039 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31040 +void set_fs(mm_segment_t x)
31041 {
31042 - if (access_ok(VERIFY_READ, from, n))
31043 - n = __copy_from_user(to, from, n);
31044 - else
31045 - memset(to, 0, n);
31046 - return n;
31047 + current_thread_info()->addr_limit = x;
31048 + __set_fs(x);
31049 }
31050 -EXPORT_SYMBOL(_copy_from_user);
31051 +EXPORT_SYMBOL(set_fs);
31052 +#endif
31053 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31054 index c905e89..01ab928 100644
31055 --- a/arch/x86/lib/usercopy_64.c
31056 +++ b/arch/x86/lib/usercopy_64.c
31057 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31058 might_fault();
31059 /* no memory constraint because it doesn't change any memory gcc knows
31060 about */
31061 + pax_open_userland();
31062 stac();
31063 asm volatile(
31064 " testq %[size8],%[size8]\n"
31065 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31066 _ASM_EXTABLE(0b,3b)
31067 _ASM_EXTABLE(1b,2b)
31068 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31069 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31070 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31071 [zero] "r" (0UL), [eight] "r" (8UL));
31072 clac();
31073 + pax_close_userland();
31074 return size;
31075 }
31076 EXPORT_SYMBOL(__clear_user);
31077 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31078 }
31079 EXPORT_SYMBOL(clear_user);
31080
31081 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31082 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31083 {
31084 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31085 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31086 - }
31087 - return len;
31088 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31089 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31090 + return len;
31091 }
31092 EXPORT_SYMBOL(copy_in_user);
31093
31094 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31095 * it is not necessary to optimize tail handling.
31096 */
31097 __visible unsigned long
31098 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31099 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31100 {
31101 char c;
31102 unsigned zero_len;
31103
31104 + clac();
31105 + pax_close_userland();
31106 for (; len; --len, to++) {
31107 if (__get_user_nocheck(c, from++, sizeof(char)))
31108 break;
31109 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31110 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31111 if (__put_user_nocheck(c, to++, sizeof(char)))
31112 break;
31113 - clac();
31114 return len;
31115 }
31116 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31117 index 6a19ad9..1c48f9a 100644
31118 --- a/arch/x86/mm/Makefile
31119 +++ b/arch/x86/mm/Makefile
31120 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31121 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31122
31123 obj-$(CONFIG_MEMTEST) += memtest.o
31124 +
31125 +quote:="
31126 +obj-$(CONFIG_X86_64) += uderef_64.o
31127 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31128 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31129 index 903ec1e..c4166b2 100644
31130 --- a/arch/x86/mm/extable.c
31131 +++ b/arch/x86/mm/extable.c
31132 @@ -6,12 +6,24 @@
31133 static inline unsigned long
31134 ex_insn_addr(const struct exception_table_entry *x)
31135 {
31136 - return (unsigned long)&x->insn + x->insn;
31137 + unsigned long reloc = 0;
31138 +
31139 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31140 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31141 +#endif
31142 +
31143 + return (unsigned long)&x->insn + x->insn + reloc;
31144 }
31145 static inline unsigned long
31146 ex_fixup_addr(const struct exception_table_entry *x)
31147 {
31148 - return (unsigned long)&x->fixup + x->fixup;
31149 + unsigned long reloc = 0;
31150 +
31151 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31152 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31153 +#endif
31154 +
31155 + return (unsigned long)&x->fixup + x->fixup + reloc;
31156 }
31157
31158 int fixup_exception(struct pt_regs *regs)
31159 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31160 unsigned long new_ip;
31161
31162 #ifdef CONFIG_PNPBIOS
31163 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31164 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31165 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31166 extern u32 pnp_bios_is_utter_crap;
31167 pnp_bios_is_utter_crap = 1;
31168 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31169 i += 4;
31170 p->fixup -= i;
31171 i += 4;
31172 +
31173 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31174 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31175 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31176 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31177 +#endif
31178 +
31179 }
31180 }
31181
31182 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31183 index a10c8c7..35a5abb 100644
31184 --- a/arch/x86/mm/fault.c
31185 +++ b/arch/x86/mm/fault.c
31186 @@ -14,11 +14,18 @@
31187 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31188 #include <linux/prefetch.h> /* prefetchw */
31189 #include <linux/context_tracking.h> /* exception_enter(), ... */
31190 +#include <linux/unistd.h>
31191 +#include <linux/compiler.h>
31192
31193 #include <asm/traps.h> /* dotraplinkage, ... */
31194 #include <asm/pgalloc.h> /* pgd_*(), ... */
31195 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31196 #include <asm/fixmap.h> /* VSYSCALL_START */
31197 +#include <asm/tlbflush.h>
31198 +
31199 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31200 +#include <asm/stacktrace.h>
31201 +#endif
31202
31203 #define CREATE_TRACE_POINTS
31204 #include <asm/trace/exceptions.h>
31205 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31206 int ret = 0;
31207
31208 /* kprobe_running() needs smp_processor_id() */
31209 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31210 + if (kprobes_built_in() && !user_mode(regs)) {
31211 preempt_disable();
31212 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31213 ret = 1;
31214 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31215 return !instr_lo || (instr_lo>>1) == 1;
31216 case 0x00:
31217 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31218 - if (probe_kernel_address(instr, opcode))
31219 + if (user_mode(regs)) {
31220 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31221 + return 0;
31222 + } else if (probe_kernel_address(instr, opcode))
31223 return 0;
31224
31225 *prefetch = (instr_lo == 0xF) &&
31226 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31227 while (instr < max_instr) {
31228 unsigned char opcode;
31229
31230 - if (probe_kernel_address(instr, opcode))
31231 + if (user_mode(regs)) {
31232 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31233 + break;
31234 + } else if (probe_kernel_address(instr, opcode))
31235 break;
31236
31237 instr++;
31238 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31239 force_sig_info(si_signo, &info, tsk);
31240 }
31241
31242 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31243 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31244 +#endif
31245 +
31246 +#ifdef CONFIG_PAX_EMUTRAMP
31247 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31248 +#endif
31249 +
31250 +#ifdef CONFIG_PAX_PAGEEXEC
31251 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31252 +{
31253 + pgd_t *pgd;
31254 + pud_t *pud;
31255 + pmd_t *pmd;
31256 +
31257 + pgd = pgd_offset(mm, address);
31258 + if (!pgd_present(*pgd))
31259 + return NULL;
31260 + pud = pud_offset(pgd, address);
31261 + if (!pud_present(*pud))
31262 + return NULL;
31263 + pmd = pmd_offset(pud, address);
31264 + if (!pmd_present(*pmd))
31265 + return NULL;
31266 + return pmd;
31267 +}
31268 +#endif
31269 +
31270 DEFINE_SPINLOCK(pgd_lock);
31271 LIST_HEAD(pgd_list);
31272
31273 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31274 for (address = VMALLOC_START & PMD_MASK;
31275 address >= TASK_SIZE && address < FIXADDR_TOP;
31276 address += PMD_SIZE) {
31277 +
31278 +#ifdef CONFIG_PAX_PER_CPU_PGD
31279 + unsigned long cpu;
31280 +#else
31281 struct page *page;
31282 +#endif
31283
31284 spin_lock(&pgd_lock);
31285 +
31286 +#ifdef CONFIG_PAX_PER_CPU_PGD
31287 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31288 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31289 + pmd_t *ret;
31290 +
31291 + ret = vmalloc_sync_one(pgd, address);
31292 + if (!ret)
31293 + break;
31294 + pgd = get_cpu_pgd(cpu, kernel);
31295 +#else
31296 list_for_each_entry(page, &pgd_list, lru) {
31297 + pgd_t *pgd;
31298 spinlock_t *pgt_lock;
31299 pmd_t *ret;
31300
31301 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31302 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31303
31304 spin_lock(pgt_lock);
31305 - ret = vmalloc_sync_one(page_address(page), address);
31306 + pgd = page_address(page);
31307 +#endif
31308 +
31309 + ret = vmalloc_sync_one(pgd, address);
31310 +
31311 +#ifndef CONFIG_PAX_PER_CPU_PGD
31312 spin_unlock(pgt_lock);
31313 +#endif
31314
31315 if (!ret)
31316 break;
31317 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31318 * an interrupt in the middle of a task switch..
31319 */
31320 pgd_paddr = read_cr3();
31321 +
31322 +#ifdef CONFIG_PAX_PER_CPU_PGD
31323 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31324 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31325 +#endif
31326 +
31327 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31328 if (!pmd_k)
31329 return -1;
31330 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31331 * happen within a race in page table update. In the later
31332 * case just flush:
31333 */
31334 - pgd = pgd_offset(current->active_mm, address);
31335 +
31336 pgd_ref = pgd_offset_k(address);
31337 if (pgd_none(*pgd_ref))
31338 return -1;
31339
31340 +#ifdef CONFIG_PAX_PER_CPU_PGD
31341 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31342 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31343 + if (pgd_none(*pgd)) {
31344 + set_pgd(pgd, *pgd_ref);
31345 + arch_flush_lazy_mmu_mode();
31346 + } else {
31347 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31348 + }
31349 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31350 +#else
31351 + pgd = pgd_offset(current->active_mm, address);
31352 +#endif
31353 +
31354 if (pgd_none(*pgd)) {
31355 set_pgd(pgd, *pgd_ref);
31356 arch_flush_lazy_mmu_mode();
31357 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31358 static int is_errata100(struct pt_regs *regs, unsigned long address)
31359 {
31360 #ifdef CONFIG_X86_64
31361 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31362 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31363 return 1;
31364 #endif
31365 return 0;
31366 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31367 }
31368
31369 static const char nx_warning[] = KERN_CRIT
31370 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31371 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31372
31373 static void
31374 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31375 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31376 if (!oops_may_print())
31377 return;
31378
31379 - if (error_code & PF_INSTR) {
31380 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31381 unsigned int level;
31382
31383 pte_t *pte = lookup_address(address, &level);
31384
31385 if (pte && pte_present(*pte) && !pte_exec(*pte))
31386 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31387 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31388 }
31389
31390 +#ifdef CONFIG_PAX_KERNEXEC
31391 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31392 + if (current->signal->curr_ip)
31393 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31394 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31395 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31396 + else
31397 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31398 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31399 + }
31400 +#endif
31401 +
31402 printk(KERN_ALERT "BUG: unable to handle kernel ");
31403 if (address < PAGE_SIZE)
31404 printk(KERN_CONT "NULL pointer dereference");
31405 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31406 return;
31407 }
31408 #endif
31409 +
31410 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31411 + if (pax_is_fetch_fault(regs, error_code, address)) {
31412 +
31413 +#ifdef CONFIG_PAX_EMUTRAMP
31414 + switch (pax_handle_fetch_fault(regs)) {
31415 + case 2:
31416 + return;
31417 + }
31418 +#endif
31419 +
31420 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31421 + do_group_exit(SIGKILL);
31422 + }
31423 +#endif
31424 +
31425 /* Kernel addresses are always protection faults: */
31426 if (address >= TASK_SIZE)
31427 error_code |= PF_PROT;
31428 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31429 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31430 printk(KERN_ERR
31431 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31432 - tsk->comm, tsk->pid, address);
31433 + tsk->comm, task_pid_nr(tsk), address);
31434 code = BUS_MCEERR_AR;
31435 }
31436 #endif
31437 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31438 return 1;
31439 }
31440
31441 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31442 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31443 +{
31444 + pte_t *pte;
31445 + pmd_t *pmd;
31446 + spinlock_t *ptl;
31447 + unsigned char pte_mask;
31448 +
31449 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31450 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31451 + return 0;
31452 +
31453 + /* PaX: it's our fault, let's handle it if we can */
31454 +
31455 + /* PaX: take a look at read faults before acquiring any locks */
31456 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31457 + /* instruction fetch attempt from a protected page in user mode */
31458 + up_read(&mm->mmap_sem);
31459 +
31460 +#ifdef CONFIG_PAX_EMUTRAMP
31461 + switch (pax_handle_fetch_fault(regs)) {
31462 + case 2:
31463 + return 1;
31464 + }
31465 +#endif
31466 +
31467 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31468 + do_group_exit(SIGKILL);
31469 + }
31470 +
31471 + pmd = pax_get_pmd(mm, address);
31472 + if (unlikely(!pmd))
31473 + return 0;
31474 +
31475 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31476 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31477 + pte_unmap_unlock(pte, ptl);
31478 + return 0;
31479 + }
31480 +
31481 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31482 + /* write attempt to a protected page in user mode */
31483 + pte_unmap_unlock(pte, ptl);
31484 + return 0;
31485 + }
31486 +
31487 +#ifdef CONFIG_SMP
31488 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31489 +#else
31490 + if (likely(address > get_limit(regs->cs)))
31491 +#endif
31492 + {
31493 + set_pte(pte, pte_mkread(*pte));
31494 + __flush_tlb_one(address);
31495 + pte_unmap_unlock(pte, ptl);
31496 + up_read(&mm->mmap_sem);
31497 + return 1;
31498 + }
31499 +
31500 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31501 +
31502 + /*
31503 + * PaX: fill DTLB with user rights and retry
31504 + */
31505 + __asm__ __volatile__ (
31506 + "orb %2,(%1)\n"
31507 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31508 +/*
31509 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31510 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31511 + * page fault when examined during a TLB load attempt. this is true not only
31512 + * for PTEs holding a non-present entry but also present entries that will
31513 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31514 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31515 + * for our target pages since their PTEs are simply not in the TLBs at all.
31516 +
31517 + * the best thing in omitting it is that we gain around 15-20% speed in the
31518 + * fast path of the page fault handler and can get rid of tracing since we
31519 + * can no longer flush unintended entries.
31520 + */
31521 + "invlpg (%0)\n"
31522 +#endif
31523 + __copyuser_seg"testb $0,(%0)\n"
31524 + "xorb %3,(%1)\n"
31525 + :
31526 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31527 + : "memory", "cc");
31528 + pte_unmap_unlock(pte, ptl);
31529 + up_read(&mm->mmap_sem);
31530 + return 1;
31531 +}
31532 +#endif
31533 +
31534 /*
31535 * Handle a spurious fault caused by a stale TLB entry.
31536 *
31537 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31538 static inline int
31539 access_error(unsigned long error_code, struct vm_area_struct *vma)
31540 {
31541 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31542 + return 1;
31543 +
31544 if (error_code & PF_WRITE) {
31545 /* write, present and write, not present: */
31546 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31547 @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31548 if (error_code & PF_USER)
31549 return false;
31550
31551 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31552 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31553 return false;
31554
31555 return true;
31556 @@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31557 tsk = current;
31558 mm = tsk->mm;
31559
31560 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31561 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31562 + if (!search_exception_tables(regs->ip)) {
31563 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31564 + bad_area_nosemaphore(regs, error_code, address);
31565 + return;
31566 + }
31567 + if (address < pax_user_shadow_base) {
31568 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31569 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31570 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31571 + } else
31572 + address -= pax_user_shadow_base;
31573 + }
31574 +#endif
31575 +
31576 /*
31577 * Detect and handle instructions that would cause a page fault for
31578 * both a tracked kernel page and a userspace page.
31579 @@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31580 * User-mode registers count as a user access even for any
31581 * potential system fault or CPU buglet:
31582 */
31583 - if (user_mode_vm(regs)) {
31584 + if (user_mode(regs)) {
31585 local_irq_enable();
31586 error_code |= PF_USER;
31587 flags |= FAULT_FLAG_USER;
31588 @@ -1162,6 +1386,11 @@ retry:
31589 might_sleep();
31590 }
31591
31592 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31593 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31594 + return;
31595 +#endif
31596 +
31597 vma = find_vma(mm, address);
31598 if (unlikely(!vma)) {
31599 bad_area(regs, error_code, address);
31600 @@ -1173,18 +1402,24 @@ retry:
31601 bad_area(regs, error_code, address);
31602 return;
31603 }
31604 - if (error_code & PF_USER) {
31605 - /*
31606 - * Accessing the stack below %sp is always a bug.
31607 - * The large cushion allows instructions like enter
31608 - * and pusha to work. ("enter $65535, $31" pushes
31609 - * 32 pointers and then decrements %sp by 65535.)
31610 - */
31611 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31612 - bad_area(regs, error_code, address);
31613 - return;
31614 - }
31615 + /*
31616 + * Accessing the stack below %sp is always a bug.
31617 + * The large cushion allows instructions like enter
31618 + * and pusha to work. ("enter $65535, $31" pushes
31619 + * 32 pointers and then decrements %sp by 65535.)
31620 + */
31621 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31622 + bad_area(regs, error_code, address);
31623 + return;
31624 }
31625 +
31626 +#ifdef CONFIG_PAX_SEGMEXEC
31627 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31628 + bad_area(regs, error_code, address);
31629 + return;
31630 + }
31631 +#endif
31632 +
31633 if (unlikely(expand_stack(vma, address))) {
31634 bad_area(regs, error_code, address);
31635 return;
31636 @@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31637 exception_exit(prev_state);
31638 }
31639 #endif /* CONFIG_TRACING */
31640 +
31641 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31642 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31643 +{
31644 + struct mm_struct *mm = current->mm;
31645 + unsigned long ip = regs->ip;
31646 +
31647 + if (v8086_mode(regs))
31648 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31649 +
31650 +#ifdef CONFIG_PAX_PAGEEXEC
31651 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31652 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31653 + return true;
31654 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31655 + return true;
31656 + return false;
31657 + }
31658 +#endif
31659 +
31660 +#ifdef CONFIG_PAX_SEGMEXEC
31661 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31662 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31663 + return true;
31664 + return false;
31665 + }
31666 +#endif
31667 +
31668 + return false;
31669 +}
31670 +#endif
31671 +
31672 +#ifdef CONFIG_PAX_EMUTRAMP
31673 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31674 +{
31675 + int err;
31676 +
31677 + do { /* PaX: libffi trampoline emulation */
31678 + unsigned char mov, jmp;
31679 + unsigned int addr1, addr2;
31680 +
31681 +#ifdef CONFIG_X86_64
31682 + if ((regs->ip + 9) >> 32)
31683 + break;
31684 +#endif
31685 +
31686 + err = get_user(mov, (unsigned char __user *)regs->ip);
31687 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31688 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31689 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31690 +
31691 + if (err)
31692 + break;
31693 +
31694 + if (mov == 0xB8 && jmp == 0xE9) {
31695 + regs->ax = addr1;
31696 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31697 + return 2;
31698 + }
31699 + } while (0);
31700 +
31701 + do { /* PaX: gcc trampoline emulation #1 */
31702 + unsigned char mov1, mov2;
31703 + unsigned short jmp;
31704 + unsigned int addr1, addr2;
31705 +
31706 +#ifdef CONFIG_X86_64
31707 + if ((regs->ip + 11) >> 32)
31708 + break;
31709 +#endif
31710 +
31711 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31712 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31713 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31714 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31715 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31716 +
31717 + if (err)
31718 + break;
31719 +
31720 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31721 + regs->cx = addr1;
31722 + regs->ax = addr2;
31723 + regs->ip = addr2;
31724 + return 2;
31725 + }
31726 + } while (0);
31727 +
31728 + do { /* PaX: gcc trampoline emulation #2 */
31729 + unsigned char mov, jmp;
31730 + unsigned int addr1, addr2;
31731 +
31732 +#ifdef CONFIG_X86_64
31733 + if ((regs->ip + 9) >> 32)
31734 + break;
31735 +#endif
31736 +
31737 + err = get_user(mov, (unsigned char __user *)regs->ip);
31738 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31739 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31740 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31741 +
31742 + if (err)
31743 + break;
31744 +
31745 + if (mov == 0xB9 && jmp == 0xE9) {
31746 + regs->cx = addr1;
31747 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31748 + return 2;
31749 + }
31750 + } while (0);
31751 +
31752 + return 1; /* PaX in action */
31753 +}
31754 +
31755 +#ifdef CONFIG_X86_64
31756 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31757 +{
31758 + int err;
31759 +
31760 + do { /* PaX: libffi trampoline emulation */
31761 + unsigned short mov1, mov2, jmp1;
31762 + unsigned char stcclc, jmp2;
31763 + unsigned long addr1, addr2;
31764 +
31765 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31766 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31767 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31768 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31769 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31770 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31771 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31772 +
31773 + if (err)
31774 + break;
31775 +
31776 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31777 + regs->r11 = addr1;
31778 + regs->r10 = addr2;
31779 + if (stcclc == 0xF8)
31780 + regs->flags &= ~X86_EFLAGS_CF;
31781 + else
31782 + regs->flags |= X86_EFLAGS_CF;
31783 + regs->ip = addr1;
31784 + return 2;
31785 + }
31786 + } while (0);
31787 +
31788 + do { /* PaX: gcc trampoline emulation #1 */
31789 + unsigned short mov1, mov2, jmp1;
31790 + unsigned char jmp2;
31791 + unsigned int addr1;
31792 + unsigned long addr2;
31793 +
31794 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31795 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31796 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31797 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31798 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31799 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31800 +
31801 + if (err)
31802 + break;
31803 +
31804 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31805 + regs->r11 = addr1;
31806 + regs->r10 = addr2;
31807 + regs->ip = addr1;
31808 + return 2;
31809 + }
31810 + } while (0);
31811 +
31812 + do { /* PaX: gcc trampoline emulation #2 */
31813 + unsigned short mov1, mov2, jmp1;
31814 + unsigned char jmp2;
31815 + unsigned long addr1, addr2;
31816 +
31817 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31818 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31819 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31820 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31821 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31822 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31823 +
31824 + if (err)
31825 + break;
31826 +
31827 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31828 + regs->r11 = addr1;
31829 + regs->r10 = addr2;
31830 + regs->ip = addr1;
31831 + return 2;
31832 + }
31833 + } while (0);
31834 +
31835 + return 1; /* PaX in action */
31836 +}
31837 +#endif
31838 +
31839 +/*
31840 + * PaX: decide what to do with offenders (regs->ip = fault address)
31841 + *
31842 + * returns 1 when task should be killed
31843 + * 2 when gcc trampoline was detected
31844 + */
31845 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31846 +{
31847 + if (v8086_mode(regs))
31848 + return 1;
31849 +
31850 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31851 + return 1;
31852 +
31853 +#ifdef CONFIG_X86_32
31854 + return pax_handle_fetch_fault_32(regs);
31855 +#else
31856 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31857 + return pax_handle_fetch_fault_32(regs);
31858 + else
31859 + return pax_handle_fetch_fault_64(regs);
31860 +#endif
31861 +}
31862 +#endif
31863 +
31864 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31865 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31866 +{
31867 + long i;
31868 +
31869 + printk(KERN_ERR "PAX: bytes at PC: ");
31870 + for (i = 0; i < 20; i++) {
31871 + unsigned char c;
31872 + if (get_user(c, (unsigned char __force_user *)pc+i))
31873 + printk(KERN_CONT "?? ");
31874 + else
31875 + printk(KERN_CONT "%02x ", c);
31876 + }
31877 + printk("\n");
31878 +
31879 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31880 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31881 + unsigned long c;
31882 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31883 +#ifdef CONFIG_X86_32
31884 + printk(KERN_CONT "???????? ");
31885 +#else
31886 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31887 + printk(KERN_CONT "???????? ???????? ");
31888 + else
31889 + printk(KERN_CONT "???????????????? ");
31890 +#endif
31891 + } else {
31892 +#ifdef CONFIG_X86_64
31893 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31894 + printk(KERN_CONT "%08x ", (unsigned int)c);
31895 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31896 + } else
31897 +#endif
31898 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31899 + }
31900 + }
31901 + printk("\n");
31902 +}
31903 +#endif
31904 +
31905 +/**
31906 + * probe_kernel_write(): safely attempt to write to a location
31907 + * @dst: address to write to
31908 + * @src: pointer to the data that shall be written
31909 + * @size: size of the data chunk
31910 + *
31911 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31912 + * happens, handle that and return -EFAULT.
31913 + */
31914 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31915 +{
31916 + long ret;
31917 + mm_segment_t old_fs = get_fs();
31918 +
31919 + set_fs(KERNEL_DS);
31920 + pagefault_disable();
31921 + pax_open_kernel();
31922 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31923 + pax_close_kernel();
31924 + pagefault_enable();
31925 + set_fs(old_fs);
31926 +
31927 + return ret ? -EFAULT : 0;
31928 +}
31929 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31930 index 207d9aef..69030980 100644
31931 --- a/arch/x86/mm/gup.c
31932 +++ b/arch/x86/mm/gup.c
31933 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31934 addr = start;
31935 len = (unsigned long) nr_pages << PAGE_SHIFT;
31936 end = start + len;
31937 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31938 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31939 (void __user *)start, len)))
31940 return 0;
31941
31942 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31943 goto slow_irqon;
31944 #endif
31945
31946 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31947 + (void __user *)start, len)))
31948 + return 0;
31949 +
31950 /*
31951 * XXX: batch / limit 'nr', to avoid large irq off latency
31952 * needs some instrumenting to determine the common sizes used by
31953 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31954 index 4500142..53a363c 100644
31955 --- a/arch/x86/mm/highmem_32.c
31956 +++ b/arch/x86/mm/highmem_32.c
31957 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31958 idx = type + KM_TYPE_NR*smp_processor_id();
31959 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31960 BUG_ON(!pte_none(*(kmap_pte-idx)));
31961 +
31962 + pax_open_kernel();
31963 set_pte(kmap_pte-idx, mk_pte(page, prot));
31964 + pax_close_kernel();
31965 +
31966 arch_flush_lazy_mmu_mode();
31967
31968 return (void *)vaddr;
31969 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31970 index 8c9f647..57cb402 100644
31971 --- a/arch/x86/mm/hugetlbpage.c
31972 +++ b/arch/x86/mm/hugetlbpage.c
31973 @@ -90,23 +90,24 @@ int pmd_huge_support(void)
31974 #ifdef CONFIG_HUGETLB_PAGE
31975 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31976 unsigned long addr, unsigned long len,
31977 - unsigned long pgoff, unsigned long flags)
31978 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31979 {
31980 struct hstate *h = hstate_file(file);
31981 struct vm_unmapped_area_info info;
31982 -
31983 +
31984 info.flags = 0;
31985 info.length = len;
31986 info.low_limit = current->mm->mmap_legacy_base;
31987 info.high_limit = TASK_SIZE;
31988 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31989 info.align_offset = 0;
31990 + info.threadstack_offset = offset;
31991 return vm_unmapped_area(&info);
31992 }
31993
31994 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31995 unsigned long addr0, unsigned long len,
31996 - unsigned long pgoff, unsigned long flags)
31997 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31998 {
31999 struct hstate *h = hstate_file(file);
32000 struct vm_unmapped_area_info info;
32001 @@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32002 info.high_limit = current->mm->mmap_base;
32003 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32004 info.align_offset = 0;
32005 + info.threadstack_offset = offset;
32006 addr = vm_unmapped_area(&info);
32007
32008 /*
32009 @@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32010 VM_BUG_ON(addr != -ENOMEM);
32011 info.flags = 0;
32012 info.low_limit = TASK_UNMAPPED_BASE;
32013 +
32014 +#ifdef CONFIG_PAX_RANDMMAP
32015 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32016 + info.low_limit += current->mm->delta_mmap;
32017 +#endif
32018 +
32019 info.high_limit = TASK_SIZE;
32020 addr = vm_unmapped_area(&info);
32021 }
32022 @@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32023 struct hstate *h = hstate_file(file);
32024 struct mm_struct *mm = current->mm;
32025 struct vm_area_struct *vma;
32026 + unsigned long pax_task_size = TASK_SIZE;
32027 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32028
32029 if (len & ~huge_page_mask(h))
32030 return -EINVAL;
32031 - if (len > TASK_SIZE)
32032 +
32033 +#ifdef CONFIG_PAX_SEGMEXEC
32034 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32035 + pax_task_size = SEGMEXEC_TASK_SIZE;
32036 +#endif
32037 +
32038 + pax_task_size -= PAGE_SIZE;
32039 +
32040 + if (len > pax_task_size)
32041 return -ENOMEM;
32042
32043 if (flags & MAP_FIXED) {
32044 @@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32045 return addr;
32046 }
32047
32048 +#ifdef CONFIG_PAX_RANDMMAP
32049 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32050 +#endif
32051 +
32052 if (addr) {
32053 addr = ALIGN(addr, huge_page_size(h));
32054 vma = find_vma(mm, addr);
32055 - if (TASK_SIZE - len >= addr &&
32056 - (!vma || addr + len <= vma->vm_start))
32057 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32058 return addr;
32059 }
32060 if (mm->get_unmapped_area == arch_get_unmapped_area)
32061 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32062 - pgoff, flags);
32063 + pgoff, flags, offset);
32064 else
32065 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32066 - pgoff, flags);
32067 + pgoff, flags, offset);
32068 }
32069 #endif /* CONFIG_HUGETLB_PAGE */
32070
32071 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32072 index f971306..e83e0f6 100644
32073 --- a/arch/x86/mm/init.c
32074 +++ b/arch/x86/mm/init.c
32075 @@ -4,6 +4,7 @@
32076 #include <linux/swap.h>
32077 #include <linux/memblock.h>
32078 #include <linux/bootmem.h> /* for max_low_pfn */
32079 +#include <linux/tboot.h>
32080
32081 #include <asm/cacheflush.h>
32082 #include <asm/e820.h>
32083 @@ -17,6 +18,8 @@
32084 #include <asm/proto.h>
32085 #include <asm/dma.h> /* for MAX_DMA_PFN */
32086 #include <asm/microcode.h>
32087 +#include <asm/desc.h>
32088 +#include <asm/bios_ebda.h>
32089
32090 #include "mm_internal.h"
32091
32092 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32093 early_ioremap_page_table_range_init();
32094 #endif
32095
32096 +#ifdef CONFIG_PAX_PER_CPU_PGD
32097 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32098 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32099 + KERNEL_PGD_PTRS);
32100 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32101 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32102 + KERNEL_PGD_PTRS);
32103 + load_cr3(get_cpu_pgd(0, kernel));
32104 +#else
32105 load_cr3(swapper_pg_dir);
32106 +#endif
32107 +
32108 __flush_tlb_all();
32109
32110 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32111 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32112 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32113 * mmio resources as well as potential bios/acpi data regions.
32114 */
32115 +
32116 +#ifdef CONFIG_GRKERNSEC_KMEM
32117 +static unsigned int ebda_start __read_only;
32118 +static unsigned int ebda_end __read_only;
32119 +#endif
32120 +
32121 int devmem_is_allowed(unsigned long pagenr)
32122 {
32123 - if (pagenr < 256)
32124 +#ifdef CONFIG_GRKERNSEC_KMEM
32125 + /* allow BDA */
32126 + if (!pagenr)
32127 return 1;
32128 + /* allow EBDA */
32129 + if (pagenr >= ebda_start && pagenr < ebda_end)
32130 + return 1;
32131 + /* if tboot is in use, allow access to its hardcoded serial log range */
32132 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32133 + return 1;
32134 +#else
32135 + if (!pagenr)
32136 + return 1;
32137 +#ifdef CONFIG_VM86
32138 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32139 + return 1;
32140 +#endif
32141 +#endif
32142 +
32143 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32144 + return 1;
32145 +#ifdef CONFIG_GRKERNSEC_KMEM
32146 + /* throw out everything else below 1MB */
32147 + if (pagenr <= 256)
32148 + return 0;
32149 +#endif
32150 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32151 return 0;
32152 if (!page_is_ram(pagenr))
32153 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32154 #endif
32155 }
32156
32157 +#ifdef CONFIG_GRKERNSEC_KMEM
32158 +static inline void gr_init_ebda(void)
32159 +{
32160 + unsigned int ebda_addr;
32161 + unsigned int ebda_size = 0;
32162 +
32163 + ebda_addr = get_bios_ebda();
32164 + if (ebda_addr) {
32165 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32166 + ebda_size <<= 10;
32167 + }
32168 + if (ebda_addr && ebda_size) {
32169 + ebda_start = ebda_addr >> PAGE_SHIFT;
32170 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32171 + } else {
32172 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32173 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32174 + }
32175 +}
32176 +#else
32177 +static inline void gr_init_ebda(void) { }
32178 +#endif
32179 +
32180 void free_initmem(void)
32181 {
32182 +#ifdef CONFIG_PAX_KERNEXEC
32183 +#ifdef CONFIG_X86_32
32184 + /* PaX: limit KERNEL_CS to actual size */
32185 + unsigned long addr, limit;
32186 + struct desc_struct d;
32187 + int cpu;
32188 +#else
32189 + pgd_t *pgd;
32190 + pud_t *pud;
32191 + pmd_t *pmd;
32192 + unsigned long addr, end;
32193 +#endif
32194 +#endif
32195 +
32196 + gr_init_ebda();
32197 +
32198 +#ifdef CONFIG_PAX_KERNEXEC
32199 +#ifdef CONFIG_X86_32
32200 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32201 + limit = (limit - 1UL) >> PAGE_SHIFT;
32202 +
32203 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32204 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32205 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32206 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32207 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32208 + }
32209 +
32210 + /* PaX: make KERNEL_CS read-only */
32211 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32212 + if (!paravirt_enabled())
32213 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32214 +/*
32215 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32216 + pgd = pgd_offset_k(addr);
32217 + pud = pud_offset(pgd, addr);
32218 + pmd = pmd_offset(pud, addr);
32219 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32220 + }
32221 +*/
32222 +#ifdef CONFIG_X86_PAE
32223 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32224 +/*
32225 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32226 + pgd = pgd_offset_k(addr);
32227 + pud = pud_offset(pgd, addr);
32228 + pmd = pmd_offset(pud, addr);
32229 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32230 + }
32231 +*/
32232 +#endif
32233 +
32234 +#ifdef CONFIG_MODULES
32235 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32236 +#endif
32237 +
32238 +#else
32239 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32240 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32241 + pgd = pgd_offset_k(addr);
32242 + pud = pud_offset(pgd, addr);
32243 + pmd = pmd_offset(pud, addr);
32244 + if (!pmd_present(*pmd))
32245 + continue;
32246 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32247 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32248 + else
32249 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32250 + }
32251 +
32252 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32253 + end = addr + KERNEL_IMAGE_SIZE;
32254 + for (; addr < end; addr += PMD_SIZE) {
32255 + pgd = pgd_offset_k(addr);
32256 + pud = pud_offset(pgd, addr);
32257 + pmd = pmd_offset(pud, addr);
32258 + if (!pmd_present(*pmd))
32259 + continue;
32260 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32261 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32262 + }
32263 +#endif
32264 +
32265 + flush_tlb_all();
32266 +#endif
32267 +
32268 free_init_pages("unused kernel",
32269 (unsigned long)(&__init_begin),
32270 (unsigned long)(&__init_end));
32271 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32272 index e395048..cd38278 100644
32273 --- a/arch/x86/mm/init_32.c
32274 +++ b/arch/x86/mm/init_32.c
32275 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32276 bool __read_mostly __vmalloc_start_set = false;
32277
32278 /*
32279 - * Creates a middle page table and puts a pointer to it in the
32280 - * given global directory entry. This only returns the gd entry
32281 - * in non-PAE compilation mode, since the middle layer is folded.
32282 - */
32283 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32284 -{
32285 - pud_t *pud;
32286 - pmd_t *pmd_table;
32287 -
32288 -#ifdef CONFIG_X86_PAE
32289 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32290 - pmd_table = (pmd_t *)alloc_low_page();
32291 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32292 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32293 - pud = pud_offset(pgd, 0);
32294 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32295 -
32296 - return pmd_table;
32297 - }
32298 -#endif
32299 - pud = pud_offset(pgd, 0);
32300 - pmd_table = pmd_offset(pud, 0);
32301 -
32302 - return pmd_table;
32303 -}
32304 -
32305 -/*
32306 * Create a page table and place a pointer to it in a middle page
32307 * directory entry:
32308 */
32309 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32310 pte_t *page_table = (pte_t *)alloc_low_page();
32311
32312 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32313 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32314 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32315 +#else
32316 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32317 +#endif
32318 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32319 }
32320
32321 return pte_offset_kernel(pmd, 0);
32322 }
32323
32324 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32325 +{
32326 + pud_t *pud;
32327 + pmd_t *pmd_table;
32328 +
32329 + pud = pud_offset(pgd, 0);
32330 + pmd_table = pmd_offset(pud, 0);
32331 +
32332 + return pmd_table;
32333 +}
32334 +
32335 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32336 {
32337 int pgd_idx = pgd_index(vaddr);
32338 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32339 int pgd_idx, pmd_idx;
32340 unsigned long vaddr;
32341 pgd_t *pgd;
32342 + pud_t *pud;
32343 pmd_t *pmd;
32344 pte_t *pte = NULL;
32345 unsigned long count = page_table_range_init_count(start, end);
32346 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32347 pgd = pgd_base + pgd_idx;
32348
32349 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32350 - pmd = one_md_table_init(pgd);
32351 - pmd = pmd + pmd_index(vaddr);
32352 + pud = pud_offset(pgd, vaddr);
32353 + pmd = pmd_offset(pud, vaddr);
32354 +
32355 +#ifdef CONFIG_X86_PAE
32356 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32357 +#endif
32358 +
32359 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32360 pmd++, pmd_idx++) {
32361 pte = page_table_kmap_check(one_page_table_init(pmd),
32362 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32363 }
32364 }
32365
32366 -static inline int is_kernel_text(unsigned long addr)
32367 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32368 {
32369 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32370 - return 1;
32371 - return 0;
32372 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32373 + end <= ktla_ktva((unsigned long)_stext)) &&
32374 + (start >= ktla_ktva((unsigned long)_einittext) ||
32375 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32376 +
32377 +#ifdef CONFIG_ACPI_SLEEP
32378 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32379 +#endif
32380 +
32381 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32382 + return 0;
32383 + return 1;
32384 }
32385
32386 /*
32387 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32388 unsigned long last_map_addr = end;
32389 unsigned long start_pfn, end_pfn;
32390 pgd_t *pgd_base = swapper_pg_dir;
32391 - int pgd_idx, pmd_idx, pte_ofs;
32392 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32393 unsigned long pfn;
32394 pgd_t *pgd;
32395 + pud_t *pud;
32396 pmd_t *pmd;
32397 pte_t *pte;
32398 unsigned pages_2m, pages_4k;
32399 @@ -291,8 +295,13 @@ repeat:
32400 pfn = start_pfn;
32401 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32402 pgd = pgd_base + pgd_idx;
32403 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32404 - pmd = one_md_table_init(pgd);
32405 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32406 + pud = pud_offset(pgd, 0);
32407 + pmd = pmd_offset(pud, 0);
32408 +
32409 +#ifdef CONFIG_X86_PAE
32410 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32411 +#endif
32412
32413 if (pfn >= end_pfn)
32414 continue;
32415 @@ -304,14 +313,13 @@ repeat:
32416 #endif
32417 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32418 pmd++, pmd_idx++) {
32419 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32420 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32421
32422 /*
32423 * Map with big pages if possible, otherwise
32424 * create normal page tables:
32425 */
32426 if (use_pse) {
32427 - unsigned int addr2;
32428 pgprot_t prot = PAGE_KERNEL_LARGE;
32429 /*
32430 * first pass will use the same initial
32431 @@ -322,11 +330,7 @@ repeat:
32432 _PAGE_PSE);
32433
32434 pfn &= PMD_MASK >> PAGE_SHIFT;
32435 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32436 - PAGE_OFFSET + PAGE_SIZE-1;
32437 -
32438 - if (is_kernel_text(addr) ||
32439 - is_kernel_text(addr2))
32440 + if (is_kernel_text(address, address + PMD_SIZE))
32441 prot = PAGE_KERNEL_LARGE_EXEC;
32442
32443 pages_2m++;
32444 @@ -343,7 +347,7 @@ repeat:
32445 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32446 pte += pte_ofs;
32447 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32448 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32449 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32450 pgprot_t prot = PAGE_KERNEL;
32451 /*
32452 * first pass will use the same initial
32453 @@ -351,7 +355,7 @@ repeat:
32454 */
32455 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32456
32457 - if (is_kernel_text(addr))
32458 + if (is_kernel_text(address, address + PAGE_SIZE))
32459 prot = PAGE_KERNEL_EXEC;
32460
32461 pages_4k++;
32462 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32463
32464 pud = pud_offset(pgd, va);
32465 pmd = pmd_offset(pud, va);
32466 - if (!pmd_present(*pmd))
32467 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32468 break;
32469
32470 /* should not be large page here */
32471 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32472
32473 static void __init pagetable_init(void)
32474 {
32475 - pgd_t *pgd_base = swapper_pg_dir;
32476 -
32477 - permanent_kmaps_init(pgd_base);
32478 + permanent_kmaps_init(swapper_pg_dir);
32479 }
32480
32481 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32482 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32483 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32484
32485 /* user-defined highmem size */
32486 @@ -787,10 +789,10 @@ void __init mem_init(void)
32487 ((unsigned long)&__init_end -
32488 (unsigned long)&__init_begin) >> 10,
32489
32490 - (unsigned long)&_etext, (unsigned long)&_edata,
32491 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32492 + (unsigned long)&_sdata, (unsigned long)&_edata,
32493 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32494
32495 - (unsigned long)&_text, (unsigned long)&_etext,
32496 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32497 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32498
32499 /*
32500 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32501 if (!kernel_set_to_readonly)
32502 return;
32503
32504 + start = ktla_ktva(start);
32505 pr_debug("Set kernel text: %lx - %lx for read write\n",
32506 start, start+size);
32507
32508 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32509 if (!kernel_set_to_readonly)
32510 return;
32511
32512 + start = ktla_ktva(start);
32513 pr_debug("Set kernel text: %lx - %lx for read only\n",
32514 start, start+size);
32515
32516 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32517 unsigned long start = PFN_ALIGN(_text);
32518 unsigned long size = PFN_ALIGN(_etext) - start;
32519
32520 + start = ktla_ktva(start);
32521 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32522 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32523 size >> 10);
32524 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32525 index f35c66c..84b95ef 100644
32526 --- a/arch/x86/mm/init_64.c
32527 +++ b/arch/x86/mm/init_64.c
32528 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32529 * around without checking the pgd every time.
32530 */
32531
32532 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32533 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32534 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32535
32536 int force_personality32;
32537 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32538
32539 for (address = start; address <= end; address += PGDIR_SIZE) {
32540 const pgd_t *pgd_ref = pgd_offset_k(address);
32541 +
32542 +#ifdef CONFIG_PAX_PER_CPU_PGD
32543 + unsigned long cpu;
32544 +#else
32545 struct page *page;
32546 +#endif
32547
32548 if (pgd_none(*pgd_ref))
32549 continue;
32550
32551 spin_lock(&pgd_lock);
32552 +
32553 +#ifdef CONFIG_PAX_PER_CPU_PGD
32554 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32555 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32556 +
32557 + if (pgd_none(*pgd))
32558 + set_pgd(pgd, *pgd_ref);
32559 + else
32560 + BUG_ON(pgd_page_vaddr(*pgd)
32561 + != pgd_page_vaddr(*pgd_ref));
32562 + pgd = pgd_offset_cpu(cpu, kernel, address);
32563 +#else
32564 list_for_each_entry(page, &pgd_list, lru) {
32565 pgd_t *pgd;
32566 spinlock_t *pgt_lock;
32567 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32568 /* the pgt_lock only for Xen */
32569 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32570 spin_lock(pgt_lock);
32571 +#endif
32572
32573 if (pgd_none(*pgd))
32574 set_pgd(pgd, *pgd_ref);
32575 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32576 BUG_ON(pgd_page_vaddr(*pgd)
32577 != pgd_page_vaddr(*pgd_ref));
32578
32579 +#ifndef CONFIG_PAX_PER_CPU_PGD
32580 spin_unlock(pgt_lock);
32581 +#endif
32582 +
32583 }
32584 spin_unlock(&pgd_lock);
32585 }
32586 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32587 {
32588 if (pgd_none(*pgd)) {
32589 pud_t *pud = (pud_t *)spp_getpage();
32590 - pgd_populate(&init_mm, pgd, pud);
32591 + pgd_populate_kernel(&init_mm, pgd, pud);
32592 if (pud != pud_offset(pgd, 0))
32593 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32594 pud, pud_offset(pgd, 0));
32595 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32596 {
32597 if (pud_none(*pud)) {
32598 pmd_t *pmd = (pmd_t *) spp_getpage();
32599 - pud_populate(&init_mm, pud, pmd);
32600 + pud_populate_kernel(&init_mm, pud, pmd);
32601 if (pmd != pmd_offset(pud, 0))
32602 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32603 pmd, pmd_offset(pud, 0));
32604 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32605 pmd = fill_pmd(pud, vaddr);
32606 pte = fill_pte(pmd, vaddr);
32607
32608 + pax_open_kernel();
32609 set_pte(pte, new_pte);
32610 + pax_close_kernel();
32611
32612 /*
32613 * It's enough to flush this one mapping.
32614 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32615 pgd = pgd_offset_k((unsigned long)__va(phys));
32616 if (pgd_none(*pgd)) {
32617 pud = (pud_t *) spp_getpage();
32618 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32619 - _PAGE_USER));
32620 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32621 }
32622 pud = pud_offset(pgd, (unsigned long)__va(phys));
32623 if (pud_none(*pud)) {
32624 pmd = (pmd_t *) spp_getpage();
32625 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32626 - _PAGE_USER));
32627 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32628 }
32629 pmd = pmd_offset(pud, phys);
32630 BUG_ON(!pmd_none(*pmd));
32631 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32632 prot);
32633
32634 spin_lock(&init_mm.page_table_lock);
32635 - pud_populate(&init_mm, pud, pmd);
32636 + pud_populate_kernel(&init_mm, pud, pmd);
32637 spin_unlock(&init_mm.page_table_lock);
32638 }
32639 __flush_tlb_all();
32640 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32641 page_size_mask);
32642
32643 spin_lock(&init_mm.page_table_lock);
32644 - pgd_populate(&init_mm, pgd, pud);
32645 + pgd_populate_kernel(&init_mm, pgd, pud);
32646 spin_unlock(&init_mm.page_table_lock);
32647 pgd_changed = true;
32648 }
32649 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32650 static struct vm_area_struct gate_vma = {
32651 .vm_start = VSYSCALL_START,
32652 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32653 - .vm_page_prot = PAGE_READONLY_EXEC,
32654 - .vm_flags = VM_READ | VM_EXEC
32655 + .vm_page_prot = PAGE_READONLY,
32656 + .vm_flags = VM_READ
32657 };
32658
32659 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32660 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32661
32662 const char *arch_vma_name(struct vm_area_struct *vma)
32663 {
32664 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32665 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32666 return "[vdso]";
32667 if (vma == &gate_vma)
32668 return "[vsyscall]";
32669 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32670 index 7b179b4..6bd17777 100644
32671 --- a/arch/x86/mm/iomap_32.c
32672 +++ b/arch/x86/mm/iomap_32.c
32673 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32674 type = kmap_atomic_idx_push();
32675 idx = type + KM_TYPE_NR * smp_processor_id();
32676 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32677 +
32678 + pax_open_kernel();
32679 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32680 + pax_close_kernel();
32681 +
32682 arch_flush_lazy_mmu_mode();
32683
32684 return (void *)vaddr;
32685 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32686 index 799580c..72f9fe0 100644
32687 --- a/arch/x86/mm/ioremap.c
32688 +++ b/arch/x86/mm/ioremap.c
32689 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32690 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32691 int is_ram = page_is_ram(pfn);
32692
32693 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32694 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32695 return NULL;
32696 WARN_ON_ONCE(is_ram);
32697 }
32698 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32699 *
32700 * Caller must ensure there is only one unmapping for the same pointer.
32701 */
32702 -void iounmap(volatile void __iomem *addr)
32703 +void iounmap(const volatile void __iomem *addr)
32704 {
32705 struct vm_struct *p, *o;
32706
32707 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32708
32709 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32710 if (page_is_ram(start >> PAGE_SHIFT))
32711 +#ifdef CONFIG_HIGHMEM
32712 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32713 +#endif
32714 return __va(phys);
32715
32716 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32717 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32718 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32719 {
32720 if (page_is_ram(phys >> PAGE_SHIFT))
32721 +#ifdef CONFIG_HIGHMEM
32722 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32723 +#endif
32724 return;
32725
32726 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32727 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32728 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32729
32730 static __initdata int after_paging_init;
32731 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32732 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32733
32734 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32735 {
32736 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32737 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32738
32739 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32740 - memset(bm_pte, 0, sizeof(bm_pte));
32741 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32742 + pmd_populate_user(&init_mm, pmd, bm_pte);
32743
32744 /*
32745 * The boot-ioremap range spans multiple pmds, for which
32746 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32747 index d87dd6d..bf3fa66 100644
32748 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32749 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32750 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32751 * memory (e.g. tracked pages)? For now, we need this to avoid
32752 * invoking kmemcheck for PnP BIOS calls.
32753 */
32754 - if (regs->flags & X86_VM_MASK)
32755 + if (v8086_mode(regs))
32756 return false;
32757 - if (regs->cs != __KERNEL_CS)
32758 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32759 return false;
32760
32761 pte = kmemcheck_pte_lookup(address);
32762 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32763 index 25e7e13..1964579 100644
32764 --- a/arch/x86/mm/mmap.c
32765 +++ b/arch/x86/mm/mmap.c
32766 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32767 * Leave an at least ~128 MB hole with possible stack randomization.
32768 */
32769 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32770 -#define MAX_GAP (TASK_SIZE/6*5)
32771 +#define MAX_GAP (pax_task_size/6*5)
32772
32773 static int mmap_is_legacy(void)
32774 {
32775 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32776 return rnd << PAGE_SHIFT;
32777 }
32778
32779 -static unsigned long mmap_base(void)
32780 +static unsigned long mmap_base(struct mm_struct *mm)
32781 {
32782 unsigned long gap = rlimit(RLIMIT_STACK);
32783 + unsigned long pax_task_size = TASK_SIZE;
32784 +
32785 +#ifdef CONFIG_PAX_SEGMEXEC
32786 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32787 + pax_task_size = SEGMEXEC_TASK_SIZE;
32788 +#endif
32789
32790 if (gap < MIN_GAP)
32791 gap = MIN_GAP;
32792 else if (gap > MAX_GAP)
32793 gap = MAX_GAP;
32794
32795 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32796 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32797 }
32798
32799 /*
32800 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32801 * does, but not when emulating X86_32
32802 */
32803 -static unsigned long mmap_legacy_base(void)
32804 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32805 {
32806 - if (mmap_is_ia32())
32807 + if (mmap_is_ia32()) {
32808 +
32809 +#ifdef CONFIG_PAX_SEGMEXEC
32810 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32811 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32812 + else
32813 +#endif
32814 +
32815 return TASK_UNMAPPED_BASE;
32816 - else
32817 + } else
32818 return TASK_UNMAPPED_BASE + mmap_rnd();
32819 }
32820
32821 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32822 */
32823 void arch_pick_mmap_layout(struct mm_struct *mm)
32824 {
32825 - mm->mmap_legacy_base = mmap_legacy_base();
32826 - mm->mmap_base = mmap_base();
32827 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32828 + mm->mmap_base = mmap_base(mm);
32829 +
32830 +#ifdef CONFIG_PAX_RANDMMAP
32831 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32832 + mm->mmap_legacy_base += mm->delta_mmap;
32833 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32834 + }
32835 +#endif
32836
32837 if (mmap_is_legacy()) {
32838 mm->mmap_base = mm->mmap_legacy_base;
32839 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32840 index 0057a7a..95c7edd 100644
32841 --- a/arch/x86/mm/mmio-mod.c
32842 +++ b/arch/x86/mm/mmio-mod.c
32843 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32844 break;
32845 default:
32846 {
32847 - unsigned char *ip = (unsigned char *)instptr;
32848 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32849 my_trace->opcode = MMIO_UNKNOWN_OP;
32850 my_trace->width = 0;
32851 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32852 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32853 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32854 void __iomem *addr)
32855 {
32856 - static atomic_t next_id;
32857 + static atomic_unchecked_t next_id;
32858 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32859 /* These are page-unaligned. */
32860 struct mmiotrace_map map = {
32861 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32862 .private = trace
32863 },
32864 .phys = offset,
32865 - .id = atomic_inc_return(&next_id)
32866 + .id = atomic_inc_return_unchecked(&next_id)
32867 };
32868 map.map_id = trace->id;
32869
32870 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32871 ioremap_trace_core(offset, size, addr);
32872 }
32873
32874 -static void iounmap_trace_core(volatile void __iomem *addr)
32875 +static void iounmap_trace_core(const volatile void __iomem *addr)
32876 {
32877 struct mmiotrace_map map = {
32878 .phys = 0,
32879 @@ -328,7 +328,7 @@ not_enabled:
32880 }
32881 }
32882
32883 -void mmiotrace_iounmap(volatile void __iomem *addr)
32884 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32885 {
32886 might_sleep();
32887 if (is_enabled()) /* recheck and proper locking in *_core() */
32888 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32889 index 27aa0455..0eb1406 100644
32890 --- a/arch/x86/mm/numa.c
32891 +++ b/arch/x86/mm/numa.c
32892 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32893 return true;
32894 }
32895
32896 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32897 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32898 {
32899 unsigned long uninitialized_var(pfn_align);
32900 int i, nid;
32901 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32902 index 461bc82..4e091a3 100644
32903 --- a/arch/x86/mm/pageattr-test.c
32904 +++ b/arch/x86/mm/pageattr-test.c
32905 @@ -35,7 +35,7 @@ enum {
32906
32907 static int pte_testbit(pte_t pte)
32908 {
32909 - return pte_flags(pte) & _PAGE_UNUSED1;
32910 + return pte_flags(pte) & _PAGE_CPA_TEST;
32911 }
32912
32913 struct split_state {
32914 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32915 index a348868..3c64310 100644
32916 --- a/arch/x86/mm/pageattr.c
32917 +++ b/arch/x86/mm/pageattr.c
32918 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32919 */
32920 #ifdef CONFIG_PCI_BIOS
32921 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32922 - pgprot_val(forbidden) |= _PAGE_NX;
32923 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32924 #endif
32925
32926 /*
32927 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32928 * Does not cover __inittext since that is gone later on. On
32929 * 64bit we do not enforce !NX on the low mapping
32930 */
32931 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32932 - pgprot_val(forbidden) |= _PAGE_NX;
32933 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32934 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32935
32936 +#ifdef CONFIG_DEBUG_RODATA
32937 /*
32938 * The .rodata section needs to be read-only. Using the pfn
32939 * catches all aliases.
32940 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32941 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32942 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32943 pgprot_val(forbidden) |= _PAGE_RW;
32944 +#endif
32945
32946 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32947 /*
32948 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32949 }
32950 #endif
32951
32952 +#ifdef CONFIG_PAX_KERNEXEC
32953 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32954 + pgprot_val(forbidden) |= _PAGE_RW;
32955 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32956 + }
32957 +#endif
32958 +
32959 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32960
32961 return prot;
32962 @@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32963 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32964 {
32965 /* change init_mm */
32966 + pax_open_kernel();
32967 set_pte_atomic(kpte, pte);
32968 +
32969 #ifdef CONFIG_X86_32
32970 if (!SHARED_KERNEL_PMD) {
32971 +
32972 +#ifdef CONFIG_PAX_PER_CPU_PGD
32973 + unsigned long cpu;
32974 +#else
32975 struct page *page;
32976 +#endif
32977
32978 +#ifdef CONFIG_PAX_PER_CPU_PGD
32979 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32980 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32981 +#else
32982 list_for_each_entry(page, &pgd_list, lru) {
32983 - pgd_t *pgd;
32984 + pgd_t *pgd = (pgd_t *)page_address(page);
32985 +#endif
32986 +
32987 pud_t *pud;
32988 pmd_t *pmd;
32989
32990 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
32991 + pgd += pgd_index(address);
32992 pud = pud_offset(pgd, address);
32993 pmd = pmd_offset(pud, address);
32994 set_pte_atomic((pte_t *)pmd, pte);
32995 }
32996 }
32997 #endif
32998 + pax_close_kernel();
32999 }
33000
33001 static int
33002 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33003 index 6574388..87e9bef 100644
33004 --- a/arch/x86/mm/pat.c
33005 +++ b/arch/x86/mm/pat.c
33006 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33007
33008 if (!entry) {
33009 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33010 - current->comm, current->pid, start, end - 1);
33011 + current->comm, task_pid_nr(current), start, end - 1);
33012 return -EINVAL;
33013 }
33014
33015 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33016
33017 while (cursor < to) {
33018 if (!devmem_is_allowed(pfn)) {
33019 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33020 - current->comm, from, to - 1);
33021 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33022 + current->comm, from, to - 1, cursor);
33023 return 0;
33024 }
33025 cursor += PAGE_SIZE;
33026 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33027 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33028 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33029 "for [mem %#010Lx-%#010Lx]\n",
33030 - current->comm, current->pid,
33031 + current->comm, task_pid_nr(current),
33032 cattr_name(flags),
33033 base, (unsigned long long)(base + size-1));
33034 return -EINVAL;
33035 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33036 flags = lookup_memtype(paddr);
33037 if (want_flags != flags) {
33038 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33039 - current->comm, current->pid,
33040 + current->comm, task_pid_nr(current),
33041 cattr_name(want_flags),
33042 (unsigned long long)paddr,
33043 (unsigned long long)(paddr + size - 1),
33044 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33045 free_memtype(paddr, paddr + size);
33046 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33047 " for [mem %#010Lx-%#010Lx], got %s\n",
33048 - current->comm, current->pid,
33049 + current->comm, task_pid_nr(current),
33050 cattr_name(want_flags),
33051 (unsigned long long)paddr,
33052 (unsigned long long)(paddr + size - 1),
33053 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33054 index 415f6c4..d319983 100644
33055 --- a/arch/x86/mm/pat_rbtree.c
33056 +++ b/arch/x86/mm/pat_rbtree.c
33057 @@ -160,7 +160,7 @@ success:
33058
33059 failure:
33060 printk(KERN_INFO "%s:%d conflicting memory types "
33061 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33062 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33063 end, cattr_name(found_type), cattr_name(match->type));
33064 return -EBUSY;
33065 }
33066 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33067 index 9f0614d..92ae64a 100644
33068 --- a/arch/x86/mm/pf_in.c
33069 +++ b/arch/x86/mm/pf_in.c
33070 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33071 int i;
33072 enum reason_type rv = OTHERS;
33073
33074 - p = (unsigned char *)ins_addr;
33075 + p = (unsigned char *)ktla_ktva(ins_addr);
33076 p += skip_prefix(p, &prf);
33077 p += get_opcode(p, &opcode);
33078
33079 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33080 struct prefix_bits prf;
33081 int i;
33082
33083 - p = (unsigned char *)ins_addr;
33084 + p = (unsigned char *)ktla_ktva(ins_addr);
33085 p += skip_prefix(p, &prf);
33086 p += get_opcode(p, &opcode);
33087
33088 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33089 struct prefix_bits prf;
33090 int i;
33091
33092 - p = (unsigned char *)ins_addr;
33093 + p = (unsigned char *)ktla_ktva(ins_addr);
33094 p += skip_prefix(p, &prf);
33095 p += get_opcode(p, &opcode);
33096
33097 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33098 struct prefix_bits prf;
33099 int i;
33100
33101 - p = (unsigned char *)ins_addr;
33102 + p = (unsigned char *)ktla_ktva(ins_addr);
33103 p += skip_prefix(p, &prf);
33104 p += get_opcode(p, &opcode);
33105 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33106 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33107 struct prefix_bits prf;
33108 int i;
33109
33110 - p = (unsigned char *)ins_addr;
33111 + p = (unsigned char *)ktla_ktva(ins_addr);
33112 p += skip_prefix(p, &prf);
33113 p += get_opcode(p, &opcode);
33114 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33115 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33116 index c96314a..433b127 100644
33117 --- a/arch/x86/mm/pgtable.c
33118 +++ b/arch/x86/mm/pgtable.c
33119 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33120 list_del(&page->lru);
33121 }
33122
33123 -#define UNSHARED_PTRS_PER_PGD \
33124 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33125 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33126 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33127
33128 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33129 +{
33130 + unsigned int count = USER_PGD_PTRS;
33131
33132 + if (!pax_user_shadow_base)
33133 + return;
33134 +
33135 + while (count--)
33136 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33137 +}
33138 +#endif
33139 +
33140 +#ifdef CONFIG_PAX_PER_CPU_PGD
33141 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33142 +{
33143 + unsigned int count = USER_PGD_PTRS;
33144 +
33145 + while (count--) {
33146 + pgd_t pgd;
33147 +
33148 +#ifdef CONFIG_X86_64
33149 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33150 +#else
33151 + pgd = *src++;
33152 +#endif
33153 +
33154 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33155 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33156 +#endif
33157 +
33158 + *dst++ = pgd;
33159 + }
33160 +
33161 +}
33162 +#endif
33163 +
33164 +#ifdef CONFIG_X86_64
33165 +#define pxd_t pud_t
33166 +#define pyd_t pgd_t
33167 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33168 +#define pgtable_pxd_page_ctor(page) true
33169 +#define pgtable_pxd_page_dtor(page)
33170 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33171 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33172 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33173 +#define PYD_SIZE PGDIR_SIZE
33174 +#else
33175 +#define pxd_t pmd_t
33176 +#define pyd_t pud_t
33177 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33178 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33179 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33180 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33181 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33182 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33183 +#define PYD_SIZE PUD_SIZE
33184 +#endif
33185 +
33186 +#ifdef CONFIG_PAX_PER_CPU_PGD
33187 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33188 +static inline void pgd_dtor(pgd_t *pgd) {}
33189 +#else
33190 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33191 {
33192 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33193 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33194 pgd_list_del(pgd);
33195 spin_unlock(&pgd_lock);
33196 }
33197 +#endif
33198
33199 /*
33200 * List of all pgd's needed for non-PAE so it can invalidate entries
33201 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33202 * -- nyc
33203 */
33204
33205 -#ifdef CONFIG_X86_PAE
33206 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33207 /*
33208 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33209 * updating the top-level pagetable entries to guarantee the
33210 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33211 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33212 * and initialize the kernel pmds here.
33213 */
33214 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33215 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33216
33217 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33218 {
33219 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33220 */
33221 flush_tlb_mm(mm);
33222 }
33223 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33224 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33225 #else /* !CONFIG_X86_PAE */
33226
33227 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33228 -#define PREALLOCATED_PMDS 0
33229 +#define PREALLOCATED_PXDS 0
33230
33231 #endif /* CONFIG_X86_PAE */
33232
33233 -static void free_pmds(pmd_t *pmds[])
33234 +static void free_pxds(pxd_t *pxds[])
33235 {
33236 int i;
33237
33238 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33239 - if (pmds[i]) {
33240 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33241 - free_page((unsigned long)pmds[i]);
33242 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33243 + if (pxds[i]) {
33244 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33245 + free_page((unsigned long)pxds[i]);
33246 }
33247 }
33248
33249 -static int preallocate_pmds(pmd_t *pmds[])
33250 +static int preallocate_pxds(pxd_t *pxds[])
33251 {
33252 int i;
33253 bool failed = false;
33254
33255 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33256 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33257 - if (!pmd)
33258 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33259 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33260 + if (!pxd)
33261 failed = true;
33262 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33263 - free_page((unsigned long)pmd);
33264 - pmd = NULL;
33265 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33266 + free_page((unsigned long)pxd);
33267 + pxd = NULL;
33268 failed = true;
33269 }
33270 - pmds[i] = pmd;
33271 + pxds[i] = pxd;
33272 }
33273
33274 if (failed) {
33275 - free_pmds(pmds);
33276 + free_pxds(pxds);
33277 return -ENOMEM;
33278 }
33279
33280 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33281 * preallocate which never got a corresponding vma will need to be
33282 * freed manually.
33283 */
33284 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33285 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33286 {
33287 int i;
33288
33289 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33290 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33291 pgd_t pgd = pgdp[i];
33292
33293 if (pgd_val(pgd) != 0) {
33294 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33295 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33296
33297 - pgdp[i] = native_make_pgd(0);
33298 + set_pgd(pgdp + i, native_make_pgd(0));
33299
33300 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33301 - pmd_free(mm, pmd);
33302 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33303 + pxd_free(mm, pxd);
33304 }
33305 }
33306 }
33307
33308 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33309 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33310 {
33311 - pud_t *pud;
33312 + pyd_t *pyd;
33313 int i;
33314
33315 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33316 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33317 return;
33318
33319 - pud = pud_offset(pgd, 0);
33320 -
33321 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33322 - pmd_t *pmd = pmds[i];
33323 +#ifdef CONFIG_X86_64
33324 + pyd = pyd_offset(mm, 0L);
33325 +#else
33326 + pyd = pyd_offset(pgd, 0L);
33327 +#endif
33328
33329 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33330 + pxd_t *pxd = pxds[i];
33331 if (i >= KERNEL_PGD_BOUNDARY)
33332 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33333 - sizeof(pmd_t) * PTRS_PER_PMD);
33334 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33335 + sizeof(pxd_t) * PTRS_PER_PMD);
33336
33337 - pud_populate(mm, pud, pmd);
33338 + pyd_populate(mm, pyd, pxd);
33339 }
33340 }
33341
33342 pgd_t *pgd_alloc(struct mm_struct *mm)
33343 {
33344 pgd_t *pgd;
33345 - pmd_t *pmds[PREALLOCATED_PMDS];
33346 + pxd_t *pxds[PREALLOCATED_PXDS];
33347
33348 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33349
33350 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33351
33352 mm->pgd = pgd;
33353
33354 - if (preallocate_pmds(pmds) != 0)
33355 + if (preallocate_pxds(pxds) != 0)
33356 goto out_free_pgd;
33357
33358 if (paravirt_pgd_alloc(mm) != 0)
33359 - goto out_free_pmds;
33360 + goto out_free_pxds;
33361
33362 /*
33363 * Make sure that pre-populating the pmds is atomic with
33364 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33365 spin_lock(&pgd_lock);
33366
33367 pgd_ctor(mm, pgd);
33368 - pgd_prepopulate_pmd(mm, pgd, pmds);
33369 + pgd_prepopulate_pxd(mm, pgd, pxds);
33370
33371 spin_unlock(&pgd_lock);
33372
33373 return pgd;
33374
33375 -out_free_pmds:
33376 - free_pmds(pmds);
33377 +out_free_pxds:
33378 + free_pxds(pxds);
33379 out_free_pgd:
33380 free_page((unsigned long)pgd);
33381 out:
33382 @@ -313,7 +380,7 @@ out:
33383
33384 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33385 {
33386 - pgd_mop_up_pmds(mm, pgd);
33387 + pgd_mop_up_pxds(mm, pgd);
33388 pgd_dtor(pgd);
33389 paravirt_pgd_free(mm, pgd);
33390 free_page((unsigned long)pgd);
33391 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33392 index a69bcb8..19068ab 100644
33393 --- a/arch/x86/mm/pgtable_32.c
33394 +++ b/arch/x86/mm/pgtable_32.c
33395 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33396 return;
33397 }
33398 pte = pte_offset_kernel(pmd, vaddr);
33399 +
33400 + pax_open_kernel();
33401 if (pte_val(pteval))
33402 set_pte_at(&init_mm, vaddr, pte, pteval);
33403 else
33404 pte_clear(&init_mm, vaddr, pte);
33405 + pax_close_kernel();
33406
33407 /*
33408 * It's enough to flush this one mapping.
33409 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33410 index e666cbb..61788c45 100644
33411 --- a/arch/x86/mm/physaddr.c
33412 +++ b/arch/x86/mm/physaddr.c
33413 @@ -10,7 +10,7 @@
33414 #ifdef CONFIG_X86_64
33415
33416 #ifdef CONFIG_DEBUG_VIRTUAL
33417 -unsigned long __phys_addr(unsigned long x)
33418 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33419 {
33420 unsigned long y = x - __START_KERNEL_map;
33421
33422 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33423 #else
33424
33425 #ifdef CONFIG_DEBUG_VIRTUAL
33426 -unsigned long __phys_addr(unsigned long x)
33427 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33428 {
33429 unsigned long phys_addr = x - PAGE_OFFSET;
33430 /* VMALLOC_* aren't constants */
33431 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33432 index 90555bf..f5f1828 100644
33433 --- a/arch/x86/mm/setup_nx.c
33434 +++ b/arch/x86/mm/setup_nx.c
33435 @@ -5,8 +5,10 @@
33436 #include <asm/pgtable.h>
33437 #include <asm/proto.h>
33438
33439 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33440 static int disable_nx;
33441
33442 +#ifndef CONFIG_PAX_PAGEEXEC
33443 /*
33444 * noexec = on|off
33445 *
33446 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33447 return 0;
33448 }
33449 early_param("noexec", noexec_setup);
33450 +#endif
33451 +
33452 +#endif
33453
33454 void x86_configure_nx(void)
33455 {
33456 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33457 if (cpu_has_nx && !disable_nx)
33458 __supported_pte_mask |= _PAGE_NX;
33459 else
33460 +#endif
33461 __supported_pte_mask &= ~_PAGE_NX;
33462 }
33463
33464 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33465 index dd8dda1..9e9b0f6 100644
33466 --- a/arch/x86/mm/tlb.c
33467 +++ b/arch/x86/mm/tlb.c
33468 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33469 BUG();
33470 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33471 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33472 +
33473 +#ifndef CONFIG_PAX_PER_CPU_PGD
33474 load_cr3(swapper_pg_dir);
33475 +#endif
33476 +
33477 }
33478 }
33479 EXPORT_SYMBOL_GPL(leave_mm);
33480 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33481 new file mode 100644
33482 index 0000000..dace51c
33483 --- /dev/null
33484 +++ b/arch/x86/mm/uderef_64.c
33485 @@ -0,0 +1,37 @@
33486 +#include <linux/mm.h>
33487 +#include <asm/pgtable.h>
33488 +#include <asm/uaccess.h>
33489 +
33490 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33491 +/* PaX: due to the special call convention these functions must
33492 + * - remain leaf functions under all configurations,
33493 + * - never be called directly, only dereferenced from the wrappers.
33494 + */
33495 +void __pax_open_userland(void)
33496 +{
33497 + unsigned int cpu;
33498 +
33499 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33500 + return;
33501 +
33502 + cpu = raw_get_cpu();
33503 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33504 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33505 + raw_put_cpu_no_resched();
33506 +}
33507 +EXPORT_SYMBOL(__pax_open_userland);
33508 +
33509 +void __pax_close_userland(void)
33510 +{
33511 + unsigned int cpu;
33512 +
33513 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33514 + return;
33515 +
33516 + cpu = raw_get_cpu();
33517 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33518 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33519 + raw_put_cpu_no_resched();
33520 +}
33521 +EXPORT_SYMBOL(__pax_close_userland);
33522 +#endif
33523 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33524 index 0149575..f746de8 100644
33525 --- a/arch/x86/net/bpf_jit.S
33526 +++ b/arch/x86/net/bpf_jit.S
33527 @@ -9,6 +9,7 @@
33528 */
33529 #include <linux/linkage.h>
33530 #include <asm/dwarf2.h>
33531 +#include <asm/alternative-asm.h>
33532
33533 /*
33534 * Calling convention :
33535 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33536 jle bpf_slow_path_word
33537 mov (SKBDATA,%rsi),%eax
33538 bswap %eax /* ntohl() */
33539 + pax_force_retaddr
33540 ret
33541
33542 sk_load_half:
33543 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33544 jle bpf_slow_path_half
33545 movzwl (SKBDATA,%rsi),%eax
33546 rol $8,%ax # ntohs()
33547 + pax_force_retaddr
33548 ret
33549
33550 sk_load_byte:
33551 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33552 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33553 jle bpf_slow_path_byte
33554 movzbl (SKBDATA,%rsi),%eax
33555 + pax_force_retaddr
33556 ret
33557
33558 /**
33559 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33560 movzbl (SKBDATA,%rsi),%ebx
33561 and $15,%bl
33562 shl $2,%bl
33563 + pax_force_retaddr
33564 ret
33565
33566 /* rsi contains offset and can be scratched */
33567 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33568 js bpf_error
33569 mov -12(%rbp),%eax
33570 bswap %eax
33571 + pax_force_retaddr
33572 ret
33573
33574 bpf_slow_path_half:
33575 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33576 mov -12(%rbp),%ax
33577 rol $8,%ax
33578 movzwl %ax,%eax
33579 + pax_force_retaddr
33580 ret
33581
33582 bpf_slow_path_byte:
33583 bpf_slow_path_common(1)
33584 js bpf_error
33585 movzbl -12(%rbp),%eax
33586 + pax_force_retaddr
33587 ret
33588
33589 bpf_slow_path_byte_msh:
33590 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33591 and $15,%al
33592 shl $2,%al
33593 xchg %eax,%ebx
33594 + pax_force_retaddr
33595 ret
33596
33597 #define sk_negative_common(SIZE) \
33598 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33599 sk_negative_common(4)
33600 mov (%rax), %eax
33601 bswap %eax
33602 + pax_force_retaddr
33603 ret
33604
33605 bpf_slow_path_half_neg:
33606 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33607 mov (%rax),%ax
33608 rol $8,%ax
33609 movzwl %ax,%eax
33610 + pax_force_retaddr
33611 ret
33612
33613 bpf_slow_path_byte_neg:
33614 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33615 .globl sk_load_byte_negative_offset
33616 sk_negative_common(1)
33617 movzbl (%rax), %eax
33618 + pax_force_retaddr
33619 ret
33620
33621 bpf_slow_path_byte_msh_neg:
33622 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33623 and $15,%al
33624 shl $2,%al
33625 xchg %eax,%ebx
33626 + pax_force_retaddr
33627 ret
33628
33629 bpf_error:
33630 @@ -197,4 +210,5 @@ bpf_error:
33631 xor %eax,%eax
33632 mov -8(%rbp),%rbx
33633 leaveq
33634 + pax_force_retaddr
33635 ret
33636 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33637 index 4ed75dd..3cf24f0b 100644
33638 --- a/arch/x86/net/bpf_jit_comp.c
33639 +++ b/arch/x86/net/bpf_jit_comp.c
33640 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33641 return ptr + len;
33642 }
33643
33644 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33645 +#define MAX_INSTR_CODE_SIZE 96
33646 +#else
33647 +#define MAX_INSTR_CODE_SIZE 64
33648 +#endif
33649 +
33650 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33651
33652 #define EMIT1(b1) EMIT(b1, 1)
33653 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33654 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33655 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33656 +
33657 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33658 +/* original constant will appear in ecx */
33659 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33660 +do { \
33661 + /* mov ecx, randkey */ \
33662 + EMIT1(0xb9); \
33663 + EMIT(_key, 4); \
33664 + /* xor ecx, randkey ^ off */ \
33665 + EMIT2(0x81, 0xf1); \
33666 + EMIT((_key) ^ (_off), 4); \
33667 +} while (0)
33668 +
33669 +#define EMIT1_off32(b1, _off) \
33670 +do { \
33671 + switch (b1) { \
33672 + case 0x05: /* add eax, imm32 */ \
33673 + case 0x2d: /* sub eax, imm32 */ \
33674 + case 0x25: /* and eax, imm32 */ \
33675 + case 0x0d: /* or eax, imm32 */ \
33676 + case 0xb8: /* mov eax, imm32 */ \
33677 + case 0x35: /* xor eax, imm32 */ \
33678 + case 0x3d: /* cmp eax, imm32 */ \
33679 + case 0xa9: /* test eax, imm32 */ \
33680 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33681 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33682 + break; \
33683 + case 0xbb: /* mov ebx, imm32 */ \
33684 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33685 + /* mov ebx, ecx */ \
33686 + EMIT2(0x89, 0xcb); \
33687 + break; \
33688 + case 0xbe: /* mov esi, imm32 */ \
33689 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33690 + /* mov esi, ecx */ \
33691 + EMIT2(0x89, 0xce); \
33692 + break; \
33693 + case 0xe8: /* call rel imm32, always to known funcs */ \
33694 + EMIT1(b1); \
33695 + EMIT(_off, 4); \
33696 + break; \
33697 + case 0xe9: /* jmp rel imm32 */ \
33698 + EMIT1(b1); \
33699 + EMIT(_off, 4); \
33700 + /* prevent fall-through, we're not called if off = 0 */ \
33701 + EMIT(0xcccccccc, 4); \
33702 + EMIT(0xcccccccc, 4); \
33703 + break; \
33704 + default: \
33705 + BUILD_BUG(); \
33706 + } \
33707 +} while (0)
33708 +
33709 +#define EMIT2_off32(b1, b2, _off) \
33710 +do { \
33711 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33712 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33713 + EMIT(randkey, 4); \
33714 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33715 + EMIT((_off) - randkey, 4); \
33716 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33717 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33718 + /* imul eax, ecx */ \
33719 + EMIT3(0x0f, 0xaf, 0xc1); \
33720 + } else { \
33721 + BUILD_BUG(); \
33722 + } \
33723 +} while (0)
33724 +#else
33725 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33726 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33727 +#endif
33728
33729 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33730 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33731 @@ -91,6 +168,24 @@ do { \
33732 #define X86_JBE 0x76
33733 #define X86_JA 0x77
33734
33735 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33736 +#define APPEND_FLOW_VERIFY() \
33737 +do { \
33738 + /* mov ecx, randkey */ \
33739 + EMIT1(0xb9); \
33740 + EMIT(randkey, 4); \
33741 + /* cmp ecx, randkey */ \
33742 + EMIT2(0x81, 0xf9); \
33743 + EMIT(randkey, 4); \
33744 + /* jz after 8 int 3s */ \
33745 + EMIT2(0x74, 0x08); \
33746 + EMIT(0xcccccccc, 4); \
33747 + EMIT(0xcccccccc, 4); \
33748 +} while (0)
33749 +#else
33750 +#define APPEND_FLOW_VERIFY() do { } while (0)
33751 +#endif
33752 +
33753 #define EMIT_COND_JMP(op, offset) \
33754 do { \
33755 if (is_near(offset)) \
33756 @@ -98,6 +193,7 @@ do { \
33757 else { \
33758 EMIT2(0x0f, op + 0x10); \
33759 EMIT(offset, 4); /* jxx .+off32 */ \
33760 + APPEND_FLOW_VERIFY(); \
33761 } \
33762 } while (0)
33763
33764 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33765 return -1;
33766 }
33767
33768 -struct bpf_binary_header {
33769 - unsigned int pages;
33770 - /* Note : for security reasons, bpf code will follow a randomly
33771 - * sized amount of int3 instructions
33772 - */
33773 - u8 image[];
33774 -};
33775 -
33776 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33777 +/* Note : for security reasons, bpf code will follow a randomly
33778 + * sized amount of int3 instructions
33779 + */
33780 +static u8 *bpf_alloc_binary(unsigned int proglen,
33781 u8 **image_ptr)
33782 {
33783 unsigned int sz, hole;
33784 - struct bpf_binary_header *header;
33785 + u8 *header;
33786
33787 /* Most of BPF filters are really small,
33788 * but if some of them fill a page, allow at least
33789 * 128 extra bytes to insert a random section of int3
33790 */
33791 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33792 - header = module_alloc(sz);
33793 + sz = round_up(proglen + 128, PAGE_SIZE);
33794 + header = module_alloc_exec(sz);
33795 if (!header)
33796 return NULL;
33797
33798 + pax_open_kernel();
33799 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33800 + pax_close_kernel();
33801
33802 - header->pages = sz / PAGE_SIZE;
33803 - hole = sz - (proglen + sizeof(*header));
33804 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33805
33806 /* insert a random number of int3 instructions before BPF code */
33807 - *image_ptr = &header->image[prandom_u32() % hole];
33808 + *image_ptr = &header[prandom_u32() % hole];
33809 return header;
33810 }
33811
33812 void bpf_jit_compile(struct sk_filter *fp)
33813 {
33814 - u8 temp[64];
33815 + u8 temp[MAX_INSTR_CODE_SIZE];
33816 u8 *prog;
33817 unsigned int proglen, oldproglen = 0;
33818 int ilen, i;
33819 int t_offset, f_offset;
33820 u8 t_op, f_op, seen = 0, pass;
33821 u8 *image = NULL;
33822 - struct bpf_binary_header *header = NULL;
33823 + u8 *header = NULL;
33824 u8 *func;
33825 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33826 unsigned int cleanup_addr; /* epilogue code offset */
33827 unsigned int *addrs;
33828 const struct sock_filter *filter = fp->insns;
33829 int flen = fp->len;
33830 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33831 + unsigned int randkey;
33832 +#endif
33833
33834 if (!bpf_jit_enable)
33835 return;
33836 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33837 return;
33838
33839 /* Before first pass, make a rough estimation of addrs[]
33840 - * each bpf instruction is translated to less than 64 bytes
33841 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33842 */
33843 for (proglen = 0, i = 0; i < flen; i++) {
33844 - proglen += 64;
33845 + proglen += MAX_INSTR_CODE_SIZE;
33846 addrs[i] = proglen;
33847 }
33848 cleanup_addr = proglen; /* epilogue address */
33849 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33850 for (i = 0; i < flen; i++) {
33851 unsigned int K = filter[i].k;
33852
33853 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33854 + randkey = prandom_u32();
33855 +#endif
33856 +
33857 switch (filter[i].code) {
33858 case BPF_S_ALU_ADD_X: /* A += X; */
33859 seen |= SEEN_XREG;
33860 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33861 case BPF_S_ALU_MUL_K: /* A *= K */
33862 if (is_imm8(K))
33863 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33864 - else {
33865 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33866 - EMIT(K, 4);
33867 - }
33868 + else
33869 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33870 break;
33871 case BPF_S_ALU_DIV_X: /* A /= X; */
33872 seen |= SEEN_XREG;
33873 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33874 break;
33875 }
33876 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33877 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33878 + DILUTE_CONST_SEQUENCE(K, randkey);
33879 +#else
33880 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33881 +#endif
33882 EMIT2(0xf7, 0xf1); /* div %ecx */
33883 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33884 break;
33885 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33886 if (K == 1)
33887 break;
33888 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33889 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33890 + DILUTE_CONST_SEQUENCE(K, randkey);
33891 +#else
33892 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33893 +#endif
33894 EMIT2(0xf7, 0xf1); /* div %ecx */
33895 break;
33896 case BPF_S_ALU_AND_X:
33897 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33898 if (is_imm8(K)) {
33899 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33900 } else {
33901 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33902 - EMIT(K, 4);
33903 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33904 }
33905 } else {
33906 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33907 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33908 if (unlikely(proglen + ilen > oldproglen)) {
33909 pr_err("bpb_jit_compile fatal error\n");
33910 kfree(addrs);
33911 - module_free(NULL, header);
33912 + module_free_exec(NULL, image);
33913 return;
33914 }
33915 + pax_open_kernel();
33916 memcpy(image + proglen, temp, ilen);
33917 + pax_close_kernel();
33918 }
33919 proglen += ilen;
33920 addrs[i] = proglen;
33921 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33922
33923 if (image) {
33924 bpf_flush_icache(header, image + proglen);
33925 - set_memory_ro((unsigned long)header, header->pages);
33926 fp->bpf_func = (void *)image;
33927 }
33928 out:
33929 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33930 {
33931 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33932 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33933 - struct bpf_binary_header *header = (void *)addr;
33934
33935 - set_memory_rw(addr, header->pages);
33936 - module_free(NULL, header);
33937 + set_memory_rw(addr, 1);
33938 + module_free_exec(NULL, (void *)addr);
33939 kfree(fp);
33940 }
33941
33942 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33943 index 5d04be5..2beeaa2 100644
33944 --- a/arch/x86/oprofile/backtrace.c
33945 +++ b/arch/x86/oprofile/backtrace.c
33946 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33947 struct stack_frame_ia32 *fp;
33948 unsigned long bytes;
33949
33950 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33951 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33952 if (bytes != 0)
33953 return NULL;
33954
33955 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33956 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33957
33958 oprofile_add_trace(bufhead[0].return_address);
33959
33960 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33961 struct stack_frame bufhead[2];
33962 unsigned long bytes;
33963
33964 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33965 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33966 if (bytes != 0)
33967 return NULL;
33968
33969 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33970 {
33971 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33972
33973 - if (!user_mode_vm(regs)) {
33974 + if (!user_mode(regs)) {
33975 unsigned long stack = kernel_stack_pointer(regs);
33976 if (depth)
33977 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33978 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33979 index 6890d84..1dad1f1 100644
33980 --- a/arch/x86/oprofile/nmi_int.c
33981 +++ b/arch/x86/oprofile/nmi_int.c
33982 @@ -23,6 +23,7 @@
33983 #include <asm/nmi.h>
33984 #include <asm/msr.h>
33985 #include <asm/apic.h>
33986 +#include <asm/pgtable.h>
33987
33988 #include "op_counter.h"
33989 #include "op_x86_model.h"
33990 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33991 if (ret)
33992 return ret;
33993
33994 - if (!model->num_virt_counters)
33995 - model->num_virt_counters = model->num_counters;
33996 + if (!model->num_virt_counters) {
33997 + pax_open_kernel();
33998 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
33999 + pax_close_kernel();
34000 + }
34001
34002 mux_init(ops);
34003
34004 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34005 index 50d86c0..7985318 100644
34006 --- a/arch/x86/oprofile/op_model_amd.c
34007 +++ b/arch/x86/oprofile/op_model_amd.c
34008 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34009 num_counters = AMD64_NUM_COUNTERS;
34010 }
34011
34012 - op_amd_spec.num_counters = num_counters;
34013 - op_amd_spec.num_controls = num_counters;
34014 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34015 + pax_open_kernel();
34016 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34017 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34018 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34019 + pax_close_kernel();
34020
34021 return 0;
34022 }
34023 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34024 index d90528e..0127e2b 100644
34025 --- a/arch/x86/oprofile/op_model_ppro.c
34026 +++ b/arch/x86/oprofile/op_model_ppro.c
34027 @@ -19,6 +19,7 @@
34028 #include <asm/msr.h>
34029 #include <asm/apic.h>
34030 #include <asm/nmi.h>
34031 +#include <asm/pgtable.h>
34032
34033 #include "op_x86_model.h"
34034 #include "op_counter.h"
34035 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34036
34037 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34038
34039 - op_arch_perfmon_spec.num_counters = num_counters;
34040 - op_arch_perfmon_spec.num_controls = num_counters;
34041 + pax_open_kernel();
34042 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34043 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34044 + pax_close_kernel();
34045 }
34046
34047 static int arch_perfmon_init(struct oprofile_operations *ignore)
34048 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34049 index 71e8a67..6a313bb 100644
34050 --- a/arch/x86/oprofile/op_x86_model.h
34051 +++ b/arch/x86/oprofile/op_x86_model.h
34052 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34053 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34054 struct op_msrs const * const msrs);
34055 #endif
34056 -};
34057 +} __do_const;
34058
34059 struct op_counter_config;
34060
34061 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34062 index 84b9d67..260e5ff 100644
34063 --- a/arch/x86/pci/intel_mid_pci.c
34064 +++ b/arch/x86/pci/intel_mid_pci.c
34065 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34066 pr_info("Intel MID platform detected, using MID PCI ops\n");
34067 pci_mmcfg_late_init();
34068 pcibios_enable_irq = intel_mid_pci_irq_enable;
34069 - pci_root_ops = intel_mid_pci_ops;
34070 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34071 pci_soc_mode = 1;
34072 /* Continue with standard init */
34073 return 1;
34074 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34075 index 372e9b8..e775a6c 100644
34076 --- a/arch/x86/pci/irq.c
34077 +++ b/arch/x86/pci/irq.c
34078 @@ -50,7 +50,7 @@ struct irq_router {
34079 struct irq_router_handler {
34080 u16 vendor;
34081 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34082 -};
34083 +} __do_const;
34084
34085 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34086 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34087 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34088 return 0;
34089 }
34090
34091 -static __initdata struct irq_router_handler pirq_routers[] = {
34092 +static __initconst const struct irq_router_handler pirq_routers[] = {
34093 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34094 { PCI_VENDOR_ID_AL, ali_router_probe },
34095 { PCI_VENDOR_ID_ITE, ite_router_probe },
34096 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34097 static void __init pirq_find_router(struct irq_router *r)
34098 {
34099 struct irq_routing_table *rt = pirq_table;
34100 - struct irq_router_handler *h;
34101 + const struct irq_router_handler *h;
34102
34103 #ifdef CONFIG_PCI_BIOS
34104 if (!rt->signature) {
34105 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34106 return 0;
34107 }
34108
34109 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34110 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34111 {
34112 .callback = fix_broken_hp_bios_irq9,
34113 .ident = "HP Pavilion N5400 Series Laptop",
34114 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34115 index c77b24a..c979855 100644
34116 --- a/arch/x86/pci/pcbios.c
34117 +++ b/arch/x86/pci/pcbios.c
34118 @@ -79,7 +79,7 @@ union bios32 {
34119 static struct {
34120 unsigned long address;
34121 unsigned short segment;
34122 -} bios32_indirect = { 0, __KERNEL_CS };
34123 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34124
34125 /*
34126 * Returns the entry point for the given service, NULL on error
34127 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34128 unsigned long length; /* %ecx */
34129 unsigned long entry; /* %edx */
34130 unsigned long flags;
34131 + struct desc_struct d, *gdt;
34132
34133 local_irq_save(flags);
34134 - __asm__("lcall *(%%edi); cld"
34135 +
34136 + gdt = get_cpu_gdt_table(smp_processor_id());
34137 +
34138 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34139 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34140 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34141 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34142 +
34143 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34144 : "=a" (return_code),
34145 "=b" (address),
34146 "=c" (length),
34147 "=d" (entry)
34148 : "0" (service),
34149 "1" (0),
34150 - "D" (&bios32_indirect));
34151 + "D" (&bios32_indirect),
34152 + "r"(__PCIBIOS_DS)
34153 + : "memory");
34154 +
34155 + pax_open_kernel();
34156 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34157 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34158 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34159 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34160 + pax_close_kernel();
34161 +
34162 local_irq_restore(flags);
34163
34164 switch (return_code) {
34165 - case 0:
34166 - return address + entry;
34167 - case 0x80: /* Not present */
34168 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34169 - return 0;
34170 - default: /* Shouldn't happen */
34171 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34172 - service, return_code);
34173 + case 0: {
34174 + int cpu;
34175 + unsigned char flags;
34176 +
34177 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34178 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34179 + printk(KERN_WARNING "bios32_service: not valid\n");
34180 return 0;
34181 + }
34182 + address = address + PAGE_OFFSET;
34183 + length += 16UL; /* some BIOSs underreport this... */
34184 + flags = 4;
34185 + if (length >= 64*1024*1024) {
34186 + length >>= PAGE_SHIFT;
34187 + flags |= 8;
34188 + }
34189 +
34190 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34191 + gdt = get_cpu_gdt_table(cpu);
34192 + pack_descriptor(&d, address, length, 0x9b, flags);
34193 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34194 + pack_descriptor(&d, address, length, 0x93, flags);
34195 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34196 + }
34197 + return entry;
34198 + }
34199 + case 0x80: /* Not present */
34200 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34201 + return 0;
34202 + default: /* Shouldn't happen */
34203 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34204 + service, return_code);
34205 + return 0;
34206 }
34207 }
34208
34209 static struct {
34210 unsigned long address;
34211 unsigned short segment;
34212 -} pci_indirect = { 0, __KERNEL_CS };
34213 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34214
34215 -static int pci_bios_present;
34216 +static int pci_bios_present __read_only;
34217
34218 static int check_pcibios(void)
34219 {
34220 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34221 unsigned long flags, pcibios_entry;
34222
34223 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34224 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34225 + pci_indirect.address = pcibios_entry;
34226
34227 local_irq_save(flags);
34228 - __asm__(
34229 - "lcall *(%%edi); cld\n\t"
34230 + __asm__("movw %w6, %%ds\n\t"
34231 + "lcall *%%ss:(%%edi); cld\n\t"
34232 + "push %%ss\n\t"
34233 + "pop %%ds\n\t"
34234 "jc 1f\n\t"
34235 "xor %%ah, %%ah\n"
34236 "1:"
34237 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34238 "=b" (ebx),
34239 "=c" (ecx)
34240 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34241 - "D" (&pci_indirect)
34242 + "D" (&pci_indirect),
34243 + "r" (__PCIBIOS_DS)
34244 : "memory");
34245 local_irq_restore(flags);
34246
34247 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34248
34249 switch (len) {
34250 case 1:
34251 - __asm__("lcall *(%%esi); cld\n\t"
34252 + __asm__("movw %w6, %%ds\n\t"
34253 + "lcall *%%ss:(%%esi); cld\n\t"
34254 + "push %%ss\n\t"
34255 + "pop %%ds\n\t"
34256 "jc 1f\n\t"
34257 "xor %%ah, %%ah\n"
34258 "1:"
34259 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34260 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34261 "b" (bx),
34262 "D" ((long)reg),
34263 - "S" (&pci_indirect));
34264 + "S" (&pci_indirect),
34265 + "r" (__PCIBIOS_DS));
34266 /*
34267 * Zero-extend the result beyond 8 bits, do not trust the
34268 * BIOS having done it:
34269 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34270 *value &= 0xff;
34271 break;
34272 case 2:
34273 - __asm__("lcall *(%%esi); cld\n\t"
34274 + __asm__("movw %w6, %%ds\n\t"
34275 + "lcall *%%ss:(%%esi); cld\n\t"
34276 + "push %%ss\n\t"
34277 + "pop %%ds\n\t"
34278 "jc 1f\n\t"
34279 "xor %%ah, %%ah\n"
34280 "1:"
34281 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34282 : "1" (PCIBIOS_READ_CONFIG_WORD),
34283 "b" (bx),
34284 "D" ((long)reg),
34285 - "S" (&pci_indirect));
34286 + "S" (&pci_indirect),
34287 + "r" (__PCIBIOS_DS));
34288 /*
34289 * Zero-extend the result beyond 16 bits, do not trust the
34290 * BIOS having done it:
34291 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34292 *value &= 0xffff;
34293 break;
34294 case 4:
34295 - __asm__("lcall *(%%esi); cld\n\t"
34296 + __asm__("movw %w6, %%ds\n\t"
34297 + "lcall *%%ss:(%%esi); cld\n\t"
34298 + "push %%ss\n\t"
34299 + "pop %%ds\n\t"
34300 "jc 1f\n\t"
34301 "xor %%ah, %%ah\n"
34302 "1:"
34303 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34304 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34305 "b" (bx),
34306 "D" ((long)reg),
34307 - "S" (&pci_indirect));
34308 + "S" (&pci_indirect),
34309 + "r" (__PCIBIOS_DS));
34310 break;
34311 }
34312
34313 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34314
34315 switch (len) {
34316 case 1:
34317 - __asm__("lcall *(%%esi); cld\n\t"
34318 + __asm__("movw %w6, %%ds\n\t"
34319 + "lcall *%%ss:(%%esi); cld\n\t"
34320 + "push %%ss\n\t"
34321 + "pop %%ds\n\t"
34322 "jc 1f\n\t"
34323 "xor %%ah, %%ah\n"
34324 "1:"
34325 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34326 "c" (value),
34327 "b" (bx),
34328 "D" ((long)reg),
34329 - "S" (&pci_indirect));
34330 + "S" (&pci_indirect),
34331 + "r" (__PCIBIOS_DS));
34332 break;
34333 case 2:
34334 - __asm__("lcall *(%%esi); cld\n\t"
34335 + __asm__("movw %w6, %%ds\n\t"
34336 + "lcall *%%ss:(%%esi); cld\n\t"
34337 + "push %%ss\n\t"
34338 + "pop %%ds\n\t"
34339 "jc 1f\n\t"
34340 "xor %%ah, %%ah\n"
34341 "1:"
34342 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34343 "c" (value),
34344 "b" (bx),
34345 "D" ((long)reg),
34346 - "S" (&pci_indirect));
34347 + "S" (&pci_indirect),
34348 + "r" (__PCIBIOS_DS));
34349 break;
34350 case 4:
34351 - __asm__("lcall *(%%esi); cld\n\t"
34352 + __asm__("movw %w6, %%ds\n\t"
34353 + "lcall *%%ss:(%%esi); cld\n\t"
34354 + "push %%ss\n\t"
34355 + "pop %%ds\n\t"
34356 "jc 1f\n\t"
34357 "xor %%ah, %%ah\n"
34358 "1:"
34359 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34360 "c" (value),
34361 "b" (bx),
34362 "D" ((long)reg),
34363 - "S" (&pci_indirect));
34364 + "S" (&pci_indirect),
34365 + "r" (__PCIBIOS_DS));
34366 break;
34367 }
34368
34369 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34370
34371 DBG("PCI: Fetching IRQ routing table... ");
34372 __asm__("push %%es\n\t"
34373 + "movw %w8, %%ds\n\t"
34374 "push %%ds\n\t"
34375 "pop %%es\n\t"
34376 - "lcall *(%%esi); cld\n\t"
34377 + "lcall *%%ss:(%%esi); cld\n\t"
34378 "pop %%es\n\t"
34379 + "push %%ss\n\t"
34380 + "pop %%ds\n"
34381 "jc 1f\n\t"
34382 "xor %%ah, %%ah\n"
34383 "1:"
34384 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34385 "1" (0),
34386 "D" ((long) &opt),
34387 "S" (&pci_indirect),
34388 - "m" (opt)
34389 + "m" (opt),
34390 + "r" (__PCIBIOS_DS)
34391 : "memory");
34392 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34393 if (ret & 0xff00)
34394 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34395 {
34396 int ret;
34397
34398 - __asm__("lcall *(%%esi); cld\n\t"
34399 + __asm__("movw %w5, %%ds\n\t"
34400 + "lcall *%%ss:(%%esi); cld\n\t"
34401 + "push %%ss\n\t"
34402 + "pop %%ds\n"
34403 "jc 1f\n\t"
34404 "xor %%ah, %%ah\n"
34405 "1:"
34406 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34407 : "0" (PCIBIOS_SET_PCI_HW_INT),
34408 "b" ((dev->bus->number << 8) | dev->devfn),
34409 "c" ((irq << 8) | (pin + 10)),
34410 - "S" (&pci_indirect));
34411 + "S" (&pci_indirect),
34412 + "r" (__PCIBIOS_DS));
34413 return !(ret & 0xff00);
34414 }
34415 EXPORT_SYMBOL(pcibios_set_irq_routing);
34416 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34417 index 9ee3491..872192f 100644
34418 --- a/arch/x86/platform/efi/efi_32.c
34419 +++ b/arch/x86/platform/efi/efi_32.c
34420 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34421 {
34422 struct desc_ptr gdt_descr;
34423
34424 +#ifdef CONFIG_PAX_KERNEXEC
34425 + struct desc_struct d;
34426 +#endif
34427 +
34428 local_irq_save(efi_rt_eflags);
34429
34430 load_cr3(initial_page_table);
34431 __flush_tlb_all();
34432
34433 +#ifdef CONFIG_PAX_KERNEXEC
34434 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34435 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34436 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34437 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34438 +#endif
34439 +
34440 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34441 gdt_descr.size = GDT_SIZE - 1;
34442 load_gdt(&gdt_descr);
34443 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34444 {
34445 struct desc_ptr gdt_descr;
34446
34447 +#ifdef CONFIG_PAX_KERNEXEC
34448 + struct desc_struct d;
34449 +
34450 + memset(&d, 0, sizeof d);
34451 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34452 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34453 +#endif
34454 +
34455 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34456 gdt_descr.size = GDT_SIZE - 1;
34457 load_gdt(&gdt_descr);
34458
34459 +#ifdef CONFIG_PAX_PER_CPU_PGD
34460 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34461 +#else
34462 load_cr3(swapper_pg_dir);
34463 +#endif
34464 +
34465 __flush_tlb_all();
34466
34467 local_irq_restore(efi_rt_eflags);
34468 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34469 index 666b74a..673d88f 100644
34470 --- a/arch/x86/platform/efi/efi_64.c
34471 +++ b/arch/x86/platform/efi/efi_64.c
34472 @@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34473 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34474 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34475 }
34476 +
34477 +#ifdef CONFIG_PAX_PER_CPU_PGD
34478 + load_cr3(swapper_pg_dir);
34479 +#endif
34480 +
34481 __flush_tlb_all();
34482 }
34483
34484 @@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34485 for (pgd = 0; pgd < n_pgds; pgd++)
34486 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34487 kfree(save_pgd);
34488 +
34489 +#ifdef CONFIG_PAX_PER_CPU_PGD
34490 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34491 +#endif
34492 +
34493 __flush_tlb_all();
34494 local_irq_restore(efi_flags);
34495 early_code_mapping_set_exec(0);
34496 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34497 index fbe66e6..eae5e38 100644
34498 --- a/arch/x86/platform/efi/efi_stub_32.S
34499 +++ b/arch/x86/platform/efi/efi_stub_32.S
34500 @@ -6,7 +6,9 @@
34501 */
34502
34503 #include <linux/linkage.h>
34504 +#include <linux/init.h>
34505 #include <asm/page_types.h>
34506 +#include <asm/segment.h>
34507
34508 /*
34509 * efi_call_phys(void *, ...) is a function with variable parameters.
34510 @@ -20,7 +22,7 @@
34511 * service functions will comply with gcc calling convention, too.
34512 */
34513
34514 -.text
34515 +__INIT
34516 ENTRY(efi_call_phys)
34517 /*
34518 * 0. The function can only be called in Linux kernel. So CS has been
34519 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34520 * The mapping of lower virtual memory has been created in prelog and
34521 * epilog.
34522 */
34523 - movl $1f, %edx
34524 - subl $__PAGE_OFFSET, %edx
34525 - jmp *%edx
34526 +#ifdef CONFIG_PAX_KERNEXEC
34527 + movl $(__KERNEXEC_EFI_DS), %edx
34528 + mov %edx, %ds
34529 + mov %edx, %es
34530 + mov %edx, %ss
34531 + addl $2f,(1f)
34532 + ljmp *(1f)
34533 +
34534 +__INITDATA
34535 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34536 +.previous
34537 +
34538 +2:
34539 + subl $2b,(1b)
34540 +#else
34541 + jmp 1f-__PAGE_OFFSET
34542 1:
34543 +#endif
34544
34545 /*
34546 * 2. Now on the top of stack is the return
34547 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34548 * parameter 2, ..., param n. To make things easy, we save the return
34549 * address of efi_call_phys in a global variable.
34550 */
34551 - popl %edx
34552 - movl %edx, saved_return_addr
34553 - /* get the function pointer into ECX*/
34554 - popl %ecx
34555 - movl %ecx, efi_rt_function_ptr
34556 - movl $2f, %edx
34557 - subl $__PAGE_OFFSET, %edx
34558 - pushl %edx
34559 + popl (saved_return_addr)
34560 + popl (efi_rt_function_ptr)
34561
34562 /*
34563 * 3. Clear PG bit in %CR0.
34564 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34565 /*
34566 * 5. Call the physical function.
34567 */
34568 - jmp *%ecx
34569 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34570
34571 -2:
34572 /*
34573 * 6. After EFI runtime service returns, control will return to
34574 * following instruction. We'd better readjust stack pointer first.
34575 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34576 movl %cr0, %edx
34577 orl $0x80000000, %edx
34578 movl %edx, %cr0
34579 - jmp 1f
34580 -1:
34581 +
34582 /*
34583 * 8. Now restore the virtual mode from flat mode by
34584 * adding EIP with PAGE_OFFSET.
34585 */
34586 - movl $1f, %edx
34587 - jmp *%edx
34588 +#ifdef CONFIG_PAX_KERNEXEC
34589 + movl $(__KERNEL_DS), %edx
34590 + mov %edx, %ds
34591 + mov %edx, %es
34592 + mov %edx, %ss
34593 + ljmp $(__KERNEL_CS),$1f
34594 +#else
34595 + jmp 1f+__PAGE_OFFSET
34596 +#endif
34597 1:
34598
34599 /*
34600 * 9. Balance the stack. And because EAX contain the return value,
34601 * we'd better not clobber it.
34602 */
34603 - leal efi_rt_function_ptr, %edx
34604 - movl (%edx), %ecx
34605 - pushl %ecx
34606 + pushl (efi_rt_function_ptr)
34607
34608 /*
34609 - * 10. Push the saved return address onto the stack and return.
34610 + * 10. Return to the saved return address.
34611 */
34612 - leal saved_return_addr, %edx
34613 - movl (%edx), %ecx
34614 - pushl %ecx
34615 - ret
34616 + jmpl *(saved_return_addr)
34617 ENDPROC(efi_call_phys)
34618 .previous
34619
34620 -.data
34621 +__INITDATA
34622 saved_return_addr:
34623 .long 0
34624 efi_rt_function_ptr:
34625 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34626 index 88073b1..1cc2f53 100644
34627 --- a/arch/x86/platform/efi/efi_stub_64.S
34628 +++ b/arch/x86/platform/efi/efi_stub_64.S
34629 @@ -7,6 +7,7 @@
34630 */
34631
34632 #include <linux/linkage.h>
34633 +#include <asm/alternative-asm.h>
34634
34635 #define SAVE_XMM \
34636 mov %rsp, %rax; \
34637 @@ -77,6 +78,7 @@ ENTRY(efi_call0)
34638 RESTORE_PGT
34639 addq $32, %rsp
34640 RESTORE_XMM
34641 + pax_force_retaddr 0, 1
34642 ret
34643 ENDPROC(efi_call0)
34644
34645 @@ -89,6 +91,7 @@ ENTRY(efi_call1)
34646 RESTORE_PGT
34647 addq $32, %rsp
34648 RESTORE_XMM
34649 + pax_force_retaddr 0, 1
34650 ret
34651 ENDPROC(efi_call1)
34652
34653 @@ -101,6 +104,7 @@ ENTRY(efi_call2)
34654 RESTORE_PGT
34655 addq $32, %rsp
34656 RESTORE_XMM
34657 + pax_force_retaddr 0, 1
34658 ret
34659 ENDPROC(efi_call2)
34660
34661 @@ -114,6 +118,7 @@ ENTRY(efi_call3)
34662 RESTORE_PGT
34663 addq $32, %rsp
34664 RESTORE_XMM
34665 + pax_force_retaddr 0, 1
34666 ret
34667 ENDPROC(efi_call3)
34668
34669 @@ -128,6 +133,7 @@ ENTRY(efi_call4)
34670 RESTORE_PGT
34671 addq $32, %rsp
34672 RESTORE_XMM
34673 + pax_force_retaddr 0, 1
34674 ret
34675 ENDPROC(efi_call4)
34676
34677 @@ -143,6 +149,7 @@ ENTRY(efi_call5)
34678 RESTORE_PGT
34679 addq $48, %rsp
34680 RESTORE_XMM
34681 + pax_force_retaddr 0, 1
34682 ret
34683 ENDPROC(efi_call5)
34684
34685 @@ -161,6 +168,7 @@ ENTRY(efi_call6)
34686 RESTORE_PGT
34687 addq $48, %rsp
34688 RESTORE_XMM
34689 + pax_force_retaddr 0, 1
34690 ret
34691 ENDPROC(efi_call6)
34692
34693 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34694 index 1bbedc4..eb795b5 100644
34695 --- a/arch/x86/platform/intel-mid/intel-mid.c
34696 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34697 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34698 {
34699 };
34700
34701 -static void intel_mid_reboot(void)
34702 +static void __noreturn intel_mid_reboot(void)
34703 {
34704 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34705 + BUG();
34706 }
34707
34708 static unsigned long __init intel_mid_calibrate_tsc(void)
34709 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34710 index d6ee929..3637cb5 100644
34711 --- a/arch/x86/platform/olpc/olpc_dt.c
34712 +++ b/arch/x86/platform/olpc/olpc_dt.c
34713 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34714 return res;
34715 }
34716
34717 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34718 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34719 .nextprop = olpc_dt_nextprop,
34720 .getproplen = olpc_dt_getproplen,
34721 .getproperty = olpc_dt_getproperty,
34722 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34723 index 424f4c9..f2a2988 100644
34724 --- a/arch/x86/power/cpu.c
34725 +++ b/arch/x86/power/cpu.c
34726 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34727 static void fix_processor_context(void)
34728 {
34729 int cpu = smp_processor_id();
34730 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34731 -#ifdef CONFIG_X86_64
34732 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34733 - tss_desc tss;
34734 -#endif
34735 + struct tss_struct *t = init_tss + cpu;
34736 +
34737 set_tss_desc(cpu, t); /*
34738 * This just modifies memory; should not be
34739 * necessary. But... This is necessary, because
34740 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34741 */
34742
34743 #ifdef CONFIG_X86_64
34744 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34745 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34746 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34747 -
34748 syscall_init(); /* This sets MSR_*STAR and related */
34749 #endif
34750 load_TR_desc(); /* This does ltr */
34751 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34752 index bad628a..a102610 100644
34753 --- a/arch/x86/realmode/init.c
34754 +++ b/arch/x86/realmode/init.c
34755 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34756 __va(real_mode_header->trampoline_header);
34757
34758 #ifdef CONFIG_X86_32
34759 - trampoline_header->start = __pa_symbol(startup_32_smp);
34760 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34761 +
34762 +#ifdef CONFIG_PAX_KERNEXEC
34763 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34764 +#endif
34765 +
34766 + trampoline_header->boot_cs = __BOOT_CS;
34767 trampoline_header->gdt_limit = __BOOT_DS + 7;
34768 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34769 #else
34770 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34771 *trampoline_cr4_features = read_cr4();
34772
34773 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34774 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34775 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34776 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34777 #endif
34778 }
34779 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34780 index 3497f14..cc73b92 100644
34781 --- a/arch/x86/realmode/rm/Makefile
34782 +++ b/arch/x86/realmode/rm/Makefile
34783 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34784
34785 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34786 -I$(srctree)/arch/x86/boot
34787 +ifdef CONSTIFY_PLUGIN
34788 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34789 +endif
34790 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34791 GCOV_PROFILE := n
34792 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34793 index a28221d..93c40f1 100644
34794 --- a/arch/x86/realmode/rm/header.S
34795 +++ b/arch/x86/realmode/rm/header.S
34796 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34797 #endif
34798 /* APM/BIOS reboot */
34799 .long pa_machine_real_restart_asm
34800 -#ifdef CONFIG_X86_64
34801 +#ifdef CONFIG_X86_32
34802 + .long __KERNEL_CS
34803 +#else
34804 .long __KERNEL32_CS
34805 #endif
34806 END(real_mode_header)
34807 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34808 index 48ddd76..c26749f 100644
34809 --- a/arch/x86/realmode/rm/trampoline_32.S
34810 +++ b/arch/x86/realmode/rm/trampoline_32.S
34811 @@ -24,6 +24,12 @@
34812 #include <asm/page_types.h>
34813 #include "realmode.h"
34814
34815 +#ifdef CONFIG_PAX_KERNEXEC
34816 +#define ta(X) (X)
34817 +#else
34818 +#define ta(X) (pa_ ## X)
34819 +#endif
34820 +
34821 .text
34822 .code16
34823
34824 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
34825
34826 cli # We should be safe anyway
34827
34828 - movl tr_start, %eax # where we need to go
34829 -
34830 movl $0xA5A5A5A5, trampoline_status
34831 # write marker for master knows we're running
34832
34833 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
34834 movw $1, %dx # protected mode (PE) bit
34835 lmsw %dx # into protected mode
34836
34837 - ljmpl $__BOOT_CS, $pa_startup_32
34838 + ljmpl *(trampoline_header)
34839
34840 .section ".text32","ax"
34841 .code32
34842 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34843 .balign 8
34844 GLOBAL(trampoline_header)
34845 tr_start: .space 4
34846 - tr_gdt_pad: .space 2
34847 + tr_boot_cs: .space 2
34848 tr_gdt: .space 6
34849 END(trampoline_header)
34850
34851 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34852 index dac7b20..72dbaca 100644
34853 --- a/arch/x86/realmode/rm/trampoline_64.S
34854 +++ b/arch/x86/realmode/rm/trampoline_64.S
34855 @@ -93,6 +93,7 @@ ENTRY(startup_32)
34856 movl %edx, %gs
34857
34858 movl pa_tr_cr4, %eax
34859 + andl $~X86_CR4_PCIDE, %eax
34860 movl %eax, %cr4 # Enable PAE mode
34861
34862 # Setup trampoline 4 level pagetables
34863 @@ -106,7 +107,7 @@ ENTRY(startup_32)
34864 wrmsr
34865
34866 # Enable paging and in turn activate Long Mode
34867 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34868 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34869 movl %eax, %cr0
34870
34871 /*
34872 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34873 index e812034..c747134 100644
34874 --- a/arch/x86/tools/Makefile
34875 +++ b/arch/x86/tools/Makefile
34876 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34877
34878 $(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
34879
34880 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34881 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34882 hostprogs-y += relocs
34883 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34884 relocs: $(obj)/relocs
34885 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34886 index cfbdbdb..1aa763c 100644
34887 --- a/arch/x86/tools/relocs.c
34888 +++ b/arch/x86/tools/relocs.c
34889 @@ -1,5 +1,7 @@
34890 /* This is included from relocs_32/64.c */
34891
34892 +#include "../../../include/generated/autoconf.h"
34893 +
34894 #define ElfW(type) _ElfW(ELF_BITS, type)
34895 #define _ElfW(bits, type) __ElfW(bits, type)
34896 #define __ElfW(bits, type) Elf##bits##_##type
34897 @@ -11,6 +13,7 @@
34898 #define Elf_Sym ElfW(Sym)
34899
34900 static Elf_Ehdr ehdr;
34901 +static Elf_Phdr *phdr;
34902
34903 struct relocs {
34904 uint32_t *offset;
34905 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34906 }
34907 }
34908
34909 +static void read_phdrs(FILE *fp)
34910 +{
34911 + unsigned int i;
34912 +
34913 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34914 + if (!phdr) {
34915 + die("Unable to allocate %d program headers\n",
34916 + ehdr.e_phnum);
34917 + }
34918 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34919 + die("Seek to %d failed: %s\n",
34920 + ehdr.e_phoff, strerror(errno));
34921 + }
34922 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34923 + die("Cannot read ELF program headers: %s\n",
34924 + strerror(errno));
34925 + }
34926 + for(i = 0; i < ehdr.e_phnum; i++) {
34927 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34928 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34929 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34930 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34931 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34932 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34933 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34934 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34935 + }
34936 +
34937 +}
34938 +
34939 static void read_shdrs(FILE *fp)
34940 {
34941 - int i;
34942 + unsigned int i;
34943 Elf_Shdr shdr;
34944
34945 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34946 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34947
34948 static void read_strtabs(FILE *fp)
34949 {
34950 - int i;
34951 + unsigned int i;
34952 for (i = 0; i < ehdr.e_shnum; i++) {
34953 struct section *sec = &secs[i];
34954 if (sec->shdr.sh_type != SHT_STRTAB) {
34955 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34956
34957 static void read_symtabs(FILE *fp)
34958 {
34959 - int i,j;
34960 + unsigned int i,j;
34961 for (i = 0; i < ehdr.e_shnum; i++) {
34962 struct section *sec = &secs[i];
34963 if (sec->shdr.sh_type != SHT_SYMTAB) {
34964 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34965 }
34966
34967
34968 -static void read_relocs(FILE *fp)
34969 +static void read_relocs(FILE *fp, int use_real_mode)
34970 {
34971 - int i,j;
34972 + unsigned int i,j;
34973 + uint32_t base;
34974 +
34975 for (i = 0; i < ehdr.e_shnum; i++) {
34976 struct section *sec = &secs[i];
34977 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34978 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34979 die("Cannot read symbol table: %s\n",
34980 strerror(errno));
34981 }
34982 + base = 0;
34983 +
34984 +#ifdef CONFIG_X86_32
34985 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34986 + if (phdr[j].p_type != PT_LOAD )
34987 + continue;
34988 + 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)
34989 + continue;
34990 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34991 + break;
34992 + }
34993 +#endif
34994 +
34995 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34996 Elf_Rel *rel = &sec->reltab[j];
34997 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34998 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34999 rel->r_info = elf_xword_to_cpu(rel->r_info);
35000 #if (SHT_REL_TYPE == SHT_RELA)
35001 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35002 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35003
35004 static void print_absolute_symbols(void)
35005 {
35006 - int i;
35007 + unsigned int i;
35008 const char *format;
35009
35010 if (ELF_BITS == 64)
35011 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35012 for (i = 0; i < ehdr.e_shnum; i++) {
35013 struct section *sec = &secs[i];
35014 char *sym_strtab;
35015 - int j;
35016 + unsigned int j;
35017
35018 if (sec->shdr.sh_type != SHT_SYMTAB) {
35019 continue;
35020 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35021
35022 static void print_absolute_relocs(void)
35023 {
35024 - int i, printed = 0;
35025 + unsigned int i, printed = 0;
35026 const char *format;
35027
35028 if (ELF_BITS == 64)
35029 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35030 struct section *sec_applies, *sec_symtab;
35031 char *sym_strtab;
35032 Elf_Sym *sh_symtab;
35033 - int j;
35034 + unsigned int j;
35035 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35036 continue;
35037 }
35038 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35039 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35040 Elf_Sym *sym, const char *symname))
35041 {
35042 - int i;
35043 + unsigned int i;
35044 /* Walk through the relocations */
35045 for (i = 0; i < ehdr.e_shnum; i++) {
35046 char *sym_strtab;
35047 Elf_Sym *sh_symtab;
35048 struct section *sec_applies, *sec_symtab;
35049 - int j;
35050 + unsigned int j;
35051 struct section *sec = &secs[i];
35052
35053 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35054 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35055 {
35056 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35057 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35058 + char *sym_strtab = sec->link->link->strtab;
35059 +
35060 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35061 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35062 + return 0;
35063 +
35064 +#ifdef CONFIG_PAX_KERNEXEC
35065 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35066 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35067 + return 0;
35068 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35069 + return 0;
35070 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35071 + return 0;
35072 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35073 + return 0;
35074 +#endif
35075
35076 switch (r_type) {
35077 case R_386_NONE:
35078 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35079
35080 static void emit_relocs(int as_text, int use_real_mode)
35081 {
35082 - int i;
35083 + unsigned int i;
35084 int (*write_reloc)(uint32_t, FILE *) = write32;
35085 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35086 const char *symname);
35087 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35088 {
35089 regex_init(use_real_mode);
35090 read_ehdr(fp);
35091 + read_phdrs(fp);
35092 read_shdrs(fp);
35093 read_strtabs(fp);
35094 read_symtabs(fp);
35095 - read_relocs(fp);
35096 + read_relocs(fp, use_real_mode);
35097 if (ELF_BITS == 64)
35098 percpu_init();
35099 if (show_absolute_syms) {
35100 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35101 index 80ffa5b..a33bd15 100644
35102 --- a/arch/x86/um/tls_32.c
35103 +++ b/arch/x86/um/tls_32.c
35104 @@ -260,7 +260,7 @@ out:
35105 if (unlikely(task == current &&
35106 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35107 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35108 - "without flushed TLS.", current->pid);
35109 + "without flushed TLS.", task_pid_nr(current));
35110 }
35111
35112 return 0;
35113 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35114 index fd14be1..e3c79c0 100644
35115 --- a/arch/x86/vdso/Makefile
35116 +++ b/arch/x86/vdso/Makefile
35117 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35118 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35119 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35120
35121 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35122 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35123 GCOV_PROFILE := n
35124
35125 #
35126 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35127 index d6bfb87..876ee18 100644
35128 --- a/arch/x86/vdso/vdso32-setup.c
35129 +++ b/arch/x86/vdso/vdso32-setup.c
35130 @@ -25,6 +25,7 @@
35131 #include <asm/tlbflush.h>
35132 #include <asm/vdso.h>
35133 #include <asm/proto.h>
35134 +#include <asm/mman.h>
35135
35136 enum {
35137 VDSO_DISABLED = 0,
35138 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35139 void enable_sep_cpu(void)
35140 {
35141 int cpu = get_cpu();
35142 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35143 + struct tss_struct *tss = init_tss + cpu;
35144
35145 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35146 put_cpu();
35147 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35148 gate_vma.vm_start = FIXADDR_USER_START;
35149 gate_vma.vm_end = FIXADDR_USER_END;
35150 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35151 - gate_vma.vm_page_prot = __P101;
35152 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35153
35154 return 0;
35155 }
35156 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35157 if (compat)
35158 addr = VDSO_HIGH_BASE;
35159 else {
35160 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35161 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35162 if (IS_ERR_VALUE(addr)) {
35163 ret = addr;
35164 goto up_fail;
35165 }
35166 }
35167
35168 - current->mm->context.vdso = (void *)addr;
35169 + current->mm->context.vdso = addr;
35170
35171 if (compat_uses_vma || !compat) {
35172 /*
35173 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35174 }
35175
35176 current_thread_info()->sysenter_return =
35177 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35178 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35179
35180 up_fail:
35181 if (ret)
35182 - current->mm->context.vdso = NULL;
35183 + current->mm->context.vdso = 0;
35184
35185 up_write(&mm->mmap_sem);
35186
35187 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35188
35189 const char *arch_vma_name(struct vm_area_struct *vma)
35190 {
35191 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35192 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35193 return "[vdso]";
35194 +
35195 +#ifdef CONFIG_PAX_SEGMEXEC
35196 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35197 + return "[vdso]";
35198 +#endif
35199 +
35200 return NULL;
35201 }
35202
35203 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35204 * Check to see if the corresponding task was created in compat vdso
35205 * mode.
35206 */
35207 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35208 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35209 return &gate_vma;
35210 return NULL;
35211 }
35212 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35213 index 431e875..cbb23f3 100644
35214 --- a/arch/x86/vdso/vma.c
35215 +++ b/arch/x86/vdso/vma.c
35216 @@ -16,8 +16,6 @@
35217 #include <asm/vdso.h>
35218 #include <asm/page.h>
35219
35220 -unsigned int __read_mostly vdso_enabled = 1;
35221 -
35222 extern char vdso_start[], vdso_end[];
35223 extern unsigned short vdso_sync_cpuid;
35224
35225 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35226 * unaligned here as a result of stack start randomization.
35227 */
35228 addr = PAGE_ALIGN(addr);
35229 - addr = align_vdso_addr(addr);
35230
35231 return addr;
35232 }
35233 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35234 unsigned size)
35235 {
35236 struct mm_struct *mm = current->mm;
35237 - unsigned long addr;
35238 + unsigned long addr = 0;
35239 int ret;
35240
35241 - if (!vdso_enabled)
35242 - return 0;
35243 -
35244 down_write(&mm->mmap_sem);
35245 +
35246 +#ifdef CONFIG_PAX_RANDMMAP
35247 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35248 +#endif
35249 +
35250 addr = vdso_addr(mm->start_stack, size);
35251 + addr = align_vdso_addr(addr);
35252 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35253 if (IS_ERR_VALUE(addr)) {
35254 ret = addr;
35255 goto up_fail;
35256 }
35257
35258 - current->mm->context.vdso = (void *)addr;
35259 + mm->context.vdso = addr;
35260
35261 ret = install_special_mapping(mm, addr, size,
35262 VM_READ|VM_EXEC|
35263 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35264 pages);
35265 - if (ret) {
35266 - current->mm->context.vdso = NULL;
35267 - goto up_fail;
35268 - }
35269 + if (ret)
35270 + mm->context.vdso = 0;
35271
35272 up_fail:
35273 up_write(&mm->mmap_sem);
35274 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35275 vdsox32_size);
35276 }
35277 #endif
35278 -
35279 -static __init int vdso_setup(char *s)
35280 -{
35281 - vdso_enabled = simple_strtoul(s, NULL, 0);
35282 - return 0;
35283 -}
35284 -__setup("vdso=", vdso_setup);
35285 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35286 index 01b9026..1e476df 100644
35287 --- a/arch/x86/xen/Kconfig
35288 +++ b/arch/x86/xen/Kconfig
35289 @@ -9,6 +9,7 @@ config XEN
35290 select XEN_HAVE_PVMMU
35291 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35292 depends on X86_TSC
35293 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35294 help
35295 This is the Linux Xen port. Enabling this will allow the
35296 kernel to boot in a paravirtualized environment under the
35297 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35298 index 201d09a..e4723e5 100644
35299 --- a/arch/x86/xen/enlighten.c
35300 +++ b/arch/x86/xen/enlighten.c
35301 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35302
35303 struct shared_info xen_dummy_shared_info;
35304
35305 -void *xen_initial_gdt;
35306 -
35307 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35308 __read_mostly int xen_have_vector_callback;
35309 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35310 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35311 {
35312 unsigned long va = dtr->address;
35313 unsigned int size = dtr->size + 1;
35314 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35315 - unsigned long frames[pages];
35316 + unsigned long frames[65536 / PAGE_SIZE];
35317 int f;
35318
35319 /*
35320 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35321 {
35322 unsigned long va = dtr->address;
35323 unsigned int size = dtr->size + 1;
35324 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35325 - unsigned long frames[pages];
35326 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35327 int f;
35328
35329 /*
35330 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35331 * 8-byte entries, or 16 4k pages..
35332 */
35333
35334 - BUG_ON(size > 65536);
35335 + BUG_ON(size > GDT_SIZE);
35336 BUG_ON(va & ~PAGE_MASK);
35337
35338 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35339 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35340 return 0;
35341 }
35342
35343 -static void set_xen_basic_apic_ops(void)
35344 +static void __init set_xen_basic_apic_ops(void)
35345 {
35346 apic->read = xen_apic_read;
35347 apic->write = xen_apic_write;
35348 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35349 #endif
35350 };
35351
35352 -static void xen_reboot(int reason)
35353 +static __noreturn void xen_reboot(int reason)
35354 {
35355 struct sched_shutdown r = { .reason = reason };
35356
35357 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35358 - BUG();
35359 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35360 + BUG();
35361 }
35362
35363 -static void xen_restart(char *msg)
35364 +static __noreturn void xen_restart(char *msg)
35365 {
35366 xen_reboot(SHUTDOWN_reboot);
35367 }
35368
35369 -static void xen_emergency_restart(void)
35370 +static __noreturn void xen_emergency_restart(void)
35371 {
35372 xen_reboot(SHUTDOWN_reboot);
35373 }
35374
35375 -static void xen_machine_halt(void)
35376 +static __noreturn void xen_machine_halt(void)
35377 {
35378 xen_reboot(SHUTDOWN_poweroff);
35379 }
35380
35381 -static void xen_machine_power_off(void)
35382 +static __noreturn void xen_machine_power_off(void)
35383 {
35384 if (pm_power_off)
35385 pm_power_off();
35386 @@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35387 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35388
35389 /* Work out if we support NX */
35390 - x86_configure_nx();
35391 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35392 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35393 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35394 + unsigned l, h;
35395 +
35396 + __supported_pte_mask |= _PAGE_NX;
35397 + rdmsr(MSR_EFER, l, h);
35398 + l |= EFER_NX;
35399 + wrmsr(MSR_EFER, l, h);
35400 + }
35401 +#endif
35402
35403 /* Get mfn list */
35404 xen_build_dynamic_phys_to_machine();
35405 @@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35406
35407 machine_ops = xen_machine_ops;
35408
35409 - /*
35410 - * The only reliable way to retain the initial address of the
35411 - * percpu gdt_page is to remember it here, so we can go and
35412 - * mark it RW later, when the initial percpu area is freed.
35413 - */
35414 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35415 -
35416 xen_smp_init();
35417
35418 #ifdef CONFIG_ACPI_NUMA
35419 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35420 index 2423ef0..4f6fb5b 100644
35421 --- a/arch/x86/xen/mmu.c
35422 +++ b/arch/x86/xen/mmu.c
35423 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35424 return val;
35425 }
35426
35427 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35428 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35429 {
35430 if (val & _PAGE_PRESENT) {
35431 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35432 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35433 /* L3_k[510] -> level2_kernel_pgt
35434 * L3_i[511] -> level2_fixmap_pgt */
35435 convert_pfn_mfn(level3_kernel_pgt);
35436 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35437 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35438 + convert_pfn_mfn(level3_vmemmap_pgt);
35439 }
35440 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35441 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35442 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35443 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35444 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35445 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35446 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35447 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35448 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35449 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35450 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35451 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35452 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35453 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35454
35455 @@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35456 pv_mmu_ops.set_pud = xen_set_pud;
35457 #if PAGETABLE_LEVELS == 4
35458 pv_mmu_ops.set_pgd = xen_set_pgd;
35459 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35460 #endif
35461
35462 /* This will work as long as patching hasn't happened yet
35463 @@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35464 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35465 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35466 .set_pgd = xen_set_pgd_hyper,
35467 + .set_pgd_batched = xen_set_pgd_hyper,
35468
35469 .alloc_pud = xen_alloc_pmd_init,
35470 .release_pud = xen_release_pmd_init,
35471 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35472 index a18eadd..2e2f10e 100644
35473 --- a/arch/x86/xen/smp.c
35474 +++ b/arch/x86/xen/smp.c
35475 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35476
35477 if (xen_pv_domain()) {
35478 if (!xen_feature(XENFEAT_writable_page_tables))
35479 - /* We've switched to the "real" per-cpu gdt, so make
35480 - * sure the old memory can be recycled. */
35481 - make_lowmem_page_readwrite(xen_initial_gdt);
35482 -
35483 #ifdef CONFIG_X86_32
35484 /*
35485 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35486 * expects __USER_DS
35487 */
35488 - loadsegment(ds, __USER_DS);
35489 - loadsegment(es, __USER_DS);
35490 + loadsegment(ds, __KERNEL_DS);
35491 + loadsegment(es, __KERNEL_DS);
35492 #endif
35493
35494 xen_filter_cpu_maps();
35495 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35496 #ifdef CONFIG_X86_32
35497 /* Note: PVH is not yet supported on x86_32. */
35498 ctxt->user_regs.fs = __KERNEL_PERCPU;
35499 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35500 + savesegment(gs, ctxt->user_regs.gs);
35501 #endif
35502 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35503
35504 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35505 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35506 ctxt->flags = VGCF_IN_KERNEL;
35507 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35508 - ctxt->user_regs.ds = __USER_DS;
35509 - ctxt->user_regs.es = __USER_DS;
35510 + ctxt->user_regs.ds = __KERNEL_DS;
35511 + ctxt->user_regs.es = __KERNEL_DS;
35512 ctxt->user_regs.ss = __KERNEL_DS;
35513
35514 xen_copy_trap_info(ctxt->trap_ctxt);
35515 @@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35516 int rc;
35517
35518 per_cpu(current_task, cpu) = idle;
35519 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35520 #ifdef CONFIG_X86_32
35521 irq_ctx_init(cpu);
35522 #else
35523 clear_tsk_thread_flag(idle, TIF_FORK);
35524 - per_cpu(kernel_stack, cpu) =
35525 - (unsigned long)task_stack_page(idle) -
35526 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35527 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35528 #endif
35529 xen_setup_runstate_info(cpu);
35530 xen_setup_timer(cpu);
35531 @@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35532
35533 void __init xen_smp_init(void)
35534 {
35535 - smp_ops = xen_smp_ops;
35536 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35537 xen_fill_possible_map();
35538 }
35539
35540 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35541 index 33ca6e4..0ded929 100644
35542 --- a/arch/x86/xen/xen-asm_32.S
35543 +++ b/arch/x86/xen/xen-asm_32.S
35544 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35545 ESP_OFFSET=4 # bytes pushed onto stack
35546
35547 /*
35548 - * Store vcpu_info pointer for easy access. Do it this way to
35549 - * avoid having to reload %fs
35550 + * Store vcpu_info pointer for easy access.
35551 */
35552 #ifdef CONFIG_SMP
35553 - GET_THREAD_INFO(%eax)
35554 - movl %ss:TI_cpu(%eax), %eax
35555 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35556 - mov %ss:xen_vcpu(%eax), %eax
35557 + push %fs
35558 + mov $(__KERNEL_PERCPU), %eax
35559 + mov %eax, %fs
35560 + mov PER_CPU_VAR(xen_vcpu), %eax
35561 + pop %fs
35562 #else
35563 movl %ss:xen_vcpu, %eax
35564 #endif
35565 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35566 index 485b695..fda3e7c 100644
35567 --- a/arch/x86/xen/xen-head.S
35568 +++ b/arch/x86/xen/xen-head.S
35569 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35570 #ifdef CONFIG_X86_32
35571 mov %esi,xen_start_info
35572 mov $init_thread_union+THREAD_SIZE,%esp
35573 +#ifdef CONFIG_SMP
35574 + movl $cpu_gdt_table,%edi
35575 + movl $__per_cpu_load,%eax
35576 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35577 + rorl $16,%eax
35578 + movb %al,__KERNEL_PERCPU + 4(%edi)
35579 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35580 + movl $__per_cpu_end - 1,%eax
35581 + subl $__per_cpu_start,%eax
35582 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35583 +#endif
35584 #else
35585 mov %rsi,xen_start_info
35586 mov $init_thread_union+THREAD_SIZE,%rsp
35587 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35588 index 1cb6f4c..9981524 100644
35589 --- a/arch/x86/xen/xen-ops.h
35590 +++ b/arch/x86/xen/xen-ops.h
35591 @@ -10,8 +10,6 @@
35592 extern const char xen_hypervisor_callback[];
35593 extern const char xen_failsafe_callback[];
35594
35595 -extern void *xen_initial_gdt;
35596 -
35597 struct trap_info;
35598 void xen_copy_trap_info(struct trap_info *traps);
35599
35600 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35601 index 525bd3d..ef888b1 100644
35602 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35603 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35604 @@ -119,9 +119,9 @@
35605 ----------------------------------------------------------------------*/
35606
35607 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35608 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35609 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35610 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35611 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35612
35613 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35614 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35615 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35616 index 2f33760..835e50a 100644
35617 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35618 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35619 @@ -11,6 +11,7 @@
35620 #ifndef _XTENSA_CORE_H
35621 #define _XTENSA_CORE_H
35622
35623 +#include <linux/const.h>
35624
35625 /****************************************************************************
35626 Parameters Useful for Any Code, USER or PRIVILEGED
35627 @@ -112,9 +113,9 @@
35628 ----------------------------------------------------------------------*/
35629
35630 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35631 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35632 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35633 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35634 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35635
35636 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35637 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35638 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35639 index af00795..2bb8105 100644
35640 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35641 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35642 @@ -11,6 +11,7 @@
35643 #ifndef _XTENSA_CORE_CONFIGURATION_H
35644 #define _XTENSA_CORE_CONFIGURATION_H
35645
35646 +#include <linux/const.h>
35647
35648 /****************************************************************************
35649 Parameters Useful for Any Code, USER or PRIVILEGED
35650 @@ -118,9 +119,9 @@
35651 ----------------------------------------------------------------------*/
35652
35653 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35654 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35655 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35656 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35657 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35658
35659 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35660 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35661 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35662 index 4e491d9..c8e18e4 100644
35663 --- a/block/blk-cgroup.c
35664 +++ b/block/blk-cgroup.c
35665 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35666 static struct cgroup_subsys_state *
35667 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35668 {
35669 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35670 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35671 struct blkcg *blkcg;
35672
35673 if (!parent_css) {
35674 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35675
35676 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35677 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35678 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35679 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35680 done:
35681 spin_lock_init(&blkcg->lock);
35682 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35683 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35684 index 1855bf5..af12b06 100644
35685 --- a/block/blk-iopoll.c
35686 +++ b/block/blk-iopoll.c
35687 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35688 }
35689 EXPORT_SYMBOL(blk_iopoll_complete);
35690
35691 -static void blk_iopoll_softirq(struct softirq_action *h)
35692 +static __latent_entropy void blk_iopoll_softirq(void)
35693 {
35694 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35695 int rearm = 0, budget = blk_iopoll_budget;
35696 diff --git a/block/blk-map.c b/block/blk-map.c
35697 index ae4ae10..c470b8d 100644
35698 --- a/block/blk-map.c
35699 +++ b/block/blk-map.c
35700 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35701 if (!len || !kbuf)
35702 return -EINVAL;
35703
35704 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35705 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35706 if (do_copy)
35707 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35708 else
35709 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35710 index 57790c1..5e988dd 100644
35711 --- a/block/blk-softirq.c
35712 +++ b/block/blk-softirq.c
35713 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35714 * Softirq action handler - move entries to local list and loop over them
35715 * while passing them to the queue registered handler.
35716 */
35717 -static void blk_done_softirq(struct softirq_action *h)
35718 +static __latent_entropy void blk_done_softirq(void)
35719 {
35720 struct list_head *cpu_list, local_list;
35721
35722 diff --git a/block/bsg.c b/block/bsg.c
35723 index 420a5a9..23834aa 100644
35724 --- a/block/bsg.c
35725 +++ b/block/bsg.c
35726 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35727 struct sg_io_v4 *hdr, struct bsg_device *bd,
35728 fmode_t has_write_perm)
35729 {
35730 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35731 + unsigned char *cmdptr;
35732 +
35733 if (hdr->request_len > BLK_MAX_CDB) {
35734 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35735 if (!rq->cmd)
35736 return -ENOMEM;
35737 - }
35738 + cmdptr = rq->cmd;
35739 + } else
35740 + cmdptr = tmpcmd;
35741
35742 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35743 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35744 hdr->request_len))
35745 return -EFAULT;
35746
35747 + if (cmdptr != rq->cmd)
35748 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35749 +
35750 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35751 if (blk_verify_command(rq->cmd, has_write_perm))
35752 return -EPERM;
35753 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35754 index fbd5a67..f24fd95 100644
35755 --- a/block/compat_ioctl.c
35756 +++ b/block/compat_ioctl.c
35757 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35758 cgc = compat_alloc_user_space(sizeof(*cgc));
35759 cgc32 = compat_ptr(arg);
35760
35761 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35762 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35763 get_user(data, &cgc32->buffer) ||
35764 put_user(compat_ptr(data), &cgc->buffer) ||
35765 copy_in_user(&cgc->buflen, &cgc32->buflen,
35766 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35767 err |= __get_user(f->spec1, &uf->spec1);
35768 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35769 err |= __get_user(name, &uf->name);
35770 - f->name = compat_ptr(name);
35771 + f->name = (void __force_kernel *)compat_ptr(name);
35772 if (err) {
35773 err = -EFAULT;
35774 goto out;
35775 diff --git a/block/genhd.c b/block/genhd.c
35776 index 791f419..89f21c4 100644
35777 --- a/block/genhd.c
35778 +++ b/block/genhd.c
35779 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35780
35781 /*
35782 * Register device numbers dev..(dev+range-1)
35783 - * range must be nonzero
35784 + * Noop if @range is zero.
35785 * The hash chain is sorted on range, so that subranges can override.
35786 */
35787 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35788 struct kobject *(*probe)(dev_t, int *, void *),
35789 int (*lock)(dev_t, void *), void *data)
35790 {
35791 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35792 + if (range)
35793 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35794 }
35795
35796 EXPORT_SYMBOL(blk_register_region);
35797
35798 +/* undo blk_register_region(), noop if @range is zero */
35799 void blk_unregister_region(dev_t devt, unsigned long range)
35800 {
35801 - kobj_unmap(bdev_map, devt, range);
35802 + if (range)
35803 + kobj_unmap(bdev_map, devt, range);
35804 }
35805
35806 EXPORT_SYMBOL(blk_unregister_region);
35807 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35808 index dc51f46..d5446a8 100644
35809 --- a/block/partitions/efi.c
35810 +++ b/block/partitions/efi.c
35811 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35812 if (!gpt)
35813 return NULL;
35814
35815 + if (!le32_to_cpu(gpt->num_partition_entries))
35816 + return NULL;
35817 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35818 + if (!pte)
35819 + return NULL;
35820 +
35821 count = le32_to_cpu(gpt->num_partition_entries) *
35822 le32_to_cpu(gpt->sizeof_partition_entry);
35823 - if (!count)
35824 - return NULL;
35825 - pte = kmalloc(count, GFP_KERNEL);
35826 - if (!pte)
35827 - return NULL;
35828 -
35829 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35830 (u8 *) pte, count) < count) {
35831 kfree(pte);
35832 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35833 index 2648797..92ed21f 100644
35834 --- a/block/scsi_ioctl.c
35835 +++ b/block/scsi_ioctl.c
35836 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35837 return put_user(0, p);
35838 }
35839
35840 -static int sg_get_timeout(struct request_queue *q)
35841 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35842 {
35843 return jiffies_to_clock_t(q->sg_timeout);
35844 }
35845 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35846 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35847 struct sg_io_hdr *hdr, fmode_t mode)
35848 {
35849 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35850 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35851 + unsigned char *cmdptr;
35852 +
35853 + if (rq->cmd != rq->__cmd)
35854 + cmdptr = rq->cmd;
35855 + else
35856 + cmdptr = tmpcmd;
35857 +
35858 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35859 return -EFAULT;
35860 +
35861 + if (cmdptr != rq->cmd)
35862 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35863 +
35864 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35865 return -EPERM;
35866
35867 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35868 int err;
35869 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35870 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35871 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35872 + unsigned char *cmdptr;
35873
35874 if (!sic)
35875 return -EINVAL;
35876 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35877 */
35878 err = -EFAULT;
35879 rq->cmd_len = cmdlen;
35880 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35881 +
35882 + if (rq->cmd != rq->__cmd)
35883 + cmdptr = rq->cmd;
35884 + else
35885 + cmdptr = tmpcmd;
35886 +
35887 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35888 goto error;
35889
35890 + if (rq->cmd != cmdptr)
35891 + memcpy(rq->cmd, cmdptr, cmdlen);
35892 +
35893 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35894 goto error;
35895
35896 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35897 index 7bdd61b..afec999 100644
35898 --- a/crypto/cryptd.c
35899 +++ b/crypto/cryptd.c
35900 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35901
35902 struct cryptd_blkcipher_request_ctx {
35903 crypto_completion_t complete;
35904 -};
35905 +} __no_const;
35906
35907 struct cryptd_hash_ctx {
35908 struct crypto_shash *child;
35909 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35910
35911 struct cryptd_aead_request_ctx {
35912 crypto_completion_t complete;
35913 -};
35914 +} __no_const;
35915
35916 static void cryptd_queue_worker(struct work_struct *work);
35917
35918 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35919 index 309d345..1632720 100644
35920 --- a/crypto/pcrypt.c
35921 +++ b/crypto/pcrypt.c
35922 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35923 int ret;
35924
35925 pinst->kobj.kset = pcrypt_kset;
35926 - ret = kobject_add(&pinst->kobj, NULL, name);
35927 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35928 if (!ret)
35929 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35930
35931 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35932 index 15dddc1..b61cf0c 100644
35933 --- a/drivers/acpi/acpica/hwxfsleep.c
35934 +++ b/drivers/acpi/acpica/hwxfsleep.c
35935 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35936 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35937
35938 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35939 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35940 - acpi_hw_extended_sleep},
35941 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35942 - acpi_hw_extended_wake_prep},
35943 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35944 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35945 + .extended_function = acpi_hw_extended_sleep},
35946 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35947 + .extended_function = acpi_hw_extended_wake_prep},
35948 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35949 + .extended_function = acpi_hw_extended_wake}
35950 };
35951
35952 /*
35953 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35954 index e5bcd91..74f050d 100644
35955 --- a/drivers/acpi/apei/apei-internal.h
35956 +++ b/drivers/acpi/apei/apei-internal.h
35957 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35958 struct apei_exec_ins_type {
35959 u32 flags;
35960 apei_exec_ins_func_t run;
35961 -};
35962 +} __do_const;
35963
35964 struct apei_exec_context {
35965 u32 ip;
35966 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35967 index dab7cb7..f0d2994 100644
35968 --- a/drivers/acpi/apei/ghes.c
35969 +++ b/drivers/acpi/apei/ghes.c
35970 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
35971 const struct acpi_hest_generic *generic,
35972 const struct acpi_generic_status *estatus)
35973 {
35974 - static atomic_t seqno;
35975 + static atomic_unchecked_t seqno;
35976 unsigned int curr_seqno;
35977 char pfx_seq[64];
35978
35979 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
35980 else
35981 pfx = KERN_ERR;
35982 }
35983 - curr_seqno = atomic_inc_return(&seqno);
35984 + curr_seqno = atomic_inc_return_unchecked(&seqno);
35985 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35986 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35987 pfx_seq, generic->header.source_id);
35988 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35989 index a83e3c6..c3d617f 100644
35990 --- a/drivers/acpi/bgrt.c
35991 +++ b/drivers/acpi/bgrt.c
35992 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35993 if (!bgrt_image)
35994 return -ENODEV;
35995
35996 - bin_attr_image.private = bgrt_image;
35997 - bin_attr_image.size = bgrt_image_size;
35998 + pax_open_kernel();
35999 + *(void **)&bin_attr_image.private = bgrt_image;
36000 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36001 + pax_close_kernel();
36002
36003 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36004 if (!bgrt_kobj)
36005 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36006 index afec452..c5d8b96 100644
36007 --- a/drivers/acpi/blacklist.c
36008 +++ b/drivers/acpi/blacklist.c
36009 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36010 u32 is_critical_error;
36011 };
36012
36013 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36014 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36015
36016 /*
36017 * POLICY: If *anything* doesn't work, put it on the blacklist.
36018 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36019 return 0;
36020 }
36021
36022 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36023 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36024 {
36025 .callback = dmi_disable_osi_vista,
36026 .ident = "Fujitsu Siemens",
36027 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36028 index c68e724..e863008 100644
36029 --- a/drivers/acpi/custom_method.c
36030 +++ b/drivers/acpi/custom_method.c
36031 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36032 struct acpi_table_header table;
36033 acpi_status status;
36034
36035 +#ifdef CONFIG_GRKERNSEC_KMEM
36036 + return -EPERM;
36037 +#endif
36038 +
36039 if (!(*ppos)) {
36040 /* parse the table header to get the table length */
36041 if (count <= sizeof(struct acpi_table_header))
36042 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36043 index 3dca36d..abaf070 100644
36044 --- a/drivers/acpi/processor_idle.c
36045 +++ b/drivers/acpi/processor_idle.c
36046 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36047 {
36048 int i, count = CPUIDLE_DRIVER_STATE_START;
36049 struct acpi_processor_cx *cx;
36050 - struct cpuidle_state *state;
36051 + cpuidle_state_no_const *state;
36052 struct cpuidle_driver *drv = &acpi_idle_driver;
36053
36054 if (!pr->flags.power_setup_done)
36055 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36056 index 91a32ce..d77fcaf 100644
36057 --- a/drivers/acpi/sysfs.c
36058 +++ b/drivers/acpi/sysfs.c
36059 @@ -425,11 +425,11 @@ static u32 num_counters;
36060 static struct attribute **all_attrs;
36061 static u32 acpi_gpe_count;
36062
36063 -static struct attribute_group interrupt_stats_attr_group = {
36064 +static attribute_group_no_const interrupt_stats_attr_group = {
36065 .name = "interrupts",
36066 };
36067
36068 -static struct kobj_attribute *counter_attrs;
36069 +static kobj_attribute_no_const *counter_attrs;
36070
36071 static void delete_gpe_attr_array(void)
36072 {
36073 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36074 index 36605ab..6ef6d4b 100644
36075 --- a/drivers/ata/libahci.c
36076 +++ b/drivers/ata/libahci.c
36077 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36078 }
36079 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36080
36081 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36082 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36083 struct ata_taskfile *tf, int is_cmd, u16 flags,
36084 unsigned long timeout_msec)
36085 {
36086 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36087 index 8cb2522..a815e54 100644
36088 --- a/drivers/ata/libata-core.c
36089 +++ b/drivers/ata/libata-core.c
36090 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36091 static void ata_dev_xfermask(struct ata_device *dev);
36092 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36093
36094 -atomic_t ata_print_id = ATOMIC_INIT(0);
36095 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36096
36097 struct ata_force_param {
36098 const char *name;
36099 @@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36100 struct ata_port *ap;
36101 unsigned int tag;
36102
36103 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36104 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36105 ap = qc->ap;
36106
36107 qc->flags = 0;
36108 @@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36109 struct ata_port *ap;
36110 struct ata_link *link;
36111
36112 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36113 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36114 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36115 ap = qc->ap;
36116 link = qc->dev->link;
36117 @@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36118 return;
36119
36120 spin_lock(&lock);
36121 + pax_open_kernel();
36122
36123 for (cur = ops->inherits; cur; cur = cur->inherits) {
36124 void **inherit = (void **)cur;
36125 @@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36126 if (IS_ERR(*pp))
36127 *pp = NULL;
36128
36129 - ops->inherits = NULL;
36130 + *(struct ata_port_operations **)&ops->inherits = NULL;
36131
36132 + pax_close_kernel();
36133 spin_unlock(&lock);
36134 }
36135
36136 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36137
36138 /* give ports names and add SCSI hosts */
36139 for (i = 0; i < host->n_ports; i++) {
36140 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36141 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36142 host->ports[i]->local_port_no = i + 1;
36143 }
36144
36145 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36146 index ef8567d..8bdbd03 100644
36147 --- a/drivers/ata/libata-scsi.c
36148 +++ b/drivers/ata/libata-scsi.c
36149 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36150
36151 if (rc)
36152 return rc;
36153 - ap->print_id = atomic_inc_return(&ata_print_id);
36154 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36155 return 0;
36156 }
36157 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36158 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36159 index 45b5ab3..98446b8 100644
36160 --- a/drivers/ata/libata.h
36161 +++ b/drivers/ata/libata.h
36162 @@ -53,7 +53,7 @@ enum {
36163 ATA_DNXFER_QUIET = (1 << 31),
36164 };
36165
36166 -extern atomic_t ata_print_id;
36167 +extern atomic_unchecked_t ata_print_id;
36168 extern int atapi_passthru16;
36169 extern int libata_fua;
36170 extern int libata_noacpi;
36171 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36172 index 73492dd..ca2bff5 100644
36173 --- a/drivers/ata/pata_arasan_cf.c
36174 +++ b/drivers/ata/pata_arasan_cf.c
36175 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36176 /* Handle platform specific quirks */
36177 if (quirk) {
36178 if (quirk & CF_BROKEN_PIO) {
36179 - ap->ops->set_piomode = NULL;
36180 + pax_open_kernel();
36181 + *(void **)&ap->ops->set_piomode = NULL;
36182 + pax_close_kernel();
36183 ap->pio_mask = 0;
36184 }
36185 if (quirk & CF_BROKEN_MWDMA)
36186 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36187 index f9b983a..887b9d8 100644
36188 --- a/drivers/atm/adummy.c
36189 +++ b/drivers/atm/adummy.c
36190 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36191 vcc->pop(vcc, skb);
36192 else
36193 dev_kfree_skb_any(skb);
36194 - atomic_inc(&vcc->stats->tx);
36195 + atomic_inc_unchecked(&vcc->stats->tx);
36196
36197 return 0;
36198 }
36199 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36200 index 62a7607..cc4be104 100644
36201 --- a/drivers/atm/ambassador.c
36202 +++ b/drivers/atm/ambassador.c
36203 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36204 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36205
36206 // VC layer stats
36207 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36208 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36209
36210 // free the descriptor
36211 kfree (tx_descr);
36212 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36213 dump_skb ("<<<", vc, skb);
36214
36215 // VC layer stats
36216 - atomic_inc(&atm_vcc->stats->rx);
36217 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36218 __net_timestamp(skb);
36219 // end of our responsibility
36220 atm_vcc->push (atm_vcc, skb);
36221 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36222 } else {
36223 PRINTK (KERN_INFO, "dropped over-size frame");
36224 // should we count this?
36225 - atomic_inc(&atm_vcc->stats->rx_drop);
36226 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36227 }
36228
36229 } else {
36230 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36231 }
36232
36233 if (check_area (skb->data, skb->len)) {
36234 - atomic_inc(&atm_vcc->stats->tx_err);
36235 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36236 return -ENOMEM; // ?
36237 }
36238
36239 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36240 index 0e3f8f9..765a7a5 100644
36241 --- a/drivers/atm/atmtcp.c
36242 +++ b/drivers/atm/atmtcp.c
36243 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36244 if (vcc->pop) vcc->pop(vcc,skb);
36245 else dev_kfree_skb(skb);
36246 if (dev_data) return 0;
36247 - atomic_inc(&vcc->stats->tx_err);
36248 + atomic_inc_unchecked(&vcc->stats->tx_err);
36249 return -ENOLINK;
36250 }
36251 size = skb->len+sizeof(struct atmtcp_hdr);
36252 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36253 if (!new_skb) {
36254 if (vcc->pop) vcc->pop(vcc,skb);
36255 else dev_kfree_skb(skb);
36256 - atomic_inc(&vcc->stats->tx_err);
36257 + atomic_inc_unchecked(&vcc->stats->tx_err);
36258 return -ENOBUFS;
36259 }
36260 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36261 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36262 if (vcc->pop) vcc->pop(vcc,skb);
36263 else dev_kfree_skb(skb);
36264 out_vcc->push(out_vcc,new_skb);
36265 - atomic_inc(&vcc->stats->tx);
36266 - atomic_inc(&out_vcc->stats->rx);
36267 + atomic_inc_unchecked(&vcc->stats->tx);
36268 + atomic_inc_unchecked(&out_vcc->stats->rx);
36269 return 0;
36270 }
36271
36272 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36273 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36274 read_unlock(&vcc_sklist_lock);
36275 if (!out_vcc) {
36276 - atomic_inc(&vcc->stats->tx_err);
36277 + atomic_inc_unchecked(&vcc->stats->tx_err);
36278 goto done;
36279 }
36280 skb_pull(skb,sizeof(struct atmtcp_hdr));
36281 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36282 __net_timestamp(new_skb);
36283 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36284 out_vcc->push(out_vcc,new_skb);
36285 - atomic_inc(&vcc->stats->tx);
36286 - atomic_inc(&out_vcc->stats->rx);
36287 + atomic_inc_unchecked(&vcc->stats->tx);
36288 + atomic_inc_unchecked(&out_vcc->stats->rx);
36289 done:
36290 if (vcc->pop) vcc->pop(vcc,skb);
36291 else dev_kfree_skb(skb);
36292 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36293 index b1955ba..b179940 100644
36294 --- a/drivers/atm/eni.c
36295 +++ b/drivers/atm/eni.c
36296 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36297 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36298 vcc->dev->number);
36299 length = 0;
36300 - atomic_inc(&vcc->stats->rx_err);
36301 + atomic_inc_unchecked(&vcc->stats->rx_err);
36302 }
36303 else {
36304 length = ATM_CELL_SIZE-1; /* no HEC */
36305 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36306 size);
36307 }
36308 eff = length = 0;
36309 - atomic_inc(&vcc->stats->rx_err);
36310 + atomic_inc_unchecked(&vcc->stats->rx_err);
36311 }
36312 else {
36313 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36314 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36315 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36316 vcc->dev->number,vcc->vci,length,size << 2,descr);
36317 length = eff = 0;
36318 - atomic_inc(&vcc->stats->rx_err);
36319 + atomic_inc_unchecked(&vcc->stats->rx_err);
36320 }
36321 }
36322 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36323 @@ -767,7 +767,7 @@ rx_dequeued++;
36324 vcc->push(vcc,skb);
36325 pushed++;
36326 }
36327 - atomic_inc(&vcc->stats->rx);
36328 + atomic_inc_unchecked(&vcc->stats->rx);
36329 }
36330 wake_up(&eni_dev->rx_wait);
36331 }
36332 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36333 PCI_DMA_TODEVICE);
36334 if (vcc->pop) vcc->pop(vcc,skb);
36335 else dev_kfree_skb_irq(skb);
36336 - atomic_inc(&vcc->stats->tx);
36337 + atomic_inc_unchecked(&vcc->stats->tx);
36338 wake_up(&eni_dev->tx_wait);
36339 dma_complete++;
36340 }
36341 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36342 index b41c948..a002b17 100644
36343 --- a/drivers/atm/firestream.c
36344 +++ b/drivers/atm/firestream.c
36345 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36346 }
36347 }
36348
36349 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36350 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36351
36352 fs_dprintk (FS_DEBUG_TXMEM, "i");
36353 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36354 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36355 #endif
36356 skb_put (skb, qe->p1 & 0xffff);
36357 ATM_SKB(skb)->vcc = atm_vcc;
36358 - atomic_inc(&atm_vcc->stats->rx);
36359 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36360 __net_timestamp(skb);
36361 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36362 atm_vcc->push (atm_vcc, skb);
36363 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36364 kfree (pe);
36365 }
36366 if (atm_vcc)
36367 - atomic_inc(&atm_vcc->stats->rx_drop);
36368 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36369 break;
36370 case 0x1f: /* Reassembly abort: no buffers. */
36371 /* Silently increment error counter. */
36372 if (atm_vcc)
36373 - atomic_inc(&atm_vcc->stats->rx_drop);
36374 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36375 break;
36376 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36377 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36378 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36379 index 204814e..cede831 100644
36380 --- a/drivers/atm/fore200e.c
36381 +++ b/drivers/atm/fore200e.c
36382 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36383 #endif
36384 /* check error condition */
36385 if (*entry->status & STATUS_ERROR)
36386 - atomic_inc(&vcc->stats->tx_err);
36387 + atomic_inc_unchecked(&vcc->stats->tx_err);
36388 else
36389 - atomic_inc(&vcc->stats->tx);
36390 + atomic_inc_unchecked(&vcc->stats->tx);
36391 }
36392 }
36393
36394 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36395 if (skb == NULL) {
36396 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36397
36398 - atomic_inc(&vcc->stats->rx_drop);
36399 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36400 return -ENOMEM;
36401 }
36402
36403 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36404
36405 dev_kfree_skb_any(skb);
36406
36407 - atomic_inc(&vcc->stats->rx_drop);
36408 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36409 return -ENOMEM;
36410 }
36411
36412 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36413
36414 vcc->push(vcc, skb);
36415 - atomic_inc(&vcc->stats->rx);
36416 + atomic_inc_unchecked(&vcc->stats->rx);
36417
36418 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36419
36420 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36421 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36422 fore200e->atm_dev->number,
36423 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36424 - atomic_inc(&vcc->stats->rx_err);
36425 + atomic_inc_unchecked(&vcc->stats->rx_err);
36426 }
36427 }
36428
36429 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36430 goto retry_here;
36431 }
36432
36433 - atomic_inc(&vcc->stats->tx_err);
36434 + atomic_inc_unchecked(&vcc->stats->tx_err);
36435
36436 fore200e->tx_sat++;
36437 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36438 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36439 index aa6be26..f70a785 100644
36440 --- a/drivers/atm/he.c
36441 +++ b/drivers/atm/he.c
36442 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36443
36444 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36445 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36446 - atomic_inc(&vcc->stats->rx_drop);
36447 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36448 goto return_host_buffers;
36449 }
36450
36451 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36452 RBRQ_LEN_ERR(he_dev->rbrq_head)
36453 ? "LEN_ERR" : "",
36454 vcc->vpi, vcc->vci);
36455 - atomic_inc(&vcc->stats->rx_err);
36456 + atomic_inc_unchecked(&vcc->stats->rx_err);
36457 goto return_host_buffers;
36458 }
36459
36460 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36461 vcc->push(vcc, skb);
36462 spin_lock(&he_dev->global_lock);
36463
36464 - atomic_inc(&vcc->stats->rx);
36465 + atomic_inc_unchecked(&vcc->stats->rx);
36466
36467 return_host_buffers:
36468 ++pdus_assembled;
36469 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36470 tpd->vcc->pop(tpd->vcc, tpd->skb);
36471 else
36472 dev_kfree_skb_any(tpd->skb);
36473 - atomic_inc(&tpd->vcc->stats->tx_err);
36474 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36475 }
36476 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36477 return;
36478 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36479 vcc->pop(vcc, skb);
36480 else
36481 dev_kfree_skb_any(skb);
36482 - atomic_inc(&vcc->stats->tx_err);
36483 + atomic_inc_unchecked(&vcc->stats->tx_err);
36484 return -EINVAL;
36485 }
36486
36487 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36488 vcc->pop(vcc, skb);
36489 else
36490 dev_kfree_skb_any(skb);
36491 - atomic_inc(&vcc->stats->tx_err);
36492 + atomic_inc_unchecked(&vcc->stats->tx_err);
36493 return -EINVAL;
36494 }
36495 #endif
36496 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36497 vcc->pop(vcc, skb);
36498 else
36499 dev_kfree_skb_any(skb);
36500 - atomic_inc(&vcc->stats->tx_err);
36501 + atomic_inc_unchecked(&vcc->stats->tx_err);
36502 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36503 return -ENOMEM;
36504 }
36505 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36506 vcc->pop(vcc, skb);
36507 else
36508 dev_kfree_skb_any(skb);
36509 - atomic_inc(&vcc->stats->tx_err);
36510 + atomic_inc_unchecked(&vcc->stats->tx_err);
36511 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36512 return -ENOMEM;
36513 }
36514 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36515 __enqueue_tpd(he_dev, tpd, cid);
36516 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36517
36518 - atomic_inc(&vcc->stats->tx);
36519 + atomic_inc_unchecked(&vcc->stats->tx);
36520
36521 return 0;
36522 }
36523 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36524 index 1dc0519..1aadaf7 100644
36525 --- a/drivers/atm/horizon.c
36526 +++ b/drivers/atm/horizon.c
36527 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36528 {
36529 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36530 // VC layer stats
36531 - atomic_inc(&vcc->stats->rx);
36532 + atomic_inc_unchecked(&vcc->stats->rx);
36533 __net_timestamp(skb);
36534 // end of our responsibility
36535 vcc->push (vcc, skb);
36536 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36537 dev->tx_iovec = NULL;
36538
36539 // VC layer stats
36540 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36541 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36542
36543 // free the skb
36544 hrz_kfree_skb (skb);
36545 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36546 index 1bdf104..9dc44b1 100644
36547 --- a/drivers/atm/idt77252.c
36548 +++ b/drivers/atm/idt77252.c
36549 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36550 else
36551 dev_kfree_skb(skb);
36552
36553 - atomic_inc(&vcc->stats->tx);
36554 + atomic_inc_unchecked(&vcc->stats->tx);
36555 }
36556
36557 atomic_dec(&scq->used);
36558 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36559 if ((sb = dev_alloc_skb(64)) == NULL) {
36560 printk("%s: Can't allocate buffers for aal0.\n",
36561 card->name);
36562 - atomic_add(i, &vcc->stats->rx_drop);
36563 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36564 break;
36565 }
36566 if (!atm_charge(vcc, sb->truesize)) {
36567 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36568 card->name);
36569 - atomic_add(i - 1, &vcc->stats->rx_drop);
36570 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36571 dev_kfree_skb(sb);
36572 break;
36573 }
36574 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36575 ATM_SKB(sb)->vcc = vcc;
36576 __net_timestamp(sb);
36577 vcc->push(vcc, sb);
36578 - atomic_inc(&vcc->stats->rx);
36579 + atomic_inc_unchecked(&vcc->stats->rx);
36580
36581 cell += ATM_CELL_PAYLOAD;
36582 }
36583 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36584 "(CDC: %08x)\n",
36585 card->name, len, rpp->len, readl(SAR_REG_CDC));
36586 recycle_rx_pool_skb(card, rpp);
36587 - atomic_inc(&vcc->stats->rx_err);
36588 + atomic_inc_unchecked(&vcc->stats->rx_err);
36589 return;
36590 }
36591 if (stat & SAR_RSQE_CRC) {
36592 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36593 recycle_rx_pool_skb(card, rpp);
36594 - atomic_inc(&vcc->stats->rx_err);
36595 + atomic_inc_unchecked(&vcc->stats->rx_err);
36596 return;
36597 }
36598 if (skb_queue_len(&rpp->queue) > 1) {
36599 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36600 RXPRINTK("%s: Can't alloc RX skb.\n",
36601 card->name);
36602 recycle_rx_pool_skb(card, rpp);
36603 - atomic_inc(&vcc->stats->rx_err);
36604 + atomic_inc_unchecked(&vcc->stats->rx_err);
36605 return;
36606 }
36607 if (!atm_charge(vcc, skb->truesize)) {
36608 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36609 __net_timestamp(skb);
36610
36611 vcc->push(vcc, skb);
36612 - atomic_inc(&vcc->stats->rx);
36613 + atomic_inc_unchecked(&vcc->stats->rx);
36614
36615 return;
36616 }
36617 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36618 __net_timestamp(skb);
36619
36620 vcc->push(vcc, skb);
36621 - atomic_inc(&vcc->stats->rx);
36622 + atomic_inc_unchecked(&vcc->stats->rx);
36623
36624 if (skb->truesize > SAR_FB_SIZE_3)
36625 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36626 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36627 if (vcc->qos.aal != ATM_AAL0) {
36628 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36629 card->name, vpi, vci);
36630 - atomic_inc(&vcc->stats->rx_drop);
36631 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36632 goto drop;
36633 }
36634
36635 if ((sb = dev_alloc_skb(64)) == NULL) {
36636 printk("%s: Can't allocate buffers for AAL0.\n",
36637 card->name);
36638 - atomic_inc(&vcc->stats->rx_err);
36639 + atomic_inc_unchecked(&vcc->stats->rx_err);
36640 goto drop;
36641 }
36642
36643 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36644 ATM_SKB(sb)->vcc = vcc;
36645 __net_timestamp(sb);
36646 vcc->push(vcc, sb);
36647 - atomic_inc(&vcc->stats->rx);
36648 + atomic_inc_unchecked(&vcc->stats->rx);
36649
36650 drop:
36651 skb_pull(queue, 64);
36652 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36653
36654 if (vc == NULL) {
36655 printk("%s: NULL connection in send().\n", card->name);
36656 - atomic_inc(&vcc->stats->tx_err);
36657 + atomic_inc_unchecked(&vcc->stats->tx_err);
36658 dev_kfree_skb(skb);
36659 return -EINVAL;
36660 }
36661 if (!test_bit(VCF_TX, &vc->flags)) {
36662 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36663 - atomic_inc(&vcc->stats->tx_err);
36664 + atomic_inc_unchecked(&vcc->stats->tx_err);
36665 dev_kfree_skb(skb);
36666 return -EINVAL;
36667 }
36668 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36669 break;
36670 default:
36671 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36672 - atomic_inc(&vcc->stats->tx_err);
36673 + atomic_inc_unchecked(&vcc->stats->tx_err);
36674 dev_kfree_skb(skb);
36675 return -EINVAL;
36676 }
36677
36678 if (skb_shinfo(skb)->nr_frags != 0) {
36679 printk("%s: No scatter-gather yet.\n", card->name);
36680 - atomic_inc(&vcc->stats->tx_err);
36681 + atomic_inc_unchecked(&vcc->stats->tx_err);
36682 dev_kfree_skb(skb);
36683 return -EINVAL;
36684 }
36685 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36686
36687 err = queue_skb(card, vc, skb, oam);
36688 if (err) {
36689 - atomic_inc(&vcc->stats->tx_err);
36690 + atomic_inc_unchecked(&vcc->stats->tx_err);
36691 dev_kfree_skb(skb);
36692 return err;
36693 }
36694 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36695 skb = dev_alloc_skb(64);
36696 if (!skb) {
36697 printk("%s: Out of memory in send_oam().\n", card->name);
36698 - atomic_inc(&vcc->stats->tx_err);
36699 + atomic_inc_unchecked(&vcc->stats->tx_err);
36700 return -ENOMEM;
36701 }
36702 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36703 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36704 index 4217f29..88f547a 100644
36705 --- a/drivers/atm/iphase.c
36706 +++ b/drivers/atm/iphase.c
36707 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36708 status = (u_short) (buf_desc_ptr->desc_mode);
36709 if (status & (RX_CER | RX_PTE | RX_OFL))
36710 {
36711 - atomic_inc(&vcc->stats->rx_err);
36712 + atomic_inc_unchecked(&vcc->stats->rx_err);
36713 IF_ERR(printk("IA: bad packet, dropping it");)
36714 if (status & RX_CER) {
36715 IF_ERR(printk(" cause: packet CRC error\n");)
36716 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36717 len = dma_addr - buf_addr;
36718 if (len > iadev->rx_buf_sz) {
36719 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36720 - atomic_inc(&vcc->stats->rx_err);
36721 + atomic_inc_unchecked(&vcc->stats->rx_err);
36722 goto out_free_desc;
36723 }
36724
36725 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36726 ia_vcc = INPH_IA_VCC(vcc);
36727 if (ia_vcc == NULL)
36728 {
36729 - atomic_inc(&vcc->stats->rx_err);
36730 + atomic_inc_unchecked(&vcc->stats->rx_err);
36731 atm_return(vcc, skb->truesize);
36732 dev_kfree_skb_any(skb);
36733 goto INCR_DLE;
36734 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36735 if ((length > iadev->rx_buf_sz) || (length >
36736 (skb->len - sizeof(struct cpcs_trailer))))
36737 {
36738 - atomic_inc(&vcc->stats->rx_err);
36739 + atomic_inc_unchecked(&vcc->stats->rx_err);
36740 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36741 length, skb->len);)
36742 atm_return(vcc, skb->truesize);
36743 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36744
36745 IF_RX(printk("rx_dle_intr: skb push");)
36746 vcc->push(vcc,skb);
36747 - atomic_inc(&vcc->stats->rx);
36748 + atomic_inc_unchecked(&vcc->stats->rx);
36749 iadev->rx_pkt_cnt++;
36750 }
36751 INCR_DLE:
36752 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36753 {
36754 struct k_sonet_stats *stats;
36755 stats = &PRIV(_ia_dev[board])->sonet_stats;
36756 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36757 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36758 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36759 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36760 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36761 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36762 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36763 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36764 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36765 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36766 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36767 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36768 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36769 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36770 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36771 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36772 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36773 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36774 }
36775 ia_cmds.status = 0;
36776 break;
36777 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36778 if ((desc == 0) || (desc > iadev->num_tx_desc))
36779 {
36780 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36781 - atomic_inc(&vcc->stats->tx);
36782 + atomic_inc_unchecked(&vcc->stats->tx);
36783 if (vcc->pop)
36784 vcc->pop(vcc, skb);
36785 else
36786 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36787 ATM_DESC(skb) = vcc->vci;
36788 skb_queue_tail(&iadev->tx_dma_q, skb);
36789
36790 - atomic_inc(&vcc->stats->tx);
36791 + atomic_inc_unchecked(&vcc->stats->tx);
36792 iadev->tx_pkt_cnt++;
36793 /* Increment transaction counter */
36794 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36795
36796 #if 0
36797 /* add flow control logic */
36798 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36799 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36800 if (iavcc->vc_desc_cnt > 10) {
36801 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36802 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36803 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36804 index fa7d701..1e404c7 100644
36805 --- a/drivers/atm/lanai.c
36806 +++ b/drivers/atm/lanai.c
36807 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36808 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36809 lanai_endtx(lanai, lvcc);
36810 lanai_free_skb(lvcc->tx.atmvcc, skb);
36811 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36812 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36813 }
36814
36815 /* Try to fill the buffer - don't call unless there is backlog */
36816 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36817 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36818 __net_timestamp(skb);
36819 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36820 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36821 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36822 out:
36823 lvcc->rx.buf.ptr = end;
36824 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36825 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36826 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36827 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36828 lanai->stats.service_rxnotaal5++;
36829 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36830 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36831 return 0;
36832 }
36833 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36834 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36835 int bytes;
36836 read_unlock(&vcc_sklist_lock);
36837 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36838 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36839 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36840 lvcc->stats.x.aal5.service_trash++;
36841 bytes = (SERVICE_GET_END(s) * 16) -
36842 (((unsigned long) lvcc->rx.buf.ptr) -
36843 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36844 }
36845 if (s & SERVICE_STREAM) {
36846 read_unlock(&vcc_sklist_lock);
36847 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36848 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36849 lvcc->stats.x.aal5.service_stream++;
36850 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36851 "PDU on VCI %d!\n", lanai->number, vci);
36852 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36853 return 0;
36854 }
36855 DPRINTK("got rx crc error on vci %d\n", vci);
36856 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36857 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36858 lvcc->stats.x.aal5.service_rxcrc++;
36859 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36860 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36861 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36862 index 9587e95..b45c5cb 100644
36863 --- a/drivers/atm/nicstar.c
36864 +++ b/drivers/atm/nicstar.c
36865 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36866 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36867 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36868 card->index);
36869 - atomic_inc(&vcc->stats->tx_err);
36870 + atomic_inc_unchecked(&vcc->stats->tx_err);
36871 dev_kfree_skb_any(skb);
36872 return -EINVAL;
36873 }
36874 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36875 if (!vc->tx) {
36876 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36877 card->index);
36878 - atomic_inc(&vcc->stats->tx_err);
36879 + atomic_inc_unchecked(&vcc->stats->tx_err);
36880 dev_kfree_skb_any(skb);
36881 return -EINVAL;
36882 }
36883 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36884 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36885 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36886 card->index);
36887 - atomic_inc(&vcc->stats->tx_err);
36888 + atomic_inc_unchecked(&vcc->stats->tx_err);
36889 dev_kfree_skb_any(skb);
36890 return -EINVAL;
36891 }
36892
36893 if (skb_shinfo(skb)->nr_frags != 0) {
36894 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36895 - atomic_inc(&vcc->stats->tx_err);
36896 + atomic_inc_unchecked(&vcc->stats->tx_err);
36897 dev_kfree_skb_any(skb);
36898 return -EINVAL;
36899 }
36900 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36901 }
36902
36903 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36904 - atomic_inc(&vcc->stats->tx_err);
36905 + atomic_inc_unchecked(&vcc->stats->tx_err);
36906 dev_kfree_skb_any(skb);
36907 return -EIO;
36908 }
36909 - atomic_inc(&vcc->stats->tx);
36910 + atomic_inc_unchecked(&vcc->stats->tx);
36911
36912 return 0;
36913 }
36914 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36915 printk
36916 ("nicstar%d: Can't allocate buffers for aal0.\n",
36917 card->index);
36918 - atomic_add(i, &vcc->stats->rx_drop);
36919 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36920 break;
36921 }
36922 if (!atm_charge(vcc, sb->truesize)) {
36923 RXPRINTK
36924 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36925 card->index);
36926 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36927 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36928 dev_kfree_skb_any(sb);
36929 break;
36930 }
36931 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36932 ATM_SKB(sb)->vcc = vcc;
36933 __net_timestamp(sb);
36934 vcc->push(vcc, sb);
36935 - atomic_inc(&vcc->stats->rx);
36936 + atomic_inc_unchecked(&vcc->stats->rx);
36937 cell += ATM_CELL_PAYLOAD;
36938 }
36939
36940 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36941 if (iovb == NULL) {
36942 printk("nicstar%d: Out of iovec buffers.\n",
36943 card->index);
36944 - atomic_inc(&vcc->stats->rx_drop);
36945 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36946 recycle_rx_buf(card, skb);
36947 return;
36948 }
36949 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36950 small or large buffer itself. */
36951 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36952 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36953 - atomic_inc(&vcc->stats->rx_err);
36954 + atomic_inc_unchecked(&vcc->stats->rx_err);
36955 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36956 NS_MAX_IOVECS);
36957 NS_PRV_IOVCNT(iovb) = 0;
36958 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36959 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36960 card->index);
36961 which_list(card, skb);
36962 - atomic_inc(&vcc->stats->rx_err);
36963 + atomic_inc_unchecked(&vcc->stats->rx_err);
36964 recycle_rx_buf(card, skb);
36965 vc->rx_iov = NULL;
36966 recycle_iov_buf(card, iovb);
36967 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36968 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36969 card->index);
36970 which_list(card, skb);
36971 - atomic_inc(&vcc->stats->rx_err);
36972 + atomic_inc_unchecked(&vcc->stats->rx_err);
36973 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36974 NS_PRV_IOVCNT(iovb));
36975 vc->rx_iov = NULL;
36976 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36977 printk(" - PDU size mismatch.\n");
36978 else
36979 printk(".\n");
36980 - atomic_inc(&vcc->stats->rx_err);
36981 + atomic_inc_unchecked(&vcc->stats->rx_err);
36982 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36983 NS_PRV_IOVCNT(iovb));
36984 vc->rx_iov = NULL;
36985 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36986 /* skb points to a small buffer */
36987 if (!atm_charge(vcc, skb->truesize)) {
36988 push_rxbufs(card, skb);
36989 - atomic_inc(&vcc->stats->rx_drop);
36990 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36991 } else {
36992 skb_put(skb, len);
36993 dequeue_sm_buf(card, skb);
36994 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36995 ATM_SKB(skb)->vcc = vcc;
36996 __net_timestamp(skb);
36997 vcc->push(vcc, skb);
36998 - atomic_inc(&vcc->stats->rx);
36999 + atomic_inc_unchecked(&vcc->stats->rx);
37000 }
37001 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37002 struct sk_buff *sb;
37003 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37004 if (len <= NS_SMBUFSIZE) {
37005 if (!atm_charge(vcc, sb->truesize)) {
37006 push_rxbufs(card, sb);
37007 - atomic_inc(&vcc->stats->rx_drop);
37008 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37009 } else {
37010 skb_put(sb, len);
37011 dequeue_sm_buf(card, sb);
37012 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37013 ATM_SKB(sb)->vcc = vcc;
37014 __net_timestamp(sb);
37015 vcc->push(vcc, sb);
37016 - atomic_inc(&vcc->stats->rx);
37017 + atomic_inc_unchecked(&vcc->stats->rx);
37018 }
37019
37020 push_rxbufs(card, skb);
37021 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37022
37023 if (!atm_charge(vcc, skb->truesize)) {
37024 push_rxbufs(card, skb);
37025 - atomic_inc(&vcc->stats->rx_drop);
37026 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37027 } else {
37028 dequeue_lg_buf(card, skb);
37029 #ifdef NS_USE_DESTRUCTORS
37030 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37031 ATM_SKB(skb)->vcc = vcc;
37032 __net_timestamp(skb);
37033 vcc->push(vcc, skb);
37034 - atomic_inc(&vcc->stats->rx);
37035 + atomic_inc_unchecked(&vcc->stats->rx);
37036 }
37037
37038 push_rxbufs(card, sb);
37039 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37040 printk
37041 ("nicstar%d: Out of huge buffers.\n",
37042 card->index);
37043 - atomic_inc(&vcc->stats->rx_drop);
37044 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37045 recycle_iovec_rx_bufs(card,
37046 (struct iovec *)
37047 iovb->data,
37048 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37049 card->hbpool.count++;
37050 } else
37051 dev_kfree_skb_any(hb);
37052 - atomic_inc(&vcc->stats->rx_drop);
37053 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37054 } else {
37055 /* Copy the small buffer to the huge buffer */
37056 sb = (struct sk_buff *)iov->iov_base;
37057 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37058 #endif /* NS_USE_DESTRUCTORS */
37059 __net_timestamp(hb);
37060 vcc->push(vcc, hb);
37061 - atomic_inc(&vcc->stats->rx);
37062 + atomic_inc_unchecked(&vcc->stats->rx);
37063 }
37064 }
37065
37066 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37067 index e3fb496..d9646bf 100644
37068 --- a/drivers/atm/solos-pci.c
37069 +++ b/drivers/atm/solos-pci.c
37070 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37071 }
37072 atm_charge(vcc, skb->truesize);
37073 vcc->push(vcc, skb);
37074 - atomic_inc(&vcc->stats->rx);
37075 + atomic_inc_unchecked(&vcc->stats->rx);
37076 break;
37077
37078 case PKT_STATUS:
37079 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37080 vcc = SKB_CB(oldskb)->vcc;
37081
37082 if (vcc) {
37083 - atomic_inc(&vcc->stats->tx);
37084 + atomic_inc_unchecked(&vcc->stats->tx);
37085 solos_pop(vcc, oldskb);
37086 } else {
37087 dev_kfree_skb_irq(oldskb);
37088 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37089 index 0215934..ce9f5b1 100644
37090 --- a/drivers/atm/suni.c
37091 +++ b/drivers/atm/suni.c
37092 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37093
37094
37095 #define ADD_LIMITED(s,v) \
37096 - atomic_add((v),&stats->s); \
37097 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37098 + atomic_add_unchecked((v),&stats->s); \
37099 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37100
37101
37102 static void suni_hz(unsigned long from_timer)
37103 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37104 index 5120a96..e2572bd 100644
37105 --- a/drivers/atm/uPD98402.c
37106 +++ b/drivers/atm/uPD98402.c
37107 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37108 struct sonet_stats tmp;
37109 int error = 0;
37110
37111 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37112 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37113 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37114 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37115 if (zero && !error) {
37116 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37117
37118
37119 #define ADD_LIMITED(s,v) \
37120 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37121 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37122 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37123 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37124 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37125 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37126
37127
37128 static void stat_event(struct atm_dev *dev)
37129 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37130 if (reason & uPD98402_INT_PFM) stat_event(dev);
37131 if (reason & uPD98402_INT_PCO) {
37132 (void) GET(PCOCR); /* clear interrupt cause */
37133 - atomic_add(GET(HECCT),
37134 + atomic_add_unchecked(GET(HECCT),
37135 &PRIV(dev)->sonet_stats.uncorr_hcs);
37136 }
37137 if ((reason & uPD98402_INT_RFO) &&
37138 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37139 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37140 uPD98402_INT_LOS),PIMR); /* enable them */
37141 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37142 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37143 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37144 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37145 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37146 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37147 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37148 return 0;
37149 }
37150
37151 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37152 index 969c3c2..9b72956 100644
37153 --- a/drivers/atm/zatm.c
37154 +++ b/drivers/atm/zatm.c
37155 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37156 }
37157 if (!size) {
37158 dev_kfree_skb_irq(skb);
37159 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37160 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37161 continue;
37162 }
37163 if (!atm_charge(vcc,skb->truesize)) {
37164 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37165 skb->len = size;
37166 ATM_SKB(skb)->vcc = vcc;
37167 vcc->push(vcc,skb);
37168 - atomic_inc(&vcc->stats->rx);
37169 + atomic_inc_unchecked(&vcc->stats->rx);
37170 }
37171 zout(pos & 0xffff,MTA(mbx));
37172 #if 0 /* probably a stupid idea */
37173 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37174 skb_queue_head(&zatm_vcc->backlog,skb);
37175 break;
37176 }
37177 - atomic_inc(&vcc->stats->tx);
37178 + atomic_inc_unchecked(&vcc->stats->tx);
37179 wake_up(&zatm_vcc->tx_wait);
37180 }
37181
37182 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37183 index 59dc808..f10c74e 100644
37184 --- a/drivers/base/bus.c
37185 +++ b/drivers/base/bus.c
37186 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37187 return -EINVAL;
37188
37189 mutex_lock(&subsys->p->mutex);
37190 - list_add_tail(&sif->node, &subsys->p->interfaces);
37191 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37192 if (sif->add_dev) {
37193 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37194 while ((dev = subsys_dev_iter_next(&iter)))
37195 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37196 subsys = sif->subsys;
37197
37198 mutex_lock(&subsys->p->mutex);
37199 - list_del_init(&sif->node);
37200 + pax_list_del_init((struct list_head *)&sif->node);
37201 if (sif->remove_dev) {
37202 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37203 while ((dev = subsys_dev_iter_next(&iter)))
37204 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37205 index 25798db..15f130e 100644
37206 --- a/drivers/base/devtmpfs.c
37207 +++ b/drivers/base/devtmpfs.c
37208 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37209 if (!thread)
37210 return 0;
37211
37212 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37213 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37214 if (err)
37215 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37216 else
37217 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37218 *err = sys_unshare(CLONE_NEWNS);
37219 if (*err)
37220 goto out;
37221 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37222 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37223 if (*err)
37224 goto out;
37225 - sys_chdir("/.."); /* will traverse into overmounted root */
37226 - sys_chroot(".");
37227 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37228 + sys_chroot((char __force_user *)".");
37229 complete(&setup_done);
37230 while (1) {
37231 spin_lock(&req_lock);
37232 diff --git a/drivers/base/node.c b/drivers/base/node.c
37233 index bc9f43b..29703b8 100644
37234 --- a/drivers/base/node.c
37235 +++ b/drivers/base/node.c
37236 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37237 struct node_attr {
37238 struct device_attribute attr;
37239 enum node_states state;
37240 -};
37241 +} __do_const;
37242
37243 static ssize_t show_node_state(struct device *dev,
37244 struct device_attribute *attr, char *buf)
37245 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37246 index bfb8955..4ebff34 100644
37247 --- a/drivers/base/power/domain.c
37248 +++ b/drivers/base/power/domain.c
37249 @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37250
37251 if (dev->power.subsys_data->domain_data) {
37252 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37253 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37254 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37255 if (clear_td)
37256 - gpd_data->td = (struct gpd_timing_data){ 0 };
37257 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37258
37259 if (--gpd_data->refcount == 0) {
37260 dev->power.subsys_data->domain_data = NULL;
37261 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37262 {
37263 struct cpuidle_driver *cpuidle_drv;
37264 struct gpd_cpu_data *cpu_data;
37265 - struct cpuidle_state *idle_state;
37266 + cpuidle_state_no_const *idle_state;
37267 int ret = 0;
37268
37269 if (IS_ERR_OR_NULL(genpd) || state < 0)
37270 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37271 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37272 {
37273 struct gpd_cpu_data *cpu_data;
37274 - struct cpuidle_state *idle_state;
37275 + cpuidle_state_no_const *idle_state;
37276 int ret = 0;
37277
37278 if (IS_ERR_OR_NULL(genpd))
37279 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37280 index 03e089a..0e9560c 100644
37281 --- a/drivers/base/power/sysfs.c
37282 +++ b/drivers/base/power/sysfs.c
37283 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37284 return -EIO;
37285 }
37286 }
37287 - return sprintf(buf, p);
37288 + return sprintf(buf, "%s", p);
37289 }
37290
37291 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37292 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37293 index 2d56f41..8830f19 100644
37294 --- a/drivers/base/power/wakeup.c
37295 +++ b/drivers/base/power/wakeup.c
37296 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37297 * They need to be modified together atomically, so it's better to use one
37298 * atomic variable to hold them both.
37299 */
37300 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37301 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37302
37303 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37304 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37305
37306 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37307 {
37308 - unsigned int comb = atomic_read(&combined_event_count);
37309 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37310
37311 *cnt = (comb >> IN_PROGRESS_BITS);
37312 *inpr = comb & MAX_IN_PROGRESS;
37313 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37314 ws->start_prevent_time = ws->last_time;
37315
37316 /* Increment the counter of events in progress. */
37317 - cec = atomic_inc_return(&combined_event_count);
37318 + cec = atomic_inc_return_unchecked(&combined_event_count);
37319
37320 trace_wakeup_source_activate(ws->name, cec);
37321 }
37322 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37323 * Increment the counter of registered wakeup events and decrement the
37324 * couter of wakeup events in progress simultaneously.
37325 */
37326 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37327 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37328 trace_wakeup_source_deactivate(ws->name, cec);
37329
37330 split_counters(&cnt, &inpr);
37331 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37332 index e8d11b6..7b1b36f 100644
37333 --- a/drivers/base/syscore.c
37334 +++ b/drivers/base/syscore.c
37335 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37336 void register_syscore_ops(struct syscore_ops *ops)
37337 {
37338 mutex_lock(&syscore_ops_lock);
37339 - list_add_tail(&ops->node, &syscore_ops_list);
37340 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37341 mutex_unlock(&syscore_ops_lock);
37342 }
37343 EXPORT_SYMBOL_GPL(register_syscore_ops);
37344 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37345 void unregister_syscore_ops(struct syscore_ops *ops)
37346 {
37347 mutex_lock(&syscore_ops_lock);
37348 - list_del(&ops->node);
37349 + pax_list_del((struct list_head *)&ops->node);
37350 mutex_unlock(&syscore_ops_lock);
37351 }
37352 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37353 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37354 index 036e8ab..6221dec 100644
37355 --- a/drivers/block/cciss.c
37356 +++ b/drivers/block/cciss.c
37357 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37358 while (!list_empty(&h->reqQ)) {
37359 c = list_entry(h->reqQ.next, CommandList_struct, list);
37360 /* can't do anything if fifo is full */
37361 - if ((h->access.fifo_full(h))) {
37362 + if ((h->access->fifo_full(h))) {
37363 dev_warn(&h->pdev->dev, "fifo full\n");
37364 break;
37365 }
37366 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37367 h->Qdepth--;
37368
37369 /* Tell the controller execute command */
37370 - h->access.submit_command(h, c);
37371 + h->access->submit_command(h, c);
37372
37373 /* Put job onto the completed Q */
37374 addQ(&h->cmpQ, c);
37375 @@ -3447,17 +3447,17 @@ startio:
37376
37377 static inline unsigned long get_next_completion(ctlr_info_t *h)
37378 {
37379 - return h->access.command_completed(h);
37380 + return h->access->command_completed(h);
37381 }
37382
37383 static inline int interrupt_pending(ctlr_info_t *h)
37384 {
37385 - return h->access.intr_pending(h);
37386 + return h->access->intr_pending(h);
37387 }
37388
37389 static inline long interrupt_not_for_us(ctlr_info_t *h)
37390 {
37391 - return ((h->access.intr_pending(h) == 0) ||
37392 + return ((h->access->intr_pending(h) == 0) ||
37393 (h->interrupts_enabled == 0));
37394 }
37395
37396 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37397 u32 a;
37398
37399 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37400 - return h->access.command_completed(h);
37401 + return h->access->command_completed(h);
37402
37403 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37404 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37405 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37406 trans_support & CFGTBL_Trans_use_short_tags);
37407
37408 /* Change the access methods to the performant access methods */
37409 - h->access = SA5_performant_access;
37410 + h->access = &SA5_performant_access;
37411 h->transMethod = CFGTBL_Trans_Performant;
37412
37413 return;
37414 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37415 if (prod_index < 0)
37416 return -ENODEV;
37417 h->product_name = products[prod_index].product_name;
37418 - h->access = *(products[prod_index].access);
37419 + h->access = products[prod_index].access;
37420
37421 if (cciss_board_disabled(h)) {
37422 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37423 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37424 }
37425
37426 /* make sure the board interrupts are off */
37427 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37428 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37429 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37430 if (rc)
37431 goto clean2;
37432 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37433 * fake ones to scoop up any residual completions.
37434 */
37435 spin_lock_irqsave(&h->lock, flags);
37436 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37437 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37438 spin_unlock_irqrestore(&h->lock, flags);
37439 free_irq(h->intr[h->intr_mode], h);
37440 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37441 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37442 dev_info(&h->pdev->dev, "Board READY.\n");
37443 dev_info(&h->pdev->dev,
37444 "Waiting for stale completions to drain.\n");
37445 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37446 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37447 msleep(10000);
37448 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37449 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37450
37451 rc = controller_reset_failed(h->cfgtable);
37452 if (rc)
37453 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37454 cciss_scsi_setup(h);
37455
37456 /* Turn the interrupts on so we can service requests */
37457 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37458 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37459
37460 /* Get the firmware version */
37461 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37462 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37463 kfree(flush_buf);
37464 if (return_code != IO_OK)
37465 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37466 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37467 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37468 free_irq(h->intr[h->intr_mode], h);
37469 }
37470
37471 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37472 index 7fda30e..2f27946 100644
37473 --- a/drivers/block/cciss.h
37474 +++ b/drivers/block/cciss.h
37475 @@ -101,7 +101,7 @@ struct ctlr_info
37476 /* information about each logical volume */
37477 drive_info_struct *drv[CISS_MAX_LUN];
37478
37479 - struct access_method access;
37480 + struct access_method *access;
37481
37482 /* queue and queue Info */
37483 struct list_head reqQ;
37484 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37485 }
37486
37487 static struct access_method SA5_access = {
37488 - SA5_submit_command,
37489 - SA5_intr_mask,
37490 - SA5_fifo_full,
37491 - SA5_intr_pending,
37492 - SA5_completed,
37493 + .submit_command = SA5_submit_command,
37494 + .set_intr_mask = SA5_intr_mask,
37495 + .fifo_full = SA5_fifo_full,
37496 + .intr_pending = SA5_intr_pending,
37497 + .command_completed = SA5_completed,
37498 };
37499
37500 static struct access_method SA5B_access = {
37501 - SA5_submit_command,
37502 - SA5B_intr_mask,
37503 - SA5_fifo_full,
37504 - SA5B_intr_pending,
37505 - SA5_completed,
37506 + .submit_command = SA5_submit_command,
37507 + .set_intr_mask = SA5B_intr_mask,
37508 + .fifo_full = SA5_fifo_full,
37509 + .intr_pending = SA5B_intr_pending,
37510 + .command_completed = SA5_completed,
37511 };
37512
37513 static struct access_method SA5_performant_access = {
37514 - SA5_submit_command,
37515 - SA5_performant_intr_mask,
37516 - SA5_fifo_full,
37517 - SA5_performant_intr_pending,
37518 - SA5_performant_completed,
37519 + .submit_command = SA5_submit_command,
37520 + .set_intr_mask = SA5_performant_intr_mask,
37521 + .fifo_full = SA5_fifo_full,
37522 + .intr_pending = SA5_performant_intr_pending,
37523 + .command_completed = SA5_performant_completed,
37524 };
37525
37526 struct board_type {
37527 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37528 index 2b94403..fd6ad1f 100644
37529 --- a/drivers/block/cpqarray.c
37530 +++ b/drivers/block/cpqarray.c
37531 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37532 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37533 goto Enomem4;
37534 }
37535 - hba[i]->access.set_intr_mask(hba[i], 0);
37536 + hba[i]->access->set_intr_mask(hba[i], 0);
37537 if (request_irq(hba[i]->intr, do_ida_intr,
37538 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37539 {
37540 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37541 add_timer(&hba[i]->timer);
37542
37543 /* Enable IRQ now that spinlock and rate limit timer are set up */
37544 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37545 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37546
37547 for(j=0; j<NWD; j++) {
37548 struct gendisk *disk = ida_gendisk[i][j];
37549 @@ -694,7 +694,7 @@ DBGINFO(
37550 for(i=0; i<NR_PRODUCTS; i++) {
37551 if (board_id == products[i].board_id) {
37552 c->product_name = products[i].product_name;
37553 - c->access = *(products[i].access);
37554 + c->access = products[i].access;
37555 break;
37556 }
37557 }
37558 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37559 hba[ctlr]->intr = intr;
37560 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37561 hba[ctlr]->product_name = products[j].product_name;
37562 - hba[ctlr]->access = *(products[j].access);
37563 + hba[ctlr]->access = products[j].access;
37564 hba[ctlr]->ctlr = ctlr;
37565 hba[ctlr]->board_id = board_id;
37566 hba[ctlr]->pci_dev = NULL; /* not PCI */
37567 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37568
37569 while((c = h->reqQ) != NULL) {
37570 /* Can't do anything if we're busy */
37571 - if (h->access.fifo_full(h) == 0)
37572 + if (h->access->fifo_full(h) == 0)
37573 return;
37574
37575 /* Get the first entry from the request Q */
37576 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37577 h->Qdepth--;
37578
37579 /* Tell the controller to do our bidding */
37580 - h->access.submit_command(h, c);
37581 + h->access->submit_command(h, c);
37582
37583 /* Get onto the completion Q */
37584 addQ(&h->cmpQ, c);
37585 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37586 unsigned long flags;
37587 __u32 a,a1;
37588
37589 - istat = h->access.intr_pending(h);
37590 + istat = h->access->intr_pending(h);
37591 /* Is this interrupt for us? */
37592 if (istat == 0)
37593 return IRQ_NONE;
37594 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37595 */
37596 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37597 if (istat & FIFO_NOT_EMPTY) {
37598 - while((a = h->access.command_completed(h))) {
37599 + while((a = h->access->command_completed(h))) {
37600 a1 = a; a &= ~3;
37601 if ((c = h->cmpQ) == NULL)
37602 {
37603 @@ -1448,11 +1448,11 @@ static int sendcmd(
37604 /*
37605 * Disable interrupt
37606 */
37607 - info_p->access.set_intr_mask(info_p, 0);
37608 + info_p->access->set_intr_mask(info_p, 0);
37609 /* Make sure there is room in the command FIFO */
37610 /* Actually it should be completely empty at this time. */
37611 for (i = 200000; i > 0; i--) {
37612 - temp = info_p->access.fifo_full(info_p);
37613 + temp = info_p->access->fifo_full(info_p);
37614 if (temp != 0) {
37615 break;
37616 }
37617 @@ -1465,7 +1465,7 @@ DBG(
37618 /*
37619 * Send the cmd
37620 */
37621 - info_p->access.submit_command(info_p, c);
37622 + info_p->access->submit_command(info_p, c);
37623 complete = pollcomplete(ctlr);
37624
37625 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37626 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37627 * we check the new geometry. Then turn interrupts back on when
37628 * we're done.
37629 */
37630 - host->access.set_intr_mask(host, 0);
37631 + host->access->set_intr_mask(host, 0);
37632 getgeometry(ctlr);
37633 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37634 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37635
37636 for(i=0; i<NWD; i++) {
37637 struct gendisk *disk = ida_gendisk[ctlr][i];
37638 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37639 /* Wait (up to 2 seconds) for a command to complete */
37640
37641 for (i = 200000; i > 0; i--) {
37642 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37643 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37644 if (done == 0) {
37645 udelay(10); /* a short fixed delay */
37646 } else
37647 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37648 index be73e9d..7fbf140 100644
37649 --- a/drivers/block/cpqarray.h
37650 +++ b/drivers/block/cpqarray.h
37651 @@ -99,7 +99,7 @@ struct ctlr_info {
37652 drv_info_t drv[NWD];
37653 struct proc_dir_entry *proc;
37654
37655 - struct access_method access;
37656 + struct access_method *access;
37657
37658 cmdlist_t *reqQ;
37659 cmdlist_t *cmpQ;
37660 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37661 index 0e06f0c..c47b81d 100644
37662 --- a/drivers/block/drbd/drbd_int.h
37663 +++ b/drivers/block/drbd/drbd_int.h
37664 @@ -582,7 +582,7 @@ struct drbd_epoch {
37665 struct drbd_tconn *tconn;
37666 struct list_head list;
37667 unsigned int barrier_nr;
37668 - atomic_t epoch_size; /* increased on every request added. */
37669 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37670 atomic_t active; /* increased on every req. added, and dec on every finished. */
37671 unsigned long flags;
37672 };
37673 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37674 unsigned int al_tr_number;
37675 int al_tr_cycle;
37676 wait_queue_head_t seq_wait;
37677 - atomic_t packet_seq;
37678 + atomic_unchecked_t packet_seq;
37679 unsigned int peer_seq;
37680 spinlock_t peer_seq_lock;
37681 unsigned int minor;
37682 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37683 char __user *uoptval;
37684 int err;
37685
37686 - uoptval = (char __user __force *)optval;
37687 + uoptval = (char __force_user *)optval;
37688
37689 set_fs(KERNEL_DS);
37690 if (level == SOL_SOCKET)
37691 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37692 index 89c497c..9c736ae 100644
37693 --- a/drivers/block/drbd/drbd_interval.c
37694 +++ b/drivers/block/drbd/drbd_interval.c
37695 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37696 }
37697
37698 static const struct rb_augment_callbacks augment_callbacks = {
37699 - augment_propagate,
37700 - augment_copy,
37701 - augment_rotate,
37702 + .propagate = augment_propagate,
37703 + .copy = augment_copy,
37704 + .rotate = augment_rotate,
37705 };
37706
37707 /**
37708 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37709 index 929468e..7d934eb 100644
37710 --- a/drivers/block/drbd/drbd_main.c
37711 +++ b/drivers/block/drbd/drbd_main.c
37712 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37713 p->sector = sector;
37714 p->block_id = block_id;
37715 p->blksize = blksize;
37716 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37717 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37718 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37719 }
37720
37721 @@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37722 return -EIO;
37723 p->sector = cpu_to_be64(req->i.sector);
37724 p->block_id = (unsigned long)req;
37725 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37726 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37727 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37728 if (mdev->state.conn >= C_SYNC_SOURCE &&
37729 mdev->state.conn <= C_PAUSED_SYNC_T)
37730 @@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
37731 {
37732 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37733
37734 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37735 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37736 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37737 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37738 kfree(tconn->current_epoch);
37739
37740 idr_destroy(&tconn->volumes);
37741 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37742 index c706d50..5e1b472 100644
37743 --- a/drivers/block/drbd/drbd_nl.c
37744 +++ b/drivers/block/drbd/drbd_nl.c
37745 @@ -3440,7 +3440,7 @@ out:
37746
37747 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37748 {
37749 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37750 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37751 struct sk_buff *msg;
37752 struct drbd_genlmsghdr *d_out;
37753 unsigned seq;
37754 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37755 return;
37756 }
37757
37758 - seq = atomic_inc_return(&drbd_genl_seq);
37759 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37760 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37761 if (!msg)
37762 goto failed;
37763 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37764 index d073305..4998fea 100644
37765 --- a/drivers/block/drbd/drbd_receiver.c
37766 +++ b/drivers/block/drbd/drbd_receiver.c
37767 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37768 {
37769 int err;
37770
37771 - atomic_set(&mdev->packet_seq, 0);
37772 + atomic_set_unchecked(&mdev->packet_seq, 0);
37773 mdev->peer_seq = 0;
37774
37775 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37776 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37777 do {
37778 next_epoch = NULL;
37779
37780 - epoch_size = atomic_read(&epoch->epoch_size);
37781 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37782
37783 switch (ev & ~EV_CLEANUP) {
37784 case EV_PUT:
37785 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37786 rv = FE_DESTROYED;
37787 } else {
37788 epoch->flags = 0;
37789 - atomic_set(&epoch->epoch_size, 0);
37790 + atomic_set_unchecked(&epoch->epoch_size, 0);
37791 /* atomic_set(&epoch->active, 0); is already zero */
37792 if (rv == FE_STILL_LIVE)
37793 rv = FE_RECYCLED;
37794 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37795 conn_wait_active_ee_empty(tconn);
37796 drbd_flush(tconn);
37797
37798 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37799 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37800 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37801 if (epoch)
37802 break;
37803 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37804 }
37805
37806 epoch->flags = 0;
37807 - atomic_set(&epoch->epoch_size, 0);
37808 + atomic_set_unchecked(&epoch->epoch_size, 0);
37809 atomic_set(&epoch->active, 0);
37810
37811 spin_lock(&tconn->epoch_lock);
37812 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37813 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37814 list_add(&epoch->list, &tconn->current_epoch->list);
37815 tconn->current_epoch = epoch;
37816 tconn->epochs++;
37817 @@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37818
37819 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37820 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37821 - atomic_inc(&tconn->current_epoch->epoch_size);
37822 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37823 err2 = drbd_drain_block(mdev, pi->size);
37824 if (!err)
37825 err = err2;
37826 @@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37827
37828 spin_lock(&tconn->epoch_lock);
37829 peer_req->epoch = tconn->current_epoch;
37830 - atomic_inc(&peer_req->epoch->epoch_size);
37831 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37832 atomic_inc(&peer_req->epoch->active);
37833 spin_unlock(&tconn->epoch_lock);
37834
37835 @@ -4345,7 +4345,7 @@ struct data_cmd {
37836 int expect_payload;
37837 size_t pkt_size;
37838 int (*fn)(struct drbd_tconn *, struct packet_info *);
37839 -};
37840 +} __do_const;
37841
37842 static struct data_cmd drbd_cmd_handler[] = {
37843 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37844 @@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37845 if (!list_empty(&tconn->current_epoch->list))
37846 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37847 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37848 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37849 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37850 tconn->send.seen_any_write_yet = false;
37851
37852 conn_info(tconn, "Connection closed\n");
37853 @@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37854 struct asender_cmd {
37855 size_t pkt_size;
37856 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37857 -};
37858 +} __do_const;
37859
37860 static struct asender_cmd asender_tbl[] = {
37861 [P_PING] = { 0, got_Ping },
37862 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37863 index 66e8c3b..9b68dd9 100644
37864 --- a/drivers/block/loop.c
37865 +++ b/drivers/block/loop.c
37866 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37867
37868 file_start_write(file);
37869 set_fs(get_ds());
37870 - bw = file->f_op->write(file, buf, len, &pos);
37871 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37872 set_fs(old_fs);
37873 file_end_write(file);
37874 if (likely(bw == len))
37875 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37876 index 091b9ea..f5428f8 100644
37877 --- a/drivers/block/null_blk.c
37878 +++ b/drivers/block/null_blk.c
37879 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37880 return 0;
37881 }
37882
37883 -static struct blk_mq_ops null_mq_ops = {
37884 - .queue_rq = null_queue_rq,
37885 - .map_queue = blk_mq_map_queue,
37886 +static struct blk_mq_ops null_mq_single_ops = {
37887 + .queue_rq = null_queue_rq,
37888 + .map_queue = blk_mq_map_queue,
37889 .init_hctx = null_init_hctx,
37890 .complete = null_softirq_done_fn,
37891 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37892 + .free_hctx = blk_mq_free_single_hw_queue,
37893 +};
37894 +
37895 +static struct blk_mq_ops null_mq_per_node_ops = {
37896 + .queue_rq = null_queue_rq,
37897 + .map_queue = blk_mq_map_queue,
37898 + .init_hctx = null_init_hctx,
37899 + .alloc_hctx = null_alloc_hctx,
37900 + .free_hctx = null_free_hctx,
37901 };
37902
37903 static struct blk_mq_reg null_mq_reg = {
37904 - .ops = &null_mq_ops,
37905 + .ops = &null_mq_single_ops,
37906 .queue_depth = 64,
37907 .cmd_size = sizeof(struct nullb_cmd),
37908 .flags = BLK_MQ_F_SHOULD_MERGE,
37909 @@ -521,13 +531,8 @@ static int null_add_dev(void)
37910 null_mq_reg.queue_depth = hw_queue_depth;
37911 null_mq_reg.nr_hw_queues = submit_queues;
37912
37913 - if (use_per_node_hctx) {
37914 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37915 - null_mq_reg.ops->free_hctx = null_free_hctx;
37916 - } else {
37917 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37918 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37919 - }
37920 + if (use_per_node_hctx)
37921 + null_mq_reg.ops = &null_mq_per_node_ops;
37922
37923 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37924 } else if (queue_mode == NULL_Q_BIO) {
37925 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37926 index a2af73d..c0b8f61 100644
37927 --- a/drivers/block/pktcdvd.c
37928 +++ b/drivers/block/pktcdvd.c
37929 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37930
37931 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37932 {
37933 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37934 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37935 }
37936
37937 /*
37938 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37939 return -EROFS;
37940 }
37941 pd->settings.fp = ti.fp;
37942 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37943 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37944
37945 if (ti.nwa_v) {
37946 pd->nwa = be32_to_cpu(ti.next_writable);
37947 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37948 index e5565fb..71be10b4 100644
37949 --- a/drivers/block/smart1,2.h
37950 +++ b/drivers/block/smart1,2.h
37951 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37952 }
37953
37954 static struct access_method smart4_access = {
37955 - smart4_submit_command,
37956 - smart4_intr_mask,
37957 - smart4_fifo_full,
37958 - smart4_intr_pending,
37959 - smart4_completed,
37960 + .submit_command = smart4_submit_command,
37961 + .set_intr_mask = smart4_intr_mask,
37962 + .fifo_full = smart4_fifo_full,
37963 + .intr_pending = smart4_intr_pending,
37964 + .command_completed = smart4_completed,
37965 };
37966
37967 /*
37968 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37969 }
37970
37971 static struct access_method smart2_access = {
37972 - smart2_submit_command,
37973 - smart2_intr_mask,
37974 - smart2_fifo_full,
37975 - smart2_intr_pending,
37976 - smart2_completed,
37977 + .submit_command = smart2_submit_command,
37978 + .set_intr_mask = smart2_intr_mask,
37979 + .fifo_full = smart2_fifo_full,
37980 + .intr_pending = smart2_intr_pending,
37981 + .command_completed = smart2_completed,
37982 };
37983
37984 /*
37985 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37986 }
37987
37988 static struct access_method smart2e_access = {
37989 - smart2e_submit_command,
37990 - smart2e_intr_mask,
37991 - smart2e_fifo_full,
37992 - smart2e_intr_pending,
37993 - smart2e_completed,
37994 + .submit_command = smart2e_submit_command,
37995 + .set_intr_mask = smart2e_intr_mask,
37996 + .fifo_full = smart2e_fifo_full,
37997 + .intr_pending = smart2e_intr_pending,
37998 + .command_completed = smart2e_completed,
37999 };
38000
38001 /*
38002 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38003 }
38004
38005 static struct access_method smart1_access = {
38006 - smart1_submit_command,
38007 - smart1_intr_mask,
38008 - smart1_fifo_full,
38009 - smart1_intr_pending,
38010 - smart1_completed,
38011 + .submit_command = smart1_submit_command,
38012 + .set_intr_mask = smart1_intr_mask,
38013 + .fifo_full = smart1_fifo_full,
38014 + .intr_pending = smart1_intr_pending,
38015 + .command_completed = smart1_completed,
38016 };
38017 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38018 index f038dba..bb74c08 100644
38019 --- a/drivers/bluetooth/btwilink.c
38020 +++ b/drivers/bluetooth/btwilink.c
38021 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38022
38023 static int bt_ti_probe(struct platform_device *pdev)
38024 {
38025 - static struct ti_st *hst;
38026 + struct ti_st *hst;
38027 struct hci_dev *hdev;
38028 int err;
38029
38030 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38031 index 8a3aff7..d7538c2 100644
38032 --- a/drivers/cdrom/cdrom.c
38033 +++ b/drivers/cdrom/cdrom.c
38034 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38035 ENSURE(reset, CDC_RESET);
38036 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38037 cdi->mc_flags = 0;
38038 - cdo->n_minors = 0;
38039 cdi->options = CDO_USE_FFLAGS;
38040
38041 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38042 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38043 else
38044 cdi->cdda_method = CDDA_OLD;
38045
38046 - if (!cdo->generic_packet)
38047 - cdo->generic_packet = cdrom_dummy_generic_packet;
38048 + if (!cdo->generic_packet) {
38049 + pax_open_kernel();
38050 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38051 + pax_close_kernel();
38052 + }
38053
38054 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38055 mutex_lock(&cdrom_mutex);
38056 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38057 if (cdi->exit)
38058 cdi->exit(cdi);
38059
38060 - cdi->ops->n_minors--;
38061 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38062 }
38063
38064 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38065 */
38066 nr = nframes;
38067 do {
38068 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38069 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38070 if (cgc.buffer)
38071 break;
38072
38073 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38074 struct cdrom_device_info *cdi;
38075 int ret;
38076
38077 - ret = scnprintf(info + *pos, max_size - *pos, header);
38078 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38079 if (!ret)
38080 return 1;
38081
38082 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38083 index 51e75ad..39c4c76 100644
38084 --- a/drivers/cdrom/gdrom.c
38085 +++ b/drivers/cdrom/gdrom.c
38086 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38087 .audio_ioctl = gdrom_audio_ioctl,
38088 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38089 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38090 - .n_minors = 1,
38091 };
38092
38093 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38094 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38095 index 1386749..5430258 100644
38096 --- a/drivers/char/Kconfig
38097 +++ b/drivers/char/Kconfig
38098 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38099
38100 config DEVKMEM
38101 bool "/dev/kmem virtual device support"
38102 - default y
38103 + default n
38104 + depends on !GRKERNSEC_KMEM
38105 help
38106 Say Y here if you want to support the /dev/kmem device. The
38107 /dev/kmem device is rarely used, but can be used for certain
38108 @@ -577,6 +578,7 @@ config DEVPORT
38109 bool
38110 depends on !M68K
38111 depends on ISA || PCI
38112 + depends on !GRKERNSEC_KMEM
38113 default y
38114
38115 source "drivers/s390/char/Kconfig"
38116 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38117 index a48e05b..6bac831 100644
38118 --- a/drivers/char/agp/compat_ioctl.c
38119 +++ b/drivers/char/agp/compat_ioctl.c
38120 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38121 return -ENOMEM;
38122 }
38123
38124 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38125 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38126 sizeof(*usegment) * ureserve.seg_count)) {
38127 kfree(usegment);
38128 kfree(ksegment);
38129 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38130 index 1b19239..b87b143 100644
38131 --- a/drivers/char/agp/frontend.c
38132 +++ b/drivers/char/agp/frontend.c
38133 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38134 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38135 return -EFAULT;
38136
38137 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38138 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38139 return -EFAULT;
38140
38141 client = agp_find_client_by_pid(reserve.pid);
38142 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38143 if (segment == NULL)
38144 return -ENOMEM;
38145
38146 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38147 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38148 sizeof(struct agp_segment) * reserve.seg_count)) {
38149 kfree(segment);
38150 return -EFAULT;
38151 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38152 index 4f94375..413694e 100644
38153 --- a/drivers/char/genrtc.c
38154 +++ b/drivers/char/genrtc.c
38155 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38156 switch (cmd) {
38157
38158 case RTC_PLL_GET:
38159 + memset(&pll, 0, sizeof(pll));
38160 if (get_rtc_pll(&pll))
38161 return -EINVAL;
38162 else
38163 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38164 index d5d4cd8..22d561d 100644
38165 --- a/drivers/char/hpet.c
38166 +++ b/drivers/char/hpet.c
38167 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38168 }
38169
38170 static int
38171 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38172 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38173 struct hpet_info *info)
38174 {
38175 struct hpet_timer __iomem *timer;
38176 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38177 index 86fe45c..c0ea948 100644
38178 --- a/drivers/char/hw_random/intel-rng.c
38179 +++ b/drivers/char/hw_random/intel-rng.c
38180 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38181
38182 if (no_fwh_detect)
38183 return -ENODEV;
38184 - printk(warning);
38185 + printk("%s", warning);
38186 return -EBUSY;
38187 }
38188
38189 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38190 index ec4e10f..f2a763b 100644
38191 --- a/drivers/char/ipmi/ipmi_msghandler.c
38192 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38193 @@ -420,7 +420,7 @@ struct ipmi_smi {
38194 struct proc_dir_entry *proc_dir;
38195 char proc_dir_name[10];
38196
38197 - atomic_t stats[IPMI_NUM_STATS];
38198 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38199
38200 /*
38201 * run_to_completion duplicate of smb_info, smi_info
38202 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38203
38204
38205 #define ipmi_inc_stat(intf, stat) \
38206 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38207 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38208 #define ipmi_get_stat(intf, stat) \
38209 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38210 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38211
38212 static int is_lan_addr(struct ipmi_addr *addr)
38213 {
38214 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38215 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38216 init_waitqueue_head(&intf->waitq);
38217 for (i = 0; i < IPMI_NUM_STATS; i++)
38218 - atomic_set(&intf->stats[i], 0);
38219 + atomic_set_unchecked(&intf->stats[i], 0);
38220
38221 intf->proc_dir = NULL;
38222
38223 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38224 index 03f4189..e79f5e0 100644
38225 --- a/drivers/char/ipmi/ipmi_si_intf.c
38226 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38227 @@ -280,7 +280,7 @@ struct smi_info {
38228 unsigned char slave_addr;
38229
38230 /* Counters and things for the proc filesystem. */
38231 - atomic_t stats[SI_NUM_STATS];
38232 + atomic_unchecked_t stats[SI_NUM_STATS];
38233
38234 struct task_struct *thread;
38235
38236 @@ -289,9 +289,9 @@ struct smi_info {
38237 };
38238
38239 #define smi_inc_stat(smi, stat) \
38240 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38241 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38242 #define smi_get_stat(smi, stat) \
38243 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38244 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38245
38246 #define SI_MAX_PARMS 4
38247
38248 @@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38249 atomic_set(&new_smi->req_events, 0);
38250 new_smi->run_to_completion = 0;
38251 for (i = 0; i < SI_NUM_STATS; i++)
38252 - atomic_set(&new_smi->stats[i], 0);
38253 + atomic_set_unchecked(&new_smi->stats[i], 0);
38254
38255 new_smi->interrupt_disabled = 1;
38256 atomic_set(&new_smi->stop_operation, 0);
38257 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38258 index 92c5937..1be4e4d 100644
38259 --- a/drivers/char/mem.c
38260 +++ b/drivers/char/mem.c
38261 @@ -18,6 +18,7 @@
38262 #include <linux/raw.h>
38263 #include <linux/tty.h>
38264 #include <linux/capability.h>
38265 +#include <linux/security.h>
38266 #include <linux/ptrace.h>
38267 #include <linux/device.h>
38268 #include <linux/highmem.h>
38269 @@ -36,6 +37,10 @@
38270
38271 #define DEVPORT_MINOR 4
38272
38273 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38274 +extern const struct file_operations grsec_fops;
38275 +#endif
38276 +
38277 static inline unsigned long size_inside_page(unsigned long start,
38278 unsigned long size)
38279 {
38280 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38281
38282 while (cursor < to) {
38283 if (!devmem_is_allowed(pfn)) {
38284 +#ifdef CONFIG_GRKERNSEC_KMEM
38285 + gr_handle_mem_readwrite(from, to);
38286 +#else
38287 printk(KERN_INFO
38288 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38289 current->comm, from, to);
38290 +#endif
38291 return 0;
38292 }
38293 cursor += PAGE_SIZE;
38294 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38295 }
38296 return 1;
38297 }
38298 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38299 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38300 +{
38301 + return 0;
38302 +}
38303 #else
38304 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38305 {
38306 @@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38307
38308 while (count > 0) {
38309 unsigned long remaining;
38310 + char *temp;
38311
38312 sz = size_inside_page(p, count);
38313
38314 @@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38315 if (!ptr)
38316 return -EFAULT;
38317
38318 - remaining = copy_to_user(buf, ptr, sz);
38319 +#ifdef CONFIG_PAX_USERCOPY
38320 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38321 + if (!temp) {
38322 + unxlate_dev_mem_ptr(p, ptr);
38323 + return -ENOMEM;
38324 + }
38325 + memcpy(temp, ptr, sz);
38326 +#else
38327 + temp = ptr;
38328 +#endif
38329 +
38330 + remaining = copy_to_user(buf, temp, sz);
38331 +
38332 +#ifdef CONFIG_PAX_USERCOPY
38333 + kfree(temp);
38334 +#endif
38335 +
38336 unxlate_dev_mem_ptr(p, ptr);
38337 if (remaining)
38338 return -EFAULT;
38339 @@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38340 size_t count, loff_t *ppos)
38341 {
38342 unsigned long p = *ppos;
38343 - ssize_t low_count, read, sz;
38344 + ssize_t low_count, read, sz, err = 0;
38345 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38346 - int err = 0;
38347
38348 read = 0;
38349 if (p < (unsigned long) high_memory) {
38350 @@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38351 }
38352 #endif
38353 while (low_count > 0) {
38354 + char *temp;
38355 +
38356 sz = size_inside_page(p, low_count);
38357
38358 /*
38359 @@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38360 */
38361 kbuf = xlate_dev_kmem_ptr((char *)p);
38362
38363 - if (copy_to_user(buf, kbuf, sz))
38364 +#ifdef CONFIG_PAX_USERCOPY
38365 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38366 + if (!temp)
38367 + return -ENOMEM;
38368 + memcpy(temp, kbuf, sz);
38369 +#else
38370 + temp = kbuf;
38371 +#endif
38372 +
38373 + err = copy_to_user(buf, temp, sz);
38374 +
38375 +#ifdef CONFIG_PAX_USERCOPY
38376 + kfree(temp);
38377 +#endif
38378 +
38379 + if (err)
38380 return -EFAULT;
38381 buf += sz;
38382 p += sz;
38383 @@ -821,6 +868,9 @@ static const struct memdev {
38384 #ifdef CONFIG_PRINTK
38385 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38386 #endif
38387 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38388 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38389 +#endif
38390 };
38391
38392 static int memory_open(struct inode *inode, struct file *filp)
38393 @@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38394 continue;
38395
38396 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38397 - NULL, devlist[minor].name);
38398 + NULL, "%s", devlist[minor].name);
38399 }
38400
38401 return tty_init();
38402 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38403 index 9df78e2..01ba9ae 100644
38404 --- a/drivers/char/nvram.c
38405 +++ b/drivers/char/nvram.c
38406 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38407
38408 spin_unlock_irq(&rtc_lock);
38409
38410 - if (copy_to_user(buf, contents, tmp - contents))
38411 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38412 return -EFAULT;
38413
38414 *ppos = i;
38415 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38416 index 8320abd..ec48108 100644
38417 --- a/drivers/char/pcmcia/synclink_cs.c
38418 +++ b/drivers/char/pcmcia/synclink_cs.c
38419 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38420
38421 if (debug_level >= DEBUG_LEVEL_INFO)
38422 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38423 - __FILE__, __LINE__, info->device_name, port->count);
38424 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38425
38426 - WARN_ON(!port->count);
38427 + WARN_ON(!atomic_read(&port->count));
38428
38429 if (tty_port_close_start(port, tty, filp) == 0)
38430 goto cleanup;
38431 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38432 cleanup:
38433 if (debug_level >= DEBUG_LEVEL_INFO)
38434 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38435 - tty->driver->name, port->count);
38436 + tty->driver->name, atomic_read(&port->count));
38437 }
38438
38439 /* Wait until the transmitter is empty.
38440 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38441
38442 if (debug_level >= DEBUG_LEVEL_INFO)
38443 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38444 - __FILE__, __LINE__, tty->driver->name, port->count);
38445 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38446
38447 /* If port is closing, signal caller to try again */
38448 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38449 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38450 goto cleanup;
38451 }
38452 spin_lock(&port->lock);
38453 - port->count++;
38454 + atomic_inc(&port->count);
38455 spin_unlock(&port->lock);
38456 spin_unlock_irqrestore(&info->netlock, flags);
38457
38458 - if (port->count == 1) {
38459 + if (atomic_read(&port->count) == 1) {
38460 /* 1st open on this device, init hardware */
38461 retval = startup(info, tty);
38462 if (retval < 0)
38463 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38464 unsigned short new_crctype;
38465
38466 /* return error if TTY interface open */
38467 - if (info->port.count)
38468 + if (atomic_read(&info->port.count))
38469 return -EBUSY;
38470
38471 switch (encoding)
38472 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38473
38474 /* arbitrate between network and tty opens */
38475 spin_lock_irqsave(&info->netlock, flags);
38476 - if (info->port.count != 0 || info->netcount != 0) {
38477 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38478 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38479 spin_unlock_irqrestore(&info->netlock, flags);
38480 return -EBUSY;
38481 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38482 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38483
38484 /* return error if TTY interface open */
38485 - if (info->port.count)
38486 + if (atomic_read(&info->port.count))
38487 return -EBUSY;
38488
38489 if (cmd != SIOCWANDEV)
38490 diff --git a/drivers/char/random.c b/drivers/char/random.c
38491 index 429b75b..a7f4145 100644
38492 --- a/drivers/char/random.c
38493 +++ b/drivers/char/random.c
38494 @@ -270,10 +270,17 @@
38495 /*
38496 * Configuration information
38497 */
38498 +#ifdef CONFIG_GRKERNSEC_RANDNET
38499 +#define INPUT_POOL_SHIFT 14
38500 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38501 +#define OUTPUT_POOL_SHIFT 12
38502 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38503 +#else
38504 #define INPUT_POOL_SHIFT 12
38505 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38506 #define OUTPUT_POOL_SHIFT 10
38507 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38508 +#endif
38509 #define SEC_XFER_SIZE 512
38510 #define EXTRACT_SIZE 10
38511
38512 @@ -284,9 +291,6 @@
38513 /*
38514 * To allow fractional bits to be tracked, the entropy_count field is
38515 * denominated in units of 1/8th bits.
38516 - *
38517 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38518 - * credit_entropy_bits() needs to be 64 bits wide.
38519 */
38520 #define ENTROPY_SHIFT 3
38521 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38522 @@ -361,12 +365,19 @@ static struct poolinfo {
38523 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38524 int tap1, tap2, tap3, tap4, tap5;
38525 } poolinfo_table[] = {
38526 +#ifdef CONFIG_GRKERNSEC_RANDNET
38527 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38528 + { S(512), 411, 308, 208, 104, 1 },
38529 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38530 + { S(128), 104, 76, 51, 25, 1 },
38531 +#else
38532 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38533 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38534 { S(128), 104, 76, 51, 25, 1 },
38535 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38536 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38537 { S(32), 26, 19, 14, 7, 1 },
38538 +#endif
38539 #if 0
38540 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38541 { S(2048), 1638, 1231, 819, 411, 1 },
38542 @@ -433,9 +444,9 @@ struct entropy_store {
38543 };
38544
38545 static void push_to_pool(struct work_struct *work);
38546 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38547 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38548 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38549 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38550 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38551 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38552
38553 static struct entropy_store input_pool = {
38554 .poolinfo = &poolinfo_table[0],
38555 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38556 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38557 }
38558
38559 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38560 - ACCESS_ONCE(r->add_ptr) = i;
38561 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38562 + ACCESS_ONCE_RW(r->add_ptr) = i;
38563 smp_wmb();
38564
38565 if (out)
38566 @@ -632,7 +643,7 @@ retry:
38567 /* The +2 corresponds to the /4 in the denominator */
38568
38569 do {
38570 - unsigned int anfrac = min(pnfrac, pool_size/2);
38571 + u64 anfrac = min(pnfrac, pool_size/2);
38572 unsigned int add =
38573 ((pool_size - entropy_count)*anfrac*3) >> s;
38574
38575 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38576
38577 extract_buf(r, tmp);
38578 i = min_t(int, nbytes, EXTRACT_SIZE);
38579 - if (copy_to_user(buf, tmp, i)) {
38580 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38581 ret = -EFAULT;
38582 break;
38583 }
38584 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38585 #include <linux/sysctl.h>
38586
38587 static int min_read_thresh = 8, min_write_thresh;
38588 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38589 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38590 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38591 static char sysctl_bootid[16];
38592
38593 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38594 static int proc_do_uuid(struct ctl_table *table, int write,
38595 void __user *buffer, size_t *lenp, loff_t *ppos)
38596 {
38597 - struct ctl_table fake_table;
38598 + ctl_table_no_const fake_table;
38599 unsigned char buf[64], tmp_uuid[16], *uuid;
38600
38601 uuid = table->data;
38602 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38603 static int proc_do_entropy(ctl_table *table, int write,
38604 void __user *buffer, size_t *lenp, loff_t *ppos)
38605 {
38606 - ctl_table fake_table;
38607 + ctl_table_no_const fake_table;
38608 int entropy_count;
38609
38610 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38611 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38612 index 7cc1fe22..b602d6b 100644
38613 --- a/drivers/char/sonypi.c
38614 +++ b/drivers/char/sonypi.c
38615 @@ -54,6 +54,7 @@
38616
38617 #include <asm/uaccess.h>
38618 #include <asm/io.h>
38619 +#include <asm/local.h>
38620
38621 #include <linux/sonypi.h>
38622
38623 @@ -490,7 +491,7 @@ static struct sonypi_device {
38624 spinlock_t fifo_lock;
38625 wait_queue_head_t fifo_proc_list;
38626 struct fasync_struct *fifo_async;
38627 - int open_count;
38628 + local_t open_count;
38629 int model;
38630 struct input_dev *input_jog_dev;
38631 struct input_dev *input_key_dev;
38632 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38633 static int sonypi_misc_release(struct inode *inode, struct file *file)
38634 {
38635 mutex_lock(&sonypi_device.lock);
38636 - sonypi_device.open_count--;
38637 + local_dec(&sonypi_device.open_count);
38638 mutex_unlock(&sonypi_device.lock);
38639 return 0;
38640 }
38641 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38642 {
38643 mutex_lock(&sonypi_device.lock);
38644 /* Flush input queue on first open */
38645 - if (!sonypi_device.open_count)
38646 + if (!local_read(&sonypi_device.open_count))
38647 kfifo_reset(&sonypi_device.fifo);
38648 - sonypi_device.open_count++;
38649 + local_inc(&sonypi_device.open_count);
38650 mutex_unlock(&sonypi_device.lock);
38651
38652 return 0;
38653 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38654 index b9a57fa..5bb9e38 100644
38655 --- a/drivers/char/tpm/tpm_acpi.c
38656 +++ b/drivers/char/tpm/tpm_acpi.c
38657 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38658 virt = acpi_os_map_memory(start, len);
38659 if (!virt) {
38660 kfree(log->bios_event_log);
38661 + log->bios_event_log = NULL;
38662 printk("%s: ERROR - Unable to map memory\n", __func__);
38663 return -EIO;
38664 }
38665
38666 - memcpy_fromio(log->bios_event_log, virt, len);
38667 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38668
38669 acpi_os_unmap_memory(virt, len);
38670 return 0;
38671 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38672 index 59f7cb2..bac8b6d 100644
38673 --- a/drivers/char/tpm/tpm_eventlog.c
38674 +++ b/drivers/char/tpm/tpm_eventlog.c
38675 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38676 event = addr;
38677
38678 if ((event->event_type == 0 && event->event_size == 0) ||
38679 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38680 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38681 return NULL;
38682
38683 return addr;
38684 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38685 return NULL;
38686
38687 if ((event->event_type == 0 && event->event_size == 0) ||
38688 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38689 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38690 return NULL;
38691
38692 (*pos)++;
38693 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38694 int i;
38695
38696 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38697 - seq_putc(m, data[i]);
38698 + if (!seq_putc(m, data[i]))
38699 + return -EFAULT;
38700
38701 return 0;
38702 }
38703 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38704 index 6928d09..ff6abe8 100644
38705 --- a/drivers/char/virtio_console.c
38706 +++ b/drivers/char/virtio_console.c
38707 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38708 if (to_user) {
38709 ssize_t ret;
38710
38711 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38712 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38713 if (ret)
38714 return -EFAULT;
38715 } else {
38716 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38717 if (!port_has_data(port) && !port->host_connected)
38718 return 0;
38719
38720 - return fill_readbuf(port, ubuf, count, true);
38721 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38722 }
38723
38724 static int wait_port_writable(struct port *port, bool nonblock)
38725 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38726 index 57a078e..c17cde8 100644
38727 --- a/drivers/clk/clk-composite.c
38728 +++ b/drivers/clk/clk-composite.c
38729 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38730 struct clk *clk;
38731 struct clk_init_data init;
38732 struct clk_composite *composite;
38733 - struct clk_ops *clk_composite_ops;
38734 + clk_ops_no_const *clk_composite_ops;
38735
38736 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38737 if (!composite) {
38738 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38739 index 5983a26..65d5f46 100644
38740 --- a/drivers/clk/socfpga/clk.c
38741 +++ b/drivers/clk/socfpga/clk.c
38742 @@ -22,6 +22,7 @@
38743 #include <linux/clk-provider.h>
38744 #include <linux/io.h>
38745 #include <linux/of.h>
38746 +#include <asm/pgtable.h>
38747
38748 /* Clock Manager offsets */
38749 #define CLKMGR_CTRL 0x0
38750 @@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38751 streq(clk_name, "periph_pll") ||
38752 streq(clk_name, "sdram_pll")) {
38753 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38754 - clk_pll_ops.enable = clk_gate_ops.enable;
38755 - clk_pll_ops.disable = clk_gate_ops.disable;
38756 + pax_open_kernel();
38757 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38758 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38759 + pax_close_kernel();
38760 }
38761
38762 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38763 @@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38764 return parent_rate / div;
38765 }
38766
38767 -static struct clk_ops gateclk_ops = {
38768 +static clk_ops_no_const gateclk_ops __read_only = {
38769 .recalc_rate = socfpga_clk_recalc_rate,
38770 .get_parent = socfpga_clk_get_parent,
38771 .set_parent = socfpga_clk_set_parent,
38772 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38773 index 18448a7..d5fad43 100644
38774 --- a/drivers/cpufreq/acpi-cpufreq.c
38775 +++ b/drivers/cpufreq/acpi-cpufreq.c
38776 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38777 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38778 per_cpu(acfreq_data, cpu) = data;
38779
38780 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38781 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38782 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38783 + pax_open_kernel();
38784 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38785 + pax_close_kernel();
38786 + }
38787
38788 result = acpi_processor_register_performance(data->acpi_data, cpu);
38789 if (result)
38790 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38791 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38792 break;
38793 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38794 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38795 + pax_open_kernel();
38796 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38797 + pax_close_kernel();
38798 break;
38799 default:
38800 break;
38801 @@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
38802 if (!msrs)
38803 return;
38804
38805 - acpi_cpufreq_driver.boost_supported = true;
38806 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
38807 + pax_open_kernel();
38808 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
38809 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
38810 + pax_close_kernel();
38811 get_online_cpus();
38812
38813 /* Force all MSRs to the same value */
38814 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38815 index 199b52b..e3503bb 100644
38816 --- a/drivers/cpufreq/cpufreq.c
38817 +++ b/drivers/cpufreq/cpufreq.c
38818 @@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38819 #endif
38820
38821 mutex_lock(&cpufreq_governor_mutex);
38822 - list_del(&governor->governor_list);
38823 + pax_list_del(&governor->governor_list);
38824 mutex_unlock(&cpufreq_governor_mutex);
38825 return;
38826 }
38827 @@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38828 return NOTIFY_OK;
38829 }
38830
38831 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38832 +static struct notifier_block cpufreq_cpu_notifier = {
38833 .notifier_call = cpufreq_cpu_callback,
38834 };
38835
38836 @@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
38837 return 0;
38838
38839 write_lock_irqsave(&cpufreq_driver_lock, flags);
38840 - cpufreq_driver->boost_enabled = state;
38841 + pax_open_kernel();
38842 + *(bool *)&cpufreq_driver->boost_enabled = state;
38843 + pax_close_kernel();
38844 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38845
38846 ret = cpufreq_driver->set_boost(state);
38847 if (ret) {
38848 write_lock_irqsave(&cpufreq_driver_lock, flags);
38849 - cpufreq_driver->boost_enabled = !state;
38850 + pax_open_kernel();
38851 + *(bool *)&cpufreq_driver->boost_enabled = !state;
38852 + pax_close_kernel();
38853 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38854
38855 pr_err("%s: Cannot %s BOOST\n", __func__,
38856 @@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38857
38858 pr_debug("trying to register driver %s\n", driver_data->name);
38859
38860 - if (driver_data->setpolicy)
38861 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38862 + if (driver_data->setpolicy) {
38863 + pax_open_kernel();
38864 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38865 + pax_close_kernel();
38866 + }
38867
38868 write_lock_irqsave(&cpufreq_driver_lock, flags);
38869 if (cpufreq_driver) {
38870 @@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38871 * Check if driver provides function to enable boost -
38872 * if not, use cpufreq_boost_set_sw as default
38873 */
38874 - if (!cpufreq_driver->set_boost)
38875 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38876 + if (!cpufreq_driver->set_boost) {
38877 + pax_open_kernel();
38878 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38879 + pax_close_kernel();
38880 + }
38881
38882 ret = cpufreq_sysfs_create_file(&boost.attr);
38883 if (ret) {
38884 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38885 index ba43991..23858ffb 100644
38886 --- a/drivers/cpufreq/cpufreq_governor.c
38887 +++ b/drivers/cpufreq/cpufreq_governor.c
38888 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38889 struct dbs_data *dbs_data;
38890 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38891 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38892 - struct od_ops *od_ops = NULL;
38893 + const struct od_ops *od_ops = NULL;
38894 struct od_dbs_tuners *od_tuners = NULL;
38895 struct cs_dbs_tuners *cs_tuners = NULL;
38896 struct cpu_dbs_common_info *cpu_cdbs;
38897 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38898
38899 if ((cdata->governor == GOV_CONSERVATIVE) &&
38900 (!policy->governor->initialized)) {
38901 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38902 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38903
38904 cpufreq_register_notifier(cs_ops->notifier_block,
38905 CPUFREQ_TRANSITION_NOTIFIER);
38906 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38907
38908 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38909 (policy->governor->initialized == 1)) {
38910 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38911 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38912
38913 cpufreq_unregister_notifier(cs_ops->notifier_block,
38914 CPUFREQ_TRANSITION_NOTIFIER);
38915 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38916 index bfb9ae1..e1d3a7e 100644
38917 --- a/drivers/cpufreq/cpufreq_governor.h
38918 +++ b/drivers/cpufreq/cpufreq_governor.h
38919 @@ -205,7 +205,7 @@ struct common_dbs_data {
38920 void (*exit)(struct dbs_data *dbs_data);
38921
38922 /* Governor specific ops, see below */
38923 - void *gov_ops;
38924 + const void *gov_ops;
38925 };
38926
38927 /* Governor Per policy data */
38928 @@ -225,7 +225,7 @@ struct od_ops {
38929 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38930 unsigned int freq_next, unsigned int relation);
38931 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38932 -};
38933 +} __no_const;
38934
38935 struct cs_ops {
38936 struct notifier_block *notifier_block;
38937 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38938 index 18d4091..434be15 100644
38939 --- a/drivers/cpufreq/cpufreq_ondemand.c
38940 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38941 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38942
38943 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38944
38945 -static struct od_ops od_ops = {
38946 +static struct od_ops od_ops __read_only = {
38947 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38948 .powersave_bias_target = generic_powersave_bias_target,
38949 .freq_increase = dbs_freq_increase,
38950 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38951 (struct cpufreq_policy *, unsigned int, unsigned int),
38952 unsigned int powersave_bias)
38953 {
38954 - od_ops.powersave_bias_target = f;
38955 + pax_open_kernel();
38956 + *(void **)&od_ops.powersave_bias_target = f;
38957 + pax_close_kernel();
38958 od_set_powersave_bias(powersave_bias);
38959 }
38960 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38961
38962 void od_unregister_powersave_bias_handler(void)
38963 {
38964 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38965 + pax_open_kernel();
38966 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38967 + pax_close_kernel();
38968 od_set_powersave_bias(0);
38969 }
38970 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38971 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38972 index 2cd36b9..8f07fae 100644
38973 --- a/drivers/cpufreq/intel_pstate.c
38974 +++ b/drivers/cpufreq/intel_pstate.c
38975 @@ -124,10 +124,10 @@ struct pstate_funcs {
38976 struct cpu_defaults {
38977 struct pstate_adjust_policy pid_policy;
38978 struct pstate_funcs funcs;
38979 -};
38980 +} __do_const;
38981
38982 static struct pstate_adjust_policy pid_params;
38983 -static struct pstate_funcs pstate_funcs;
38984 +static struct pstate_funcs *pstate_funcs;
38985
38986 struct perf_limits {
38987 int no_turbo;
38988 @@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38989
38990 cpu->pstate.current_pstate = pstate;
38991
38992 - pstate_funcs.set(cpu, pstate);
38993 + pstate_funcs->set(cpu, pstate);
38994 }
38995
38996 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38997 @@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38998 {
38999 sprintf(cpu->name, "Intel 2nd generation core");
39000
39001 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39002 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39003 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39004 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39005 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39006 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39007
39008 - if (pstate_funcs.get_vid)
39009 - pstate_funcs.get_vid(cpu);
39010 + if (pstate_funcs->get_vid)
39011 + pstate_funcs->get_vid(cpu);
39012
39013 /*
39014 * goto max pstate so we don't slow up boot if we are built-in if we are
39015 @@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39016 rdmsrl(MSR_IA32_APERF, aperf);
39017 rdmsrl(MSR_IA32_MPERF, mperf);
39018
39019 - if (!pstate_funcs.get_max() ||
39020 - !pstate_funcs.get_min() ||
39021 - !pstate_funcs.get_turbo())
39022 + if (!pstate_funcs->get_max() ||
39023 + !pstate_funcs->get_min() ||
39024 + !pstate_funcs->get_turbo())
39025 return -ENODEV;
39026
39027 rdmsrl(MSR_IA32_APERF, tmp);
39028 @@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39029 return 0;
39030 }
39031
39032 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39033 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39034 {
39035 pid_params.sample_rate_ms = policy->sample_rate_ms;
39036 pid_params.p_gain_pct = policy->p_gain_pct;
39037 @@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39038
39039 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39040 {
39041 - pstate_funcs.get_max = funcs->get_max;
39042 - pstate_funcs.get_min = funcs->get_min;
39043 - pstate_funcs.get_turbo = funcs->get_turbo;
39044 - pstate_funcs.set = funcs->set;
39045 - pstate_funcs.get_vid = funcs->get_vid;
39046 + pstate_funcs = funcs;
39047 }
39048
39049 #if IS_ENABLED(CONFIG_ACPI)
39050 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39051 index 3d1cba9..0ab21d2 100644
39052 --- a/drivers/cpufreq/p4-clockmod.c
39053 +++ b/drivers/cpufreq/p4-clockmod.c
39054 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39055 case 0x0F: /* Core Duo */
39056 case 0x16: /* Celeron Core */
39057 case 0x1C: /* Atom */
39058 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39059 + pax_open_kernel();
39060 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39061 + pax_close_kernel();
39062 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39063 case 0x0D: /* Pentium M (Dothan) */
39064 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39065 + pax_open_kernel();
39066 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39067 + pax_close_kernel();
39068 /* fall through */
39069 case 0x09: /* Pentium M (Banias) */
39070 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39071 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39072
39073 /* on P-4s, the TSC runs with constant frequency independent whether
39074 * throttling is active or not. */
39075 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39076 + pax_open_kernel();
39077 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39078 + pax_close_kernel();
39079
39080 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39081 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39082 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39083 index 724ffbd..ad83692 100644
39084 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39085 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39086 @@ -18,14 +18,12 @@
39087 #include <asm/head.h>
39088 #include <asm/timer.h>
39089
39090 -static struct cpufreq_driver *cpufreq_us3_driver;
39091 -
39092 struct us3_freq_percpu_info {
39093 struct cpufreq_frequency_table table[4];
39094 };
39095
39096 /* Indexed by cpu number. */
39097 -static struct us3_freq_percpu_info *us3_freq_table;
39098 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39099
39100 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39101 * in the Safari config register.
39102 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39103
39104 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39105 {
39106 - if (cpufreq_us3_driver) {
39107 - cpufreq_frequency_table_put_attr(policy->cpu);
39108 - us3_freq_target(policy, 0);
39109 - }
39110 + cpufreq_frequency_table_put_attr(policy->cpu);
39111 + us3_freq_target(policy, 0);
39112
39113 return 0;
39114 }
39115
39116 +static int __init us3_freq_init(void);
39117 +static void __exit us3_freq_exit(void);
39118 +
39119 +static struct cpufreq_driver cpufreq_us3_driver = {
39120 + .init = us3_freq_cpu_init,
39121 + .verify = cpufreq_generic_frequency_table_verify,
39122 + .target_index = us3_freq_target,
39123 + .get = us3_freq_get,
39124 + .exit = us3_freq_cpu_exit,
39125 + .owner = THIS_MODULE,
39126 + .name = "UltraSPARC-III",
39127 +
39128 +};
39129 +
39130 static int __init us3_freq_init(void)
39131 {
39132 unsigned long manuf, impl, ver;
39133 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39134 (impl == CHEETAH_IMPL ||
39135 impl == CHEETAH_PLUS_IMPL ||
39136 impl == JAGUAR_IMPL ||
39137 - impl == PANTHER_IMPL)) {
39138 - struct cpufreq_driver *driver;
39139 -
39140 - ret = -ENOMEM;
39141 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39142 - if (!driver)
39143 - goto err_out;
39144 -
39145 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39146 - GFP_KERNEL);
39147 - if (!us3_freq_table)
39148 - goto err_out;
39149 -
39150 - driver->init = us3_freq_cpu_init;
39151 - driver->verify = cpufreq_generic_frequency_table_verify;
39152 - driver->target_index = us3_freq_target;
39153 - driver->get = us3_freq_get;
39154 - driver->exit = us3_freq_cpu_exit;
39155 - strcpy(driver->name, "UltraSPARC-III");
39156 -
39157 - cpufreq_us3_driver = driver;
39158 - ret = cpufreq_register_driver(driver);
39159 - if (ret)
39160 - goto err_out;
39161 -
39162 - return 0;
39163 -
39164 -err_out:
39165 - if (driver) {
39166 - kfree(driver);
39167 - cpufreq_us3_driver = NULL;
39168 - }
39169 - kfree(us3_freq_table);
39170 - us3_freq_table = NULL;
39171 - return ret;
39172 - }
39173 + impl == PANTHER_IMPL))
39174 + return cpufreq_register_driver(&cpufreq_us3_driver);
39175
39176 return -ENODEV;
39177 }
39178
39179 static void __exit us3_freq_exit(void)
39180 {
39181 - if (cpufreq_us3_driver) {
39182 - cpufreq_unregister_driver(cpufreq_us3_driver);
39183 - kfree(cpufreq_us3_driver);
39184 - cpufreq_us3_driver = NULL;
39185 - kfree(us3_freq_table);
39186 - us3_freq_table = NULL;
39187 - }
39188 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39189 }
39190
39191 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39192 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39193 index 4e1daca..e707b61 100644
39194 --- a/drivers/cpufreq/speedstep-centrino.c
39195 +++ b/drivers/cpufreq/speedstep-centrino.c
39196 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39197 !cpu_has(cpu, X86_FEATURE_EST))
39198 return -ENODEV;
39199
39200 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39201 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39202 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39203 + pax_open_kernel();
39204 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39205 + pax_close_kernel();
39206 + }
39207
39208 if (policy->cpu != 0)
39209 return -ENODEV;
39210 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39211 index 06dbe7c..c2c8671 100644
39212 --- a/drivers/cpuidle/driver.c
39213 +++ b/drivers/cpuidle/driver.c
39214 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39215
39216 static void poll_idle_init(struct cpuidle_driver *drv)
39217 {
39218 - struct cpuidle_state *state = &drv->states[0];
39219 + cpuidle_state_no_const *state = &drv->states[0];
39220
39221 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39222 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39223 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39224 index ca89412..a7b9c49 100644
39225 --- a/drivers/cpuidle/governor.c
39226 +++ b/drivers/cpuidle/governor.c
39227 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39228 mutex_lock(&cpuidle_lock);
39229 if (__cpuidle_find_governor(gov->name) == NULL) {
39230 ret = 0;
39231 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39232 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39233 if (!cpuidle_curr_governor ||
39234 cpuidle_curr_governor->rating < gov->rating)
39235 cpuidle_switch_governor(gov);
39236 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39237 index e918b6d..f87ea80 100644
39238 --- a/drivers/cpuidle/sysfs.c
39239 +++ b/drivers/cpuidle/sysfs.c
39240 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39241 NULL
39242 };
39243
39244 -static struct attribute_group cpuidle_attr_group = {
39245 +static attribute_group_no_const cpuidle_attr_group = {
39246 .attrs = cpuidle_default_attrs,
39247 .name = "cpuidle",
39248 };
39249 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39250 index 12fea3e..1e28f47 100644
39251 --- a/drivers/crypto/hifn_795x.c
39252 +++ b/drivers/crypto/hifn_795x.c
39253 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39254 MODULE_PARM_DESC(hifn_pll_ref,
39255 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39256
39257 -static atomic_t hifn_dev_number;
39258 +static atomic_unchecked_t hifn_dev_number;
39259
39260 #define ACRYPTO_OP_DECRYPT 0
39261 #define ACRYPTO_OP_ENCRYPT 1
39262 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39263 goto err_out_disable_pci_device;
39264
39265 snprintf(name, sizeof(name), "hifn%d",
39266 - atomic_inc_return(&hifn_dev_number)-1);
39267 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39268
39269 err = pci_request_regions(pdev, name);
39270 if (err)
39271 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39272 index a0b2f7e..1b6f028 100644
39273 --- a/drivers/devfreq/devfreq.c
39274 +++ b/drivers/devfreq/devfreq.c
39275 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39276 goto err_out;
39277 }
39278
39279 - list_add(&governor->node, &devfreq_governor_list);
39280 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39281
39282 list_for_each_entry(devfreq, &devfreq_list, node) {
39283 int ret = 0;
39284 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39285 }
39286 }
39287
39288 - list_del(&governor->node);
39289 + pax_list_del((struct list_head *)&governor->node);
39290 err_out:
39291 mutex_unlock(&devfreq_list_lock);
39292
39293 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39294 index 2e7b394..1371a64 100644
39295 --- a/drivers/dma/sh/shdma-base.c
39296 +++ b/drivers/dma/sh/shdma-base.c
39297 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39298 schan->slave_id = -EINVAL;
39299 }
39300
39301 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39302 - sdev->desc_size, GFP_KERNEL);
39303 + schan->desc = kcalloc(sdev->desc_size,
39304 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39305 if (!schan->desc) {
39306 ret = -ENOMEM;
39307 goto edescalloc;
39308 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39309 index 0d765c0..60b7480 100644
39310 --- a/drivers/dma/sh/shdmac.c
39311 +++ b/drivers/dma/sh/shdmac.c
39312 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39313 return ret;
39314 }
39315
39316 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39317 +static struct notifier_block sh_dmae_nmi_notifier = {
39318 .notifier_call = sh_dmae_nmi_handler,
39319
39320 /* Run before NMI debug handler and KGDB */
39321 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39322 index 592af5f..bb1d583 100644
39323 --- a/drivers/edac/edac_device.c
39324 +++ b/drivers/edac/edac_device.c
39325 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39326 */
39327 int edac_device_alloc_index(void)
39328 {
39329 - static atomic_t device_indexes = ATOMIC_INIT(0);
39330 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39331
39332 - return atomic_inc_return(&device_indexes) - 1;
39333 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39334 }
39335 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39336
39337 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39338 index b335c6a..db65b44 100644
39339 --- a/drivers/edac/edac_mc_sysfs.c
39340 +++ b/drivers/edac/edac_mc_sysfs.c
39341 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39342 struct dev_ch_attribute {
39343 struct device_attribute attr;
39344 int channel;
39345 -};
39346 +} __do_const;
39347
39348 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39349 struct dev_ch_attribute dev_attr_legacy_##_name = \
39350 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39351 }
39352
39353 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39354 + pax_open_kernel();
39355 if (mci->get_sdram_scrub_rate) {
39356 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39357 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39358 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39359 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39360 }
39361 if (mci->set_sdram_scrub_rate) {
39362 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39363 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39364 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39365 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39366 }
39367 + pax_close_kernel();
39368 err = device_create_file(&mci->dev,
39369 &dev_attr_sdram_scrub_rate);
39370 if (err) {
39371 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39372 index 2cf44b4d..6dd2dc7 100644
39373 --- a/drivers/edac/edac_pci.c
39374 +++ b/drivers/edac/edac_pci.c
39375 @@ -29,7 +29,7 @@
39376
39377 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39378 static LIST_HEAD(edac_pci_list);
39379 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39380 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39381
39382 /*
39383 * edac_pci_alloc_ctl_info
39384 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39385 */
39386 int edac_pci_alloc_index(void)
39387 {
39388 - return atomic_inc_return(&pci_indexes) - 1;
39389 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39390 }
39391 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39392
39393 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39394 index e8658e4..22746d6 100644
39395 --- a/drivers/edac/edac_pci_sysfs.c
39396 +++ b/drivers/edac/edac_pci_sysfs.c
39397 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39398 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39399 static int edac_pci_poll_msec = 1000; /* one second workq period */
39400
39401 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39402 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39403 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39404 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39405
39406 static struct kobject *edac_pci_top_main_kobj;
39407 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39408 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39409 void *value;
39410 ssize_t(*show) (void *, char *);
39411 ssize_t(*store) (void *, const char *, size_t);
39412 -};
39413 +} __do_const;
39414
39415 /* Set of show/store abstract level functions for PCI Parity object */
39416 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39417 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39418 edac_printk(KERN_CRIT, EDAC_PCI,
39419 "Signaled System Error on %s\n",
39420 pci_name(dev));
39421 - atomic_inc(&pci_nonparity_count);
39422 + atomic_inc_unchecked(&pci_nonparity_count);
39423 }
39424
39425 if (status & (PCI_STATUS_PARITY)) {
39426 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39427 "Master Data Parity Error on %s\n",
39428 pci_name(dev));
39429
39430 - atomic_inc(&pci_parity_count);
39431 + atomic_inc_unchecked(&pci_parity_count);
39432 }
39433
39434 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39435 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39436 "Detected Parity Error on %s\n",
39437 pci_name(dev));
39438
39439 - atomic_inc(&pci_parity_count);
39440 + atomic_inc_unchecked(&pci_parity_count);
39441 }
39442 }
39443
39444 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39445 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39446 "Signaled System Error on %s\n",
39447 pci_name(dev));
39448 - atomic_inc(&pci_nonparity_count);
39449 + atomic_inc_unchecked(&pci_nonparity_count);
39450 }
39451
39452 if (status & (PCI_STATUS_PARITY)) {
39453 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39454 "Master Data Parity Error on "
39455 "%s\n", pci_name(dev));
39456
39457 - atomic_inc(&pci_parity_count);
39458 + atomic_inc_unchecked(&pci_parity_count);
39459 }
39460
39461 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39462 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39463 "Detected Parity Error on %s\n",
39464 pci_name(dev));
39465
39466 - atomic_inc(&pci_parity_count);
39467 + atomic_inc_unchecked(&pci_parity_count);
39468 }
39469 }
39470 }
39471 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39472 if (!check_pci_errors)
39473 return;
39474
39475 - before_count = atomic_read(&pci_parity_count);
39476 + before_count = atomic_read_unchecked(&pci_parity_count);
39477
39478 /* scan all PCI devices looking for a Parity Error on devices and
39479 * bridges.
39480 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39481 /* Only if operator has selected panic on PCI Error */
39482 if (edac_pci_get_panic_on_pe()) {
39483 /* If the count is different 'after' from 'before' */
39484 - if (before_count != atomic_read(&pci_parity_count))
39485 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39486 panic("EDAC: PCI Parity Error");
39487 }
39488 }
39489 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39490 index 51b7e3a..aa8a3e8 100644
39491 --- a/drivers/edac/mce_amd.h
39492 +++ b/drivers/edac/mce_amd.h
39493 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39494 bool (*mc0_mce)(u16, u8);
39495 bool (*mc1_mce)(u16, u8);
39496 bool (*mc2_mce)(u16, u8);
39497 -};
39498 +} __no_const;
39499
39500 void amd_report_gart_errors(bool);
39501 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39502 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39503 index 57ea7f4..af06b76 100644
39504 --- a/drivers/firewire/core-card.c
39505 +++ b/drivers/firewire/core-card.c
39506 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39507 const struct fw_card_driver *driver,
39508 struct device *device)
39509 {
39510 - static atomic_t index = ATOMIC_INIT(-1);
39511 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39512
39513 - card->index = atomic_inc_return(&index);
39514 + card->index = atomic_inc_return_unchecked(&index);
39515 card->driver = driver;
39516 card->device = device;
39517 card->current_tlabel = 0;
39518 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39519
39520 void fw_core_remove_card(struct fw_card *card)
39521 {
39522 - struct fw_card_driver dummy_driver = dummy_driver_template;
39523 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39524
39525 card->driver->update_phy_reg(card, 4,
39526 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39527 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39528 index 2c6d5e1..a2cca6b 100644
39529 --- a/drivers/firewire/core-device.c
39530 +++ b/drivers/firewire/core-device.c
39531 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39532 struct config_rom_attribute {
39533 struct device_attribute attr;
39534 u32 key;
39535 -};
39536 +} __do_const;
39537
39538 static ssize_t show_immediate(struct device *dev,
39539 struct device_attribute *dattr, char *buf)
39540 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39541 index eb6935c..3cc2bfa 100644
39542 --- a/drivers/firewire/core-transaction.c
39543 +++ b/drivers/firewire/core-transaction.c
39544 @@ -38,6 +38,7 @@
39545 #include <linux/timer.h>
39546 #include <linux/types.h>
39547 #include <linux/workqueue.h>
39548 +#include <linux/sched.h>
39549
39550 #include <asm/byteorder.h>
39551
39552 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39553 index c98764a..551b520 100644
39554 --- a/drivers/firewire/core.h
39555 +++ b/drivers/firewire/core.h
39556 @@ -111,6 +111,7 @@ struct fw_card_driver {
39557
39558 int (*stop_iso)(struct fw_iso_context *ctx);
39559 };
39560 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39561
39562 void fw_card_initialize(struct fw_card *card,
39563 const struct fw_card_driver *driver, struct device *device);
39564 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39565 index 8db6632..9bbc8ca 100644
39566 --- a/drivers/firewire/ohci.c
39567 +++ b/drivers/firewire/ohci.c
39568 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39569 be32_to_cpu(ohci->next_header));
39570 }
39571
39572 +#ifndef CONFIG_GRKERNSEC
39573 if (param_remote_dma) {
39574 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39575 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39576 }
39577 +#endif
39578
39579 spin_unlock_irq(&ohci->lock);
39580
39581 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39582 unsigned long flags;
39583 int n, ret = 0;
39584
39585 +#ifndef CONFIG_GRKERNSEC
39586 if (param_remote_dma)
39587 return 0;
39588 +#endif
39589
39590 /*
39591 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39592 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39593 index 94a58a0..f5eba42 100644
39594 --- a/drivers/firmware/dmi-id.c
39595 +++ b/drivers/firmware/dmi-id.c
39596 @@ -16,7 +16,7 @@
39597 struct dmi_device_attribute{
39598 struct device_attribute dev_attr;
39599 int field;
39600 -};
39601 +} __do_const;
39602 #define to_dmi_dev_attr(_dev_attr) \
39603 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39604
39605 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39606 index 17afc51..0ef90cd 100644
39607 --- a/drivers/firmware/dmi_scan.c
39608 +++ b/drivers/firmware/dmi_scan.c
39609 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39610 if (buf == NULL)
39611 return -1;
39612
39613 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39614 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39615
39616 dmi_unmap(buf);
39617 return 0;
39618 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39619 index 1491dd4..aa910db 100644
39620 --- a/drivers/firmware/efi/cper.c
39621 +++ b/drivers/firmware/efi/cper.c
39622 @@ -41,12 +41,12 @@
39623 */
39624 u64 cper_next_record_id(void)
39625 {
39626 - static atomic64_t seq;
39627 + static atomic64_unchecked_t seq;
39628
39629 - if (!atomic64_read(&seq))
39630 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39631 + if (!atomic64_read_unchecked(&seq))
39632 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39633
39634 - return atomic64_inc_return(&seq);
39635 + return atomic64_inc_return_unchecked(&seq);
39636 }
39637 EXPORT_SYMBOL_GPL(cper_next_record_id);
39638
39639 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39640 index 4753bac..02861a2 100644
39641 --- a/drivers/firmware/efi/efi.c
39642 +++ b/drivers/firmware/efi/efi.c
39643 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39644 };
39645
39646 static struct efivars generic_efivars;
39647 -static struct efivar_operations generic_ops;
39648 +static efivar_operations_no_const generic_ops __read_only;
39649
39650 static int generic_ops_register(void)
39651 {
39652 - generic_ops.get_variable = efi.get_variable;
39653 - generic_ops.set_variable = efi.set_variable;
39654 - generic_ops.get_next_variable = efi.get_next_variable;
39655 - generic_ops.query_variable_store = efi_query_variable_store;
39656 + pax_open_kernel();
39657 + *(void **)&generic_ops.get_variable = efi.get_variable;
39658 + *(void **)&generic_ops.set_variable = efi.set_variable;
39659 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39660 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39661 + pax_close_kernel();
39662
39663 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39664 }
39665 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39666 index 3dc2482..7bd2f61 100644
39667 --- a/drivers/firmware/efi/efivars.c
39668 +++ b/drivers/firmware/efi/efivars.c
39669 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39670 static int
39671 create_efivars_bin_attributes(void)
39672 {
39673 - struct bin_attribute *attr;
39674 + bin_attribute_no_const *attr;
39675 int error;
39676
39677 /* new_var */
39678 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39679 index 2a90ba6..07f3733 100644
39680 --- a/drivers/firmware/google/memconsole.c
39681 +++ b/drivers/firmware/google/memconsole.c
39682 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39683 if (!found_memconsole())
39684 return -ENODEV;
39685
39686 - memconsole_bin_attr.size = memconsole_length;
39687 + pax_open_kernel();
39688 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39689 + pax_close_kernel();
39690
39691 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39692
39693 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39694 index 1e98a98..b444372 100644
39695 --- a/drivers/gpio/gpio-em.c
39696 +++ b/drivers/gpio/gpio-em.c
39697 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39698 struct em_gio_priv *p;
39699 struct resource *io[2], *irq[2];
39700 struct gpio_chip *gpio_chip;
39701 - struct irq_chip *irq_chip;
39702 + irq_chip_no_const *irq_chip;
39703 const char *name = dev_name(&pdev->dev);
39704 int ret;
39705
39706 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39707 index f5bf3c3..7baaa59 100644
39708 --- a/drivers/gpio/gpio-ich.c
39709 +++ b/drivers/gpio/gpio-ich.c
39710 @@ -71,7 +71,7 @@ struct ichx_desc {
39711 /* Some chipsets have quirks, let these use their own request/get */
39712 int (*request)(struct gpio_chip *chip, unsigned offset);
39713 int (*get)(struct gpio_chip *chip, unsigned offset);
39714 -};
39715 +} __do_const;
39716
39717 static struct {
39718 spinlock_t lock;
39719 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39720 index ca76ce7..68b384b 100644
39721 --- a/drivers/gpio/gpio-rcar.c
39722 +++ b/drivers/gpio/gpio-rcar.c
39723 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39724 struct gpio_rcar_priv *p;
39725 struct resource *io, *irq;
39726 struct gpio_chip *gpio_chip;
39727 - struct irq_chip *irq_chip;
39728 + irq_chip_no_const *irq_chip;
39729 const char *name = dev_name(&pdev->dev);
39730 int ret;
39731
39732 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39733 index 9902732..64b62dd 100644
39734 --- a/drivers/gpio/gpio-vr41xx.c
39735 +++ b/drivers/gpio/gpio-vr41xx.c
39736 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39737 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39738 maskl, pendl, maskh, pendh);
39739
39740 - atomic_inc(&irq_err_count);
39741 + atomic_inc_unchecked(&irq_err_count);
39742
39743 return -EINVAL;
39744 }
39745 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39746 index 3b7d32d..05c2f74 100644
39747 --- a/drivers/gpu/drm/drm_crtc.c
39748 +++ b/drivers/gpu/drm/drm_crtc.c
39749 @@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39750 goto done;
39751 }
39752
39753 - if (copy_to_user(&enum_ptr[copied].name,
39754 + if (copy_to_user(enum_ptr[copied].name,
39755 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39756 ret = -EFAULT;
39757 goto done;
39758 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39759 index 345be03..158368d 100644
39760 --- a/drivers/gpu/drm/drm_drv.c
39761 +++ b/drivers/gpu/drm/drm_drv.c
39762 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39763 /**
39764 * Copy and IOCTL return string to user space
39765 */
39766 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39767 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39768 {
39769 int len;
39770
39771 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39772 struct drm_file *file_priv = filp->private_data;
39773 struct drm_device *dev;
39774 const struct drm_ioctl_desc *ioctl = NULL;
39775 - drm_ioctl_t *func;
39776 + drm_ioctl_no_const_t func;
39777 unsigned int nr = DRM_IOCTL_NR(cmd);
39778 int retcode = -EINVAL;
39779 char stack_kdata[128];
39780 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39781 index 7f2af9a..1561914 100644
39782 --- a/drivers/gpu/drm/drm_fops.c
39783 +++ b/drivers/gpu/drm/drm_fops.c
39784 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39785 if (drm_device_is_unplugged(dev))
39786 return -ENODEV;
39787
39788 - if (!dev->open_count++)
39789 + if (local_inc_return(&dev->open_count) == 1)
39790 need_setup = 1;
39791 mutex_lock(&dev->struct_mutex);
39792 old_imapping = inode->i_mapping;
39793 @@ -127,7 +127,7 @@ err_undo:
39794 iput(container_of(dev->dev_mapping, struct inode, i_data));
39795 dev->dev_mapping = old_mapping;
39796 mutex_unlock(&dev->struct_mutex);
39797 - dev->open_count--;
39798 + local_dec(&dev->open_count);
39799 return retcode;
39800 }
39801 EXPORT_SYMBOL(drm_open);
39802 @@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
39803
39804 mutex_lock(&drm_global_mutex);
39805
39806 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39807 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39808
39809 if (dev->driver->preclose)
39810 dev->driver->preclose(dev, file_priv);
39811 @@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
39812 * Begin inline drm_release
39813 */
39814
39815 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39816 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39817 task_pid_nr(current),
39818 (long)old_encode_dev(file_priv->minor->device),
39819 - dev->open_count);
39820 + local_read(&dev->open_count));
39821
39822 /* Release any auth tokens that might point to this file_priv,
39823 (do that under the drm_global_mutex) */
39824 @@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
39825 * End inline drm_release
39826 */
39827
39828 - if (!--dev->open_count) {
39829 + if (local_dec_and_test(&dev->open_count)) {
39830 retcode = drm_lastclose(dev);
39831 if (drm_device_is_unplugged(dev))
39832 drm_put_dev(dev);
39833 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39834 index 3d2e91c..d31c4c9 100644
39835 --- a/drivers/gpu/drm/drm_global.c
39836 +++ b/drivers/gpu/drm/drm_global.c
39837 @@ -36,7 +36,7 @@
39838 struct drm_global_item {
39839 struct mutex mutex;
39840 void *object;
39841 - int refcount;
39842 + atomic_t refcount;
39843 };
39844
39845 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39846 @@ -49,7 +49,7 @@ void drm_global_init(void)
39847 struct drm_global_item *item = &glob[i];
39848 mutex_init(&item->mutex);
39849 item->object = NULL;
39850 - item->refcount = 0;
39851 + atomic_set(&item->refcount, 0);
39852 }
39853 }
39854
39855 @@ -59,7 +59,7 @@ void drm_global_release(void)
39856 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39857 struct drm_global_item *item = &glob[i];
39858 BUG_ON(item->object != NULL);
39859 - BUG_ON(item->refcount != 0);
39860 + BUG_ON(atomic_read(&item->refcount) != 0);
39861 }
39862 }
39863
39864 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39865 struct drm_global_item *item = &glob[ref->global_type];
39866
39867 mutex_lock(&item->mutex);
39868 - if (item->refcount == 0) {
39869 + if (atomic_read(&item->refcount) == 0) {
39870 item->object = kzalloc(ref->size, GFP_KERNEL);
39871 if (unlikely(item->object == NULL)) {
39872 ret = -ENOMEM;
39873 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39874 goto out_err;
39875
39876 }
39877 - ++item->refcount;
39878 + atomic_inc(&item->refcount);
39879 ref->object = item->object;
39880 mutex_unlock(&item->mutex);
39881 return 0;
39882 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39883 struct drm_global_item *item = &glob[ref->global_type];
39884
39885 mutex_lock(&item->mutex);
39886 - BUG_ON(item->refcount == 0);
39887 + BUG_ON(atomic_read(&item->refcount) == 0);
39888 BUG_ON(ref->object != item->object);
39889 - if (--item->refcount == 0) {
39890 + if (atomic_dec_and_test(&item->refcount)) {
39891 ref->release(ref);
39892 item->object = NULL;
39893 }
39894 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39895 index 7473035..a48b9c5 100644
39896 --- a/drivers/gpu/drm/drm_info.c
39897 +++ b/drivers/gpu/drm/drm_info.c
39898 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
39899 struct drm_local_map *map;
39900 struct drm_map_list *r_list;
39901
39902 - /* Hardcoded from _DRM_FRAME_BUFFER,
39903 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39904 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39905 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39906 + static const char * const types[] = {
39907 + [_DRM_FRAME_BUFFER] = "FB",
39908 + [_DRM_REGISTERS] = "REG",
39909 + [_DRM_SHM] = "SHM",
39910 + [_DRM_AGP] = "AGP",
39911 + [_DRM_SCATTER_GATHER] = "SG",
39912 + [_DRM_CONSISTENT] = "PCI"};
39913 const char *type;
39914 int i;
39915
39916 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39917 map = r_list->map;
39918 if (!map)
39919 continue;
39920 - if (map->type < 0 || map->type > 5)
39921 + if (map->type >= ARRAY_SIZE(types))
39922 type = "??";
39923 else
39924 type = types[map->type];
39925 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39926 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39927 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39928 vma->vm_flags & VM_IO ? 'i' : '-',
39929 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39930 + 0);
39931 +#else
39932 vma->vm_pgoff);
39933 +#endif
39934
39935 #if defined(__i386__)
39936 pgprot = pgprot_val(vma->vm_page_prot);
39937 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39938 index 2f4c4343..dd12cd2 100644
39939 --- a/drivers/gpu/drm/drm_ioc32.c
39940 +++ b/drivers/gpu/drm/drm_ioc32.c
39941 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39942 request = compat_alloc_user_space(nbytes);
39943 if (!access_ok(VERIFY_WRITE, request, nbytes))
39944 return -EFAULT;
39945 - list = (struct drm_buf_desc *) (request + 1);
39946 + list = (struct drm_buf_desc __user *) (request + 1);
39947
39948 if (__put_user(count, &request->count)
39949 || __put_user(list, &request->list))
39950 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39951 request = compat_alloc_user_space(nbytes);
39952 if (!access_ok(VERIFY_WRITE, request, nbytes))
39953 return -EFAULT;
39954 - list = (struct drm_buf_pub *) (request + 1);
39955 + list = (struct drm_buf_pub __user *) (request + 1);
39956
39957 if (__put_user(count, &request->count)
39958 || __put_user(list, &request->list))
39959 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39960 return 0;
39961 }
39962
39963 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39964 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39965 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39966 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39967 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39968 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39969 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39970 {
39971 unsigned int nr = DRM_IOCTL_NR(cmd);
39972 - drm_ioctl_compat_t *fn;
39973 int ret;
39974
39975 /* Assume that ioctls without an explicit compat routine will just
39976 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39977 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39978 return drm_ioctl(filp, cmd, arg);
39979
39980 - fn = drm_compat_ioctls[nr];
39981 -
39982 - if (fn != NULL)
39983 - ret = (*fn) (filp, cmd, arg);
39984 + if (drm_compat_ioctls[nr] != NULL)
39985 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39986 else
39987 ret = drm_ioctl(filp, cmd, arg);
39988
39989 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39990 index 98a33c580..8fd1c2b 100644
39991 --- a/drivers/gpu/drm/drm_stub.c
39992 +++ b/drivers/gpu/drm/drm_stub.c
39993 @@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
39994
39995 drm_device_set_unplugged(dev);
39996
39997 - if (dev->open_count == 0) {
39998 + if (local_read(&dev->open_count) == 0) {
39999 drm_put_dev(dev);
40000 }
40001 mutex_unlock(&drm_global_mutex);
40002 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40003 index c22c309..ae758c3 100644
40004 --- a/drivers/gpu/drm/drm_sysfs.c
40005 +++ b/drivers/gpu/drm/drm_sysfs.c
40006 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40007 */
40008 int drm_sysfs_device_add(struct drm_minor *minor)
40009 {
40010 - char *minor_str;
40011 + const char *minor_str;
40012 int r;
40013
40014 if (minor->type == DRM_MINOR_CONTROL)
40015 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40016 index d4d16ed..8fb0b51 100644
40017 --- a/drivers/gpu/drm/i810/i810_drv.h
40018 +++ b/drivers/gpu/drm/i810/i810_drv.h
40019 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40020 int page_flipping;
40021
40022 wait_queue_head_t irq_queue;
40023 - atomic_t irq_received;
40024 - atomic_t irq_emitted;
40025 + atomic_unchecked_t irq_received;
40026 + atomic_unchecked_t irq_emitted;
40027
40028 int front_offset;
40029 } drm_i810_private_t;
40030 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40031 index b2b46c5..feb9fe7 100644
40032 --- a/drivers/gpu/drm/i915/i915_debugfs.c
40033 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
40034 @@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40035 I915_READ(GTIMR));
40036 }
40037 seq_printf(m, "Interrupts received: %d\n",
40038 - atomic_read(&dev_priv->irq_received));
40039 + atomic_read_unchecked(&dev_priv->irq_received));
40040 for_each_ring(ring, dev_priv, i) {
40041 if (INTEL_INFO(dev)->gen >= 6) {
40042 seq_printf(m,
40043 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40044 index 15a74f9..4278889 100644
40045 --- a/drivers/gpu/drm/i915/i915_dma.c
40046 +++ b/drivers/gpu/drm/i915/i915_dma.c
40047 @@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40048 bool can_switch;
40049
40050 spin_lock(&dev->count_lock);
40051 - can_switch = (dev->open_count == 0);
40052 + can_switch = (local_read(&dev->open_count) == 0);
40053 spin_unlock(&dev->count_lock);
40054 return can_switch;
40055 }
40056 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40057 index df77e20..d3fda9f 100644
40058 --- a/drivers/gpu/drm/i915/i915_drv.h
40059 +++ b/drivers/gpu/drm/i915/i915_drv.h
40060 @@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40061 drm_dma_handle_t *status_page_dmah;
40062 struct resource mch_res;
40063
40064 - atomic_t irq_received;
40065 + atomic_unchecked_t irq_received;
40066
40067 /* protects the irq masks */
40068 spinlock_t irq_lock;
40069 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40070 index d269ecf..6d857bc 100644
40071 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40072 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40073 @@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40074
40075 static int
40076 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40077 - int count)
40078 + unsigned int count)
40079 {
40080 - int i;
40081 + unsigned int i;
40082 unsigned relocs_total = 0;
40083 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40084
40085 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40086 index 3c59584..500f2e9 100644
40087 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40088 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40089 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40090 (unsigned long)request);
40091 }
40092
40093 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40094 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40095 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40096 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40097 [DRM_I915_GETPARAM] = compat_i915_getparam,
40098 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40099 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40100 {
40101 unsigned int nr = DRM_IOCTL_NR(cmd);
40102 - drm_ioctl_compat_t *fn = NULL;
40103 int ret;
40104
40105 if (nr < DRM_COMMAND_BASE)
40106 return drm_compat_ioctl(filp, cmd, arg);
40107
40108 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40109 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40110 -
40111 - if (fn != NULL)
40112 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40113 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40114 ret = (*fn) (filp, cmd, arg);
40115 - else
40116 + } else
40117 ret = drm_ioctl(filp, cmd, arg);
40118
40119 return ret;
40120 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40121 index d554169..f4426bb 100644
40122 --- a/drivers/gpu/drm/i915/i915_irq.c
40123 +++ b/drivers/gpu/drm/i915/i915_irq.c
40124 @@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40125 int pipe;
40126 u32 pipe_stats[I915_MAX_PIPES];
40127
40128 - atomic_inc(&dev_priv->irq_received);
40129 + atomic_inc_unchecked(&dev_priv->irq_received);
40130
40131 while (true) {
40132 iir = I915_READ(VLV_IIR);
40133 @@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40134 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40135 irqreturn_t ret = IRQ_NONE;
40136
40137 - atomic_inc(&dev_priv->irq_received);
40138 + atomic_inc_unchecked(&dev_priv->irq_received);
40139
40140 /* We get interrupts on unclaimed registers, so check for this before we
40141 * do any I915_{READ,WRITE}. */
40142 @@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40143 uint32_t tmp = 0;
40144 enum pipe pipe;
40145
40146 - atomic_inc(&dev_priv->irq_received);
40147 + atomic_inc_unchecked(&dev_priv->irq_received);
40148
40149 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40150 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40151 @@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40152 {
40153 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40154
40155 - atomic_set(&dev_priv->irq_received, 0);
40156 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40157
40158 I915_WRITE(HWSTAM, 0xeffe);
40159
40160 @@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40161 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40162 int pipe;
40163
40164 - atomic_set(&dev_priv->irq_received, 0);
40165 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40166
40167 /* VLV magic */
40168 I915_WRITE(VLV_IMR, 0);
40169 @@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40170 struct drm_i915_private *dev_priv = dev->dev_private;
40171 int pipe;
40172
40173 - atomic_set(&dev_priv->irq_received, 0);
40174 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40175
40176 I915_WRITE(GEN8_MASTER_IRQ, 0);
40177 POSTING_READ(GEN8_MASTER_IRQ);
40178 @@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40179 if (!dev_priv)
40180 return;
40181
40182 - atomic_set(&dev_priv->irq_received, 0);
40183 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40184
40185 I915_WRITE(GEN8_MASTER_IRQ, 0);
40186
40187 @@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40188 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40189 int pipe;
40190
40191 - atomic_set(&dev_priv->irq_received, 0);
40192 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40193
40194 for_each_pipe(pipe)
40195 I915_WRITE(PIPESTAT(pipe), 0);
40196 @@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40197 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40198 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40199
40200 - atomic_inc(&dev_priv->irq_received);
40201 + atomic_inc_unchecked(&dev_priv->irq_received);
40202
40203 iir = I915_READ16(IIR);
40204 if (iir == 0)
40205 @@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40206 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40207 int pipe;
40208
40209 - atomic_set(&dev_priv->irq_received, 0);
40210 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40211
40212 if (I915_HAS_HOTPLUG(dev)) {
40213 I915_WRITE(PORT_HOTPLUG_EN, 0);
40214 @@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40215 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40216 int pipe, ret = IRQ_NONE;
40217
40218 - atomic_inc(&dev_priv->irq_received);
40219 + atomic_inc_unchecked(&dev_priv->irq_received);
40220
40221 iir = I915_READ(IIR);
40222 do {
40223 @@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40224 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40225 int pipe;
40226
40227 - atomic_set(&dev_priv->irq_received, 0);
40228 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40229
40230 I915_WRITE(PORT_HOTPLUG_EN, 0);
40231 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40232 @@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40233 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40234 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40235
40236 - atomic_inc(&dev_priv->irq_received);
40237 + atomic_inc_unchecked(&dev_priv->irq_received);
40238
40239 iir = I915_READ(IIR);
40240
40241 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40242 index 9b8a7c7..60f6003 100644
40243 --- a/drivers/gpu/drm/i915/intel_display.c
40244 +++ b/drivers/gpu/drm/i915/intel_display.c
40245 @@ -10776,13 +10776,13 @@ struct intel_quirk {
40246 int subsystem_vendor;
40247 int subsystem_device;
40248 void (*hook)(struct drm_device *dev);
40249 -};
40250 +} __do_const;
40251
40252 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40253 struct intel_dmi_quirk {
40254 void (*hook)(struct drm_device *dev);
40255 const struct dmi_system_id (*dmi_id_list)[];
40256 -};
40257 +} __do_const;
40258
40259 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40260 {
40261 @@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40262 return 1;
40263 }
40264
40265 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40266 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40267 {
40268 - .dmi_id_list = &(const struct dmi_system_id[]) {
40269 - {
40270 - .callback = intel_dmi_reverse_brightness,
40271 - .ident = "NCR Corporation",
40272 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40273 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40274 - },
40275 - },
40276 - { } /* terminating entry */
40277 + .callback = intel_dmi_reverse_brightness,
40278 + .ident = "NCR Corporation",
40279 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40280 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40281 },
40282 + },
40283 + { } /* terminating entry */
40284 +};
40285 +
40286 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40287 + {
40288 + .dmi_id_list = &intel_dmi_quirks_table,
40289 .hook = quirk_invert_brightness,
40290 },
40291 };
40292 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40293 index fe45321..836fdca 100644
40294 --- a/drivers/gpu/drm/mga/mga_drv.h
40295 +++ b/drivers/gpu/drm/mga/mga_drv.h
40296 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40297 u32 clear_cmd;
40298 u32 maccess;
40299
40300 - atomic_t vbl_received; /**< Number of vblanks received. */
40301 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40302 wait_queue_head_t fence_queue;
40303 - atomic_t last_fence_retired;
40304 + atomic_unchecked_t last_fence_retired;
40305 u32 next_fence_to_post;
40306
40307 unsigned int fb_cpp;
40308 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40309 index 86b4bb8..ae237ad 100644
40310 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40311 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40312 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40313 return 0;
40314 }
40315
40316 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40317 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40318 [DRM_MGA_INIT] = compat_mga_init,
40319 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40320 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40321 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40322 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40323 {
40324 unsigned int nr = DRM_IOCTL_NR(cmd);
40325 - drm_ioctl_compat_t *fn = NULL;
40326 int ret;
40327
40328 if (nr < DRM_COMMAND_BASE)
40329 return drm_compat_ioctl(filp, cmd, arg);
40330
40331 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40332 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40333 -
40334 - if (fn != NULL)
40335 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40336 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40337 ret = (*fn) (filp, cmd, arg);
40338 - else
40339 + } else
40340 ret = drm_ioctl(filp, cmd, arg);
40341
40342 return ret;
40343 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40344 index 1b071b8..de8601a 100644
40345 --- a/drivers/gpu/drm/mga/mga_irq.c
40346 +++ b/drivers/gpu/drm/mga/mga_irq.c
40347 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40348 if (crtc != 0)
40349 return 0;
40350
40351 - return atomic_read(&dev_priv->vbl_received);
40352 + return atomic_read_unchecked(&dev_priv->vbl_received);
40353 }
40354
40355
40356 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40357 /* VBLANK interrupt */
40358 if (status & MGA_VLINEPEN) {
40359 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40360 - atomic_inc(&dev_priv->vbl_received);
40361 + atomic_inc_unchecked(&dev_priv->vbl_received);
40362 drm_handle_vblank(dev, 0);
40363 handled = 1;
40364 }
40365 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40366 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40367 MGA_WRITE(MGA_PRIMEND, prim_end);
40368
40369 - atomic_inc(&dev_priv->last_fence_retired);
40370 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40371 wake_up(&dev_priv->fence_queue);
40372 handled = 1;
40373 }
40374 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40375 * using fences.
40376 */
40377 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40378 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40379 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40380 - *sequence) <= (1 << 23)));
40381
40382 *sequence = cur_fence;
40383 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40384 index 4c3feaa..26391ce 100644
40385 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40386 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40387 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40388 struct bit_table {
40389 const char id;
40390 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40391 -};
40392 +} __no_const;
40393
40394 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40395
40396 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40397 index 23ca7a5..b6c955d 100644
40398 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40399 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40400 @@ -97,7 +97,6 @@ struct nouveau_drm {
40401 struct drm_global_reference mem_global_ref;
40402 struct ttm_bo_global_ref bo_global_ref;
40403 struct ttm_bo_device bdev;
40404 - atomic_t validate_sequence;
40405 int (*move)(struct nouveau_channel *,
40406 struct ttm_buffer_object *,
40407 struct ttm_mem_reg *, struct ttm_mem_reg *);
40408 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40409 index c1a7e5a..38b8539 100644
40410 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40411 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40412 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40413 unsigned long arg)
40414 {
40415 unsigned int nr = DRM_IOCTL_NR(cmd);
40416 - drm_ioctl_compat_t *fn = NULL;
40417 + drm_ioctl_compat_t fn = NULL;
40418 int ret;
40419
40420 if (nr < DRM_COMMAND_BASE)
40421 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40422 index d45d50d..72a5dd2 100644
40423 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40424 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40425 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40426 }
40427
40428 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40429 - nouveau_vram_manager_init,
40430 - nouveau_vram_manager_fini,
40431 - nouveau_vram_manager_new,
40432 - nouveau_vram_manager_del,
40433 - nouveau_vram_manager_debug
40434 + .init = nouveau_vram_manager_init,
40435 + .takedown = nouveau_vram_manager_fini,
40436 + .get_node = nouveau_vram_manager_new,
40437 + .put_node = nouveau_vram_manager_del,
40438 + .debug = nouveau_vram_manager_debug
40439 };
40440
40441 static int
40442 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40443 }
40444
40445 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40446 - nouveau_gart_manager_init,
40447 - nouveau_gart_manager_fini,
40448 - nouveau_gart_manager_new,
40449 - nouveau_gart_manager_del,
40450 - nouveau_gart_manager_debug
40451 + .init = nouveau_gart_manager_init,
40452 + .takedown = nouveau_gart_manager_fini,
40453 + .get_node = nouveau_gart_manager_new,
40454 + .put_node = nouveau_gart_manager_del,
40455 + .debug = nouveau_gart_manager_debug
40456 };
40457
40458 #include <core/subdev/vm/nv04.h>
40459 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40460 }
40461
40462 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40463 - nv04_gart_manager_init,
40464 - nv04_gart_manager_fini,
40465 - nv04_gart_manager_new,
40466 - nv04_gart_manager_del,
40467 - nv04_gart_manager_debug
40468 + .init = nv04_gart_manager_init,
40469 + .takedown = nv04_gart_manager_fini,
40470 + .get_node = nv04_gart_manager_new,
40471 + .put_node = nv04_gart_manager_del,
40472 + .debug = nv04_gart_manager_debug
40473 };
40474
40475 int
40476 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40477 index 471347e..5adc6b9 100644
40478 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40479 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40480 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40481 bool can_switch;
40482
40483 spin_lock(&dev->count_lock);
40484 - can_switch = (dev->open_count == 0);
40485 + can_switch = (local_read(&dev->open_count) == 0);
40486 spin_unlock(&dev->count_lock);
40487 return can_switch;
40488 }
40489 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40490 index eb89653..613cf71 100644
40491 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40492 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40493 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40494 int ret;
40495
40496 mutex_lock(&qdev->async_io_mutex);
40497 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40498 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40499 if (qdev->last_sent_io_cmd > irq_num) {
40500 if (intr)
40501 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40502 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40503 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40504 else
40505 ret = wait_event_timeout(qdev->io_cmd_event,
40506 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40507 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40508 /* 0 is timeout, just bail the "hw" has gone away */
40509 if (ret <= 0)
40510 goto out;
40511 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40512 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40513 }
40514 outb(val, addr);
40515 qdev->last_sent_io_cmd = irq_num + 1;
40516 if (intr)
40517 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40518 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40519 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40520 else
40521 ret = wait_event_timeout(qdev->io_cmd_event,
40522 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40523 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40524 out:
40525 if (ret > 0)
40526 ret = 0;
40527 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40528 index c3c2bbd..bc3c0fb 100644
40529 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40530 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40531 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40532 struct drm_info_node *node = (struct drm_info_node *) m->private;
40533 struct qxl_device *qdev = node->minor->dev->dev_private;
40534
40535 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40536 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40537 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40538 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40539 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40540 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40541 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40542 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40543 seq_printf(m, "%d\n", qdev->irq_received_error);
40544 return 0;
40545 }
40546 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40547 index 36ed40b..0397633 100644
40548 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40549 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40550 @@ -290,10 +290,10 @@ struct qxl_device {
40551 unsigned int last_sent_io_cmd;
40552
40553 /* interrupt handling */
40554 - atomic_t irq_received;
40555 - atomic_t irq_received_display;
40556 - atomic_t irq_received_cursor;
40557 - atomic_t irq_received_io_cmd;
40558 + atomic_unchecked_t irq_received;
40559 + atomic_unchecked_t irq_received_display;
40560 + atomic_unchecked_t irq_received_cursor;
40561 + atomic_unchecked_t irq_received_io_cmd;
40562 unsigned irq_received_error;
40563 wait_queue_head_t display_event;
40564 wait_queue_head_t cursor_event;
40565 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40566 index 0bb86e6..d41416d 100644
40567 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40568 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40569 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40570
40571 /* TODO copy slow path code from i915 */
40572 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40573 - 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);
40574 + 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);
40575
40576 {
40577 struct qxl_drawable *draw = fb_cmd;
40578 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40579 struct drm_qxl_reloc reloc;
40580
40581 if (copy_from_user(&reloc,
40582 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40583 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40584 sizeof(reloc))) {
40585 ret = -EFAULT;
40586 goto out_free_bos;
40587 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40588
40589 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40590
40591 - struct drm_qxl_command *commands =
40592 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40593 + struct drm_qxl_command __user *commands =
40594 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40595
40596 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40597 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40598 sizeof(user_cmd)))
40599 return -EFAULT;
40600
40601 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40602 index 28f84b4..fb3e224 100644
40603 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40604 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40605 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40606
40607 pending = xchg(&qdev->ram_header->int_pending, 0);
40608
40609 - atomic_inc(&qdev->irq_received);
40610 + atomic_inc_unchecked(&qdev->irq_received);
40611
40612 if (pending & QXL_INTERRUPT_DISPLAY) {
40613 - atomic_inc(&qdev->irq_received_display);
40614 + atomic_inc_unchecked(&qdev->irq_received_display);
40615 wake_up_all(&qdev->display_event);
40616 qxl_queue_garbage_collect(qdev, false);
40617 }
40618 if (pending & QXL_INTERRUPT_CURSOR) {
40619 - atomic_inc(&qdev->irq_received_cursor);
40620 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40621 wake_up_all(&qdev->cursor_event);
40622 }
40623 if (pending & QXL_INTERRUPT_IO_CMD) {
40624 - atomic_inc(&qdev->irq_received_io_cmd);
40625 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40626 wake_up_all(&qdev->io_cmd_event);
40627 }
40628 if (pending & QXL_INTERRUPT_ERROR) {
40629 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40630 init_waitqueue_head(&qdev->io_cmd_event);
40631 INIT_WORK(&qdev->client_monitors_config_work,
40632 qxl_client_monitors_config_work_func);
40633 - atomic_set(&qdev->irq_received, 0);
40634 - atomic_set(&qdev->irq_received_display, 0);
40635 - atomic_set(&qdev->irq_received_cursor, 0);
40636 - atomic_set(&qdev->irq_received_io_cmd, 0);
40637 + atomic_set_unchecked(&qdev->irq_received, 0);
40638 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40639 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40640 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40641 qdev->irq_received_error = 0;
40642 ret = drm_irq_install(qdev->ddev);
40643 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40644 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40645 index c7e7e65..7dddd4d 100644
40646 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40647 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40648 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40649 }
40650 }
40651
40652 -static struct vm_operations_struct qxl_ttm_vm_ops;
40653 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40654 static const struct vm_operations_struct *ttm_vm_ops;
40655
40656 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40657 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40658 return r;
40659 if (unlikely(ttm_vm_ops == NULL)) {
40660 ttm_vm_ops = vma->vm_ops;
40661 + pax_open_kernel();
40662 qxl_ttm_vm_ops = *ttm_vm_ops;
40663 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40664 + pax_close_kernel();
40665 }
40666 vma->vm_ops = &qxl_ttm_vm_ops;
40667 return 0;
40668 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40669 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40670 {
40671 #if defined(CONFIG_DEBUG_FS)
40672 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40673 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40674 - unsigned i;
40675 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40676 + {
40677 + .name = "qxl_mem_mm",
40678 + .show = &qxl_mm_dump_table,
40679 + },
40680 + {
40681 + .name = "qxl_surf_mm",
40682 + .show = &qxl_mm_dump_table,
40683 + }
40684 + };
40685
40686 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40687 - if (i == 0)
40688 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40689 - else
40690 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40691 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40692 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40693 - qxl_mem_types_list[i].driver_features = 0;
40694 - if (i == 0)
40695 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40696 - else
40697 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40698 + pax_open_kernel();
40699 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40700 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40701 + pax_close_kernel();
40702
40703 - }
40704 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40705 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40706 #else
40707 return 0;
40708 #endif
40709 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40710 index 59459fe..be26b31 100644
40711 --- a/drivers/gpu/drm/r128/r128_cce.c
40712 +++ b/drivers/gpu/drm/r128/r128_cce.c
40713 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40714
40715 /* GH: Simple idle check.
40716 */
40717 - atomic_set(&dev_priv->idle_count, 0);
40718 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40719
40720 /* We don't support anything other than bus-mastering ring mode,
40721 * but the ring can be in either AGP or PCI space for the ring
40722 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40723 index 5bf3f5f..7000661 100644
40724 --- a/drivers/gpu/drm/r128/r128_drv.h
40725 +++ b/drivers/gpu/drm/r128/r128_drv.h
40726 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40727 int is_pci;
40728 unsigned long cce_buffers_offset;
40729
40730 - atomic_t idle_count;
40731 + atomic_unchecked_t idle_count;
40732
40733 int page_flipping;
40734 int current_page;
40735 u32 crtc_offset;
40736 u32 crtc_offset_cntl;
40737
40738 - atomic_t vbl_received;
40739 + atomic_unchecked_t vbl_received;
40740
40741 u32 color_fmt;
40742 unsigned int front_offset;
40743 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40744 index b0d0fd3..a6fbbe4 100644
40745 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40746 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40747 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40748 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40749 }
40750
40751 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40752 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40753 [DRM_R128_INIT] = compat_r128_init,
40754 [DRM_R128_DEPTH] = compat_r128_depth,
40755 [DRM_R128_STIPPLE] = compat_r128_stipple,
40756 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40757 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40758 {
40759 unsigned int nr = DRM_IOCTL_NR(cmd);
40760 - drm_ioctl_compat_t *fn = NULL;
40761 int ret;
40762
40763 if (nr < DRM_COMMAND_BASE)
40764 return drm_compat_ioctl(filp, cmd, arg);
40765
40766 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40767 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40768 -
40769 - if (fn != NULL)
40770 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40771 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40772 ret = (*fn) (filp, cmd, arg);
40773 - else
40774 + } else
40775 ret = drm_ioctl(filp, cmd, arg);
40776
40777 return ret;
40778 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40779 index c2ae496..30b5993 100644
40780 --- a/drivers/gpu/drm/r128/r128_irq.c
40781 +++ b/drivers/gpu/drm/r128/r128_irq.c
40782 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40783 if (crtc != 0)
40784 return 0;
40785
40786 - return atomic_read(&dev_priv->vbl_received);
40787 + return atomic_read_unchecked(&dev_priv->vbl_received);
40788 }
40789
40790 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40791 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40792 /* VBLANK interrupt */
40793 if (status & R128_CRTC_VBLANK_INT) {
40794 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40795 - atomic_inc(&dev_priv->vbl_received);
40796 + atomic_inc_unchecked(&dev_priv->vbl_received);
40797 drm_handle_vblank(dev, 0);
40798 return IRQ_HANDLED;
40799 }
40800 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40801 index e806dac..f81d32f 100644
40802 --- a/drivers/gpu/drm/r128/r128_state.c
40803 +++ b/drivers/gpu/drm/r128/r128_state.c
40804 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40805
40806 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40807 {
40808 - if (atomic_read(&dev_priv->idle_count) == 0)
40809 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40810 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40811 else
40812 - atomic_set(&dev_priv->idle_count, 0);
40813 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40814 }
40815
40816 #endif
40817 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40818 index 4a85bb6..aaea819 100644
40819 --- a/drivers/gpu/drm/radeon/mkregtable.c
40820 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40821 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40822 regex_t mask_rex;
40823 regmatch_t match[4];
40824 char buf[1024];
40825 - size_t end;
40826 + long end;
40827 int len;
40828 int done = 0;
40829 int r;
40830 unsigned o;
40831 struct offset *offset;
40832 char last_reg_s[10];
40833 - int last_reg;
40834 + unsigned long last_reg;
40835
40836 if (regcomp
40837 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40838 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40839 index 044bc98..50ced9b 100644
40840 --- a/drivers/gpu/drm/radeon/radeon_device.c
40841 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40842 @@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40843 bool can_switch;
40844
40845 spin_lock(&dev->count_lock);
40846 - can_switch = (dev->open_count == 0);
40847 + can_switch = (local_read(&dev->open_count) == 0);
40848 spin_unlock(&dev->count_lock);
40849 return can_switch;
40850 }
40851 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40852 index dafd812..1bf20c7 100644
40853 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40854 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40855 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40856
40857 /* SW interrupt */
40858 wait_queue_head_t swi_queue;
40859 - atomic_t swi_emitted;
40860 + atomic_unchecked_t swi_emitted;
40861 int vblank_crtc;
40862 uint32_t irq_enable_reg;
40863 uint32_t r500_disp_irq_reg;
40864 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40865 index bdb0f93..5ff558f 100644
40866 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40867 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40868 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40869 request = compat_alloc_user_space(sizeof(*request));
40870 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40871 || __put_user(req32.param, &request->param)
40872 - || __put_user((void __user *)(unsigned long)req32.value,
40873 + || __put_user((unsigned long)req32.value,
40874 &request->value))
40875 return -EFAULT;
40876
40877 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40878 #define compat_radeon_cp_setparam NULL
40879 #endif /* X86_64 || IA64 */
40880
40881 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40882 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40883 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40884 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40885 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40886 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40887 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40888 {
40889 unsigned int nr = DRM_IOCTL_NR(cmd);
40890 - drm_ioctl_compat_t *fn = NULL;
40891 int ret;
40892
40893 if (nr < DRM_COMMAND_BASE)
40894 return drm_compat_ioctl(filp, cmd, arg);
40895
40896 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40897 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40898 -
40899 - if (fn != NULL)
40900 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40901 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40902 ret = (*fn) (filp, cmd, arg);
40903 - else
40904 + } else
40905 ret = drm_ioctl(filp, cmd, arg);
40906
40907 return ret;
40908 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40909 index 244b19b..c19226d 100644
40910 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40911 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40912 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40913 unsigned int ret;
40914 RING_LOCALS;
40915
40916 - atomic_inc(&dev_priv->swi_emitted);
40917 - ret = atomic_read(&dev_priv->swi_emitted);
40918 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40919 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40920
40921 BEGIN_RING(4);
40922 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40923 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40924 drm_radeon_private_t *dev_priv =
40925 (drm_radeon_private_t *) dev->dev_private;
40926
40927 - atomic_set(&dev_priv->swi_emitted, 0);
40928 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40929 init_waitqueue_head(&dev_priv->swi_queue);
40930
40931 dev->max_vblank_count = 0x001fffff;
40932 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40933 index 956ab7f..fbd36d8 100644
40934 --- a/drivers/gpu/drm/radeon/radeon_state.c
40935 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40936 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40937 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40938 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40939
40940 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
40941 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
40942 sarea_priv->nbox * sizeof(depth_boxes[0])))
40943 return -EFAULT;
40944
40945 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40946 {
40947 drm_radeon_private_t *dev_priv = dev->dev_private;
40948 drm_radeon_getparam_t *param = data;
40949 - int value;
40950 + int value = 0;
40951
40952 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40953
40954 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40955 index 040a2a1..eae4e54 100644
40956 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40957 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40958 @@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40959 man->size = size >> PAGE_SHIFT;
40960 }
40961
40962 -static struct vm_operations_struct radeon_ttm_vm_ops;
40963 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40964 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40965
40966 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40967 @@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40968 }
40969 if (unlikely(ttm_vm_ops == NULL)) {
40970 ttm_vm_ops = vma->vm_ops;
40971 + pax_open_kernel();
40972 radeon_ttm_vm_ops = *ttm_vm_ops;
40973 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40974 + pax_close_kernel();
40975 }
40976 vma->vm_ops = &radeon_ttm_vm_ops;
40977 return 0;
40978 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40979 index 9336006..ce78aa7 100644
40980 --- a/drivers/gpu/drm/tegra/dc.c
40981 +++ b/drivers/gpu/drm/tegra/dc.c
40982 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40983 }
40984
40985 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40986 - dc->debugfs_files[i].data = dc;
40987 + *(void **)&dc->debugfs_files[i].data = dc;
40988
40989 err = drm_debugfs_create_files(dc->debugfs_files,
40990 ARRAY_SIZE(debugfs_files),
40991 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
40992 index d452faab..f8cbc6a 100644
40993 --- a/drivers/gpu/drm/tegra/dsi.c
40994 +++ b/drivers/gpu/drm/tegra/dsi.c
40995 @@ -53,7 +53,7 @@ struct tegra_dsi {
40996 struct clk *clk_lp;
40997 struct clk *clk;
40998
40999 - struct drm_info_list *debugfs_files;
41000 + drm_info_list_no_const *debugfs_files;
41001 struct drm_minor *minor;
41002 struct dentry *debugfs;
41003
41004 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41005 index 6928015..c9853e7 100644
41006 --- a/drivers/gpu/drm/tegra/hdmi.c
41007 +++ b/drivers/gpu/drm/tegra/hdmi.c
41008 @@ -59,7 +59,7 @@ struct tegra_hdmi {
41009 bool stereo;
41010 bool dvi;
41011
41012 - struct drm_info_list *debugfs_files;
41013 + drm_info_list_no_const *debugfs_files;
41014 struct drm_minor *minor;
41015 struct dentry *debugfs;
41016 };
41017 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41018 index c58eba33..83c2728 100644
41019 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41020 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41021 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41022 }
41023
41024 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41025 - ttm_bo_man_init,
41026 - ttm_bo_man_takedown,
41027 - ttm_bo_man_get_node,
41028 - ttm_bo_man_put_node,
41029 - ttm_bo_man_debug
41030 + .init = ttm_bo_man_init,
41031 + .takedown = ttm_bo_man_takedown,
41032 + .get_node = ttm_bo_man_get_node,
41033 + .put_node = ttm_bo_man_put_node,
41034 + .debug = ttm_bo_man_debug
41035 };
41036 EXPORT_SYMBOL(ttm_bo_manager_func);
41037 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41038 index dbc2def..0a9f710 100644
41039 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41040 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41041 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41042 zone->glob = glob;
41043 glob->zone_kernel = zone;
41044 ret = kobject_init_and_add(
41045 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41046 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41047 if (unlikely(ret != 0)) {
41048 kobject_put(&zone->kobj);
41049 return ret;
41050 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41051 zone->glob = glob;
41052 glob->zone_dma32 = zone;
41053 ret = kobject_init_and_add(
41054 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41055 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41056 if (unlikely(ret != 0)) {
41057 kobject_put(&zone->kobj);
41058 return ret;
41059 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41060 index 863bef9..cba15cf 100644
41061 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41062 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41063 @@ -391,9 +391,9 @@ out:
41064 static unsigned long
41065 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41066 {
41067 - static atomic_t start_pool = ATOMIC_INIT(0);
41068 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41069 unsigned i;
41070 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41071 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41072 struct ttm_page_pool *pool;
41073 int shrink_pages = sc->nr_to_scan;
41074 unsigned long freed = 0;
41075 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41076 index dbadd49..1b7457b 100644
41077 --- a/drivers/gpu/drm/udl/udl_fb.c
41078 +++ b/drivers/gpu/drm/udl/udl_fb.c
41079 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41080 fb_deferred_io_cleanup(info);
41081 kfree(info->fbdefio);
41082 info->fbdefio = NULL;
41083 - info->fbops->fb_mmap = udl_fb_mmap;
41084 }
41085
41086 pr_warn("released /dev/fb%d user=%d count=%d\n",
41087 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41088 index ad02732..144f5ed 100644
41089 --- a/drivers/gpu/drm/via/via_drv.h
41090 +++ b/drivers/gpu/drm/via/via_drv.h
41091 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41092 typedef uint32_t maskarray_t[5];
41093
41094 typedef struct drm_via_irq {
41095 - atomic_t irq_received;
41096 + atomic_unchecked_t irq_received;
41097 uint32_t pending_mask;
41098 uint32_t enable_mask;
41099 wait_queue_head_t irq_queue;
41100 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41101 struct timeval last_vblank;
41102 int last_vblank_valid;
41103 unsigned usec_per_vblank;
41104 - atomic_t vbl_received;
41105 + atomic_unchecked_t vbl_received;
41106 drm_via_state_t hc_state;
41107 char pci_buf[VIA_PCI_BUF_SIZE];
41108 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41109 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41110 index 1319433..a993b0c 100644
41111 --- a/drivers/gpu/drm/via/via_irq.c
41112 +++ b/drivers/gpu/drm/via/via_irq.c
41113 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41114 if (crtc != 0)
41115 return 0;
41116
41117 - return atomic_read(&dev_priv->vbl_received);
41118 + return atomic_read_unchecked(&dev_priv->vbl_received);
41119 }
41120
41121 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41122 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41123
41124 status = VIA_READ(VIA_REG_INTERRUPT);
41125 if (status & VIA_IRQ_VBLANK_PENDING) {
41126 - atomic_inc(&dev_priv->vbl_received);
41127 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41128 + atomic_inc_unchecked(&dev_priv->vbl_received);
41129 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41130 do_gettimeofday(&cur_vblank);
41131 if (dev_priv->last_vblank_valid) {
41132 dev_priv->usec_per_vblank =
41133 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41134 dev_priv->last_vblank = cur_vblank;
41135 dev_priv->last_vblank_valid = 1;
41136 }
41137 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41138 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41139 DRM_DEBUG("US per vblank is: %u\n",
41140 dev_priv->usec_per_vblank);
41141 }
41142 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41143
41144 for (i = 0; i < dev_priv->num_irqs; ++i) {
41145 if (status & cur_irq->pending_mask) {
41146 - atomic_inc(&cur_irq->irq_received);
41147 + atomic_inc_unchecked(&cur_irq->irq_received);
41148 wake_up(&cur_irq->irq_queue);
41149 handled = 1;
41150 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41151 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41152 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41153 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41154 masks[irq][4]));
41155 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41156 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41157 } else {
41158 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41159 (((cur_irq_sequence =
41160 - atomic_read(&cur_irq->irq_received)) -
41161 + atomic_read_unchecked(&cur_irq->irq_received)) -
41162 *sequence) <= (1 << 23)));
41163 }
41164 *sequence = cur_irq_sequence;
41165 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41166 }
41167
41168 for (i = 0; i < dev_priv->num_irqs; ++i) {
41169 - atomic_set(&cur_irq->irq_received, 0);
41170 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41171 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41172 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41173 init_waitqueue_head(&cur_irq->irq_queue);
41174 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41175 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41176 case VIA_IRQ_RELATIVE:
41177 irqwait->request.sequence +=
41178 - atomic_read(&cur_irq->irq_received);
41179 + atomic_read_unchecked(&cur_irq->irq_received);
41180 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41181 case VIA_IRQ_ABSOLUTE:
41182 break;
41183 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41184 index 0783155..b29e18e 100644
41185 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41186 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41187 @@ -437,7 +437,7 @@ struct vmw_private {
41188 * Fencing and IRQs.
41189 */
41190
41191 - atomic_t marker_seq;
41192 + atomic_unchecked_t marker_seq;
41193 wait_queue_head_t fence_queue;
41194 wait_queue_head_t fifo_queue;
41195 int fence_queue_waiters; /* Protected by hw_mutex */
41196 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41197 index 6ccd993..618d592 100644
41198 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41199 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41200 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41201 (unsigned int) min,
41202 (unsigned int) fifo->capabilities);
41203
41204 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41205 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41206 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41207 vmw_marker_queue_init(&fifo->marker_queue);
41208 return vmw_fifo_send_fence(dev_priv, &dummy);
41209 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41210 if (reserveable)
41211 iowrite32(bytes, fifo_mem +
41212 SVGA_FIFO_RESERVED);
41213 - return fifo_mem + (next_cmd >> 2);
41214 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41215 } else {
41216 need_bounce = true;
41217 }
41218 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41219
41220 fm = vmw_fifo_reserve(dev_priv, bytes);
41221 if (unlikely(fm == NULL)) {
41222 - *seqno = atomic_read(&dev_priv->marker_seq);
41223 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41224 ret = -ENOMEM;
41225 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41226 false, 3*HZ);
41227 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41228 }
41229
41230 do {
41231 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41232 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41233 } while (*seqno == 0);
41234
41235 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41236 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41237 index b1273e8..9c274fd 100644
41238 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41239 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41240 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41241 }
41242
41243 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41244 - vmw_gmrid_man_init,
41245 - vmw_gmrid_man_takedown,
41246 - vmw_gmrid_man_get_node,
41247 - vmw_gmrid_man_put_node,
41248 - vmw_gmrid_man_debug
41249 + .init = vmw_gmrid_man_init,
41250 + .takedown = vmw_gmrid_man_takedown,
41251 + .get_node = vmw_gmrid_man_get_node,
41252 + .put_node = vmw_gmrid_man_put_node,
41253 + .debug = vmw_gmrid_man_debug
41254 };
41255 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41256 index 47b7094..698ba09 100644
41257 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41258 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41259 @@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41260 int ret;
41261
41262 num_clips = arg->num_clips;
41263 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41264 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41265
41266 if (unlikely(num_clips == 0))
41267 return 0;
41268 @@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41269 int ret;
41270
41271 num_clips = arg->num_clips;
41272 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41273 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41274
41275 if (unlikely(num_clips == 0))
41276 return 0;
41277 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41278 index 0c42376..6febe77 100644
41279 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41280 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41281 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41282 * emitted. Then the fence is stale and signaled.
41283 */
41284
41285 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41286 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41287 > VMW_FENCE_WRAP);
41288
41289 return ret;
41290 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41291
41292 if (fifo_idle)
41293 down_read(&fifo_state->rwsem);
41294 - signal_seq = atomic_read(&dev_priv->marker_seq);
41295 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41296 ret = 0;
41297
41298 for (;;) {
41299 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41300 index 8a8725c2..afed796 100644
41301 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41302 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41303 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41304 while (!vmw_lag_lt(queue, us)) {
41305 spin_lock(&queue->lock);
41306 if (list_empty(&queue->head))
41307 - seqno = atomic_read(&dev_priv->marker_seq);
41308 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41309 else {
41310 marker = list_first_entry(&queue->head,
41311 struct vmw_marker, head);
41312 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41313 index ec0ae2d..dc0780b 100644
41314 --- a/drivers/gpu/vga/vga_switcheroo.c
41315 +++ b/drivers/gpu/vga/vga_switcheroo.c
41316 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41317
41318 /* this version is for the case where the power switch is separate
41319 to the device being powered down. */
41320 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41321 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41322 {
41323 /* copy over all the bus versions */
41324 if (dev->bus && dev->bus->pm) {
41325 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41326 return ret;
41327 }
41328
41329 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41330 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41331 {
41332 /* copy over all the bus versions */
41333 if (dev->bus && dev->bus->pm) {
41334 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41335 index cc32a6f..02a4b1c 100644
41336 --- a/drivers/hid/hid-core.c
41337 +++ b/drivers/hid/hid-core.c
41338 @@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41339
41340 int hid_add_device(struct hid_device *hdev)
41341 {
41342 - static atomic_t id = ATOMIC_INIT(0);
41343 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41344 int ret;
41345
41346 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41347 @@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41348 /* XXX hack, any other cleaner solution after the driver core
41349 * is converted to allow more than 20 bytes as the device name? */
41350 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41351 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41352 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41353
41354 hid_debug_register(hdev, dev_name(&hdev->dev));
41355 ret = device_add(&hdev->dev);
41356 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41357 index c13fb5b..55a3802 100644
41358 --- a/drivers/hid/hid-wiimote-debug.c
41359 +++ b/drivers/hid/hid-wiimote-debug.c
41360 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41361 else if (size == 0)
41362 return -EIO;
41363
41364 - if (copy_to_user(u, buf, size))
41365 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41366 return -EFAULT;
41367
41368 *off += size;
41369 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41370 index cedc6da..2c3da2a 100644
41371 --- a/drivers/hid/uhid.c
41372 +++ b/drivers/hid/uhid.c
41373 @@ -47,7 +47,7 @@ struct uhid_device {
41374 struct mutex report_lock;
41375 wait_queue_head_t report_wait;
41376 atomic_t report_done;
41377 - atomic_t report_id;
41378 + atomic_unchecked_t report_id;
41379 struct uhid_event report_buf;
41380 };
41381
41382 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41383
41384 spin_lock_irqsave(&uhid->qlock, flags);
41385 ev->type = UHID_FEATURE;
41386 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41387 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41388 ev->u.feature.rnum = rnum;
41389 ev->u.feature.rtype = report_type;
41390
41391 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41392 spin_lock_irqsave(&uhid->qlock, flags);
41393
41394 /* id for old report; drop it silently */
41395 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41396 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41397 goto unlock;
41398 if (atomic_read(&uhid->report_done))
41399 goto unlock;
41400 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41401 index 69ea36f..8dbf4bb 100644
41402 --- a/drivers/hv/channel.c
41403 +++ b/drivers/hv/channel.c
41404 @@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41405 int ret = 0;
41406 int t;
41407
41408 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41409 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41410 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41411 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41412
41413 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41414 if (ret)
41415 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41416 index bcb4950..61dba6c 100644
41417 --- a/drivers/hv/hv.c
41418 +++ b/drivers/hv/hv.c
41419 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41420 u64 output_address = (output) ? virt_to_phys(output) : 0;
41421 u32 output_address_hi = output_address >> 32;
41422 u32 output_address_lo = output_address & 0xFFFFFFFF;
41423 - void *hypercall_page = hv_context.hypercall_page;
41424 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41425
41426 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41427 "=a"(hv_status_lo) : "d" (control_hi),
41428 @@ -154,7 +154,7 @@ int hv_init(void)
41429 /* See if the hypercall page is already set */
41430 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41431
41432 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41433 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41434
41435 if (!virtaddr)
41436 goto cleanup;
41437 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41438 index 7e17a54..a50a33d 100644
41439 --- a/drivers/hv/hv_balloon.c
41440 +++ b/drivers/hv/hv_balloon.c
41441 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41442
41443 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41444 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41445 -static atomic_t trans_id = ATOMIC_INIT(0);
41446 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41447
41448 static int dm_ring_size = (5 * PAGE_SIZE);
41449
41450 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41451 pr_info("Memory hot add failed\n");
41452
41453 dm->state = DM_INITIALIZED;
41454 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41455 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41456 vmbus_sendpacket(dm->dev->channel, &resp,
41457 sizeof(struct dm_hot_add_response),
41458 (unsigned long)NULL,
41459 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41460 memset(&status, 0, sizeof(struct dm_status));
41461 status.hdr.type = DM_STATUS_REPORT;
41462 status.hdr.size = sizeof(struct dm_status);
41463 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41464 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41465
41466 /*
41467 * The host expects the guest to report free memory.
41468 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41469 * send the status. This can happen if we were interrupted
41470 * after we picked our transaction ID.
41471 */
41472 - if (status.hdr.trans_id != atomic_read(&trans_id))
41473 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41474 return;
41475
41476 vmbus_sendpacket(dm->dev->channel, &status,
41477 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41478 */
41479
41480 do {
41481 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41482 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41483 ret = vmbus_sendpacket(dm_device.dev->channel,
41484 bl_resp,
41485 bl_resp->hdr.size,
41486 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41487
41488 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41489 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41490 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41491 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41492 resp.hdr.size = sizeof(struct dm_unballoon_response);
41493
41494 vmbus_sendpacket(dm_device.dev->channel, &resp,
41495 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41496 memset(&version_req, 0, sizeof(struct dm_version_request));
41497 version_req.hdr.type = DM_VERSION_REQUEST;
41498 version_req.hdr.size = sizeof(struct dm_version_request);
41499 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41500 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41501 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41502 version_req.is_last_attempt = 1;
41503
41504 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41505 memset(&version_req, 0, sizeof(struct dm_version_request));
41506 version_req.hdr.type = DM_VERSION_REQUEST;
41507 version_req.hdr.size = sizeof(struct dm_version_request);
41508 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41509 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41510 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41511 version_req.is_last_attempt = 0;
41512
41513 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41514 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41515 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41516 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41517 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41518 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41519
41520 cap_msg.caps.cap_bits.balloon = 1;
41521 cap_msg.caps.cap_bits.hot_add = 1;
41522 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41523 index e055176..c22ff1f 100644
41524 --- a/drivers/hv/hyperv_vmbus.h
41525 +++ b/drivers/hv/hyperv_vmbus.h
41526 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41527 struct vmbus_connection {
41528 enum vmbus_connect_state conn_state;
41529
41530 - atomic_t next_gpadl_handle;
41531 + atomic_unchecked_t next_gpadl_handle;
41532
41533 /*
41534 * Represents channel interrupts. Each bit position represents a
41535 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41536 index 077bb1b..d433d74 100644
41537 --- a/drivers/hv/vmbus_drv.c
41538 +++ b/drivers/hv/vmbus_drv.c
41539 @@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41540 {
41541 int ret = 0;
41542
41543 - static atomic_t device_num = ATOMIC_INIT(0);
41544 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41545
41546 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41547 - atomic_inc_return(&device_num));
41548 + atomic_inc_return_unchecked(&device_num));
41549
41550 child_device_obj->device.bus = &hv_bus;
41551 child_device_obj->device.parent = &hv_acpi_dev->dev;
41552 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41553 index 579bdf9..75118b5 100644
41554 --- a/drivers/hwmon/acpi_power_meter.c
41555 +++ b/drivers/hwmon/acpi_power_meter.c
41556 @@ -116,7 +116,7 @@ struct sensor_template {
41557 struct device_attribute *devattr,
41558 const char *buf, size_t count);
41559 int index;
41560 -};
41561 +} __do_const;
41562
41563 /* Averaging interval */
41564 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41565 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41566 struct sensor_template *attrs)
41567 {
41568 struct device *dev = &resource->acpi_dev->dev;
41569 - struct sensor_device_attribute *sensors =
41570 + sensor_device_attribute_no_const *sensors =
41571 &resource->sensors[resource->num_sensors];
41572 int res = 0;
41573
41574 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41575 index 3288f13..71cfb4e 100644
41576 --- a/drivers/hwmon/applesmc.c
41577 +++ b/drivers/hwmon/applesmc.c
41578 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41579 {
41580 struct applesmc_node_group *grp;
41581 struct applesmc_dev_attr *node;
41582 - struct attribute *attr;
41583 + attribute_no_const *attr;
41584 int ret, i;
41585
41586 for (grp = groups; grp->format; grp++) {
41587 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41588 index ae208f6..48b6c5b 100644
41589 --- a/drivers/hwmon/asus_atk0110.c
41590 +++ b/drivers/hwmon/asus_atk0110.c
41591 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41592 struct atk_sensor_data {
41593 struct list_head list;
41594 struct atk_data *data;
41595 - struct device_attribute label_attr;
41596 - struct device_attribute input_attr;
41597 - struct device_attribute limit1_attr;
41598 - struct device_attribute limit2_attr;
41599 + device_attribute_no_const label_attr;
41600 + device_attribute_no_const input_attr;
41601 + device_attribute_no_const limit1_attr;
41602 + device_attribute_no_const limit2_attr;
41603 char label_attr_name[ATTR_NAME_SIZE];
41604 char input_attr_name[ATTR_NAME_SIZE];
41605 char limit1_attr_name[ATTR_NAME_SIZE];
41606 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41607 static struct device_attribute atk_name_attr =
41608 __ATTR(name, 0444, atk_name_show, NULL);
41609
41610 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41611 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41612 sysfs_show_func show)
41613 {
41614 sysfs_attr_init(&attr->attr);
41615 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41616 index bbb0b0d..9fe1332 100644
41617 --- a/drivers/hwmon/coretemp.c
41618 +++ b/drivers/hwmon/coretemp.c
41619 @@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41620 return NOTIFY_OK;
41621 }
41622
41623 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41624 +static struct notifier_block coretemp_cpu_notifier = {
41625 .notifier_call = coretemp_cpu_callback,
41626 };
41627
41628 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41629 index 632f1dc..57e6a58 100644
41630 --- a/drivers/hwmon/ibmaem.c
41631 +++ b/drivers/hwmon/ibmaem.c
41632 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41633 struct aem_rw_sensor_template *rw)
41634 {
41635 struct device *dev = &data->pdev->dev;
41636 - struct sensor_device_attribute *sensors = data->sensors;
41637 + sensor_device_attribute_no_const *sensors = data->sensors;
41638 int err;
41639
41640 /* Set up read-only sensors */
41641 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41642 index 708081b..fe2d4ab 100644
41643 --- a/drivers/hwmon/iio_hwmon.c
41644 +++ b/drivers/hwmon/iio_hwmon.c
41645 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41646 {
41647 struct device *dev = &pdev->dev;
41648 struct iio_hwmon_state *st;
41649 - struct sensor_device_attribute *a;
41650 + sensor_device_attribute_no_const *a;
41651 int ret, i;
41652 int in_i = 1, temp_i = 1, curr_i = 1;
41653 enum iio_chan_type type;
41654 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41655 index 38d5a63..cf2c2ea 100644
41656 --- a/drivers/hwmon/nct6775.c
41657 +++ b/drivers/hwmon/nct6775.c
41658 @@ -944,10 +944,10 @@ static struct attribute_group *
41659 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41660 int repeat)
41661 {
41662 - struct attribute_group *group;
41663 + attribute_group_no_const *group;
41664 struct sensor_device_attr_u *su;
41665 - struct sensor_device_attribute *a;
41666 - struct sensor_device_attribute_2 *a2;
41667 + sensor_device_attribute_no_const *a;
41668 + sensor_device_attribute_2_no_const *a2;
41669 struct attribute **attrs;
41670 struct sensor_device_template **t;
41671 int i, count;
41672 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41673 index 291d11f..3f0dbbd 100644
41674 --- a/drivers/hwmon/pmbus/pmbus_core.c
41675 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41676 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41677 return 0;
41678 }
41679
41680 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41681 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41682 const char *name,
41683 umode_t mode,
41684 ssize_t (*show)(struct device *dev,
41685 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41686 dev_attr->store = store;
41687 }
41688
41689 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41690 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41691 const char *name,
41692 umode_t mode,
41693 ssize_t (*show)(struct device *dev,
41694 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41695 u16 reg, u8 mask)
41696 {
41697 struct pmbus_boolean *boolean;
41698 - struct sensor_device_attribute *a;
41699 + sensor_device_attribute_no_const *a;
41700
41701 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41702 if (!boolean)
41703 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41704 bool update, bool readonly)
41705 {
41706 struct pmbus_sensor *sensor;
41707 - struct device_attribute *a;
41708 + device_attribute_no_const *a;
41709
41710 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41711 if (!sensor)
41712 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41713 const char *lstring, int index)
41714 {
41715 struct pmbus_label *label;
41716 - struct device_attribute *a;
41717 + device_attribute_no_const *a;
41718
41719 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41720 if (!label)
41721 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41722 index 97cd45a..ac54d8b 100644
41723 --- a/drivers/hwmon/sht15.c
41724 +++ b/drivers/hwmon/sht15.c
41725 @@ -169,7 +169,7 @@ struct sht15_data {
41726 int supply_uv;
41727 bool supply_uv_valid;
41728 struct work_struct update_supply_work;
41729 - atomic_t interrupt_handled;
41730 + atomic_unchecked_t interrupt_handled;
41731 };
41732
41733 /**
41734 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41735 ret = gpio_direction_input(data->pdata->gpio_data);
41736 if (ret)
41737 return ret;
41738 - atomic_set(&data->interrupt_handled, 0);
41739 + atomic_set_unchecked(&data->interrupt_handled, 0);
41740
41741 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41742 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41743 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41744 /* Only relevant if the interrupt hasn't occurred. */
41745 - if (!atomic_read(&data->interrupt_handled))
41746 + if (!atomic_read_unchecked(&data->interrupt_handled))
41747 schedule_work(&data->read_work);
41748 }
41749 ret = wait_event_timeout(data->wait_queue,
41750 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41751
41752 /* First disable the interrupt */
41753 disable_irq_nosync(irq);
41754 - atomic_inc(&data->interrupt_handled);
41755 + atomic_inc_unchecked(&data->interrupt_handled);
41756 /* Then schedule a reading work struct */
41757 if (data->state != SHT15_READING_NOTHING)
41758 schedule_work(&data->read_work);
41759 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41760 * If not, then start the interrupt again - care here as could
41761 * have gone low in meantime so verify it hasn't!
41762 */
41763 - atomic_set(&data->interrupt_handled, 0);
41764 + atomic_set_unchecked(&data->interrupt_handled, 0);
41765 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41766 /* If still not occurred or another handler was scheduled */
41767 if (gpio_get_value(data->pdata->gpio_data)
41768 - || atomic_read(&data->interrupt_handled))
41769 + || atomic_read_unchecked(&data->interrupt_handled))
41770 return;
41771 }
41772
41773 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41774 index 38944e9..ae9e5ed 100644
41775 --- a/drivers/hwmon/via-cputemp.c
41776 +++ b/drivers/hwmon/via-cputemp.c
41777 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41778 return NOTIFY_OK;
41779 }
41780
41781 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41782 +static struct notifier_block via_cputemp_cpu_notifier = {
41783 .notifier_call = via_cputemp_cpu_callback,
41784 };
41785
41786 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41787 index 41fc683..a39cfea 100644
41788 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41789 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41790 @@ -43,7 +43,7 @@
41791 extern struct i2c_adapter amd756_smbus;
41792
41793 static struct i2c_adapter *s4882_adapter;
41794 -static struct i2c_algorithm *s4882_algo;
41795 +static i2c_algorithm_no_const *s4882_algo;
41796
41797 /* Wrapper access functions for multiplexed SMBus */
41798 static DEFINE_MUTEX(amd756_lock);
41799 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41800 index 721f7eb..0fd2a09 100644
41801 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41802 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41803 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41804 /* usb layer */
41805
41806 /* Send command to device, and get response. */
41807 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41808 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41809 {
41810 int ret = 0;
41811 int actual;
41812 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41813 index b170bdf..3c76427 100644
41814 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41815 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41816 @@ -41,7 +41,7 @@
41817 extern struct i2c_adapter *nforce2_smbus;
41818
41819 static struct i2c_adapter *s4985_adapter;
41820 -static struct i2c_algorithm *s4985_algo;
41821 +static i2c_algorithm_no_const *s4985_algo;
41822
41823 /* Wrapper access functions for multiplexed SMBus */
41824 static DEFINE_MUTEX(nforce2_lock);
41825 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41826 index 80b47e8..1a6040d9 100644
41827 --- a/drivers/i2c/i2c-dev.c
41828 +++ b/drivers/i2c/i2c-dev.c
41829 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41830 break;
41831 }
41832
41833 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41834 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41835 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41836 if (IS_ERR(rdwr_pa[i].buf)) {
41837 res = PTR_ERR(rdwr_pa[i].buf);
41838 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41839 index 0b510ba..4fbb5085 100644
41840 --- a/drivers/ide/ide-cd.c
41841 +++ b/drivers/ide/ide-cd.c
41842 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41843 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41844 if ((unsigned long)buf & alignment
41845 || blk_rq_bytes(rq) & q->dma_pad_mask
41846 - || object_is_on_stack(buf))
41847 + || object_starts_on_stack(buf))
41848 drive->dma = 0;
41849 }
41850 }
41851 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41852 index acc911a..8700c3c 100644
41853 --- a/drivers/iio/industrialio-core.c
41854 +++ b/drivers/iio/industrialio-core.c
41855 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41856 }
41857
41858 static
41859 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41860 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41861 const char *postfix,
41862 struct iio_chan_spec const *chan,
41863 ssize_t (*readfunc)(struct device *dev,
41864 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41865 index 0601b9d..e9dc455 100644
41866 --- a/drivers/infiniband/core/cm.c
41867 +++ b/drivers/infiniband/core/cm.c
41868 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41869
41870 struct cm_counter_group {
41871 struct kobject obj;
41872 - atomic_long_t counter[CM_ATTR_COUNT];
41873 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41874 };
41875
41876 struct cm_counter_attribute {
41877 @@ -1415,7 +1415,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41878 struct ib_mad_send_buf *msg = NULL;
41879 int ret;
41880
41881 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41882 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41883 counter[CM_REQ_COUNTER]);
41884
41885 /* Quick state check to discard duplicate REQs. */
41886 @@ -1802,7 +1802,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41887 if (!cm_id_priv)
41888 return;
41889
41890 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41891 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41892 counter[CM_REP_COUNTER]);
41893 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41894 if (ret)
41895 @@ -1969,7 +1969,7 @@ static int cm_rtu_handler(struct cm_work *work)
41896 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41897 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41898 spin_unlock_irq(&cm_id_priv->lock);
41899 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41900 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41901 counter[CM_RTU_COUNTER]);
41902 goto out;
41903 }
41904 @@ -2152,7 +2152,7 @@ static int cm_dreq_handler(struct cm_work *work)
41905 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41906 dreq_msg->local_comm_id);
41907 if (!cm_id_priv) {
41908 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41909 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41910 counter[CM_DREQ_COUNTER]);
41911 cm_issue_drep(work->port, work->mad_recv_wc);
41912 return -EINVAL;
41913 @@ -2177,7 +2177,7 @@ static int cm_dreq_handler(struct cm_work *work)
41914 case IB_CM_MRA_REP_RCVD:
41915 break;
41916 case IB_CM_TIMEWAIT:
41917 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41918 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41919 counter[CM_DREQ_COUNTER]);
41920 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41921 goto unlock;
41922 @@ -2191,7 +2191,7 @@ static int cm_dreq_handler(struct cm_work *work)
41923 cm_free_msg(msg);
41924 goto deref;
41925 case IB_CM_DREQ_RCVD:
41926 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41927 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41928 counter[CM_DREQ_COUNTER]);
41929 goto unlock;
41930 default:
41931 @@ -2558,7 +2558,7 @@ static int cm_mra_handler(struct cm_work *work)
41932 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41933 cm_id_priv->msg, timeout)) {
41934 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41935 - atomic_long_inc(&work->port->
41936 + atomic_long_inc_unchecked(&work->port->
41937 counter_group[CM_RECV_DUPLICATES].
41938 counter[CM_MRA_COUNTER]);
41939 goto out;
41940 @@ -2567,7 +2567,7 @@ static int cm_mra_handler(struct cm_work *work)
41941 break;
41942 case IB_CM_MRA_REQ_RCVD:
41943 case IB_CM_MRA_REP_RCVD:
41944 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41945 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41946 counter[CM_MRA_COUNTER]);
41947 /* fall through */
41948 default:
41949 @@ -2729,7 +2729,7 @@ static int cm_lap_handler(struct cm_work *work)
41950 case IB_CM_LAP_IDLE:
41951 break;
41952 case IB_CM_MRA_LAP_SENT:
41953 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41954 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41955 counter[CM_LAP_COUNTER]);
41956 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41957 goto unlock;
41958 @@ -2745,7 +2745,7 @@ static int cm_lap_handler(struct cm_work *work)
41959 cm_free_msg(msg);
41960 goto deref;
41961 case IB_CM_LAP_RCVD:
41962 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41963 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41964 counter[CM_LAP_COUNTER]);
41965 goto unlock;
41966 default:
41967 @@ -3029,7 +3029,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41968 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41969 if (cur_cm_id_priv) {
41970 spin_unlock_irq(&cm.lock);
41971 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41972 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41973 counter[CM_SIDR_REQ_COUNTER]);
41974 goto out; /* Duplicate message. */
41975 }
41976 @@ -3241,10 +3241,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41977 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41978 msg->retries = 1;
41979
41980 - atomic_long_add(1 + msg->retries,
41981 + atomic_long_add_unchecked(1 + msg->retries,
41982 &port->counter_group[CM_XMIT].counter[attr_index]);
41983 if (msg->retries)
41984 - atomic_long_add(msg->retries,
41985 + atomic_long_add_unchecked(msg->retries,
41986 &port->counter_group[CM_XMIT_RETRIES].
41987 counter[attr_index]);
41988
41989 @@ -3454,7 +3454,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41990 }
41991
41992 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41993 - atomic_long_inc(&port->counter_group[CM_RECV].
41994 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41995 counter[attr_id - CM_ATTR_ID_OFFSET]);
41996
41997 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41998 @@ -3685,7 +3685,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41999 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42000
42001 return sprintf(buf, "%ld\n",
42002 - atomic_long_read(&group->counter[cm_attr->index]));
42003 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42004 }
42005
42006 static const struct sysfs_ops cm_counter_ops = {
42007 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42008 index 9f5ad7c..588cd84 100644
42009 --- a/drivers/infiniband/core/fmr_pool.c
42010 +++ b/drivers/infiniband/core/fmr_pool.c
42011 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42012
42013 struct task_struct *thread;
42014
42015 - atomic_t req_ser;
42016 - atomic_t flush_ser;
42017 + atomic_unchecked_t req_ser;
42018 + atomic_unchecked_t flush_ser;
42019
42020 wait_queue_head_t force_wait;
42021 };
42022 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42023 struct ib_fmr_pool *pool = pool_ptr;
42024
42025 do {
42026 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42027 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42028 ib_fmr_batch_release(pool);
42029
42030 - atomic_inc(&pool->flush_ser);
42031 + atomic_inc_unchecked(&pool->flush_ser);
42032 wake_up_interruptible(&pool->force_wait);
42033
42034 if (pool->flush_function)
42035 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42036 }
42037
42038 set_current_state(TASK_INTERRUPTIBLE);
42039 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42040 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42041 !kthread_should_stop())
42042 schedule();
42043 __set_current_state(TASK_RUNNING);
42044 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42045 pool->dirty_watermark = params->dirty_watermark;
42046 pool->dirty_len = 0;
42047 spin_lock_init(&pool->pool_lock);
42048 - atomic_set(&pool->req_ser, 0);
42049 - atomic_set(&pool->flush_ser, 0);
42050 + atomic_set_unchecked(&pool->req_ser, 0);
42051 + atomic_set_unchecked(&pool->flush_ser, 0);
42052 init_waitqueue_head(&pool->force_wait);
42053
42054 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42055 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42056 }
42057 spin_unlock_irq(&pool->pool_lock);
42058
42059 - serial = atomic_inc_return(&pool->req_ser);
42060 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42061 wake_up_process(pool->thread);
42062
42063 if (wait_event_interruptible(pool->force_wait,
42064 - atomic_read(&pool->flush_ser) - serial >= 0))
42065 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42066 return -EINTR;
42067
42068 return 0;
42069 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42070 } else {
42071 list_add_tail(&fmr->list, &pool->dirty_list);
42072 if (++pool->dirty_len >= pool->dirty_watermark) {
42073 - atomic_inc(&pool->req_ser);
42074 + atomic_inc_unchecked(&pool->req_ser);
42075 wake_up_process(pool->thread);
42076 }
42077 }
42078 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42079 index 41b1195..27971a0 100644
42080 --- a/drivers/infiniband/hw/cxgb4/mem.c
42081 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42082 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42083 int err;
42084 struct fw_ri_tpte tpt;
42085 u32 stag_idx;
42086 - static atomic_t key;
42087 + static atomic_unchecked_t key;
42088
42089 if (c4iw_fatal_error(rdev))
42090 return -EIO;
42091 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42092 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42093 rdev->stats.stag.max = rdev->stats.stag.cur;
42094 mutex_unlock(&rdev->stats.lock);
42095 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42096 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42097 }
42098 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42099 __func__, stag_state, type, pdid, stag_idx);
42100 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42101 index 644c2c7..ecf0879 100644
42102 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
42103 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42104 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42105 }
42106
42107 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42108 - ipath_mapping_error,
42109 - ipath_dma_map_single,
42110 - ipath_dma_unmap_single,
42111 - ipath_dma_map_page,
42112 - ipath_dma_unmap_page,
42113 - ipath_map_sg,
42114 - ipath_unmap_sg,
42115 - ipath_sg_dma_address,
42116 - ipath_sg_dma_len,
42117 - ipath_sync_single_for_cpu,
42118 - ipath_sync_single_for_device,
42119 - ipath_dma_alloc_coherent,
42120 - ipath_dma_free_coherent
42121 + .mapping_error = ipath_mapping_error,
42122 + .map_single = ipath_dma_map_single,
42123 + .unmap_single = ipath_dma_unmap_single,
42124 + .map_page = ipath_dma_map_page,
42125 + .unmap_page = ipath_dma_unmap_page,
42126 + .map_sg = ipath_map_sg,
42127 + .unmap_sg = ipath_unmap_sg,
42128 + .dma_address = ipath_sg_dma_address,
42129 + .dma_len = ipath_sg_dma_len,
42130 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
42131 + .sync_single_for_device = ipath_sync_single_for_device,
42132 + .alloc_coherent = ipath_dma_alloc_coherent,
42133 + .free_coherent = ipath_dma_free_coherent
42134 };
42135 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42136 index 79b3dbc..96e5fcc 100644
42137 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42138 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42139 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42140 struct ib_atomic_eth *ateth;
42141 struct ipath_ack_entry *e;
42142 u64 vaddr;
42143 - atomic64_t *maddr;
42144 + atomic64_unchecked_t *maddr;
42145 u64 sdata;
42146 u32 rkey;
42147 u8 next;
42148 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42149 IB_ACCESS_REMOTE_ATOMIC)))
42150 goto nack_acc_unlck;
42151 /* Perform atomic OP and save result. */
42152 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42153 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42154 sdata = be64_to_cpu(ateth->swap_data);
42155 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42156 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42157 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42158 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42159 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42160 be64_to_cpu(ateth->compare_data),
42161 sdata);
42162 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42163 index 1f95bba..9530f87 100644
42164 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42165 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42166 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42167 unsigned long flags;
42168 struct ib_wc wc;
42169 u64 sdata;
42170 - atomic64_t *maddr;
42171 + atomic64_unchecked_t *maddr;
42172 enum ib_wc_status send_status;
42173
42174 /*
42175 @@ -382,11 +382,11 @@ again:
42176 IB_ACCESS_REMOTE_ATOMIC)))
42177 goto acc_err;
42178 /* Perform atomic OP and save result. */
42179 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42180 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42181 sdata = wqe->wr.wr.atomic.compare_add;
42182 *(u64 *) sqp->s_sge.sge.vaddr =
42183 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42184 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42185 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42186 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42187 sdata, wqe->wr.wr.atomic.swap);
42188 goto send_comp;
42189 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42190 index f2a3f48..673ec79 100644
42191 --- a/drivers/infiniband/hw/mlx4/mad.c
42192 +++ b/drivers/infiniband/hw/mlx4/mad.c
42193 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42194
42195 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42196 {
42197 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42198 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42199 cpu_to_be64(0xff00000000000000LL);
42200 }
42201
42202 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42203 index 25b2cdf..099ff97 100644
42204 --- a/drivers/infiniband/hw/mlx4/mcg.c
42205 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42206 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42207 {
42208 char name[20];
42209
42210 - atomic_set(&ctx->tid, 0);
42211 + atomic_set_unchecked(&ctx->tid, 0);
42212 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42213 ctx->mcg_wq = create_singlethread_workqueue(name);
42214 if (!ctx->mcg_wq)
42215 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42216 index a230683..3723f2d 100644
42217 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42218 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42219 @@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42220 struct list_head mcg_mgid0_list;
42221 struct workqueue_struct *mcg_wq;
42222 struct mlx4_ib_demux_pv_ctx **tun;
42223 - atomic_t tid;
42224 + atomic_unchecked_t tid;
42225 int flushing; /* flushing the work queue */
42226 };
42227
42228 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42229 index 9d3e5c1..6f166df 100644
42230 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42231 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42232 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42233 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42234 }
42235
42236 -int mthca_QUERY_FW(struct mthca_dev *dev)
42237 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42238 {
42239 struct mthca_mailbox *mailbox;
42240 u32 *outbox;
42241 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42242 CMD_TIME_CLASS_B);
42243 }
42244
42245 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42246 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42247 int num_mtt)
42248 {
42249 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42250 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42251 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42252 }
42253
42254 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42255 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42256 int eq_num)
42257 {
42258 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42259 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42260 CMD_TIME_CLASS_B);
42261 }
42262
42263 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42264 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42265 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42266 void *in_mad, void *response_mad)
42267 {
42268 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42269 index 87897b9..7e79542 100644
42270 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42271 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42272 @@ -692,7 +692,7 @@ err_close:
42273 return err;
42274 }
42275
42276 -static int mthca_setup_hca(struct mthca_dev *dev)
42277 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42278 {
42279 int err;
42280
42281 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42282 index ed9a989..6aa5dc2 100644
42283 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42284 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42285 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42286 * through the bitmaps)
42287 */
42288
42289 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42290 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42291 {
42292 int o;
42293 int m;
42294 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42295 return key;
42296 }
42297
42298 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42299 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42300 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42301 {
42302 struct mthca_mailbox *mailbox;
42303 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42304 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42305 }
42306
42307 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42308 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42309 u64 *buffer_list, int buffer_size_shift,
42310 int list_len, u64 iova, u64 total_size,
42311 u32 access, struct mthca_mr *mr)
42312 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42313 index 5b71d43..35a9e14 100644
42314 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42315 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42316 @@ -763,7 +763,7 @@ unlock:
42317 return 0;
42318 }
42319
42320 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42321 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42322 {
42323 struct mthca_dev *dev = to_mdev(ibcq->device);
42324 struct mthca_cq *cq = to_mcq(ibcq);
42325 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42326 index 353c7b0..c6ce921 100644
42327 --- a/drivers/infiniband/hw/nes/nes.c
42328 +++ b/drivers/infiniband/hw/nes/nes.c
42329 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42330 LIST_HEAD(nes_adapter_list);
42331 static LIST_HEAD(nes_dev_list);
42332
42333 -atomic_t qps_destroyed;
42334 +atomic_unchecked_t qps_destroyed;
42335
42336 static unsigned int ee_flsh_adapter;
42337 static unsigned int sysfs_nonidx_addr;
42338 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42339 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42340 struct nes_adapter *nesadapter = nesdev->nesadapter;
42341
42342 - atomic_inc(&qps_destroyed);
42343 + atomic_inc_unchecked(&qps_destroyed);
42344
42345 /* Free the control structures */
42346
42347 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42348 index 33cc589..3bd6538 100644
42349 --- a/drivers/infiniband/hw/nes/nes.h
42350 +++ b/drivers/infiniband/hw/nes/nes.h
42351 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42352 extern unsigned int wqm_quanta;
42353 extern struct list_head nes_adapter_list;
42354
42355 -extern atomic_t cm_connects;
42356 -extern atomic_t cm_accepts;
42357 -extern atomic_t cm_disconnects;
42358 -extern atomic_t cm_closes;
42359 -extern atomic_t cm_connecteds;
42360 -extern atomic_t cm_connect_reqs;
42361 -extern atomic_t cm_rejects;
42362 -extern atomic_t mod_qp_timouts;
42363 -extern atomic_t qps_created;
42364 -extern atomic_t qps_destroyed;
42365 -extern atomic_t sw_qps_destroyed;
42366 +extern atomic_unchecked_t cm_connects;
42367 +extern atomic_unchecked_t cm_accepts;
42368 +extern atomic_unchecked_t cm_disconnects;
42369 +extern atomic_unchecked_t cm_closes;
42370 +extern atomic_unchecked_t cm_connecteds;
42371 +extern atomic_unchecked_t cm_connect_reqs;
42372 +extern atomic_unchecked_t cm_rejects;
42373 +extern atomic_unchecked_t mod_qp_timouts;
42374 +extern atomic_unchecked_t qps_created;
42375 +extern atomic_unchecked_t qps_destroyed;
42376 +extern atomic_unchecked_t sw_qps_destroyed;
42377 extern u32 mh_detected;
42378 extern u32 mh_pauses_sent;
42379 extern u32 cm_packets_sent;
42380 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42381 extern u32 cm_packets_received;
42382 extern u32 cm_packets_dropped;
42383 extern u32 cm_packets_retrans;
42384 -extern atomic_t cm_listens_created;
42385 -extern atomic_t cm_listens_destroyed;
42386 +extern atomic_unchecked_t cm_listens_created;
42387 +extern atomic_unchecked_t cm_listens_destroyed;
42388 extern u32 cm_backlog_drops;
42389 -extern atomic_t cm_loopbacks;
42390 -extern atomic_t cm_nodes_created;
42391 -extern atomic_t cm_nodes_destroyed;
42392 -extern atomic_t cm_accel_dropped_pkts;
42393 -extern atomic_t cm_resets_recvd;
42394 -extern atomic_t pau_qps_created;
42395 -extern atomic_t pau_qps_destroyed;
42396 +extern atomic_unchecked_t cm_loopbacks;
42397 +extern atomic_unchecked_t cm_nodes_created;
42398 +extern atomic_unchecked_t cm_nodes_destroyed;
42399 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42400 +extern atomic_unchecked_t cm_resets_recvd;
42401 +extern atomic_unchecked_t pau_qps_created;
42402 +extern atomic_unchecked_t pau_qps_destroyed;
42403
42404 extern u32 int_mod_timer_init;
42405 extern u32 int_mod_cq_depth_256;
42406 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42407 index 9c9f2f5..2559190 100644
42408 --- a/drivers/infiniband/hw/nes/nes_cm.c
42409 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42410 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42411 u32 cm_packets_retrans;
42412 u32 cm_packets_created;
42413 u32 cm_packets_received;
42414 -atomic_t cm_listens_created;
42415 -atomic_t cm_listens_destroyed;
42416 +atomic_unchecked_t cm_listens_created;
42417 +atomic_unchecked_t cm_listens_destroyed;
42418 u32 cm_backlog_drops;
42419 -atomic_t cm_loopbacks;
42420 -atomic_t cm_nodes_created;
42421 -atomic_t cm_nodes_destroyed;
42422 -atomic_t cm_accel_dropped_pkts;
42423 -atomic_t cm_resets_recvd;
42424 +atomic_unchecked_t cm_loopbacks;
42425 +atomic_unchecked_t cm_nodes_created;
42426 +atomic_unchecked_t cm_nodes_destroyed;
42427 +atomic_unchecked_t cm_accel_dropped_pkts;
42428 +atomic_unchecked_t cm_resets_recvd;
42429
42430 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42431 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42432 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42433 /* instance of function pointers for client API */
42434 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42435 static struct nes_cm_ops nes_cm_api = {
42436 - mini_cm_accelerated,
42437 - mini_cm_listen,
42438 - mini_cm_del_listen,
42439 - mini_cm_connect,
42440 - mini_cm_close,
42441 - mini_cm_accept,
42442 - mini_cm_reject,
42443 - mini_cm_recv_pkt,
42444 - mini_cm_dealloc_core,
42445 - mini_cm_get,
42446 - mini_cm_set
42447 + .accelerated = mini_cm_accelerated,
42448 + .listen = mini_cm_listen,
42449 + .stop_listener = mini_cm_del_listen,
42450 + .connect = mini_cm_connect,
42451 + .close = mini_cm_close,
42452 + .accept = mini_cm_accept,
42453 + .reject = mini_cm_reject,
42454 + .recv_pkt = mini_cm_recv_pkt,
42455 + .destroy_cm_core = mini_cm_dealloc_core,
42456 + .get = mini_cm_get,
42457 + .set = mini_cm_set
42458 };
42459
42460 static struct nes_cm_core *g_cm_core;
42461
42462 -atomic_t cm_connects;
42463 -atomic_t cm_accepts;
42464 -atomic_t cm_disconnects;
42465 -atomic_t cm_closes;
42466 -atomic_t cm_connecteds;
42467 -atomic_t cm_connect_reqs;
42468 -atomic_t cm_rejects;
42469 +atomic_unchecked_t cm_connects;
42470 +atomic_unchecked_t cm_accepts;
42471 +atomic_unchecked_t cm_disconnects;
42472 +atomic_unchecked_t cm_closes;
42473 +atomic_unchecked_t cm_connecteds;
42474 +atomic_unchecked_t cm_connect_reqs;
42475 +atomic_unchecked_t cm_rejects;
42476
42477 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42478 {
42479 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42480 kfree(listener);
42481 listener = NULL;
42482 ret = 0;
42483 - atomic_inc(&cm_listens_destroyed);
42484 + atomic_inc_unchecked(&cm_listens_destroyed);
42485 } else {
42486 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42487 }
42488 @@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42489 cm_node->rem_mac);
42490
42491 add_hte_node(cm_core, cm_node);
42492 - atomic_inc(&cm_nodes_created);
42493 + atomic_inc_unchecked(&cm_nodes_created);
42494
42495 return cm_node;
42496 }
42497 @@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42498 }
42499
42500 atomic_dec(&cm_core->node_cnt);
42501 - atomic_inc(&cm_nodes_destroyed);
42502 + atomic_inc_unchecked(&cm_nodes_destroyed);
42503 nesqp = cm_node->nesqp;
42504 if (nesqp) {
42505 nesqp->cm_node = NULL;
42506 @@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42507
42508 static void drop_packet(struct sk_buff *skb)
42509 {
42510 - atomic_inc(&cm_accel_dropped_pkts);
42511 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42512 dev_kfree_skb_any(skb);
42513 }
42514
42515 @@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42516 {
42517
42518 int reset = 0; /* whether to send reset in case of err.. */
42519 - atomic_inc(&cm_resets_recvd);
42520 + atomic_inc_unchecked(&cm_resets_recvd);
42521 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42522 " refcnt=%d\n", cm_node, cm_node->state,
42523 atomic_read(&cm_node->ref_count));
42524 @@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42525 rem_ref_cm_node(cm_node->cm_core, cm_node);
42526 return NULL;
42527 }
42528 - atomic_inc(&cm_loopbacks);
42529 + atomic_inc_unchecked(&cm_loopbacks);
42530 loopbackremotenode->loopbackpartner = cm_node;
42531 loopbackremotenode->tcp_cntxt.rcv_wscale =
42532 NES_CM_DEFAULT_RCV_WND_SCALE;
42533 @@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42534 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42535 else {
42536 rem_ref_cm_node(cm_core, cm_node);
42537 - atomic_inc(&cm_accel_dropped_pkts);
42538 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42539 dev_kfree_skb_any(skb);
42540 }
42541 break;
42542 @@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42543
42544 if ((cm_id) && (cm_id->event_handler)) {
42545 if (issue_disconn) {
42546 - atomic_inc(&cm_disconnects);
42547 + atomic_inc_unchecked(&cm_disconnects);
42548 cm_event.event = IW_CM_EVENT_DISCONNECT;
42549 cm_event.status = disconn_status;
42550 cm_event.local_addr = cm_id->local_addr;
42551 @@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42552 }
42553
42554 if (issue_close) {
42555 - atomic_inc(&cm_closes);
42556 + atomic_inc_unchecked(&cm_closes);
42557 nes_disconnect(nesqp, 1);
42558
42559 cm_id->provider_data = nesqp;
42560 @@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42561
42562 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42563 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42564 - atomic_inc(&cm_accepts);
42565 + atomic_inc_unchecked(&cm_accepts);
42566
42567 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42568 netdev_refcnt_read(nesvnic->netdev));
42569 @@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42570 struct nes_cm_core *cm_core;
42571 u8 *start_buff;
42572
42573 - atomic_inc(&cm_rejects);
42574 + atomic_inc_unchecked(&cm_rejects);
42575 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42576 loopback = cm_node->loopbackpartner;
42577 cm_core = cm_node->cm_core;
42578 @@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42579 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42580 ntohs(laddr->sin_port));
42581
42582 - atomic_inc(&cm_connects);
42583 + atomic_inc_unchecked(&cm_connects);
42584 nesqp->active_conn = 1;
42585
42586 /* cache the cm_id in the qp */
42587 @@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42588 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42589 return err;
42590 }
42591 - atomic_inc(&cm_listens_created);
42592 + atomic_inc_unchecked(&cm_listens_created);
42593 }
42594
42595 cm_id->add_ref(cm_id);
42596 @@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42597
42598 if (nesqp->destroyed)
42599 return;
42600 - atomic_inc(&cm_connecteds);
42601 + atomic_inc_unchecked(&cm_connecteds);
42602 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42603 " local port 0x%04X. jiffies = %lu.\n",
42604 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42605 @@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42606
42607 cm_id->add_ref(cm_id);
42608 ret = cm_id->event_handler(cm_id, &cm_event);
42609 - atomic_inc(&cm_closes);
42610 + atomic_inc_unchecked(&cm_closes);
42611 cm_event.event = IW_CM_EVENT_CLOSE;
42612 cm_event.status = 0;
42613 cm_event.provider_data = cm_id->provider_data;
42614 @@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42615 return;
42616 cm_id = cm_node->cm_id;
42617
42618 - atomic_inc(&cm_connect_reqs);
42619 + atomic_inc_unchecked(&cm_connect_reqs);
42620 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42621 cm_node, cm_id, jiffies);
42622
42623 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42624 return;
42625 cm_id = cm_node->cm_id;
42626
42627 - atomic_inc(&cm_connect_reqs);
42628 + atomic_inc_unchecked(&cm_connect_reqs);
42629 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42630 cm_node, cm_id, jiffies);
42631
42632 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42633 index 4166452..fc952c3 100644
42634 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42635 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42636 @@ -40,8 +40,8 @@
42637 #include "nes.h"
42638 #include "nes_mgt.h"
42639
42640 -atomic_t pau_qps_created;
42641 -atomic_t pau_qps_destroyed;
42642 +atomic_unchecked_t pau_qps_created;
42643 +atomic_unchecked_t pau_qps_destroyed;
42644
42645 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42646 {
42647 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42648 {
42649 struct sk_buff *skb;
42650 unsigned long flags;
42651 - atomic_inc(&pau_qps_destroyed);
42652 + atomic_inc_unchecked(&pau_qps_destroyed);
42653
42654 /* Free packets that have not yet been forwarded */
42655 /* Lock is acquired by skb_dequeue when removing the skb */
42656 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42657 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42658 skb_queue_head_init(&nesqp->pau_list);
42659 spin_lock_init(&nesqp->pau_lock);
42660 - atomic_inc(&pau_qps_created);
42661 + atomic_inc_unchecked(&pau_qps_created);
42662 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42663 }
42664
42665 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42666 index 49eb511..a774366 100644
42667 --- a/drivers/infiniband/hw/nes/nes_nic.c
42668 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42669 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42670 target_stat_values[++index] = mh_detected;
42671 target_stat_values[++index] = mh_pauses_sent;
42672 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42673 - target_stat_values[++index] = atomic_read(&cm_connects);
42674 - target_stat_values[++index] = atomic_read(&cm_accepts);
42675 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42676 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42677 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42678 - target_stat_values[++index] = atomic_read(&cm_rejects);
42679 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42680 - target_stat_values[++index] = atomic_read(&qps_created);
42681 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42682 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42683 - target_stat_values[++index] = atomic_read(&cm_closes);
42684 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42685 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42686 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42687 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42688 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42689 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42690 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42691 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42692 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42693 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42694 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42695 target_stat_values[++index] = cm_packets_sent;
42696 target_stat_values[++index] = cm_packets_bounced;
42697 target_stat_values[++index] = cm_packets_created;
42698 target_stat_values[++index] = cm_packets_received;
42699 target_stat_values[++index] = cm_packets_dropped;
42700 target_stat_values[++index] = cm_packets_retrans;
42701 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42702 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42703 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42704 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42705 target_stat_values[++index] = cm_backlog_drops;
42706 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42707 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42708 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42709 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42710 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42711 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42712 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42713 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42714 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42715 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42716 target_stat_values[++index] = nesadapter->free_4kpbl;
42717 target_stat_values[++index] = nesadapter->free_256pbl;
42718 target_stat_values[++index] = int_mod_timer_init;
42719 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42720 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42721 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42722 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42723 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42724 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42725 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42726 }
42727
42728 /**
42729 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42730 index 8308e36..ae0d3b5 100644
42731 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42732 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42733 @@ -46,9 +46,9 @@
42734
42735 #include <rdma/ib_umem.h>
42736
42737 -atomic_t mod_qp_timouts;
42738 -atomic_t qps_created;
42739 -atomic_t sw_qps_destroyed;
42740 +atomic_unchecked_t mod_qp_timouts;
42741 +atomic_unchecked_t qps_created;
42742 +atomic_unchecked_t sw_qps_destroyed;
42743
42744 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42745
42746 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42747 if (init_attr->create_flags)
42748 return ERR_PTR(-EINVAL);
42749
42750 - atomic_inc(&qps_created);
42751 + atomic_inc_unchecked(&qps_created);
42752 switch (init_attr->qp_type) {
42753 case IB_QPT_RC:
42754 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42755 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42756 struct iw_cm_event cm_event;
42757 int ret = 0;
42758
42759 - atomic_inc(&sw_qps_destroyed);
42760 + atomic_inc_unchecked(&sw_qps_destroyed);
42761 nesqp->destroyed = 1;
42762
42763 /* Blow away the connection if it exists. */
42764 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42765 index 1946101..09766d2 100644
42766 --- a/drivers/infiniband/hw/qib/qib.h
42767 +++ b/drivers/infiniband/hw/qib/qib.h
42768 @@ -52,6 +52,7 @@
42769 #include <linux/kref.h>
42770 #include <linux/sched.h>
42771 #include <linux/kthread.h>
42772 +#include <linux/slab.h>
42773
42774 #include "qib_common.h"
42775 #include "qib_verbs.h"
42776 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42777 index 24c41ba..102d71f 100644
42778 --- a/drivers/input/gameport/gameport.c
42779 +++ b/drivers/input/gameport/gameport.c
42780 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42781 */
42782 static void gameport_init_port(struct gameport *gameport)
42783 {
42784 - static atomic_t gameport_no = ATOMIC_INIT(0);
42785 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42786
42787 __module_get(THIS_MODULE);
42788
42789 mutex_init(&gameport->drv_mutex);
42790 device_initialize(&gameport->dev);
42791 dev_set_name(&gameport->dev, "gameport%lu",
42792 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42793 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42794 gameport->dev.bus = &gameport_bus;
42795 gameport->dev.release = gameport_release_port;
42796 if (gameport->parent)
42797 diff --git a/drivers/input/input.c b/drivers/input/input.c
42798 index 1c4c0db..6f7abe3 100644
42799 --- a/drivers/input/input.c
42800 +++ b/drivers/input/input.c
42801 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42802 */
42803 struct input_dev *input_allocate_device(void)
42804 {
42805 - static atomic_t input_no = ATOMIC_INIT(0);
42806 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42807 struct input_dev *dev;
42808
42809 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42810 @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42811 INIT_LIST_HEAD(&dev->node);
42812
42813 dev_set_name(&dev->dev, "input%ld",
42814 - (unsigned long) atomic_inc_return(&input_no) - 1);
42815 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42816
42817 __module_get(THIS_MODULE);
42818 }
42819 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42820 index 4a95b22..874c182 100644
42821 --- a/drivers/input/joystick/sidewinder.c
42822 +++ b/drivers/input/joystick/sidewinder.c
42823 @@ -30,6 +30,7 @@
42824 #include <linux/kernel.h>
42825 #include <linux/module.h>
42826 #include <linux/slab.h>
42827 +#include <linux/sched.h>
42828 #include <linux/input.h>
42829 #include <linux/gameport.h>
42830 #include <linux/jiffies.h>
42831 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42832 index 603fe0d..f63decc 100644
42833 --- a/drivers/input/joystick/xpad.c
42834 +++ b/drivers/input/joystick/xpad.c
42835 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42836
42837 static int xpad_led_probe(struct usb_xpad *xpad)
42838 {
42839 - static atomic_t led_seq = ATOMIC_INIT(0);
42840 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42841 long led_no;
42842 struct xpad_led *led;
42843 struct led_classdev *led_cdev;
42844 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42845 if (!led)
42846 return -ENOMEM;
42847
42848 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42849 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42850
42851 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42852 led->xpad = xpad;
42853 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42854 index e204f26..8459f15 100644
42855 --- a/drivers/input/misc/ims-pcu.c
42856 +++ b/drivers/input/misc/ims-pcu.c
42857 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42858
42859 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42860 {
42861 - static atomic_t device_no = ATOMIC_INIT(0);
42862 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42863
42864 const struct ims_pcu_device_info *info;
42865 u8 device_id;
42866 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42867 }
42868
42869 /* Device appears to be operable, complete initialization */
42870 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42871 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42872
42873 error = ims_pcu_setup_backlight(pcu);
42874 if (error)
42875 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42876 index 2f0b39d..7370f13 100644
42877 --- a/drivers/input/mouse/psmouse.h
42878 +++ b/drivers/input/mouse/psmouse.h
42879 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42880 ssize_t (*set)(struct psmouse *psmouse, void *data,
42881 const char *buf, size_t count);
42882 bool protect;
42883 -};
42884 +} __do_const;
42885 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42886
42887 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42888 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42889 index b604564..3f14ae4 100644
42890 --- a/drivers/input/mousedev.c
42891 +++ b/drivers/input/mousedev.c
42892 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42893
42894 spin_unlock_irq(&client->packet_lock);
42895
42896 - if (copy_to_user(buffer, data, count))
42897 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42898 return -EFAULT;
42899
42900 return count;
42901 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42902 index 8f4c4ab..5fc8a45 100644
42903 --- a/drivers/input/serio/serio.c
42904 +++ b/drivers/input/serio/serio.c
42905 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42906 */
42907 static void serio_init_port(struct serio *serio)
42908 {
42909 - static atomic_t serio_no = ATOMIC_INIT(0);
42910 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42911
42912 __module_get(THIS_MODULE);
42913
42914 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42915 mutex_init(&serio->drv_mutex);
42916 device_initialize(&serio->dev);
42917 dev_set_name(&serio->dev, "serio%ld",
42918 - (long)atomic_inc_return(&serio_no) - 1);
42919 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42920 serio->dev.bus = &serio_bus;
42921 serio->dev.release = serio_release_port;
42922 serio->dev.groups = serio_device_attr_groups;
42923 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42924 index c9a02fe..0debc75 100644
42925 --- a/drivers/input/serio/serio_raw.c
42926 +++ b/drivers/input/serio/serio_raw.c
42927 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42928
42929 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42930 {
42931 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42932 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42933 struct serio_raw *serio_raw;
42934 int err;
42935
42936 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42937 }
42938
42939 snprintf(serio_raw->name, sizeof(serio_raw->name),
42940 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42941 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42942 kref_init(&serio_raw->kref);
42943 INIT_LIST_HEAD(&serio_raw->client_list);
42944 init_waitqueue_head(&serio_raw->wait);
42945 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42946 index e5555fc..937986d 100644
42947 --- a/drivers/iommu/iommu.c
42948 +++ b/drivers/iommu/iommu.c
42949 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42950 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42951 {
42952 bus_register_notifier(bus, &iommu_bus_nb);
42953 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42954 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42955 }
42956
42957 /**
42958 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42959 index 228632c9..edfe331 100644
42960 --- a/drivers/iommu/irq_remapping.c
42961 +++ b/drivers/iommu/irq_remapping.c
42962 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42963 void panic_if_irq_remap(const char *msg)
42964 {
42965 if (irq_remapping_enabled)
42966 - panic(msg);
42967 + panic("%s", msg);
42968 }
42969
42970 static void ir_ack_apic_edge(struct irq_data *data)
42971 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42972
42973 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42974 {
42975 - chip->irq_print_chip = ir_print_prefix;
42976 - chip->irq_ack = ir_ack_apic_edge;
42977 - chip->irq_eoi = ir_ack_apic_level;
42978 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42979 + pax_open_kernel();
42980 + *(void **)&chip->irq_print_chip = ir_print_prefix;
42981 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
42982 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
42983 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42984 + pax_close_kernel();
42985 }
42986
42987 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42988 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42989 index 341c601..e5f407e 100644
42990 --- a/drivers/irqchip/irq-gic.c
42991 +++ b/drivers/irqchip/irq-gic.c
42992 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42993 * Supported arch specific GIC irq extension.
42994 * Default make them NULL.
42995 */
42996 -struct irq_chip gic_arch_extn = {
42997 +irq_chip_no_const gic_arch_extn = {
42998 .irq_eoi = NULL,
42999 .irq_mask = NULL,
43000 .irq_unmask = NULL,
43001 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43002 chained_irq_exit(chip, desc);
43003 }
43004
43005 -static struct irq_chip gic_chip = {
43006 +static irq_chip_no_const gic_chip __read_only = {
43007 .name = "GIC",
43008 .irq_mask = gic_mask_irq,
43009 .irq_unmask = gic_unmask_irq,
43010 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43011 index 8777065..a4a9967 100644
43012 --- a/drivers/irqchip/irq-renesas-irqc.c
43013 +++ b/drivers/irqchip/irq-renesas-irqc.c
43014 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43015 struct irqc_priv *p;
43016 struct resource *io;
43017 struct resource *irq;
43018 - struct irq_chip *irq_chip;
43019 + irq_chip_no_const *irq_chip;
43020 const char *name = dev_name(&pdev->dev);
43021 int ret;
43022 int k;
43023 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43024 index ac6f72b..81150f2 100644
43025 --- a/drivers/isdn/capi/capi.c
43026 +++ b/drivers/isdn/capi/capi.c
43027 @@ -81,8 +81,8 @@ struct capiminor {
43028
43029 struct capi20_appl *ap;
43030 u32 ncci;
43031 - atomic_t datahandle;
43032 - atomic_t msgid;
43033 + atomic_unchecked_t datahandle;
43034 + atomic_unchecked_t msgid;
43035
43036 struct tty_port port;
43037 int ttyinstop;
43038 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43039 capimsg_setu16(s, 2, mp->ap->applid);
43040 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43041 capimsg_setu8 (s, 5, CAPI_RESP);
43042 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43043 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43044 capimsg_setu32(s, 8, mp->ncci);
43045 capimsg_setu16(s, 12, datahandle);
43046 }
43047 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43048 mp->outbytes -= len;
43049 spin_unlock_bh(&mp->outlock);
43050
43051 - datahandle = atomic_inc_return(&mp->datahandle);
43052 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43053 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43054 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43055 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43056 capimsg_setu16(skb->data, 2, mp->ap->applid);
43057 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43058 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43059 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43060 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43061 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43062 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43063 capimsg_setu16(skb->data, 16, len); /* Data length */
43064 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43065 index c44950d..10ac276 100644
43066 --- a/drivers/isdn/gigaset/bas-gigaset.c
43067 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43068 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43069
43070
43071 static const struct gigaset_ops gigops = {
43072 - gigaset_write_cmd,
43073 - gigaset_write_room,
43074 - gigaset_chars_in_buffer,
43075 - gigaset_brkchars,
43076 - gigaset_init_bchannel,
43077 - gigaset_close_bchannel,
43078 - gigaset_initbcshw,
43079 - gigaset_freebcshw,
43080 - gigaset_reinitbcshw,
43081 - gigaset_initcshw,
43082 - gigaset_freecshw,
43083 - gigaset_set_modem_ctrl,
43084 - gigaset_baud_rate,
43085 - gigaset_set_line_ctrl,
43086 - gigaset_isoc_send_skb,
43087 - gigaset_isoc_input,
43088 + .write_cmd = gigaset_write_cmd,
43089 + .write_room = gigaset_write_room,
43090 + .chars_in_buffer = gigaset_chars_in_buffer,
43091 + .brkchars = gigaset_brkchars,
43092 + .init_bchannel = gigaset_init_bchannel,
43093 + .close_bchannel = gigaset_close_bchannel,
43094 + .initbcshw = gigaset_initbcshw,
43095 + .freebcshw = gigaset_freebcshw,
43096 + .reinitbcshw = gigaset_reinitbcshw,
43097 + .initcshw = gigaset_initcshw,
43098 + .freecshw = gigaset_freecshw,
43099 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43100 + .baud_rate = gigaset_baud_rate,
43101 + .set_line_ctrl = gigaset_set_line_ctrl,
43102 + .send_skb = gigaset_isoc_send_skb,
43103 + .handle_input = gigaset_isoc_input,
43104 };
43105
43106 /* bas_gigaset_init
43107 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43108 index 600c79b..3752bab 100644
43109 --- a/drivers/isdn/gigaset/interface.c
43110 +++ b/drivers/isdn/gigaset/interface.c
43111 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43112 }
43113 tty->driver_data = cs;
43114
43115 - ++cs->port.count;
43116 + atomic_inc(&cs->port.count);
43117
43118 - if (cs->port.count == 1) {
43119 + if (atomic_read(&cs->port.count) == 1) {
43120 tty_port_tty_set(&cs->port, tty);
43121 cs->port.low_latency = 1;
43122 }
43123 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43124
43125 if (!cs->connected)
43126 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43127 - else if (!cs->port.count)
43128 + else if (!atomic_read(&cs->port.count))
43129 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43130 - else if (!--cs->port.count)
43131 + else if (!atomic_dec_return(&cs->port.count))
43132 tty_port_tty_set(&cs->port, NULL);
43133
43134 mutex_unlock(&cs->mutex);
43135 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43136 index 8c91fd5..14f13ce 100644
43137 --- a/drivers/isdn/gigaset/ser-gigaset.c
43138 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43139 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43140 }
43141
43142 static const struct gigaset_ops ops = {
43143 - gigaset_write_cmd,
43144 - gigaset_write_room,
43145 - gigaset_chars_in_buffer,
43146 - gigaset_brkchars,
43147 - gigaset_init_bchannel,
43148 - gigaset_close_bchannel,
43149 - gigaset_initbcshw,
43150 - gigaset_freebcshw,
43151 - gigaset_reinitbcshw,
43152 - gigaset_initcshw,
43153 - gigaset_freecshw,
43154 - gigaset_set_modem_ctrl,
43155 - gigaset_baud_rate,
43156 - gigaset_set_line_ctrl,
43157 - gigaset_m10x_send_skb, /* asyncdata.c */
43158 - gigaset_m10x_input, /* asyncdata.c */
43159 + .write_cmd = gigaset_write_cmd,
43160 + .write_room = gigaset_write_room,
43161 + .chars_in_buffer = gigaset_chars_in_buffer,
43162 + .brkchars = gigaset_brkchars,
43163 + .init_bchannel = gigaset_init_bchannel,
43164 + .close_bchannel = gigaset_close_bchannel,
43165 + .initbcshw = gigaset_initbcshw,
43166 + .freebcshw = gigaset_freebcshw,
43167 + .reinitbcshw = gigaset_reinitbcshw,
43168 + .initcshw = gigaset_initcshw,
43169 + .freecshw = gigaset_freecshw,
43170 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43171 + .baud_rate = gigaset_baud_rate,
43172 + .set_line_ctrl = gigaset_set_line_ctrl,
43173 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43174 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43175 };
43176
43177
43178 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43179 index d0a41cb..b953e50 100644
43180 --- a/drivers/isdn/gigaset/usb-gigaset.c
43181 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43182 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43183 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43184 memcpy(cs->hw.usb->bchars, buf, 6);
43185 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43186 - 0, 0, &buf, 6, 2000);
43187 + 0, 0, buf, 6, 2000);
43188 }
43189
43190 static void gigaset_freebcshw(struct bc_state *bcs)
43191 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43192 }
43193
43194 static const struct gigaset_ops ops = {
43195 - gigaset_write_cmd,
43196 - gigaset_write_room,
43197 - gigaset_chars_in_buffer,
43198 - gigaset_brkchars,
43199 - gigaset_init_bchannel,
43200 - gigaset_close_bchannel,
43201 - gigaset_initbcshw,
43202 - gigaset_freebcshw,
43203 - gigaset_reinitbcshw,
43204 - gigaset_initcshw,
43205 - gigaset_freecshw,
43206 - gigaset_set_modem_ctrl,
43207 - gigaset_baud_rate,
43208 - gigaset_set_line_ctrl,
43209 - gigaset_m10x_send_skb,
43210 - gigaset_m10x_input,
43211 + .write_cmd = gigaset_write_cmd,
43212 + .write_room = gigaset_write_room,
43213 + .chars_in_buffer = gigaset_chars_in_buffer,
43214 + .brkchars = gigaset_brkchars,
43215 + .init_bchannel = gigaset_init_bchannel,
43216 + .close_bchannel = gigaset_close_bchannel,
43217 + .initbcshw = gigaset_initbcshw,
43218 + .freebcshw = gigaset_freebcshw,
43219 + .reinitbcshw = gigaset_reinitbcshw,
43220 + .initcshw = gigaset_initcshw,
43221 + .freecshw = gigaset_freecshw,
43222 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43223 + .baud_rate = gigaset_baud_rate,
43224 + .set_line_ctrl = gigaset_set_line_ctrl,
43225 + .send_skb = gigaset_m10x_send_skb,
43226 + .handle_input = gigaset_m10x_input,
43227 };
43228
43229 /*
43230 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43231 index 4d9b195..455075c 100644
43232 --- a/drivers/isdn/hardware/avm/b1.c
43233 +++ b/drivers/isdn/hardware/avm/b1.c
43234 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43235 }
43236 if (left) {
43237 if (t4file->user) {
43238 - if (copy_from_user(buf, dp, left))
43239 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43240 return -EFAULT;
43241 } else {
43242 memcpy(buf, dp, left);
43243 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43244 }
43245 if (left) {
43246 if (config->user) {
43247 - if (copy_from_user(buf, dp, left))
43248 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43249 return -EFAULT;
43250 } else {
43251 memcpy(buf, dp, left);
43252 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43253 index 9bb12ba..d4262f7 100644
43254 --- a/drivers/isdn/i4l/isdn_common.c
43255 +++ b/drivers/isdn/i4l/isdn_common.c
43256 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43257 } else
43258 return -EINVAL;
43259 case IIOCDBGVAR:
43260 + if (!capable(CAP_SYS_RAWIO))
43261 + return -EPERM;
43262 if (arg) {
43263 if (copy_to_user(argp, &dev, sizeof(ulong)))
43264 return -EFAULT;
43265 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43266 index 91d5730..336523e 100644
43267 --- a/drivers/isdn/i4l/isdn_concap.c
43268 +++ b/drivers/isdn/i4l/isdn_concap.c
43269 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43270 }
43271
43272 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43273 - &isdn_concap_dl_data_req,
43274 - &isdn_concap_dl_connect_req,
43275 - &isdn_concap_dl_disconn_req
43276 + .data_req = &isdn_concap_dl_data_req,
43277 + .connect_req = &isdn_concap_dl_connect_req,
43278 + .disconn_req = &isdn_concap_dl_disconn_req
43279 };
43280
43281 /* The following should better go into a dedicated source file such that
43282 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43283 index 3c5f249..5fac4d0 100644
43284 --- a/drivers/isdn/i4l/isdn_tty.c
43285 +++ b/drivers/isdn/i4l/isdn_tty.c
43286 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43287
43288 #ifdef ISDN_DEBUG_MODEM_OPEN
43289 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43290 - port->count);
43291 + atomic_read(&port->count));
43292 #endif
43293 - port->count++;
43294 + atomic_inc(&port->count);
43295 port->tty = tty;
43296 /*
43297 * Start up serial port
43298 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43299 #endif
43300 return;
43301 }
43302 - if ((tty->count == 1) && (port->count != 1)) {
43303 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43304 /*
43305 * Uh, oh. tty->count is 1, which means that the tty
43306 * structure will be freed. Info->count should always
43307 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43308 * serial port won't be shutdown.
43309 */
43310 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43311 - "info->count is %d\n", port->count);
43312 - port->count = 1;
43313 + "info->count is %d\n", atomic_read(&port->count));
43314 + atomic_set(&port->count, 1);
43315 }
43316 - if (--port->count < 0) {
43317 + if (atomic_dec_return(&port->count) < 0) {
43318 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43319 - info->line, port->count);
43320 - port->count = 0;
43321 + info->line, atomic_read(&port->count));
43322 + atomic_set(&port->count, 0);
43323 }
43324 - if (port->count) {
43325 + if (atomic_read(&port->count)) {
43326 #ifdef ISDN_DEBUG_MODEM_OPEN
43327 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43328 #endif
43329 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43330 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43331 return;
43332 isdn_tty_shutdown(info);
43333 - port->count = 0;
43334 + atomic_set(&port->count, 0);
43335 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43336 port->tty = NULL;
43337 wake_up_interruptible(&port->open_wait);
43338 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43339 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43340 modem_info *info = &dev->mdm.info[i];
43341
43342 - if (info->port.count == 0)
43343 + if (atomic_read(&info->port.count) == 0)
43344 continue;
43345 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43346 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43347 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43348 index e2d4e58..40cd045 100644
43349 --- a/drivers/isdn/i4l/isdn_x25iface.c
43350 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43351 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43352
43353
43354 static struct concap_proto_ops ix25_pops = {
43355 - &isdn_x25iface_proto_new,
43356 - &isdn_x25iface_proto_del,
43357 - &isdn_x25iface_proto_restart,
43358 - &isdn_x25iface_proto_close,
43359 - &isdn_x25iface_xmit,
43360 - &isdn_x25iface_receive,
43361 - &isdn_x25iface_connect_ind,
43362 - &isdn_x25iface_disconn_ind
43363 + .proto_new = &isdn_x25iface_proto_new,
43364 + .proto_del = &isdn_x25iface_proto_del,
43365 + .restart = &isdn_x25iface_proto_restart,
43366 + .close = &isdn_x25iface_proto_close,
43367 + .encap_and_xmit = &isdn_x25iface_xmit,
43368 + .data_ind = &isdn_x25iface_receive,
43369 + .connect_ind = &isdn_x25iface_connect_ind,
43370 + .disconn_ind = &isdn_x25iface_disconn_ind
43371 };
43372
43373 /* error message helper function */
43374 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43375 index 53d487f..cae33fe 100644
43376 --- a/drivers/isdn/icn/icn.c
43377 +++ b/drivers/isdn/icn/icn.c
43378 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43379 if (count > len)
43380 count = len;
43381 if (user) {
43382 - if (copy_from_user(msg, buf, count))
43383 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43384 return -EFAULT;
43385 } else
43386 memcpy(msg, buf, count);
43387 @@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43388 ulong a;
43389 ulong flags;
43390 int i;
43391 - char cbuf[60];
43392 + char cbuf[80];
43393 isdn_ctrl cmd;
43394 icn_cdef cdef;
43395 char __user *arg;
43396 @@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43397 break;
43398 if ((c->arg & 255) < ICN_BCH) {
43399 char *p;
43400 - char dial[50];
43401 char dcode[4];
43402
43403 a = c->arg;
43404 @@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43405 } else
43406 /* Normal Dial */
43407 strcpy(dcode, "CAL");
43408 - strcpy(dial, p);
43409 - sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43410 - dcode, dial, c->parm.setup.si1,
43411 - c->parm.setup.si2, c->parm.setup.eazmsn);
43412 + snprintf(cbuf, sizeof(cbuf),
43413 + "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43414 + dcode, p, c->parm.setup.si1,
43415 + c->parm.setup.si2, c->parm.setup.eazmsn);
43416 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43417 }
43418 break;
43419 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43420 index a4f05c5..1433bc5 100644
43421 --- a/drivers/isdn/mISDN/dsp_cmx.c
43422 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43423 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43424 static u16 dsp_count; /* last sample count */
43425 static int dsp_count_valid; /* if we have last sample count */
43426
43427 -void
43428 +void __intentional_overflow(-1)
43429 dsp_cmx_send(void *arg)
43430 {
43431 struct dsp_conf *conf;
43432 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43433 index d93e245..e7ece6b 100644
43434 --- a/drivers/leds/leds-clevo-mail.c
43435 +++ b/drivers/leds/leds-clevo-mail.c
43436 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43437 * detected as working, but in reality it is not) as low as
43438 * possible.
43439 */
43440 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43441 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43442 {
43443 .callback = clevo_mail_led_dmi_callback,
43444 .ident = "Clevo D410J",
43445 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43446 index 5b8f938..b73d657 100644
43447 --- a/drivers/leds/leds-ss4200.c
43448 +++ b/drivers/leds/leds-ss4200.c
43449 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43450 * detected as working, but in reality it is not) as low as
43451 * possible.
43452 */
43453 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43454 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43455 {
43456 .callback = ss4200_led_dmi_callback,
43457 .ident = "Intel SS4200-E",
43458 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43459 index 0bf1e4e..b4bf44e 100644
43460 --- a/drivers/lguest/core.c
43461 +++ b/drivers/lguest/core.c
43462 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43463 * The end address needs +1 because __get_vm_area allocates an
43464 * extra guard page, so we need space for that.
43465 */
43466 +
43467 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43468 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43469 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43470 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43471 +#else
43472 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43473 VM_ALLOC, switcher_addr, switcher_addr
43474 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43475 +#endif
43476 +
43477 if (!switcher_vma) {
43478 err = -ENOMEM;
43479 printk("lguest: could not map switcher pages high\n");
43480 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43481 * Now the Switcher is mapped at the right address, we can't fail!
43482 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43483 */
43484 - memcpy(switcher_vma->addr, start_switcher_text,
43485 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43486 end_switcher_text - start_switcher_text);
43487
43488 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43489 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43490 index bfb39bb..08a603b 100644
43491 --- a/drivers/lguest/page_tables.c
43492 +++ b/drivers/lguest/page_tables.c
43493 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43494 /*:*/
43495
43496 #ifdef CONFIG_X86_PAE
43497 -static void release_pmd(pmd_t *spmd)
43498 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43499 {
43500 /* If the entry's not present, there's nothing to release. */
43501 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43502 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43503 index 922a1ac..9dd0c2a 100644
43504 --- a/drivers/lguest/x86/core.c
43505 +++ b/drivers/lguest/x86/core.c
43506 @@ -59,7 +59,7 @@ static struct {
43507 /* Offset from where switcher.S was compiled to where we've copied it */
43508 static unsigned long switcher_offset(void)
43509 {
43510 - return switcher_addr - (unsigned long)start_switcher_text;
43511 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43512 }
43513
43514 /* This cpu's struct lguest_pages (after the Switcher text page) */
43515 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43516 * These copies are pretty cheap, so we do them unconditionally: */
43517 /* Save the current Host top-level page directory.
43518 */
43519 +
43520 +#ifdef CONFIG_PAX_PER_CPU_PGD
43521 + pages->state.host_cr3 = read_cr3();
43522 +#else
43523 pages->state.host_cr3 = __pa(current->mm->pgd);
43524 +#endif
43525 +
43526 /*
43527 * Set up the Guest's page tables to see this CPU's pages (and no
43528 * other CPU's pages).
43529 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43530 * compiled-in switcher code and the high-mapped copy we just made.
43531 */
43532 for (i = 0; i < IDT_ENTRIES; i++)
43533 - default_idt_entries[i] += switcher_offset();
43534 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43535
43536 /*
43537 * Set up the Switcher's per-cpu areas.
43538 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43539 * it will be undisturbed when we switch. To change %cs and jump we
43540 * need this structure to feed to Intel's "lcall" instruction.
43541 */
43542 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43543 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43544 lguest_entry.segment = LGUEST_CS;
43545
43546 /*
43547 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43548 index 40634b0..4f5855e 100644
43549 --- a/drivers/lguest/x86/switcher_32.S
43550 +++ b/drivers/lguest/x86/switcher_32.S
43551 @@ -87,6 +87,7 @@
43552 #include <asm/page.h>
43553 #include <asm/segment.h>
43554 #include <asm/lguest.h>
43555 +#include <asm/processor-flags.h>
43556
43557 // We mark the start of the code to copy
43558 // It's placed in .text tho it's never run here
43559 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43560 // Changes type when we load it: damn Intel!
43561 // For after we switch over our page tables
43562 // That entry will be read-only: we'd crash.
43563 +
43564 +#ifdef CONFIG_PAX_KERNEXEC
43565 + mov %cr0, %edx
43566 + xor $X86_CR0_WP, %edx
43567 + mov %edx, %cr0
43568 +#endif
43569 +
43570 movl $(GDT_ENTRY_TSS*8), %edx
43571 ltr %dx
43572
43573 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43574 // Let's clear it again for our return.
43575 // The GDT descriptor of the Host
43576 // Points to the table after two "size" bytes
43577 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43578 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43579 // Clear "used" from type field (byte 5, bit 2)
43580 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43581 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43582 +
43583 +#ifdef CONFIG_PAX_KERNEXEC
43584 + mov %cr0, %eax
43585 + xor $X86_CR0_WP, %eax
43586 + mov %eax, %cr0
43587 +#endif
43588
43589 // Once our page table's switched, the Guest is live!
43590 // The Host fades as we run this final step.
43591 @@ -295,13 +309,12 @@ deliver_to_host:
43592 // I consulted gcc, and it gave
43593 // These instructions, which I gladly credit:
43594 leal (%edx,%ebx,8), %eax
43595 - movzwl (%eax),%edx
43596 - movl 4(%eax), %eax
43597 - xorw %ax, %ax
43598 - orl %eax, %edx
43599 + movl 4(%eax), %edx
43600 + movw (%eax), %dx
43601 // Now the address of the handler's in %edx
43602 // We call it now: its "iret" drops us home.
43603 - jmp *%edx
43604 + ljmp $__KERNEL_CS, $1f
43605 +1: jmp *%edx
43606
43607 // Every interrupt can come to us here
43608 // But we must truly tell each apart.
43609 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43610 index 7ef7461..5a09dac 100644
43611 --- a/drivers/md/bcache/closure.h
43612 +++ b/drivers/md/bcache/closure.h
43613 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43614 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43615 struct workqueue_struct *wq)
43616 {
43617 - BUG_ON(object_is_on_stack(cl));
43618 + BUG_ON(object_starts_on_stack(cl));
43619 closure_set_ip(cl);
43620 cl->fn = fn;
43621 cl->wq = wq;
43622 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43623 index 4195a01..42527ac 100644
43624 --- a/drivers/md/bitmap.c
43625 +++ b/drivers/md/bitmap.c
43626 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43627 chunk_kb ? "KB" : "B");
43628 if (bitmap->storage.file) {
43629 seq_printf(seq, ", file: ");
43630 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43631 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43632 }
43633
43634 seq_printf(seq, "\n");
43635 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43636 index 5152142..623d141 100644
43637 --- a/drivers/md/dm-ioctl.c
43638 +++ b/drivers/md/dm-ioctl.c
43639 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43640 cmd == DM_LIST_VERSIONS_CMD)
43641 return 0;
43642
43643 - if ((cmd == DM_DEV_CREATE_CMD)) {
43644 + if (cmd == DM_DEV_CREATE_CMD) {
43645 if (!*param->name) {
43646 DMWARN("name not supplied when creating device");
43647 return -EINVAL;
43648 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43649 index 7dfdb5c..4caada6 100644
43650 --- a/drivers/md/dm-raid1.c
43651 +++ b/drivers/md/dm-raid1.c
43652 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43653
43654 struct mirror {
43655 struct mirror_set *ms;
43656 - atomic_t error_count;
43657 + atomic_unchecked_t error_count;
43658 unsigned long error_type;
43659 struct dm_dev *dev;
43660 sector_t offset;
43661 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43662 struct mirror *m;
43663
43664 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43665 - if (!atomic_read(&m->error_count))
43666 + if (!atomic_read_unchecked(&m->error_count))
43667 return m;
43668
43669 return NULL;
43670 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43671 * simple way to tell if a device has encountered
43672 * errors.
43673 */
43674 - atomic_inc(&m->error_count);
43675 + atomic_inc_unchecked(&m->error_count);
43676
43677 if (test_and_set_bit(error_type, &m->error_type))
43678 return;
43679 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43680 struct mirror *m = get_default_mirror(ms);
43681
43682 do {
43683 - if (likely(!atomic_read(&m->error_count)))
43684 + if (likely(!atomic_read_unchecked(&m->error_count)))
43685 return m;
43686
43687 if (m-- == ms->mirror)
43688 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43689 {
43690 struct mirror *default_mirror = get_default_mirror(m->ms);
43691
43692 - return !atomic_read(&default_mirror->error_count);
43693 + return !atomic_read_unchecked(&default_mirror->error_count);
43694 }
43695
43696 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43697 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43698 */
43699 if (likely(region_in_sync(ms, region, 1)))
43700 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43701 - else if (m && atomic_read(&m->error_count))
43702 + else if (m && atomic_read_unchecked(&m->error_count))
43703 m = NULL;
43704
43705 if (likely(m))
43706 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43707 }
43708
43709 ms->mirror[mirror].ms = ms;
43710 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43711 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43712 ms->mirror[mirror].error_type = 0;
43713 ms->mirror[mirror].offset = offset;
43714
43715 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43716 */
43717 static char device_status_char(struct mirror *m)
43718 {
43719 - if (!atomic_read(&(m->error_count)))
43720 + if (!atomic_read_unchecked(&(m->error_count)))
43721 return 'A';
43722
43723 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43724 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43725 index 28a9012..9c0f6a5 100644
43726 --- a/drivers/md/dm-stats.c
43727 +++ b/drivers/md/dm-stats.c
43728 @@ -382,7 +382,7 @@ do_sync_free:
43729 synchronize_rcu_expedited();
43730 dm_stat_free(&s->rcu_head);
43731 } else {
43732 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43733 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43734 call_rcu(&s->rcu_head, dm_stat_free);
43735 }
43736 return 0;
43737 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43738 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43739 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43740 ));
43741 - ACCESS_ONCE(last->last_sector) = end_sector;
43742 - ACCESS_ONCE(last->last_rw) = bi_rw;
43743 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43744 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43745 }
43746
43747 rcu_read_lock();
43748 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43749 index d1600d2..4c3af3a 100644
43750 --- a/drivers/md/dm-stripe.c
43751 +++ b/drivers/md/dm-stripe.c
43752 @@ -21,7 +21,7 @@ struct stripe {
43753 struct dm_dev *dev;
43754 sector_t physical_start;
43755
43756 - atomic_t error_count;
43757 + atomic_unchecked_t error_count;
43758 };
43759
43760 struct stripe_c {
43761 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43762 kfree(sc);
43763 return r;
43764 }
43765 - atomic_set(&(sc->stripe[i].error_count), 0);
43766 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43767 }
43768
43769 ti->private = sc;
43770 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43771 DMEMIT("%d ", sc->stripes);
43772 for (i = 0; i < sc->stripes; i++) {
43773 DMEMIT("%s ", sc->stripe[i].dev->name);
43774 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43775 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43776 'D' : 'A';
43777 }
43778 buffer[i] = '\0';
43779 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43780 */
43781 for (i = 0; i < sc->stripes; i++)
43782 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43783 - atomic_inc(&(sc->stripe[i].error_count));
43784 - if (atomic_read(&(sc->stripe[i].error_count)) <
43785 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43786 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43787 DM_IO_ERROR_THRESHOLD)
43788 schedule_work(&sc->trigger_event);
43789 }
43790 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43791 index 6a7f2b8..fea0bde 100644
43792 --- a/drivers/md/dm-table.c
43793 +++ b/drivers/md/dm-table.c
43794 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43795 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43796 struct mapped_device *md)
43797 {
43798 - static char *_claim_ptr = "I belong to device-mapper";
43799 + static char _claim_ptr[] = "I belong to device-mapper";
43800 struct block_device *bdev;
43801
43802 int r;
43803 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43804 if (!dev_size)
43805 return 0;
43806
43807 - if ((start >= dev_size) || (start + len > dev_size)) {
43808 + if ((start >= dev_size) || (len > dev_size - start)) {
43809 DMWARN("%s: %s too small for target: "
43810 "start=%llu, len=%llu, dev_size=%llu",
43811 dm_device_name(ti->table->md), bdevname(bdev, b),
43812 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43813 index fb9efc8..81e8986 100644
43814 --- a/drivers/md/dm-thin-metadata.c
43815 +++ b/drivers/md/dm-thin-metadata.c
43816 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43817 {
43818 pmd->info.tm = pmd->tm;
43819 pmd->info.levels = 2;
43820 - pmd->info.value_type.context = pmd->data_sm;
43821 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43822 pmd->info.value_type.size = sizeof(__le64);
43823 pmd->info.value_type.inc = data_block_inc;
43824 pmd->info.value_type.dec = data_block_dec;
43825 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43826
43827 pmd->bl_info.tm = pmd->tm;
43828 pmd->bl_info.levels = 1;
43829 - pmd->bl_info.value_type.context = pmd->data_sm;
43830 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43831 pmd->bl_info.value_type.size = sizeof(__le64);
43832 pmd->bl_info.value_type.inc = data_block_inc;
43833 pmd->bl_info.value_type.dec = data_block_dec;
43834 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43835 index 8c53b09..f1fb2b0 100644
43836 --- a/drivers/md/dm.c
43837 +++ b/drivers/md/dm.c
43838 @@ -185,9 +185,9 @@ struct mapped_device {
43839 /*
43840 * Event handling.
43841 */
43842 - atomic_t event_nr;
43843 + atomic_unchecked_t event_nr;
43844 wait_queue_head_t eventq;
43845 - atomic_t uevent_seq;
43846 + atomic_unchecked_t uevent_seq;
43847 struct list_head uevent_list;
43848 spinlock_t uevent_lock; /* Protect access to uevent_list */
43849
43850 @@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
43851 spin_lock_init(&md->deferred_lock);
43852 atomic_set(&md->holders, 1);
43853 atomic_set(&md->open_count, 0);
43854 - atomic_set(&md->event_nr, 0);
43855 - atomic_set(&md->uevent_seq, 0);
43856 + atomic_set_unchecked(&md->event_nr, 0);
43857 + atomic_set_unchecked(&md->uevent_seq, 0);
43858 INIT_LIST_HEAD(&md->uevent_list);
43859 spin_lock_init(&md->uevent_lock);
43860
43861 @@ -2043,7 +2043,7 @@ static void event_callback(void *context)
43862
43863 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43864
43865 - atomic_inc(&md->event_nr);
43866 + atomic_inc_unchecked(&md->event_nr);
43867 wake_up(&md->eventq);
43868 }
43869
43870 @@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43871
43872 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43873 {
43874 - return atomic_add_return(1, &md->uevent_seq);
43875 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43876 }
43877
43878 uint32_t dm_get_event_nr(struct mapped_device *md)
43879 {
43880 - return atomic_read(&md->event_nr);
43881 + return atomic_read_unchecked(&md->event_nr);
43882 }
43883
43884 int dm_wait_event(struct mapped_device *md, int event_nr)
43885 {
43886 return wait_event_interruptible(md->eventq,
43887 - (event_nr != atomic_read(&md->event_nr)));
43888 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43889 }
43890
43891 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43892 diff --git a/drivers/md/md.c b/drivers/md/md.c
43893 index 4ad5cc4..0f19664 100644
43894 --- a/drivers/md/md.c
43895 +++ b/drivers/md/md.c
43896 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43897 * start build, activate spare
43898 */
43899 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43900 -static atomic_t md_event_count;
43901 +static atomic_unchecked_t md_event_count;
43902 void md_new_event(struct mddev *mddev)
43903 {
43904 - atomic_inc(&md_event_count);
43905 + atomic_inc_unchecked(&md_event_count);
43906 wake_up(&md_event_waiters);
43907 }
43908 EXPORT_SYMBOL_GPL(md_new_event);
43909 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43910 */
43911 static void md_new_event_inintr(struct mddev *mddev)
43912 {
43913 - atomic_inc(&md_event_count);
43914 + atomic_inc_unchecked(&md_event_count);
43915 wake_up(&md_event_waiters);
43916 }
43917
43918 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43919 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43920 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43921 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43922 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43923 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43924
43925 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43926 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43927 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43928 else
43929 sb->resync_offset = cpu_to_le64(0);
43930
43931 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43932 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43933
43934 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43935 sb->size = cpu_to_le64(mddev->dev_sectors);
43936 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43937 static ssize_t
43938 errors_show(struct md_rdev *rdev, char *page)
43939 {
43940 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43941 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43942 }
43943
43944 static ssize_t
43945 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43946 char *e;
43947 unsigned long n = simple_strtoul(buf, &e, 10);
43948 if (*buf && (*e == 0 || *e == '\n')) {
43949 - atomic_set(&rdev->corrected_errors, n);
43950 + atomic_set_unchecked(&rdev->corrected_errors, n);
43951 return len;
43952 }
43953 return -EINVAL;
43954 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43955 rdev->sb_loaded = 0;
43956 rdev->bb_page = NULL;
43957 atomic_set(&rdev->nr_pending, 0);
43958 - atomic_set(&rdev->read_errors, 0);
43959 - atomic_set(&rdev->corrected_errors, 0);
43960 + atomic_set_unchecked(&rdev->read_errors, 0);
43961 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43962
43963 INIT_LIST_HEAD(&rdev->same_set);
43964 init_waitqueue_head(&rdev->blocked_wait);
43965 @@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43966
43967 spin_unlock(&pers_lock);
43968 seq_printf(seq, "\n");
43969 - seq->poll_event = atomic_read(&md_event_count);
43970 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43971 return 0;
43972 }
43973 if (v == (void*)2) {
43974 @@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43975 return error;
43976
43977 seq = file->private_data;
43978 - seq->poll_event = atomic_read(&md_event_count);
43979 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43980 return error;
43981 }
43982
43983 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43984 /* always allow read */
43985 mask = POLLIN | POLLRDNORM;
43986
43987 - if (seq->poll_event != atomic_read(&md_event_count))
43988 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43989 mask |= POLLERR | POLLPRI;
43990 return mask;
43991 }
43992 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43993 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43994 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43995 (int)part_stat_read(&disk->part0, sectors[1]) -
43996 - atomic_read(&disk->sync_io);
43997 + atomic_read_unchecked(&disk->sync_io);
43998 /* sync IO will cause sync_io to increase before the disk_stats
43999 * as sync_io is counted when a request starts, and
44000 * disk_stats is counted when it completes.
44001 diff --git a/drivers/md/md.h b/drivers/md/md.h
44002 index 07bba96..2d6788c 100644
44003 --- a/drivers/md/md.h
44004 +++ b/drivers/md/md.h
44005 @@ -94,13 +94,13 @@ struct md_rdev {
44006 * only maintained for arrays that
44007 * support hot removal
44008 */
44009 - atomic_t read_errors; /* number of consecutive read errors that
44010 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44011 * we have tried to ignore.
44012 */
44013 struct timespec last_read_error; /* monotonic time since our
44014 * last read error
44015 */
44016 - atomic_t corrected_errors; /* number of corrected read errors,
44017 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44018 * for reporting to userspace and storing
44019 * in superblock.
44020 */
44021 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44022
44023 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44024 {
44025 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44026 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44027 }
44028
44029 struct md_personality
44030 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44031 index 786b689..ea8c956 100644
44032 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44033 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44034 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44035 * Flick into a mode where all blocks get allocated in the new area.
44036 */
44037 smm->begin = old_len;
44038 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44039 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44040
44041 /*
44042 * Extend.
44043 @@ -710,7 +710,7 @@ out:
44044 /*
44045 * Switch back to normal behaviour.
44046 */
44047 - memcpy(sm, &ops, sizeof(*sm));
44048 + memcpy((void *)sm, &ops, sizeof(*sm));
44049 return r;
44050 }
44051
44052 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44053 index 3e6d115..ffecdeb 100644
44054 --- a/drivers/md/persistent-data/dm-space-map.h
44055 +++ b/drivers/md/persistent-data/dm-space-map.h
44056 @@ -71,6 +71,7 @@ struct dm_space_map {
44057 dm_sm_threshold_fn fn,
44058 void *context);
44059 };
44060 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44061
44062 /*----------------------------------------------------------------*/
44063
44064 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44065 index 4a6ca1c..e952750 100644
44066 --- a/drivers/md/raid1.c
44067 +++ b/drivers/md/raid1.c
44068 @@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44069 if (r1_sync_page_io(rdev, sect, s,
44070 bio->bi_io_vec[idx].bv_page,
44071 READ) != 0)
44072 - atomic_add(s, &rdev->corrected_errors);
44073 + atomic_add_unchecked(s, &rdev->corrected_errors);
44074 }
44075 sectors -= s;
44076 sect += s;
44077 @@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44078 test_bit(In_sync, &rdev->flags)) {
44079 if (r1_sync_page_io(rdev, sect, s,
44080 conf->tmppage, READ)) {
44081 - atomic_add(s, &rdev->corrected_errors);
44082 + atomic_add_unchecked(s, &rdev->corrected_errors);
44083 printk(KERN_INFO
44084 "md/raid1:%s: read error corrected "
44085 "(%d sectors at %llu on %s)\n",
44086 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44087 index 33fc408..fc61709 100644
44088 --- a/drivers/md/raid10.c
44089 +++ b/drivers/md/raid10.c
44090 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44091 /* The write handler will notice the lack of
44092 * R10BIO_Uptodate and record any errors etc
44093 */
44094 - atomic_add(r10_bio->sectors,
44095 + atomic_add_unchecked(r10_bio->sectors,
44096 &conf->mirrors[d].rdev->corrected_errors);
44097
44098 /* for reconstruct, we always reschedule after a read.
44099 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44100 {
44101 struct timespec cur_time_mon;
44102 unsigned long hours_since_last;
44103 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44104 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44105
44106 ktime_get_ts(&cur_time_mon);
44107
44108 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44109 * overflowing the shift of read_errors by hours_since_last.
44110 */
44111 if (hours_since_last >= 8 * sizeof(read_errors))
44112 - atomic_set(&rdev->read_errors, 0);
44113 + atomic_set_unchecked(&rdev->read_errors, 0);
44114 else
44115 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44116 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44117 }
44118
44119 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44120 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44121 return;
44122
44123 check_decay_read_errors(mddev, rdev);
44124 - atomic_inc(&rdev->read_errors);
44125 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44126 + atomic_inc_unchecked(&rdev->read_errors);
44127 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44128 char b[BDEVNAME_SIZE];
44129 bdevname(rdev->bdev, b);
44130
44131 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44132 "md/raid10:%s: %s: Raid device exceeded "
44133 "read_error threshold [cur %d:max %d]\n",
44134 mdname(mddev), b,
44135 - atomic_read(&rdev->read_errors), max_read_errors);
44136 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44137 printk(KERN_NOTICE
44138 "md/raid10:%s: %s: Failing raid device\n",
44139 mdname(mddev), b);
44140 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44141 sect +
44142 choose_data_offset(r10_bio, rdev)),
44143 bdevname(rdev->bdev, b));
44144 - atomic_add(s, &rdev->corrected_errors);
44145 + atomic_add_unchecked(s, &rdev->corrected_errors);
44146 }
44147
44148 rdev_dec_pending(rdev, mddev);
44149 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44150 index 16f5c21..4df20dc 100644
44151 --- a/drivers/md/raid5.c
44152 +++ b/drivers/md/raid5.c
44153 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44154 mdname(conf->mddev), STRIPE_SECTORS,
44155 (unsigned long long)s,
44156 bdevname(rdev->bdev, b));
44157 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44158 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44159 clear_bit(R5_ReadError, &sh->dev[i].flags);
44160 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44161 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44162 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44163
44164 - if (atomic_read(&rdev->read_errors))
44165 - atomic_set(&rdev->read_errors, 0);
44166 + if (atomic_read_unchecked(&rdev->read_errors))
44167 + atomic_set_unchecked(&rdev->read_errors, 0);
44168 } else {
44169 const char *bdn = bdevname(rdev->bdev, b);
44170 int retry = 0;
44171 int set_bad = 0;
44172
44173 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44174 - atomic_inc(&rdev->read_errors);
44175 + atomic_inc_unchecked(&rdev->read_errors);
44176 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44177 printk_ratelimited(
44178 KERN_WARNING
44179 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44180 mdname(conf->mddev),
44181 (unsigned long long)s,
44182 bdn);
44183 - } else if (atomic_read(&rdev->read_errors)
44184 + } else if (atomic_read_unchecked(&rdev->read_errors)
44185 > conf->max_nr_stripes)
44186 printk(KERN_WARNING
44187 "md/raid:%s: Too many read errors, failing device %s.\n",
44188 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44189 index 983db75..ef9248c 100644
44190 --- a/drivers/media/dvb-core/dvbdev.c
44191 +++ b/drivers/media/dvb-core/dvbdev.c
44192 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44193 const struct dvb_device *template, void *priv, int type)
44194 {
44195 struct dvb_device *dvbdev;
44196 - struct file_operations *dvbdevfops;
44197 + file_operations_no_const *dvbdevfops;
44198 struct device *clsdev;
44199 int minor;
44200 int id;
44201 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44202 index 9b6c3bb..baeb5c7 100644
44203 --- a/drivers/media/dvb-frontends/dib3000.h
44204 +++ b/drivers/media/dvb-frontends/dib3000.h
44205 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44206 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44207 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44208 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44209 -};
44210 +} __no_const;
44211
44212 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44213 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44214 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44215 index ed8cb90..5ef7f79 100644
44216 --- a/drivers/media/pci/cx88/cx88-video.c
44217 +++ b/drivers/media/pci/cx88/cx88-video.c
44218 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44219
44220 /* ------------------------------------------------------------------ */
44221
44222 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44223 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44224 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44225 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44226 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44227 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44228
44229 module_param_array(video_nr, int, NULL, 0444);
44230 module_param_array(vbi_nr, int, NULL, 0444);
44231 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44232 index 802642d..5534900 100644
44233 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44234 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44235 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44236 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44237
44238 /* ivtv instance counter */
44239 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44240 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44241
44242 /* Parameter declarations */
44243 static int cardtype[IVTV_MAX_CARDS];
44244 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44245 index dfd0a21..6bbb465 100644
44246 --- a/drivers/media/platform/omap/omap_vout.c
44247 +++ b/drivers/media/platform/omap/omap_vout.c
44248 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44249 OMAP_VIDEO2,
44250 };
44251
44252 -static struct videobuf_queue_ops video_vbq_ops;
44253 /* Variables configurable through module params*/
44254 static u32 video1_numbuffers = 3;
44255 static u32 video2_numbuffers = 3;
44256 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44257 {
44258 struct videobuf_queue *q;
44259 struct omap_vout_device *vout = NULL;
44260 + static struct videobuf_queue_ops video_vbq_ops = {
44261 + .buf_setup = omap_vout_buffer_setup,
44262 + .buf_prepare = omap_vout_buffer_prepare,
44263 + .buf_release = omap_vout_buffer_release,
44264 + .buf_queue = omap_vout_buffer_queue,
44265 + };
44266
44267 vout = video_drvdata(file);
44268 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44269 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44270 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44271
44272 q = &vout->vbq;
44273 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44274 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44275 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44276 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44277 spin_lock_init(&vout->vbq_lock);
44278
44279 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44280 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44281 index fb2acc5..a2fcbdc4 100644
44282 --- a/drivers/media/platform/s5p-tv/mixer.h
44283 +++ b/drivers/media/platform/s5p-tv/mixer.h
44284 @@ -156,7 +156,7 @@ struct mxr_layer {
44285 /** layer index (unique identifier) */
44286 int idx;
44287 /** callbacks for layer methods */
44288 - struct mxr_layer_ops ops;
44289 + struct mxr_layer_ops *ops;
44290 /** format array */
44291 const struct mxr_format **fmt_array;
44292 /** size of format array */
44293 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44294 index 74344c7..a39e70e 100644
44295 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44296 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44297 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44298 {
44299 struct mxr_layer *layer;
44300 int ret;
44301 - struct mxr_layer_ops ops = {
44302 + static struct mxr_layer_ops ops = {
44303 .release = mxr_graph_layer_release,
44304 .buffer_set = mxr_graph_buffer_set,
44305 .stream_set = mxr_graph_stream_set,
44306 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44307 index b713403..53cb5ad 100644
44308 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44309 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44310 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44311 layer->update_buf = next;
44312 }
44313
44314 - layer->ops.buffer_set(layer, layer->update_buf);
44315 + layer->ops->buffer_set(layer, layer->update_buf);
44316
44317 if (done && done != layer->shadow_buf)
44318 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44319 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44320 index c5059ba..2649f28 100644
44321 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44322 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44323 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44324 layer->geo.src.height = layer->geo.src.full_height;
44325
44326 mxr_geometry_dump(mdev, &layer->geo);
44327 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44328 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44329 mxr_geometry_dump(mdev, &layer->geo);
44330 }
44331
44332 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44333 layer->geo.dst.full_width = mbus_fmt.width;
44334 layer->geo.dst.full_height = mbus_fmt.height;
44335 layer->geo.dst.field = mbus_fmt.field;
44336 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44337 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44338
44339 mxr_geometry_dump(mdev, &layer->geo);
44340 }
44341 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44342 /* set source size to highest accepted value */
44343 geo->src.full_width = max(geo->dst.full_width, pix->width);
44344 geo->src.full_height = max(geo->dst.full_height, pix->height);
44345 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44346 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44347 mxr_geometry_dump(mdev, &layer->geo);
44348 /* set cropping to total visible screen */
44349 geo->src.width = pix->width;
44350 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44351 geo->src.x_offset = 0;
44352 geo->src.y_offset = 0;
44353 /* assure consistency of geometry */
44354 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44355 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44356 mxr_geometry_dump(mdev, &layer->geo);
44357 /* set full size to lowest possible value */
44358 geo->src.full_width = 0;
44359 geo->src.full_height = 0;
44360 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44361 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44362 mxr_geometry_dump(mdev, &layer->geo);
44363
44364 /* returning results */
44365 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44366 target->width = s->r.width;
44367 target->height = s->r.height;
44368
44369 - layer->ops.fix_geometry(layer, stage, s->flags);
44370 + layer->ops->fix_geometry(layer, stage, s->flags);
44371
44372 /* retrieve update selection rectangle */
44373 res.left = target->x_offset;
44374 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44375 mxr_output_get(mdev);
44376
44377 mxr_layer_update_output(layer);
44378 - layer->ops.format_set(layer);
44379 + layer->ops->format_set(layer);
44380 /* enabling layer in hardware */
44381 spin_lock_irqsave(&layer->enq_slock, flags);
44382 layer->state = MXR_LAYER_STREAMING;
44383 spin_unlock_irqrestore(&layer->enq_slock, flags);
44384
44385 - layer->ops.stream_set(layer, MXR_ENABLE);
44386 + layer->ops->stream_set(layer, MXR_ENABLE);
44387 mxr_streamer_get(mdev);
44388
44389 return 0;
44390 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44391 spin_unlock_irqrestore(&layer->enq_slock, flags);
44392
44393 /* disabling layer in hardware */
44394 - layer->ops.stream_set(layer, MXR_DISABLE);
44395 + layer->ops->stream_set(layer, MXR_DISABLE);
44396 /* remove one streamer */
44397 mxr_streamer_put(mdev);
44398 /* allow changes in output configuration */
44399 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44400
44401 void mxr_layer_release(struct mxr_layer *layer)
44402 {
44403 - if (layer->ops.release)
44404 - layer->ops.release(layer);
44405 + if (layer->ops->release)
44406 + layer->ops->release(layer);
44407 }
44408
44409 void mxr_base_layer_release(struct mxr_layer *layer)
44410 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44411
44412 layer->mdev = mdev;
44413 layer->idx = idx;
44414 - layer->ops = *ops;
44415 + layer->ops = ops;
44416
44417 spin_lock_init(&layer->enq_slock);
44418 INIT_LIST_HEAD(&layer->enq_list);
44419 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44420 index c9388c4..ce71ece 100644
44421 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44422 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44423 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44424 {
44425 struct mxr_layer *layer;
44426 int ret;
44427 - struct mxr_layer_ops ops = {
44428 + static struct mxr_layer_ops ops = {
44429 .release = mxr_vp_layer_release,
44430 .buffer_set = mxr_vp_buffer_set,
44431 .stream_set = mxr_vp_stream_set,
44432 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44433 index 2d4e73b..8b4d5b6 100644
44434 --- a/drivers/media/platform/vivi.c
44435 +++ b/drivers/media/platform/vivi.c
44436 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44437 MODULE_LICENSE("Dual BSD/GPL");
44438 MODULE_VERSION(VIVI_VERSION);
44439
44440 -static unsigned video_nr = -1;
44441 -module_param(video_nr, uint, 0644);
44442 +static int video_nr = -1;
44443 +module_param(video_nr, int, 0644);
44444 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44445
44446 static unsigned n_devs = 1;
44447 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44448 index 545c04c..a14bded 100644
44449 --- a/drivers/media/radio/radio-cadet.c
44450 +++ b/drivers/media/radio/radio-cadet.c
44451 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44452 unsigned char readbuf[RDS_BUFFER];
44453 int i = 0;
44454
44455 + if (count > RDS_BUFFER)
44456 + return -EFAULT;
44457 mutex_lock(&dev->lock);
44458 if (dev->rdsstat == 0)
44459 cadet_start_rds(dev);
44460 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44461 while (i < count && dev->rdsin != dev->rdsout)
44462 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44463
44464 - if (i && copy_to_user(data, readbuf, i))
44465 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44466 i = -EFAULT;
44467 unlock:
44468 mutex_unlock(&dev->lock);
44469 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44470 index 5236035..c622c74 100644
44471 --- a/drivers/media/radio/radio-maxiradio.c
44472 +++ b/drivers/media/radio/radio-maxiradio.c
44473 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44474 /* TEA5757 pin mappings */
44475 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44476
44477 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44478 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44479
44480 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44481 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44482 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44483 index 050b3bb..79f62b9 100644
44484 --- a/drivers/media/radio/radio-shark.c
44485 +++ b/drivers/media/radio/radio-shark.c
44486 @@ -79,7 +79,7 @@ struct shark_device {
44487 u32 last_val;
44488 };
44489
44490 -static atomic_t shark_instance = ATOMIC_INIT(0);
44491 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44492
44493 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44494 {
44495 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44496 index 8654e0d..0608a64 100644
44497 --- a/drivers/media/radio/radio-shark2.c
44498 +++ b/drivers/media/radio/radio-shark2.c
44499 @@ -74,7 +74,7 @@ struct shark_device {
44500 u8 *transfer_buffer;
44501 };
44502
44503 -static atomic_t shark_instance = ATOMIC_INIT(0);
44504 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44505
44506 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44507 {
44508 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44509 index 2fd9009..278cc1e 100644
44510 --- a/drivers/media/radio/radio-si476x.c
44511 +++ b/drivers/media/radio/radio-si476x.c
44512 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44513 struct si476x_radio *radio;
44514 struct v4l2_ctrl *ctrl;
44515
44516 - static atomic_t instance = ATOMIC_INIT(0);
44517 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44518
44519 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44520 if (!radio)
44521 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44522 index a1c641e..3007da9 100644
44523 --- a/drivers/media/usb/dvb-usb/cxusb.c
44524 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44525 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44526
44527 struct dib0700_adapter_state {
44528 int (*set_param_save) (struct dvb_frontend *);
44529 -};
44530 +} __no_const;
44531
44532 static int dib7070_set_param_override(struct dvb_frontend *fe)
44533 {
44534 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44535 index ae0f56a..ec71784 100644
44536 --- a/drivers/media/usb/dvb-usb/dw2102.c
44537 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44538 @@ -118,7 +118,7 @@ struct su3000_state {
44539
44540 struct s6x0_state {
44541 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44542 -};
44543 +} __no_const;
44544
44545 /* debug */
44546 static int dvb_usb_dw2102_debug;
44547 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44548 index 8f7a6a4..eb0e1d4 100644
44549 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44550 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44551 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44552 __u32 reserved;
44553 };
44554
44555 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44556 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44557 enum v4l2_memory memory)
44558 {
44559 void __user *up_pln;
44560 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44561 return 0;
44562 }
44563
44564 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44565 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44566 enum v4l2_memory memory)
44567 {
44568 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44569 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44570 * by passing a very big num_planes value */
44571 uplane = compat_alloc_user_space(num_planes *
44572 sizeof(struct v4l2_plane));
44573 - kp->m.planes = uplane;
44574 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44575
44576 while (--num_planes >= 0) {
44577 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44578 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44579 if (num_planes == 0)
44580 return 0;
44581
44582 - uplane = kp->m.planes;
44583 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44584 if (get_user(p, &up->m.planes))
44585 return -EFAULT;
44586 uplane32 = compat_ptr(p);
44587 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44588 get_user(kp->capability, &up->capability) ||
44589 get_user(kp->flags, &up->flags))
44590 return -EFAULT;
44591 - kp->base = compat_ptr(tmp);
44592 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44593 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44594 return 0;
44595 }
44596 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44597 n * sizeof(struct v4l2_ext_control32)))
44598 return -EFAULT;
44599 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44600 - kp->controls = kcontrols;
44601 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44602 while (--n >= 0) {
44603 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44604 return -EFAULT;
44605 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44606 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44607 {
44608 struct v4l2_ext_control32 __user *ucontrols;
44609 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44610 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44611 int n = kp->count;
44612 compat_caddr_t p;
44613
44614 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44615 put_user(kp->start_block, &up->start_block) ||
44616 put_user(kp->blocks, &up->blocks) ||
44617 put_user(tmp, &up->edid) ||
44618 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44619 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44620 return -EFAULT;
44621 return 0;
44622 }
44623 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44624 index 6ff002b..6b9316b 100644
44625 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44626 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44627 @@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44628 return 0;
44629
44630 case V4L2_CTRL_TYPE_STRING:
44631 - len = strlen(c->string);
44632 - if (len < ctrl->minimum)
44633 + len = strlen_user(c->string);
44634 + if (!len || len < ctrl->minimum)
44635 return -ERANGE;
44636 if ((len - ctrl->minimum) % ctrl->step)
44637 return -ERANGE;
44638 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44639 index 02d1b63..5fd6b16 100644
44640 --- a/drivers/media/v4l2-core/v4l2-device.c
44641 +++ b/drivers/media/v4l2-core/v4l2-device.c
44642 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44643 EXPORT_SYMBOL_GPL(v4l2_device_put);
44644
44645 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44646 - atomic_t *instance)
44647 + atomic_unchecked_t *instance)
44648 {
44649 - int num = atomic_inc_return(instance) - 1;
44650 + int num = atomic_inc_return_unchecked(instance) - 1;
44651 int len = strlen(basename);
44652
44653 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44654 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44655 index 707aef7..93b8ac0 100644
44656 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44657 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44658 @@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
44659 struct file *file, void *fh, void *p);
44660 } u;
44661 void (*debug)(const void *arg, bool write_only);
44662 -};
44663 +} __do_const;
44664 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44665
44666 /* This control needs a priority check */
44667 #define INFO_FL_PRIO (1 << 0)
44668 @@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
44669 struct video_device *vfd = video_devdata(file);
44670 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44671 bool write_only = false;
44672 - struct v4l2_ioctl_info default_info;
44673 + v4l2_ioctl_info_no_const default_info;
44674 const struct v4l2_ioctl_info *info;
44675 void *fh = file->private_data;
44676 struct v4l2_fh *vfh = NULL;
44677 @@ -2197,7 +2198,7 @@ done:
44678 }
44679
44680 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44681 - void * __user *user_ptr, void ***kernel_ptr)
44682 + void __user **user_ptr, void ***kernel_ptr)
44683 {
44684 int ret = 0;
44685
44686 @@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44687 ret = -EINVAL;
44688 break;
44689 }
44690 - *user_ptr = (void __user *)buf->m.planes;
44691 + *user_ptr = (void __force_user *)buf->m.planes;
44692 *kernel_ptr = (void *)&buf->m.planes;
44693 *array_size = sizeof(struct v4l2_plane) * buf->length;
44694 ret = 1;
44695 @@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44696 ret = -EINVAL;
44697 break;
44698 }
44699 - *user_ptr = (void __user *)ctrls->controls;
44700 + *user_ptr = (void __force_user *)ctrls->controls;
44701 *kernel_ptr = (void *)&ctrls->controls;
44702 *array_size = sizeof(struct v4l2_ext_control)
44703 * ctrls->count;
44704 @@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44705 }
44706
44707 if (has_array_args) {
44708 - *kernel_ptr = user_ptr;
44709 + *kernel_ptr = (void __force_kernel *)user_ptr;
44710 if (copy_to_user(user_ptr, mbuf, array_size))
44711 err = -EFAULT;
44712 goto out_array_args;
44713 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44714 index 570b18a..f880314 100644
44715 --- a/drivers/message/fusion/mptbase.c
44716 +++ b/drivers/message/fusion/mptbase.c
44717 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44718 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44719 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44720
44721 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44722 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44723 +#else
44724 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44725 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44726 +#endif
44727 +
44728 /*
44729 * Rounding UP to nearest 4-kB boundary here...
44730 */
44731 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44732 ioc->facts.GlobalCredits);
44733
44734 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44735 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44736 + NULL, NULL);
44737 +#else
44738 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44739 +#endif
44740 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44741 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44742 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44743 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44744 index 00d339c..2ea899d 100644
44745 --- a/drivers/message/fusion/mptsas.c
44746 +++ b/drivers/message/fusion/mptsas.c
44747 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44748 return 0;
44749 }
44750
44751 +static inline void
44752 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44753 +{
44754 + if (phy_info->port_details) {
44755 + phy_info->port_details->rphy = rphy;
44756 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44757 + ioc->name, rphy));
44758 + }
44759 +
44760 + if (rphy) {
44761 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44762 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44763 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44764 + ioc->name, rphy, rphy->dev.release));
44765 + }
44766 +}
44767 +
44768 /* no mutex */
44769 static void
44770 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44771 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44772 return NULL;
44773 }
44774
44775 -static inline void
44776 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44777 -{
44778 - if (phy_info->port_details) {
44779 - phy_info->port_details->rphy = rphy;
44780 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44781 - ioc->name, rphy));
44782 - }
44783 -
44784 - if (rphy) {
44785 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44786 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44787 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44788 - ioc->name, rphy, rphy->dev.release));
44789 - }
44790 -}
44791 -
44792 static inline struct sas_port *
44793 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44794 {
44795 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44796 index 727819c..ad74694 100644
44797 --- a/drivers/message/fusion/mptscsih.c
44798 +++ b/drivers/message/fusion/mptscsih.c
44799 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44800
44801 h = shost_priv(SChost);
44802
44803 - if (h) {
44804 - if (h->info_kbuf == NULL)
44805 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44806 - return h->info_kbuf;
44807 - h->info_kbuf[0] = '\0';
44808 + if (!h)
44809 + return NULL;
44810
44811 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44812 - h->info_kbuf[size-1] = '\0';
44813 - }
44814 + if (h->info_kbuf == NULL)
44815 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44816 + return h->info_kbuf;
44817 + h->info_kbuf[0] = '\0';
44818 +
44819 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44820 + h->info_kbuf[size-1] = '\0';
44821
44822 return h->info_kbuf;
44823 }
44824 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44825 index b7d87cd..3fb36da 100644
44826 --- a/drivers/message/i2o/i2o_proc.c
44827 +++ b/drivers/message/i2o/i2o_proc.c
44828 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44829 "Array Controller Device"
44830 };
44831
44832 -static char *chtostr(char *tmp, u8 *chars, int n)
44833 -{
44834 - tmp[0] = 0;
44835 - return strncat(tmp, (char *)chars, n);
44836 -}
44837 -
44838 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44839 char *group)
44840 {
44841 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44842 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44843 {
44844 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44845 - static u32 work32[5];
44846 - static u8 *work8 = (u8 *) work32;
44847 - static u16 *work16 = (u16 *) work32;
44848 + u32 work32[5];
44849 + u8 *work8 = (u8 *) work32;
44850 + u16 *work16 = (u16 *) work32;
44851 int token;
44852 u32 hwcap;
44853
44854 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44855 } *result;
44856
44857 i2o_exec_execute_ddm_table ddm_table;
44858 - char tmp[28 + 1];
44859
44860 result = kmalloc(sizeof(*result), GFP_KERNEL);
44861 if (!result)
44862 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44863
44864 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44865 seq_printf(seq, "%-#8x", ddm_table.module_id);
44866 - seq_printf(seq, "%-29s",
44867 - chtostr(tmp, ddm_table.module_name_version, 28));
44868 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44869 seq_printf(seq, "%9d ", ddm_table.data_size);
44870 seq_printf(seq, "%8d", ddm_table.code_size);
44871
44872 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44873
44874 i2o_driver_result_table *result;
44875 i2o_driver_store_table *dst;
44876 - char tmp[28 + 1];
44877
44878 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44879 if (result == NULL)
44880 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44881
44882 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44883 seq_printf(seq, "%-#8x", dst->module_id);
44884 - seq_printf(seq, "%-29s",
44885 - chtostr(tmp, dst->module_name_version, 28));
44886 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44887 + seq_printf(seq, "%-.28s", dst->module_name_version);
44888 + seq_printf(seq, "%-.8s", dst->date);
44889 seq_printf(seq, "%8d ", dst->module_size);
44890 seq_printf(seq, "%8d ", dst->mpb_size);
44891 seq_printf(seq, "0x%04x", dst->module_flags);
44892 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44893 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44894 {
44895 struct i2o_device *d = (struct i2o_device *)seq->private;
44896 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44897 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44898 // == (allow) 512d bytes (max)
44899 - static u16 *work16 = (u16 *) work32;
44900 + u16 *work16 = (u16 *) work32;
44901 int token;
44902 - char tmp[16 + 1];
44903
44904 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44905
44906 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44907 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44908 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44909 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44910 - seq_printf(seq, "Vendor info : %s\n",
44911 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44912 - seq_printf(seq, "Product info : %s\n",
44913 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44914 - seq_printf(seq, "Description : %s\n",
44915 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44916 - seq_printf(seq, "Product rev. : %s\n",
44917 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44918 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44919 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44920 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44921 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44922
44923 seq_printf(seq, "Serial number : ");
44924 print_serial_number(seq, (u8 *) (work32 + 16),
44925 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44926 u8 pad[256]; // allow up to 256 byte (max) serial number
44927 } result;
44928
44929 - char tmp[24 + 1];
44930 -
44931 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44932
44933 if (token < 0) {
44934 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44935 }
44936
44937 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44938 - seq_printf(seq, "Module name : %s\n",
44939 - chtostr(tmp, result.module_name, 24));
44940 - seq_printf(seq, "Module revision : %s\n",
44941 - chtostr(tmp, result.module_rev, 8));
44942 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44943 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44944
44945 seq_printf(seq, "Serial number : ");
44946 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44947 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44948 u8 instance_number[4];
44949 } result;
44950
44951 - char tmp[64 + 1];
44952 -
44953 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44954
44955 if (token < 0) {
44956 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44957 return 0;
44958 }
44959
44960 - seq_printf(seq, "Device name : %s\n",
44961 - chtostr(tmp, result.device_name, 64));
44962 - seq_printf(seq, "Service name : %s\n",
44963 - chtostr(tmp, result.service_name, 64));
44964 - seq_printf(seq, "Physical name : %s\n",
44965 - chtostr(tmp, result.physical_location, 64));
44966 - seq_printf(seq, "Instance number : %s\n",
44967 - chtostr(tmp, result.instance_number, 4));
44968 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44969 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44970 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44971 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44972
44973 return 0;
44974 }
44975 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44976 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44977 {
44978 struct i2o_device *d = (struct i2o_device *)seq->private;
44979 - static u32 work32[12];
44980 - static u16 *work16 = (u16 *) work32;
44981 - static u8 *work8 = (u8 *) work32;
44982 + u32 work32[12];
44983 + u16 *work16 = (u16 *) work32;
44984 + u8 *work8 = (u8 *) work32;
44985 int token;
44986
44987 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44988 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44989 index a8c08f3..155fe3d 100644
44990 --- a/drivers/message/i2o/iop.c
44991 +++ b/drivers/message/i2o/iop.c
44992 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44993
44994 spin_lock_irqsave(&c->context_list_lock, flags);
44995
44996 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44997 - atomic_inc(&c->context_list_counter);
44998 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44999 + atomic_inc_unchecked(&c->context_list_counter);
45000
45001 - entry->context = atomic_read(&c->context_list_counter);
45002 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45003
45004 list_add(&entry->list, &c->context_list);
45005
45006 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45007
45008 #if BITS_PER_LONG == 64
45009 spin_lock_init(&c->context_list_lock);
45010 - atomic_set(&c->context_list_counter, 0);
45011 + atomic_set_unchecked(&c->context_list_counter, 0);
45012 INIT_LIST_HEAD(&c->context_list);
45013 #endif
45014
45015 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45016 index d1a22aa..d0f7bf7 100644
45017 --- a/drivers/mfd/ab8500-debugfs.c
45018 +++ b/drivers/mfd/ab8500-debugfs.c
45019 @@ -100,7 +100,7 @@ static int irq_last;
45020 static u32 *irq_count;
45021 static int num_irqs;
45022
45023 -static struct device_attribute **dev_attr;
45024 +static device_attribute_no_const **dev_attr;
45025 static char **event_name;
45026
45027 static u8 avg_sample = SAMPLE_16;
45028 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45029 index 81b7d88..95ae998 100644
45030 --- a/drivers/mfd/janz-cmodio.c
45031 +++ b/drivers/mfd/janz-cmodio.c
45032 @@ -13,6 +13,7 @@
45033
45034 #include <linux/kernel.h>
45035 #include <linux/module.h>
45036 +#include <linux/slab.h>
45037 #include <linux/init.h>
45038 #include <linux/pci.h>
45039 #include <linux/interrupt.h>
45040 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45041 index 176aa26..27811b2 100644
45042 --- a/drivers/mfd/max8925-i2c.c
45043 +++ b/drivers/mfd/max8925-i2c.c
45044 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45045 const struct i2c_device_id *id)
45046 {
45047 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45048 - static struct max8925_chip *chip;
45049 + struct max8925_chip *chip;
45050 struct device_node *node = client->dev.of_node;
45051
45052 if (node && !pdata) {
45053 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45054 index 1f142d7..cc52c2a 100644
45055 --- a/drivers/mfd/tps65910.c
45056 +++ b/drivers/mfd/tps65910.c
45057 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45058 struct tps65910_platform_data *pdata)
45059 {
45060 int ret = 0;
45061 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45062 + struct regmap_irq_chip *tps6591x_irqs_chip;
45063
45064 if (!irq) {
45065 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45066 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45067 index 9aa6d1e..1631bfc 100644
45068 --- a/drivers/mfd/twl4030-irq.c
45069 +++ b/drivers/mfd/twl4030-irq.c
45070 @@ -35,6 +35,7 @@
45071 #include <linux/of.h>
45072 #include <linux/irqdomain.h>
45073 #include <linux/i2c/twl.h>
45074 +#include <asm/pgtable.h>
45075
45076 #include "twl-core.h"
45077
45078 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45079 * Install an irq handler for each of the SIH modules;
45080 * clone dummy irq_chip since PIH can't *do* anything
45081 */
45082 - twl4030_irq_chip = dummy_irq_chip;
45083 - twl4030_irq_chip.name = "twl4030";
45084 + pax_open_kernel();
45085 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45086 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45087
45088 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45089 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45090 + pax_close_kernel();
45091
45092 for (i = irq_base; i < irq_end; i++) {
45093 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45094 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45095 index 464419b..64bae8d 100644
45096 --- a/drivers/misc/c2port/core.c
45097 +++ b/drivers/misc/c2port/core.c
45098 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45099 goto error_idr_alloc;
45100 c2dev->id = ret;
45101
45102 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45103 + pax_open_kernel();
45104 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45105 + pax_close_kernel();
45106
45107 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45108 "c2port%d", c2dev->id);
45109 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45110 index 9c34e57..b981cda 100644
45111 --- a/drivers/misc/eeprom/sunxi_sid.c
45112 +++ b/drivers/misc/eeprom/sunxi_sid.c
45113 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45114
45115 platform_set_drvdata(pdev, sid_data);
45116
45117 - sid_bin_attr.size = sid_data->keysize;
45118 + pax_open_kernel();
45119 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45120 + pax_close_kernel();
45121 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45122 return -ENODEV;
45123
45124 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45125 index 36f5d52..32311c3 100644
45126 --- a/drivers/misc/kgdbts.c
45127 +++ b/drivers/misc/kgdbts.c
45128 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45129 char before[BREAK_INSTR_SIZE];
45130 char after[BREAK_INSTR_SIZE];
45131
45132 - probe_kernel_read(before, (char *)kgdbts_break_test,
45133 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45134 BREAK_INSTR_SIZE);
45135 init_simple_test();
45136 ts.tst = plant_and_detach_test;
45137 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45138 /* Activate test with initial breakpoint */
45139 if (!is_early)
45140 kgdb_breakpoint();
45141 - probe_kernel_read(after, (char *)kgdbts_break_test,
45142 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45143 BREAK_INSTR_SIZE);
45144 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45145 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45146 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45147 index 036effe..b3a6336 100644
45148 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45149 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45150 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45151 * the lid is closed. This leads to interrupts as soon as a little move
45152 * is done.
45153 */
45154 - atomic_inc(&lis3->count);
45155 + atomic_inc_unchecked(&lis3->count);
45156
45157 wake_up_interruptible(&lis3->misc_wait);
45158 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45159 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45160 if (lis3->pm_dev)
45161 pm_runtime_get_sync(lis3->pm_dev);
45162
45163 - atomic_set(&lis3->count, 0);
45164 + atomic_set_unchecked(&lis3->count, 0);
45165 return 0;
45166 }
45167
45168 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45169 add_wait_queue(&lis3->misc_wait, &wait);
45170 while (true) {
45171 set_current_state(TASK_INTERRUPTIBLE);
45172 - data = atomic_xchg(&lis3->count, 0);
45173 + data = atomic_xchg_unchecked(&lis3->count, 0);
45174 if (data)
45175 break;
45176
45177 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45178 struct lis3lv02d, miscdev);
45179
45180 poll_wait(file, &lis3->misc_wait, wait);
45181 - if (atomic_read(&lis3->count))
45182 + if (atomic_read_unchecked(&lis3->count))
45183 return POLLIN | POLLRDNORM;
45184 return 0;
45185 }
45186 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45187 index c439c82..1f20f57 100644
45188 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45189 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45190 @@ -297,7 +297,7 @@ struct lis3lv02d {
45191 struct input_polled_dev *idev; /* input device */
45192 struct platform_device *pdev; /* platform device */
45193 struct regulator_bulk_data regulators[2];
45194 - atomic_t count; /* interrupt count after last read */
45195 + atomic_unchecked_t count; /* interrupt count after last read */
45196 union axis_conversion ac; /* hw -> logical axis */
45197 int mapped_btns[3];
45198
45199 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45200 index 2f30bad..c4c13d0 100644
45201 --- a/drivers/misc/sgi-gru/gruhandles.c
45202 +++ b/drivers/misc/sgi-gru/gruhandles.c
45203 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45204 unsigned long nsec;
45205
45206 nsec = CLKS2NSEC(clks);
45207 - atomic_long_inc(&mcs_op_statistics[op].count);
45208 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45209 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45210 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45211 if (mcs_op_statistics[op].max < nsec)
45212 mcs_op_statistics[op].max = nsec;
45213 }
45214 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45215 index 4f76359..cdfcb2e 100644
45216 --- a/drivers/misc/sgi-gru/gruprocfs.c
45217 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45218 @@ -32,9 +32,9 @@
45219
45220 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45221
45222 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45223 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45224 {
45225 - unsigned long val = atomic_long_read(v);
45226 + unsigned long val = atomic_long_read_unchecked(v);
45227
45228 seq_printf(s, "%16lu %s\n", val, id);
45229 }
45230 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45231
45232 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45233 for (op = 0; op < mcsop_last; op++) {
45234 - count = atomic_long_read(&mcs_op_statistics[op].count);
45235 - total = atomic_long_read(&mcs_op_statistics[op].total);
45236 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45237 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45238 max = mcs_op_statistics[op].max;
45239 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45240 count ? total / count : 0, max);
45241 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45242 index 5c3ce24..4915ccb 100644
45243 --- a/drivers/misc/sgi-gru/grutables.h
45244 +++ b/drivers/misc/sgi-gru/grutables.h
45245 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45246 * GRU statistics.
45247 */
45248 struct gru_stats_s {
45249 - atomic_long_t vdata_alloc;
45250 - atomic_long_t vdata_free;
45251 - atomic_long_t gts_alloc;
45252 - atomic_long_t gts_free;
45253 - atomic_long_t gms_alloc;
45254 - atomic_long_t gms_free;
45255 - atomic_long_t gts_double_allocate;
45256 - atomic_long_t assign_context;
45257 - atomic_long_t assign_context_failed;
45258 - atomic_long_t free_context;
45259 - atomic_long_t load_user_context;
45260 - atomic_long_t load_kernel_context;
45261 - atomic_long_t lock_kernel_context;
45262 - atomic_long_t unlock_kernel_context;
45263 - atomic_long_t steal_user_context;
45264 - atomic_long_t steal_kernel_context;
45265 - atomic_long_t steal_context_failed;
45266 - atomic_long_t nopfn;
45267 - atomic_long_t asid_new;
45268 - atomic_long_t asid_next;
45269 - atomic_long_t asid_wrap;
45270 - atomic_long_t asid_reuse;
45271 - atomic_long_t intr;
45272 - atomic_long_t intr_cbr;
45273 - atomic_long_t intr_tfh;
45274 - atomic_long_t intr_spurious;
45275 - atomic_long_t intr_mm_lock_failed;
45276 - atomic_long_t call_os;
45277 - atomic_long_t call_os_wait_queue;
45278 - atomic_long_t user_flush_tlb;
45279 - atomic_long_t user_unload_context;
45280 - atomic_long_t user_exception;
45281 - atomic_long_t set_context_option;
45282 - atomic_long_t check_context_retarget_intr;
45283 - atomic_long_t check_context_unload;
45284 - atomic_long_t tlb_dropin;
45285 - atomic_long_t tlb_preload_page;
45286 - atomic_long_t tlb_dropin_fail_no_asid;
45287 - atomic_long_t tlb_dropin_fail_upm;
45288 - atomic_long_t tlb_dropin_fail_invalid;
45289 - atomic_long_t tlb_dropin_fail_range_active;
45290 - atomic_long_t tlb_dropin_fail_idle;
45291 - atomic_long_t tlb_dropin_fail_fmm;
45292 - atomic_long_t tlb_dropin_fail_no_exception;
45293 - atomic_long_t tfh_stale_on_fault;
45294 - atomic_long_t mmu_invalidate_range;
45295 - atomic_long_t mmu_invalidate_page;
45296 - atomic_long_t flush_tlb;
45297 - atomic_long_t flush_tlb_gru;
45298 - atomic_long_t flush_tlb_gru_tgh;
45299 - atomic_long_t flush_tlb_gru_zero_asid;
45300 + atomic_long_unchecked_t vdata_alloc;
45301 + atomic_long_unchecked_t vdata_free;
45302 + atomic_long_unchecked_t gts_alloc;
45303 + atomic_long_unchecked_t gts_free;
45304 + atomic_long_unchecked_t gms_alloc;
45305 + atomic_long_unchecked_t gms_free;
45306 + atomic_long_unchecked_t gts_double_allocate;
45307 + atomic_long_unchecked_t assign_context;
45308 + atomic_long_unchecked_t assign_context_failed;
45309 + atomic_long_unchecked_t free_context;
45310 + atomic_long_unchecked_t load_user_context;
45311 + atomic_long_unchecked_t load_kernel_context;
45312 + atomic_long_unchecked_t lock_kernel_context;
45313 + atomic_long_unchecked_t unlock_kernel_context;
45314 + atomic_long_unchecked_t steal_user_context;
45315 + atomic_long_unchecked_t steal_kernel_context;
45316 + atomic_long_unchecked_t steal_context_failed;
45317 + atomic_long_unchecked_t nopfn;
45318 + atomic_long_unchecked_t asid_new;
45319 + atomic_long_unchecked_t asid_next;
45320 + atomic_long_unchecked_t asid_wrap;
45321 + atomic_long_unchecked_t asid_reuse;
45322 + atomic_long_unchecked_t intr;
45323 + atomic_long_unchecked_t intr_cbr;
45324 + atomic_long_unchecked_t intr_tfh;
45325 + atomic_long_unchecked_t intr_spurious;
45326 + atomic_long_unchecked_t intr_mm_lock_failed;
45327 + atomic_long_unchecked_t call_os;
45328 + atomic_long_unchecked_t call_os_wait_queue;
45329 + atomic_long_unchecked_t user_flush_tlb;
45330 + atomic_long_unchecked_t user_unload_context;
45331 + atomic_long_unchecked_t user_exception;
45332 + atomic_long_unchecked_t set_context_option;
45333 + atomic_long_unchecked_t check_context_retarget_intr;
45334 + atomic_long_unchecked_t check_context_unload;
45335 + atomic_long_unchecked_t tlb_dropin;
45336 + atomic_long_unchecked_t tlb_preload_page;
45337 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45338 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45339 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45340 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45341 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45342 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45343 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45344 + atomic_long_unchecked_t tfh_stale_on_fault;
45345 + atomic_long_unchecked_t mmu_invalidate_range;
45346 + atomic_long_unchecked_t mmu_invalidate_page;
45347 + atomic_long_unchecked_t flush_tlb;
45348 + atomic_long_unchecked_t flush_tlb_gru;
45349 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45350 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45351
45352 - atomic_long_t copy_gpa;
45353 - atomic_long_t read_gpa;
45354 + atomic_long_unchecked_t copy_gpa;
45355 + atomic_long_unchecked_t read_gpa;
45356
45357 - atomic_long_t mesq_receive;
45358 - atomic_long_t mesq_receive_none;
45359 - atomic_long_t mesq_send;
45360 - atomic_long_t mesq_send_failed;
45361 - atomic_long_t mesq_noop;
45362 - atomic_long_t mesq_send_unexpected_error;
45363 - atomic_long_t mesq_send_lb_overflow;
45364 - atomic_long_t mesq_send_qlimit_reached;
45365 - atomic_long_t mesq_send_amo_nacked;
45366 - atomic_long_t mesq_send_put_nacked;
45367 - atomic_long_t mesq_page_overflow;
45368 - atomic_long_t mesq_qf_locked;
45369 - atomic_long_t mesq_qf_noop_not_full;
45370 - atomic_long_t mesq_qf_switch_head_failed;
45371 - atomic_long_t mesq_qf_unexpected_error;
45372 - atomic_long_t mesq_noop_unexpected_error;
45373 - atomic_long_t mesq_noop_lb_overflow;
45374 - atomic_long_t mesq_noop_qlimit_reached;
45375 - atomic_long_t mesq_noop_amo_nacked;
45376 - atomic_long_t mesq_noop_put_nacked;
45377 - atomic_long_t mesq_noop_page_overflow;
45378 + atomic_long_unchecked_t mesq_receive;
45379 + atomic_long_unchecked_t mesq_receive_none;
45380 + atomic_long_unchecked_t mesq_send;
45381 + atomic_long_unchecked_t mesq_send_failed;
45382 + atomic_long_unchecked_t mesq_noop;
45383 + atomic_long_unchecked_t mesq_send_unexpected_error;
45384 + atomic_long_unchecked_t mesq_send_lb_overflow;
45385 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45386 + atomic_long_unchecked_t mesq_send_amo_nacked;
45387 + atomic_long_unchecked_t mesq_send_put_nacked;
45388 + atomic_long_unchecked_t mesq_page_overflow;
45389 + atomic_long_unchecked_t mesq_qf_locked;
45390 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45391 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45392 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45393 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45394 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45395 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45396 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45397 + atomic_long_unchecked_t mesq_noop_put_nacked;
45398 + atomic_long_unchecked_t mesq_noop_page_overflow;
45399
45400 };
45401
45402 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45403 tghop_invalidate, mcsop_last};
45404
45405 struct mcs_op_statistic {
45406 - atomic_long_t count;
45407 - atomic_long_t total;
45408 + atomic_long_unchecked_t count;
45409 + atomic_long_unchecked_t total;
45410 unsigned long max;
45411 };
45412
45413 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45414
45415 #define STAT(id) do { \
45416 if (gru_options & OPT_STATS) \
45417 - atomic_long_inc(&gru_stats.id); \
45418 + atomic_long_inc_unchecked(&gru_stats.id); \
45419 } while (0)
45420
45421 #ifdef CONFIG_SGI_GRU_DEBUG
45422 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45423 index c862cd4..0d176fe 100644
45424 --- a/drivers/misc/sgi-xp/xp.h
45425 +++ b/drivers/misc/sgi-xp/xp.h
45426 @@ -288,7 +288,7 @@ struct xpc_interface {
45427 xpc_notify_func, void *);
45428 void (*received) (short, int, void *);
45429 enum xp_retval (*partid_to_nasids) (short, void *);
45430 -};
45431 +} __no_const;
45432
45433 extern struct xpc_interface xpc_interface;
45434
45435 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45436 index 01be66d..e3a0c7e 100644
45437 --- a/drivers/misc/sgi-xp/xp_main.c
45438 +++ b/drivers/misc/sgi-xp/xp_main.c
45439 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45440 }
45441
45442 struct xpc_interface xpc_interface = {
45443 - (void (*)(int))xpc_notloaded,
45444 - (void (*)(int))xpc_notloaded,
45445 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45446 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45447 + .connect = (void (*)(int))xpc_notloaded,
45448 + .disconnect = (void (*)(int))xpc_notloaded,
45449 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45450 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45451 void *))xpc_notloaded,
45452 - (void (*)(short, int, void *))xpc_notloaded,
45453 - (enum xp_retval(*)(short, void *))xpc_notloaded
45454 + .received = (void (*)(short, int, void *))xpc_notloaded,
45455 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45456 };
45457 EXPORT_SYMBOL_GPL(xpc_interface);
45458
45459 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45460 index b94d5f7..7f494c5 100644
45461 --- a/drivers/misc/sgi-xp/xpc.h
45462 +++ b/drivers/misc/sgi-xp/xpc.h
45463 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45464 void (*received_payload) (struct xpc_channel *, void *);
45465 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45466 };
45467 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45468
45469 /* struct xpc_partition act_state values (for XPC HB) */
45470
45471 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45472 /* found in xpc_main.c */
45473 extern struct device *xpc_part;
45474 extern struct device *xpc_chan;
45475 -extern struct xpc_arch_operations xpc_arch_ops;
45476 +extern xpc_arch_operations_no_const xpc_arch_ops;
45477 extern int xpc_disengage_timelimit;
45478 extern int xpc_disengage_timedout;
45479 extern int xpc_activate_IRQ_rcvd;
45480 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45481 index 82dc574..8539ab2 100644
45482 --- a/drivers/misc/sgi-xp/xpc_main.c
45483 +++ b/drivers/misc/sgi-xp/xpc_main.c
45484 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45485 .notifier_call = xpc_system_die,
45486 };
45487
45488 -struct xpc_arch_operations xpc_arch_ops;
45489 +xpc_arch_operations_no_const xpc_arch_ops;
45490
45491 /*
45492 * Timer function to enforce the timelimit on the partition disengage.
45493 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45494
45495 if (((die_args->trapnr == X86_TRAP_MF) ||
45496 (die_args->trapnr == X86_TRAP_XF)) &&
45497 - !user_mode_vm(die_args->regs))
45498 + !user_mode(die_args->regs))
45499 xpc_die_deactivate();
45500
45501 break;
45502 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45503 index 7b5424f..ed1d6ac 100644
45504 --- a/drivers/mmc/card/block.c
45505 +++ b/drivers/mmc/card/block.c
45506 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45507 if (idata->ic.postsleep_min_us)
45508 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45509
45510 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45511 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45512 err = -EFAULT;
45513 goto cmd_rel_host;
45514 }
45515 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45516 index e5b5eeb..7bf2212 100644
45517 --- a/drivers/mmc/core/mmc_ops.c
45518 +++ b/drivers/mmc/core/mmc_ops.c
45519 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45520 void *data_buf;
45521 int is_on_stack;
45522
45523 - is_on_stack = object_is_on_stack(buf);
45524 + is_on_stack = object_starts_on_stack(buf);
45525 if (is_on_stack) {
45526 /*
45527 * dma onto stack is unsafe/nonportable, but callers to this
45528 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45529 index 6bf24ab..13d0293b 100644
45530 --- a/drivers/mmc/host/dw_mmc.h
45531 +++ b/drivers/mmc/host/dw_mmc.h
45532 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45533 int (*parse_dt)(struct dw_mci *host);
45534 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45535 struct dw_mci_tuning_data *tuning_data);
45536 -};
45537 +} __do_const;
45538 #endif /* _DW_MMC_H_ */
45539 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45540 index b931226..df6a085 100644
45541 --- a/drivers/mmc/host/mmci.c
45542 +++ b/drivers/mmc/host/mmci.c
45543 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45544 }
45545
45546 if (variant->busy_detect) {
45547 - mmci_ops.card_busy = mmci_card_busy;
45548 + pax_open_kernel();
45549 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45550 + pax_close_kernel();
45551 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45552 }
45553
45554 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45555 index b841bb7..d82712f5 100644
45556 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45557 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45558 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45559 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45560 }
45561
45562 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45563 - sdhci_esdhc_ops.platform_execute_tuning =
45564 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45565 + pax_open_kernel();
45566 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45567 esdhc_executing_tuning;
45568 + pax_close_kernel();
45569 + }
45570
45571 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45572 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45573 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45574 index 6debda9..2ba7427 100644
45575 --- a/drivers/mmc/host/sdhci-s3c.c
45576 +++ b/drivers/mmc/host/sdhci-s3c.c
45577 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45578 * we can use overriding functions instead of default.
45579 */
45580 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45581 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45582 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45583 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45584 + pax_open_kernel();
45585 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45586 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45587 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45588 + pax_close_kernel();
45589 }
45590
45591 /* It supports additional host capabilities if needed */
45592 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45593 index 096993f..f02c23b 100644
45594 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45595 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45596 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45597 size_t totlen = 0, thislen;
45598 int ret = 0;
45599 size_t buflen = 0;
45600 - static char *buffer;
45601 + char *buffer;
45602
45603 if (!ECCBUF_SIZE) {
45604 /* We should fall back to a general writev implementation.
45605 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45606 index c07cd57..61c4fbd 100644
45607 --- a/drivers/mtd/nand/denali.c
45608 +++ b/drivers/mtd/nand/denali.c
45609 @@ -24,6 +24,7 @@
45610 #include <linux/slab.h>
45611 #include <linux/mtd/mtd.h>
45612 #include <linux/module.h>
45613 +#include <linux/slab.h>
45614
45615 #include "denali.h"
45616
45617 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45618 index ca6369f..0ce9fed 100644
45619 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45620 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45621 @@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45622
45623 /* first try to map the upper buffer directly */
45624 if (virt_addr_valid(this->upper_buf) &&
45625 - !object_is_on_stack(this->upper_buf)) {
45626 + !object_starts_on_stack(this->upper_buf)) {
45627 sg_init_one(sgl, this->upper_buf, this->upper_len);
45628 ret = dma_map_sg(this->dev, sgl, 1, dr);
45629 if (ret == 0)
45630 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45631 index 51b9d6a..52af9a7 100644
45632 --- a/drivers/mtd/nftlmount.c
45633 +++ b/drivers/mtd/nftlmount.c
45634 @@ -24,6 +24,7 @@
45635 #include <asm/errno.h>
45636 #include <linux/delay.h>
45637 #include <linux/slab.h>
45638 +#include <linux/sched.h>
45639 #include <linux/mtd/mtd.h>
45640 #include <linux/mtd/nand.h>
45641 #include <linux/mtd/nftl.h>
45642 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45643 index 4b8e895..6b3c498 100644
45644 --- a/drivers/mtd/sm_ftl.c
45645 +++ b/drivers/mtd/sm_ftl.c
45646 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45647 #define SM_CIS_VENDOR_OFFSET 0x59
45648 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45649 {
45650 - struct attribute_group *attr_group;
45651 + attribute_group_no_const *attr_group;
45652 struct attribute **attributes;
45653 struct sm_sysfs_attribute *vendor_attribute;
45654
45655 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45656 index e5628fc..ffe54d1 100644
45657 --- a/drivers/net/bonding/bond_main.c
45658 +++ b/drivers/net/bonding/bond_main.c
45659 @@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
45660
45661 bond_netlink_fini();
45662 unregister_pernet_subsys(&bond_net_ops);
45663 + rtnl_link_unregister(&bond_link_ops);
45664
45665 #ifdef CONFIG_NET_POLL_CONTROLLER
45666 /*
45667 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45668 index 70651f8..7eb1bdf 100644
45669 --- a/drivers/net/bonding/bond_netlink.c
45670 +++ b/drivers/net/bonding/bond_netlink.c
45671 @@ -542,7 +542,7 @@ nla_put_failure:
45672 return -EMSGSIZE;
45673 }
45674
45675 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45676 +struct rtnl_link_ops bond_link_ops = {
45677 .kind = "bond",
45678 .priv_size = sizeof(struct bonding),
45679 .setup = bond_setup,
45680 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45681 index 9e7d95d..d447b88 100644
45682 --- a/drivers/net/can/Kconfig
45683 +++ b/drivers/net/can/Kconfig
45684 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45685
45686 config CAN_FLEXCAN
45687 tristate "Support for Freescale FLEXCAN based chips"
45688 - depends on ARM || PPC
45689 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45690 ---help---
45691 Say Y here if you want to support for Freescale FlexCAN.
45692
45693 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45694 index 455d4c3..3353ee7 100644
45695 --- a/drivers/net/ethernet/8390/ax88796.c
45696 +++ b/drivers/net/ethernet/8390/ax88796.c
45697 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45698 if (ax->plat->reg_offsets)
45699 ei_local->reg_offset = ax->plat->reg_offsets;
45700 else {
45701 + resource_size_t _mem_size = mem_size;
45702 + do_div(_mem_size, 0x18);
45703 ei_local->reg_offset = ax->reg_offsets;
45704 for (ret = 0; ret < 0x18; ret++)
45705 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45706 + ax->reg_offsets[ret] = _mem_size * ret;
45707 }
45708
45709 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45710 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45711 index a89a40f..5a8a2ac 100644
45712 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45713 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45714 @@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45715 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45716 {
45717 /* RX_MODE controlling object */
45718 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45719 + bnx2x_init_rx_mode_obj(bp);
45720
45721 /* multicast configuration controlling object */
45722 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45723 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45724 index 0fb6ff2..78fd55c 100644
45725 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45726 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45727 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45728 return rc;
45729 }
45730
45731 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45732 - struct bnx2x_rx_mode_obj *o)
45733 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45734 {
45735 if (CHIP_IS_E1x(bp)) {
45736 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45737 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45738 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45739 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45740 } else {
45741 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45742 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45743 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45744 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45745 }
45746 }
45747
45748 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45749 index 00d7f21..2cddec4 100644
45750 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45751 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45752 @@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45753
45754 /********************* RX MODE ****************/
45755
45756 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45757 - struct bnx2x_rx_mode_obj *o);
45758 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45759
45760 /**
45761 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45762 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45763 index 04321e5..b51cdc4 100644
45764 --- a/drivers/net/ethernet/broadcom/tg3.h
45765 +++ b/drivers/net/ethernet/broadcom/tg3.h
45766 @@ -150,6 +150,7 @@
45767 #define CHIPREV_ID_5750_A0 0x4000
45768 #define CHIPREV_ID_5750_A1 0x4001
45769 #define CHIPREV_ID_5750_A3 0x4003
45770 +#define CHIPREV_ID_5750_C1 0x4201
45771 #define CHIPREV_ID_5750_C2 0x4202
45772 #define CHIPREV_ID_5752_A0_HW 0x5000
45773 #define CHIPREV_ID_5752_A0 0x6000
45774 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45775 index 13f9636..228040f 100644
45776 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45777 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45778 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45779 }
45780
45781 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45782 - bna_cb_ioceth_enable,
45783 - bna_cb_ioceth_disable,
45784 - bna_cb_ioceth_hbfail,
45785 - bna_cb_ioceth_reset
45786 + .enable_cbfn = bna_cb_ioceth_enable,
45787 + .disable_cbfn = bna_cb_ioceth_disable,
45788 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45789 + .reset_cbfn = bna_cb_ioceth_reset
45790 };
45791
45792 static void bna_attr_init(struct bna_ioceth *ioceth)
45793 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45794 index 8cffcdf..aadf043 100644
45795 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45796 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45797 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45798 */
45799 struct l2t_skb_cb {
45800 arp_failure_handler_func arp_failure_handler;
45801 -};
45802 +} __no_const;
45803
45804 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45805
45806 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45807 index 34e2488..07e2079 100644
45808 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45809 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45810 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45811
45812 int i;
45813 struct adapter *ap = netdev2adap(dev);
45814 - static const unsigned int *reg_ranges;
45815 + const unsigned int *reg_ranges;
45816 int arr_size = 0, buf_size = 0;
45817
45818 if (is_t4(ap->params.chip)) {
45819 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45820 index c05b66d..ed69872 100644
45821 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45822 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45823 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45824 for (i=0; i<ETH_ALEN; i++) {
45825 tmp.addr[i] = dev->dev_addr[i];
45826 }
45827 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45828 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45829 break;
45830
45831 case DE4X5_SET_HWADDR: /* Set the hardware address */
45832 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45833 spin_lock_irqsave(&lp->lock, flags);
45834 memcpy(&statbuf, &lp->pktStats, ioc->len);
45835 spin_unlock_irqrestore(&lp->lock, flags);
45836 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45837 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45838 return -EFAULT;
45839 break;
45840 }
45841 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45842 index 36c8061..ca5e1e0 100644
45843 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45844 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45845 @@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45846
45847 if (wrapped)
45848 newacc += 65536;
45849 - ACCESS_ONCE(*acc) = newacc;
45850 + ACCESS_ONCE_RW(*acc) = newacc;
45851 }
45852
45853 static void populate_erx_stats(struct be_adapter *adapter,
45854 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45855 index c11ecbc..13bb299 100644
45856 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45857 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45858 @@ -30,6 +30,8 @@
45859 #include <linux/netdevice.h>
45860 #include <linux/phy.h>
45861 #include <linux/platform_device.h>
45862 +#include <linux/interrupt.h>
45863 +#include <linux/irqreturn.h>
45864 #include <net/ip.h>
45865
45866 #include "ftgmac100.h"
45867 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45868 index 8be5b40..081bc1b 100644
45869 --- a/drivers/net/ethernet/faraday/ftmac100.c
45870 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45871 @@ -31,6 +31,8 @@
45872 #include <linux/module.h>
45873 #include <linux/netdevice.h>
45874 #include <linux/platform_device.h>
45875 +#include <linux/interrupt.h>
45876 +#include <linux/irqreturn.h>
45877
45878 #include "ftmac100.h"
45879
45880 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45881 index e33ec6c..f54cfe7 100644
45882 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45883 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45884 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45885 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45886
45887 /* Update the base adjustement value. */
45888 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
45889 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45890 smp_mb(); /* Force the above update. */
45891 }
45892
45893 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45894 index 5184e2a..acb28c3 100644
45895 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45896 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45897 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45898 }
45899
45900 /* update the base incval used to calculate frequency adjustment */
45901 - ACCESS_ONCE(adapter->base_incval) = incval;
45902 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45903 smp_mb();
45904
45905 /* need lock to prevent incorrect read while modifying cyclecounter */
45906 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45907 index 089b713..28d87ae 100644
45908 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45909 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45910 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45911 struct __vxge_hw_fifo *fifo;
45912 struct vxge_hw_fifo_config *config;
45913 u32 txdl_size, txdl_per_memblock;
45914 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45915 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45916 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45917 + };
45918 +
45919 struct __vxge_hw_virtualpath *vpath;
45920
45921 if ((vp == NULL) || (attr == NULL)) {
45922 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45923 goto exit;
45924 }
45925
45926 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45927 -
45928 fifo->mempool =
45929 __vxge_hw_mempool_create(vpath->hldev,
45930 fifo->config->memblock_size,
45931 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45932 index 90a2dda..47e620e 100644
45933 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45934 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45935 @@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45936 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45937 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45938 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45939 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45940 + pax_open_kernel();
45941 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45942 + pax_close_kernel();
45943 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45944 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45945 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45946 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45947 index be7d7a6..a8983f8 100644
45948 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45949 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45950 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45951 case QLCNIC_NON_PRIV_FUNC:
45952 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45953 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45954 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45955 + pax_open_kernel();
45956 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45957 + pax_close_kernel();
45958 break;
45959 case QLCNIC_PRIV_FUNC:
45960 ahw->op_mode = QLCNIC_PRIV_FUNC;
45961 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45962 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45963 + pax_open_kernel();
45964 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45965 + pax_close_kernel();
45966 break;
45967 case QLCNIC_MGMT_FUNC:
45968 ahw->op_mode = QLCNIC_MGMT_FUNC;
45969 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45970 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45971 + pax_open_kernel();
45972 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45973 + pax_close_kernel();
45974 break;
45975 default:
45976 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45977 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45978 index 7763962..c3499a7 100644
45979 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45980 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45981 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45982 struct qlcnic_dump_entry *entry;
45983 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45984 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45985 - static const struct qlcnic_dump_operations *fw_dump_ops;
45986 + const struct qlcnic_dump_operations *fw_dump_ops;
45987 struct device *dev = &adapter->pdev->dev;
45988 struct qlcnic_hardware_context *ahw;
45989 void *temp_buffer;
45990 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45991 index 3ff7bc3..366091b 100644
45992 --- a/drivers/net/ethernet/realtek/r8169.c
45993 +++ b/drivers/net/ethernet/realtek/r8169.c
45994 @@ -758,22 +758,22 @@ struct rtl8169_private {
45995 struct mdio_ops {
45996 void (*write)(struct rtl8169_private *, int, int);
45997 int (*read)(struct rtl8169_private *, int);
45998 - } mdio_ops;
45999 + } __no_const mdio_ops;
46000
46001 struct pll_power_ops {
46002 void (*down)(struct rtl8169_private *);
46003 void (*up)(struct rtl8169_private *);
46004 - } pll_power_ops;
46005 + } __no_const pll_power_ops;
46006
46007 struct jumbo_ops {
46008 void (*enable)(struct rtl8169_private *);
46009 void (*disable)(struct rtl8169_private *);
46010 - } jumbo_ops;
46011 + } __no_const jumbo_ops;
46012
46013 struct csi_ops {
46014 void (*write)(struct rtl8169_private *, int, int);
46015 u32 (*read)(struct rtl8169_private *, int);
46016 - } csi_ops;
46017 + } __no_const csi_ops;
46018
46019 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46020 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46021 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46022 index d7a3682..9ce272a 100644
46023 --- a/drivers/net/ethernet/sfc/ptp.c
46024 +++ b/drivers/net/ethernet/sfc/ptp.c
46025 @@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46026 ptp->start.dma_addr);
46027
46028 /* Clear flag that signals MC ready */
46029 - ACCESS_ONCE(*start) = 0;
46030 + ACCESS_ONCE_RW(*start) = 0;
46031 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46032 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46033 EFX_BUG_ON_PARANOID(rc);
46034 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46035 index 50617c5..b13724c 100644
46036 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46037 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46038 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46039
46040 writel(value, ioaddr + MMC_CNTRL);
46041
46042 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46043 - MMC_CNTRL, value);
46044 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46045 +// MMC_CNTRL, value);
46046 }
46047
46048 /* To mask all all interrupts.*/
46049 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46050 index 7b594ce..1f6c5708 100644
46051 --- a/drivers/net/hyperv/hyperv_net.h
46052 +++ b/drivers/net/hyperv/hyperv_net.h
46053 @@ -100,7 +100,7 @@ struct rndis_device {
46054
46055 enum rndis_device_state state;
46056 bool link_state;
46057 - atomic_t new_req_id;
46058 + atomic_unchecked_t new_req_id;
46059
46060 spinlock_t request_lock;
46061 struct list_head req_list;
46062 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46063 index b54fd25..9bd2bae 100644
46064 --- a/drivers/net/hyperv/rndis_filter.c
46065 +++ b/drivers/net/hyperv/rndis_filter.c
46066 @@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46067 * template
46068 */
46069 set = &rndis_msg->msg.set_req;
46070 - set->req_id = atomic_inc_return(&dev->new_req_id);
46071 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46072
46073 /* Add to the request list */
46074 spin_lock_irqsave(&dev->request_lock, flags);
46075 @@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46076
46077 /* Setup the rndis set */
46078 halt = &request->request_msg.msg.halt_req;
46079 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46080 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46081
46082 /* Ignore return since this msg is optional. */
46083 rndis_filter_send_request(dev, request);
46084 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46085 index bf0d55e..82bcfbd1 100644
46086 --- a/drivers/net/ieee802154/fakehard.c
46087 +++ b/drivers/net/ieee802154/fakehard.c
46088 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46089 phy->transmit_power = 0xbf;
46090
46091 dev->netdev_ops = &fake_ops;
46092 - dev->ml_priv = &fake_mlme;
46093 + dev->ml_priv = (void *)&fake_mlme;
46094
46095 priv = netdev_priv(dev);
46096 priv->phy = phy;
46097 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46098 index 1831fb7..9c24bca 100644
46099 --- a/drivers/net/macvlan.c
46100 +++ b/drivers/net/macvlan.c
46101 @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46102 int macvlan_link_register(struct rtnl_link_ops *ops)
46103 {
46104 /* common fields */
46105 - ops->priv_size = sizeof(struct macvlan_dev);
46106 - ops->validate = macvlan_validate;
46107 - ops->maxtype = IFLA_MACVLAN_MAX;
46108 - ops->policy = macvlan_policy;
46109 - ops->changelink = macvlan_changelink;
46110 - ops->get_size = macvlan_get_size;
46111 - ops->fill_info = macvlan_fill_info;
46112 + pax_open_kernel();
46113 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46114 + *(void **)&ops->validate = macvlan_validate;
46115 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46116 + *(const void **)&ops->policy = macvlan_policy;
46117 + *(void **)&ops->changelink = macvlan_changelink;
46118 + *(void **)&ops->get_size = macvlan_get_size;
46119 + *(void **)&ops->fill_info = macvlan_fill_info;
46120 + pax_close_kernel();
46121
46122 return rtnl_link_register(ops);
46123 };
46124 @@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46125 return NOTIFY_DONE;
46126 }
46127
46128 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46129 +static struct notifier_block macvlan_notifier_block = {
46130 .notifier_call = macvlan_device_event,
46131 };
46132
46133 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46134 index ff111a8..c4c3ac4 100644
46135 --- a/drivers/net/macvtap.c
46136 +++ b/drivers/net/macvtap.c
46137 @@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46138 }
46139
46140 ret = 0;
46141 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46142 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46143 put_user(q->flags, &ifr->ifr_flags))
46144 ret = -EFAULT;
46145 macvtap_put_vlan(vlan);
46146 @@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46147 return NOTIFY_DONE;
46148 }
46149
46150 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46151 +static struct notifier_block macvtap_notifier_block = {
46152 .notifier_call = macvtap_device_event,
46153 };
46154
46155 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46156 index daec9b0..6428fcb 100644
46157 --- a/drivers/net/phy/mdio-bitbang.c
46158 +++ b/drivers/net/phy/mdio-bitbang.c
46159 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46160 struct mdiobb_ctrl *ctrl = bus->priv;
46161
46162 module_put(ctrl->ops->owner);
46163 + mdiobus_unregister(bus);
46164 mdiobus_free(bus);
46165 }
46166 EXPORT_SYMBOL(free_mdio_bitbang);
46167 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46168 index 72ff14b..11d442d 100644
46169 --- a/drivers/net/ppp/ppp_generic.c
46170 +++ b/drivers/net/ppp/ppp_generic.c
46171 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46172 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46173 struct ppp_stats stats;
46174 struct ppp_comp_stats cstats;
46175 - char *vers;
46176
46177 switch (cmd) {
46178 case SIOCGPPPSTATS:
46179 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46180 break;
46181
46182 case SIOCGPPPVER:
46183 - vers = PPP_VERSION;
46184 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46185 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46186 break;
46187 err = 0;
46188 break;
46189 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46190 index 1252d9c..80e660b 100644
46191 --- a/drivers/net/slip/slhc.c
46192 +++ b/drivers/net/slip/slhc.c
46193 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46194 register struct tcphdr *thp;
46195 register struct iphdr *ip;
46196 register struct cstate *cs;
46197 - int len, hdrlen;
46198 + long len, hdrlen;
46199 unsigned char *cp = icp;
46200
46201 /* We've got a compressed packet; read the change byte */
46202 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46203 index c8624a8..f0a4f6a 100644
46204 --- a/drivers/net/team/team.c
46205 +++ b/drivers/net/team/team.c
46206 @@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46207 return NOTIFY_DONE;
46208 }
46209
46210 -static struct notifier_block team_notifier_block __read_mostly = {
46211 +static struct notifier_block team_notifier_block = {
46212 .notifier_call = team_device_event,
46213 };
46214
46215 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46216 index 26f8635..c237839 100644
46217 --- a/drivers/net/tun.c
46218 +++ b/drivers/net/tun.c
46219 @@ -1876,7 +1876,7 @@ unlock:
46220 }
46221
46222 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46223 - unsigned long arg, int ifreq_len)
46224 + unsigned long arg, size_t ifreq_len)
46225 {
46226 struct tun_file *tfile = file->private_data;
46227 struct tun_struct *tun;
46228 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46229 unsigned int ifindex;
46230 int ret;
46231
46232 + if (ifreq_len > sizeof ifr)
46233 + return -EFAULT;
46234 +
46235 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46236 if (copy_from_user(&ifr, argp, ifreq_len))
46237 return -EFAULT;
46238 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46239 index 660bd5e..ac59452 100644
46240 --- a/drivers/net/usb/hso.c
46241 +++ b/drivers/net/usb/hso.c
46242 @@ -71,7 +71,7 @@
46243 #include <asm/byteorder.h>
46244 #include <linux/serial_core.h>
46245 #include <linux/serial.h>
46246 -
46247 +#include <asm/local.h>
46248
46249 #define MOD_AUTHOR "Option Wireless"
46250 #define MOD_DESCRIPTION "USB High Speed Option driver"
46251 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46252 struct urb *urb;
46253
46254 urb = serial->rx_urb[0];
46255 - if (serial->port.count > 0) {
46256 + if (atomic_read(&serial->port.count) > 0) {
46257 count = put_rxbuf_data(urb, serial);
46258 if (count == -1)
46259 return;
46260 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46261 DUMP1(urb->transfer_buffer, urb->actual_length);
46262
46263 /* Anyone listening? */
46264 - if (serial->port.count == 0)
46265 + if (atomic_read(&serial->port.count) == 0)
46266 return;
46267
46268 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46269 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46270 tty_port_tty_set(&serial->port, tty);
46271
46272 /* check for port already opened, if not set the termios */
46273 - serial->port.count++;
46274 - if (serial->port.count == 1) {
46275 + if (atomic_inc_return(&serial->port.count) == 1) {
46276 serial->rx_state = RX_IDLE;
46277 /* Force default termio settings */
46278 _hso_serial_set_termios(tty, NULL);
46279 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46280 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46281 if (result) {
46282 hso_stop_serial_device(serial->parent);
46283 - serial->port.count--;
46284 + atomic_dec(&serial->port.count);
46285 kref_put(&serial->parent->ref, hso_serial_ref_free);
46286 }
46287 } else {
46288 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46289
46290 /* reset the rts and dtr */
46291 /* do the actual close */
46292 - serial->port.count--;
46293 + atomic_dec(&serial->port.count);
46294
46295 - if (serial->port.count <= 0) {
46296 - serial->port.count = 0;
46297 + if (atomic_read(&serial->port.count) <= 0) {
46298 + atomic_set(&serial->port.count, 0);
46299 tty_port_tty_set(&serial->port, NULL);
46300 if (!usb_gone)
46301 hso_stop_serial_device(serial->parent);
46302 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46303
46304 /* the actual setup */
46305 spin_lock_irqsave(&serial->serial_lock, flags);
46306 - if (serial->port.count)
46307 + if (atomic_read(&serial->port.count))
46308 _hso_serial_set_termios(tty, old);
46309 else
46310 tty->termios = *old;
46311 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46312 D1("Pending read interrupt on port %d\n", i);
46313 spin_lock(&serial->serial_lock);
46314 if (serial->rx_state == RX_IDLE &&
46315 - serial->port.count > 0) {
46316 + atomic_read(&serial->port.count) > 0) {
46317 /* Setup and send a ctrl req read on
46318 * port i */
46319 if (!serial->rx_urb_filled[0]) {
46320 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46321 /* Start all serial ports */
46322 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46323 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46324 - if (dev2ser(serial_table[i])->port.count) {
46325 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46326 result =
46327 hso_start_serial_device(serial_table[i], GFP_NOIO);
46328 hso_kick_transmit(dev2ser(serial_table[i]));
46329 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46330 index adb12f3..48005ab 100644
46331 --- a/drivers/net/usb/r8152.c
46332 +++ b/drivers/net/usb/r8152.c
46333 @@ -513,7 +513,7 @@ struct r8152 {
46334 void (*disable)(struct r8152 *);
46335 void (*down)(struct r8152 *);
46336 void (*unload)(struct r8152 *);
46337 - } rtl_ops;
46338 + } __no_const rtl_ops;
46339
46340 int intr_interval;
46341 u32 msg_enable;
46342 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46343 index a2515887..6d13233 100644
46344 --- a/drivers/net/usb/sierra_net.c
46345 +++ b/drivers/net/usb/sierra_net.c
46346 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46347 /* atomic counter partially included in MAC address to make sure 2 devices
46348 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46349 */
46350 -static atomic_t iface_counter = ATOMIC_INIT(0);
46351 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46352
46353 /*
46354 * SYNC Timer Delay definition used to set the expiry time
46355 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46356 dev->net->netdev_ops = &sierra_net_device_ops;
46357
46358 /* change MAC addr to include, ifacenum, and to be unique */
46359 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46360 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46361 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46362
46363 /* we will have to manufacture ethernet headers, prepare template */
46364 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46365 index d091e52..568bb179 100644
46366 --- a/drivers/net/vxlan.c
46367 +++ b/drivers/net/vxlan.c
46368 @@ -2847,7 +2847,7 @@ nla_put_failure:
46369 return -EMSGSIZE;
46370 }
46371
46372 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46373 +static struct rtnl_link_ops vxlan_link_ops = {
46374 .kind = "vxlan",
46375 .maxtype = IFLA_VXLAN_MAX,
46376 .policy = vxlan_policy,
46377 @@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46378 return NOTIFY_DONE;
46379 }
46380
46381 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46382 +static struct notifier_block vxlan_notifier_block = {
46383 .notifier_call = vxlan_lowerdev_event,
46384 };
46385
46386 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46387 index 5920c99..ff2e4a5 100644
46388 --- a/drivers/net/wan/lmc/lmc_media.c
46389 +++ b/drivers/net/wan/lmc/lmc_media.c
46390 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46391 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46392
46393 lmc_media_t lmc_ds3_media = {
46394 - lmc_ds3_init, /* special media init stuff */
46395 - lmc_ds3_default, /* reset to default state */
46396 - lmc_ds3_set_status, /* reset status to state provided */
46397 - lmc_dummy_set_1, /* set clock source */
46398 - lmc_dummy_set2_1, /* set line speed */
46399 - lmc_ds3_set_100ft, /* set cable length */
46400 - lmc_ds3_set_scram, /* set scrambler */
46401 - lmc_ds3_get_link_status, /* get link status */
46402 - lmc_dummy_set_1, /* set link status */
46403 - lmc_ds3_set_crc_length, /* set CRC length */
46404 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46405 - lmc_ds3_watchdog
46406 + .init = lmc_ds3_init, /* special media init stuff */
46407 + .defaults = lmc_ds3_default, /* reset to default state */
46408 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46409 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46410 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46411 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46412 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46413 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46414 + .set_link_status = lmc_dummy_set_1, /* set link status */
46415 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46416 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46417 + .watchdog = lmc_ds3_watchdog
46418 };
46419
46420 lmc_media_t lmc_hssi_media = {
46421 - lmc_hssi_init, /* special media init stuff */
46422 - lmc_hssi_default, /* reset to default state */
46423 - lmc_hssi_set_status, /* reset status to state provided */
46424 - lmc_hssi_set_clock, /* set clock source */
46425 - lmc_dummy_set2_1, /* set line speed */
46426 - lmc_dummy_set_1, /* set cable length */
46427 - lmc_dummy_set_1, /* set scrambler */
46428 - lmc_hssi_get_link_status, /* get link status */
46429 - lmc_hssi_set_link_status, /* set link status */
46430 - lmc_hssi_set_crc_length, /* set CRC length */
46431 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46432 - lmc_hssi_watchdog
46433 + .init = lmc_hssi_init, /* special media init stuff */
46434 + .defaults = lmc_hssi_default, /* reset to default state */
46435 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46436 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46437 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46438 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46439 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46440 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46441 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46442 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46443 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46444 + .watchdog = lmc_hssi_watchdog
46445 };
46446
46447 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46448 - lmc_ssi_default, /* reset to default state */
46449 - lmc_ssi_set_status, /* reset status to state provided */
46450 - lmc_ssi_set_clock, /* set clock source */
46451 - lmc_ssi_set_speed, /* set line speed */
46452 - lmc_dummy_set_1, /* set cable length */
46453 - lmc_dummy_set_1, /* set scrambler */
46454 - lmc_ssi_get_link_status, /* get link status */
46455 - lmc_ssi_set_link_status, /* set link status */
46456 - lmc_ssi_set_crc_length, /* set CRC length */
46457 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46458 - lmc_ssi_watchdog
46459 +lmc_media_t lmc_ssi_media = {
46460 + .init = lmc_ssi_init, /* special media init stuff */
46461 + .defaults = lmc_ssi_default, /* reset to default state */
46462 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46463 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46464 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46465 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46466 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46467 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46468 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46469 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46470 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46471 + .watchdog = lmc_ssi_watchdog
46472 };
46473
46474 lmc_media_t lmc_t1_media = {
46475 - lmc_t1_init, /* special media init stuff */
46476 - lmc_t1_default, /* reset to default state */
46477 - lmc_t1_set_status, /* reset status to state provided */
46478 - lmc_t1_set_clock, /* set clock source */
46479 - lmc_dummy_set2_1, /* set line speed */
46480 - lmc_dummy_set_1, /* set cable length */
46481 - lmc_dummy_set_1, /* set scrambler */
46482 - lmc_t1_get_link_status, /* get link status */
46483 - lmc_dummy_set_1, /* set link status */
46484 - lmc_t1_set_crc_length, /* set CRC length */
46485 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46486 - lmc_t1_watchdog
46487 + .init = lmc_t1_init, /* special media init stuff */
46488 + .defaults = lmc_t1_default, /* reset to default state */
46489 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46490 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46491 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46492 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46493 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46494 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46495 + .set_link_status = lmc_dummy_set_1, /* set link status */
46496 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46497 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46498 + .watchdog = lmc_t1_watchdog
46499 };
46500
46501 static void
46502 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46503 index feacc3b..5bac0de 100644
46504 --- a/drivers/net/wan/z85230.c
46505 +++ b/drivers/net/wan/z85230.c
46506 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46507
46508 struct z8530_irqhandler z8530_sync =
46509 {
46510 - z8530_rx,
46511 - z8530_tx,
46512 - z8530_status
46513 + .rx = z8530_rx,
46514 + .tx = z8530_tx,
46515 + .status = z8530_status
46516 };
46517
46518 EXPORT_SYMBOL(z8530_sync);
46519 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46520 }
46521
46522 static struct z8530_irqhandler z8530_dma_sync = {
46523 - z8530_dma_rx,
46524 - z8530_dma_tx,
46525 - z8530_dma_status
46526 + .rx = z8530_dma_rx,
46527 + .tx = z8530_dma_tx,
46528 + .status = z8530_dma_status
46529 };
46530
46531 static struct z8530_irqhandler z8530_txdma_sync = {
46532 - z8530_rx,
46533 - z8530_dma_tx,
46534 - z8530_dma_status
46535 + .rx = z8530_rx,
46536 + .tx = z8530_dma_tx,
46537 + .status = z8530_dma_status
46538 };
46539
46540 /**
46541 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46542
46543 struct z8530_irqhandler z8530_nop=
46544 {
46545 - z8530_rx_clear,
46546 - z8530_tx_clear,
46547 - z8530_status_clear
46548 + .rx = z8530_rx_clear,
46549 + .tx = z8530_tx_clear,
46550 + .status = z8530_status_clear
46551 };
46552
46553
46554 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46555 index 0b60295..b8bfa5b 100644
46556 --- a/drivers/net/wimax/i2400m/rx.c
46557 +++ b/drivers/net/wimax/i2400m/rx.c
46558 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46559 if (i2400m->rx_roq == NULL)
46560 goto error_roq_alloc;
46561
46562 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46563 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46564 GFP_KERNEL);
46565 if (rd == NULL) {
46566 result = -ENOMEM;
46567 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46568 index edf4b57..68b51c0 100644
46569 --- a/drivers/net/wireless/airo.c
46570 +++ b/drivers/net/wireless/airo.c
46571 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46572 struct airo_info *ai = dev->ml_priv;
46573 int ridcode;
46574 int enabled;
46575 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46576 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46577 unsigned char *iobuf;
46578
46579 /* Only super-user can write RIDs */
46580 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46581 index 99b3bfa..9559372 100644
46582 --- a/drivers/net/wireless/at76c50x-usb.c
46583 +++ b/drivers/net/wireless/at76c50x-usb.c
46584 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46585 }
46586
46587 /* Convert timeout from the DFU status to jiffies */
46588 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46589 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46590 {
46591 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46592 | (s->poll_timeout[1] << 8)
46593 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46594 index edc57ab..ff49e0a 100644
46595 --- a/drivers/net/wireless/ath/ath10k/htc.c
46596 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46597 @@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46598 /* registered target arrival callback from the HIF layer */
46599 int ath10k_htc_init(struct ath10k *ar)
46600 {
46601 - struct ath10k_hif_cb htc_callbacks;
46602 + static struct ath10k_hif_cb htc_callbacks = {
46603 + .rx_completion = ath10k_htc_rx_completion_handler,
46604 + .tx_completion = ath10k_htc_tx_completion_handler,
46605 + };
46606 struct ath10k_htc_ep *ep = NULL;
46607 struct ath10k_htc *htc = &ar->htc;
46608
46609 @@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
46610 ath10k_htc_reset_endpoint_states(htc);
46611
46612 /* setup HIF layer callbacks */
46613 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46614 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46615 htc->ar = ar;
46616
46617 /* Get HIF default pipe for HTC message exchange */
46618 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46619 index 4716d33..a688310 100644
46620 --- a/drivers/net/wireless/ath/ath10k/htc.h
46621 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46622 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46623
46624 struct ath10k_htc_ops {
46625 void (*target_send_suspend_complete)(struct ath10k *ar);
46626 -};
46627 +} __no_const;
46628
46629 struct ath10k_htc_ep_ops {
46630 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46631 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46632 void (*ep_tx_credits)(struct ath10k *);
46633 -};
46634 +} __no_const;
46635
46636 /* service connection information */
46637 struct ath10k_htc_svc_conn_req {
46638 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46639 index 741b38d..b7ae41b 100644
46640 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46641 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46642 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46643 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46644 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46645
46646 - ACCESS_ONCE(ads->ds_link) = i->link;
46647 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46648 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46649 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46650
46651 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46652 ctl6 = SM(i->keytype, AR_EncrType);
46653 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46654
46655 if ((i->is_first || i->is_last) &&
46656 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46657 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46658 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46659 | set11nTries(i->rates, 1)
46660 | set11nTries(i->rates, 2)
46661 | set11nTries(i->rates, 3)
46662 | (i->dur_update ? AR_DurUpdateEna : 0)
46663 | SM(0, AR_BurstDur);
46664
46665 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46666 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46667 | set11nRate(i->rates, 1)
46668 | set11nRate(i->rates, 2)
46669 | set11nRate(i->rates, 3);
46670 } else {
46671 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46672 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46673 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46674 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46675 }
46676
46677 if (!i->is_first) {
46678 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46679 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46680 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46681 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46682 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46683 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46684 return;
46685 }
46686
46687 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46688 break;
46689 }
46690
46691 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46692 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46693 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46694 | SM(i->txpower, AR_XmitPower)
46695 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46696 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46697 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46698 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46699
46700 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46701 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46702 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46703 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46704
46705 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46706 return;
46707
46708 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46709 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46710 | set11nPktDurRTSCTS(i->rates, 1);
46711
46712 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46713 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46714 | set11nPktDurRTSCTS(i->rates, 3);
46715
46716 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46717 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46718 | set11nRateFlags(i->rates, 1)
46719 | set11nRateFlags(i->rates, 2)
46720 | set11nRateFlags(i->rates, 3)
46721 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46722 index 729ffbf..49f50e3 100644
46723 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46724 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46725 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46726 (i->qcu << AR_TxQcuNum_S) | desc_len;
46727
46728 checksum += val;
46729 - ACCESS_ONCE(ads->info) = val;
46730 + ACCESS_ONCE_RW(ads->info) = val;
46731
46732 checksum += i->link;
46733 - ACCESS_ONCE(ads->link) = i->link;
46734 + ACCESS_ONCE_RW(ads->link) = i->link;
46735
46736 checksum += i->buf_addr[0];
46737 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46738 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46739 checksum += i->buf_addr[1];
46740 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46741 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46742 checksum += i->buf_addr[2];
46743 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46744 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46745 checksum += i->buf_addr[3];
46746 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46747 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46748
46749 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46750 - ACCESS_ONCE(ads->ctl3) = val;
46751 + ACCESS_ONCE_RW(ads->ctl3) = val;
46752 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46753 - ACCESS_ONCE(ads->ctl5) = val;
46754 + ACCESS_ONCE_RW(ads->ctl5) = val;
46755 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46756 - ACCESS_ONCE(ads->ctl7) = val;
46757 + ACCESS_ONCE_RW(ads->ctl7) = val;
46758 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46759 - ACCESS_ONCE(ads->ctl9) = val;
46760 + ACCESS_ONCE_RW(ads->ctl9) = val;
46761
46762 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46763 - ACCESS_ONCE(ads->ctl10) = checksum;
46764 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46765
46766 if (i->is_first || i->is_last) {
46767 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46768 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46769 | set11nTries(i->rates, 1)
46770 | set11nTries(i->rates, 2)
46771 | set11nTries(i->rates, 3)
46772 | (i->dur_update ? AR_DurUpdateEna : 0)
46773 | SM(0, AR_BurstDur);
46774
46775 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46776 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46777 | set11nRate(i->rates, 1)
46778 | set11nRate(i->rates, 2)
46779 | set11nRate(i->rates, 3);
46780 } else {
46781 - ACCESS_ONCE(ads->ctl13) = 0;
46782 - ACCESS_ONCE(ads->ctl14) = 0;
46783 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46784 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46785 }
46786
46787 ads->ctl20 = 0;
46788 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46789
46790 ctl17 = SM(i->keytype, AR_EncrType);
46791 if (!i->is_first) {
46792 - ACCESS_ONCE(ads->ctl11) = 0;
46793 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46794 - ACCESS_ONCE(ads->ctl15) = 0;
46795 - ACCESS_ONCE(ads->ctl16) = 0;
46796 - ACCESS_ONCE(ads->ctl17) = ctl17;
46797 - ACCESS_ONCE(ads->ctl18) = 0;
46798 - ACCESS_ONCE(ads->ctl19) = 0;
46799 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46800 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46801 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46802 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46803 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46804 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46805 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46806 return;
46807 }
46808
46809 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46810 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46811 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46812 | SM(i->txpower, AR_XmitPower)
46813 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46814 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46815 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46816 ctl12 |= SM(val, AR_PAPRDChainMask);
46817
46818 - ACCESS_ONCE(ads->ctl12) = ctl12;
46819 - ACCESS_ONCE(ads->ctl17) = ctl17;
46820 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46821 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46822
46823 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46824 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46825 | set11nPktDurRTSCTS(i->rates, 1);
46826
46827 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46828 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46829 | set11nPktDurRTSCTS(i->rates, 3);
46830
46831 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46832 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46833 | set11nRateFlags(i->rates, 1)
46834 | set11nRateFlags(i->rates, 2)
46835 | set11nRateFlags(i->rates, 3)
46836 | SM(i->rtscts_rate, AR_RTSCTSRate);
46837
46838 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46839 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46840 }
46841
46842 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46843 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46844 index 0acd4b5..0591c91 100644
46845 --- a/drivers/net/wireless/ath/ath9k/hw.h
46846 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46847 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46848
46849 /* ANI */
46850 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46851 -};
46852 +} __no_const;
46853
46854 /**
46855 * struct ath_spec_scan - parameters for Atheros spectral scan
46856 @@ -706,7 +706,7 @@ struct ath_hw_ops {
46857 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46858 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46859 #endif
46860 -};
46861 +} __no_const;
46862
46863 struct ath_nf_limits {
46864 s16 max;
46865 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46866 index 92190da..f3a4c4c 100644
46867 --- a/drivers/net/wireless/b43/phy_lp.c
46868 +++ b/drivers/net/wireless/b43/phy_lp.c
46869 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46870 {
46871 struct ssb_bus *bus = dev->dev->sdev->bus;
46872
46873 - static const struct b206x_channel *chandata = NULL;
46874 + const struct b206x_channel *chandata = NULL;
46875 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46876 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46877 u16 old_comm15, scale;
46878 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46879 index 0487461..fd9e84a 100644
46880 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46881 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46882 @@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46883 */
46884 if (il3945_mod_params.disable_hw_scan) {
46885 D_INFO("Disabling hw_scan\n");
46886 - il3945_mac_ops.hw_scan = NULL;
46887 + pax_open_kernel();
46888 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46889 + pax_close_kernel();
46890 }
46891
46892 D_INFO("*** LOAD DRIVER ***\n");
46893 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46894 index d2fe259..0c4c682 100644
46895 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46896 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46897 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46898 {
46899 struct iwl_priv *priv = file->private_data;
46900 char buf[64];
46901 - int buf_size;
46902 + size_t buf_size;
46903 u32 offset, len;
46904
46905 memset(buf, 0, sizeof(buf));
46906 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46907 struct iwl_priv *priv = file->private_data;
46908
46909 char buf[8];
46910 - int buf_size;
46911 + size_t buf_size;
46912 u32 reset_flag;
46913
46914 memset(buf, 0, sizeof(buf));
46915 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46916 {
46917 struct iwl_priv *priv = file->private_data;
46918 char buf[8];
46919 - int buf_size;
46920 + size_t buf_size;
46921 int ht40;
46922
46923 memset(buf, 0, sizeof(buf));
46924 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46925 {
46926 struct iwl_priv *priv = file->private_data;
46927 char buf[8];
46928 - int buf_size;
46929 + size_t buf_size;
46930 int value;
46931
46932 memset(buf, 0, sizeof(buf));
46933 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46934 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46935 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46936
46937 -static const char *fmt_value = " %-30s %10u\n";
46938 -static const char *fmt_hex = " %-30s 0x%02X\n";
46939 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46940 -static const char *fmt_header =
46941 +static const char fmt_value[] = " %-30s %10u\n";
46942 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46943 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46944 +static const char fmt_header[] =
46945 "%-32s current cumulative delta max\n";
46946
46947 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46948 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46949 {
46950 struct iwl_priv *priv = file->private_data;
46951 char buf[8];
46952 - int buf_size;
46953 + size_t buf_size;
46954 int clear;
46955
46956 memset(buf, 0, sizeof(buf));
46957 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46958 {
46959 struct iwl_priv *priv = file->private_data;
46960 char buf[8];
46961 - int buf_size;
46962 + size_t buf_size;
46963 int trace;
46964
46965 memset(buf, 0, sizeof(buf));
46966 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46967 {
46968 struct iwl_priv *priv = file->private_data;
46969 char buf[8];
46970 - int buf_size;
46971 + size_t buf_size;
46972 int missed;
46973
46974 memset(buf, 0, sizeof(buf));
46975 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46976
46977 struct iwl_priv *priv = file->private_data;
46978 char buf[8];
46979 - int buf_size;
46980 + size_t buf_size;
46981 int plcp;
46982
46983 memset(buf, 0, sizeof(buf));
46984 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46985
46986 struct iwl_priv *priv = file->private_data;
46987 char buf[8];
46988 - int buf_size;
46989 + size_t buf_size;
46990 int flush;
46991
46992 memset(buf, 0, sizeof(buf));
46993 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46994
46995 struct iwl_priv *priv = file->private_data;
46996 char buf[8];
46997 - int buf_size;
46998 + size_t buf_size;
46999 int rts;
47000
47001 if (!priv->cfg->ht_params)
47002 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47003 {
47004 struct iwl_priv *priv = file->private_data;
47005 char buf[8];
47006 - int buf_size;
47007 + size_t buf_size;
47008
47009 memset(buf, 0, sizeof(buf));
47010 buf_size = min(count, sizeof(buf) - 1);
47011 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47012 struct iwl_priv *priv = file->private_data;
47013 u32 event_log_flag;
47014 char buf[8];
47015 - int buf_size;
47016 + size_t buf_size;
47017
47018 /* check that the interface is up */
47019 if (!iwl_is_ready(priv))
47020 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47021 struct iwl_priv *priv = file->private_data;
47022 char buf[8];
47023 u32 calib_disabled;
47024 - int buf_size;
47025 + size_t buf_size;
47026
47027 memset(buf, 0, sizeof(buf));
47028 buf_size = min(count, sizeof(buf) - 1);
47029 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47030 index ba1b1ea..0ff7e98 100644
47031 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47032 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47033 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47034 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47035 {
47036 struct iwl_nvm_data *data = priv->nvm_data;
47037 - char *debug_msg;
47038 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47039
47040 if (data->sku_cap_11n_enable &&
47041 !priv->cfg->ht_params) {
47042 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47043 return -EINVAL;
47044 }
47045
47046 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47047 IWL_DEBUG_INFO(priv, debug_msg,
47048 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47049 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47050 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47051 index f950780..be9df93 100644
47052 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47053 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47054 @@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47055 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47056
47057 char buf[8];
47058 - int buf_size;
47059 + size_t buf_size;
47060 u32 reset_flag;
47061
47062 memset(buf, 0, sizeof(buf));
47063 @@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47064 {
47065 struct iwl_trans *trans = file->private_data;
47066 char buf[8];
47067 - int buf_size;
47068 + size_t buf_size;
47069 int csr;
47070
47071 memset(buf, 0, sizeof(buf));
47072 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47073 index 69d4c31..bd0b316 100644
47074 --- a/drivers/net/wireless/mac80211_hwsim.c
47075 +++ b/drivers/net/wireless/mac80211_hwsim.c
47076 @@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47077 if (channels < 1)
47078 return -EINVAL;
47079
47080 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47081 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47082 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47083 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47084 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47085 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47086 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47087 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47088 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47089 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47090 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47091 - mac80211_hwsim_assign_vif_chanctx;
47092 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47093 - mac80211_hwsim_unassign_vif_chanctx;
47094 + pax_open_kernel();
47095 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47096 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47097 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47098 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47099 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47100 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47101 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47102 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47103 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47104 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47105 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47106 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47107 + pax_close_kernel();
47108
47109 spin_lock_init(&hwsim_radio_lock);
47110 INIT_LIST_HEAD(&hwsim_radios);
47111 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47112 index 5028557..91cf394 100644
47113 --- a/drivers/net/wireless/rndis_wlan.c
47114 +++ b/drivers/net/wireless/rndis_wlan.c
47115 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47116
47117 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47118
47119 - if (rts_threshold < 0 || rts_threshold > 2347)
47120 + if (rts_threshold > 2347)
47121 rts_threshold = 2347;
47122
47123 tmp = cpu_to_le32(rts_threshold);
47124 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47125 index e3b885d..7a7de2f 100644
47126 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47127 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47128 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47129 * for hardware which doesn't support hardware
47130 * sequence counting.
47131 */
47132 - atomic_t seqno;
47133 + atomic_unchecked_t seqno;
47134 };
47135
47136 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47137 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47138 index 5642ccc..01f03eb 100644
47139 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47140 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47141 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47142 * sequence counter given by mac80211.
47143 */
47144 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47145 - seqno = atomic_add_return(0x10, &intf->seqno);
47146 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47147 else
47148 - seqno = atomic_read(&intf->seqno);
47149 + seqno = atomic_read_unchecked(&intf->seqno);
47150
47151 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47152 hdr->seq_ctrl |= cpu_to_le16(seqno);
47153 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47154 index e2b3d9c..67a5184 100644
47155 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47156 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47157 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47158
47159 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47160
47161 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47162 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47163 + pax_open_kernel();
47164 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47165 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47166 + pax_close_kernel();
47167
47168 wl1251_info("using dedicated interrupt line");
47169 } else {
47170 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47171 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47172 + pax_open_kernel();
47173 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47174 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47175 + pax_close_kernel();
47176
47177 wl1251_info("using SDIO interrupt");
47178 }
47179 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47180 index be7129b..4161356 100644
47181 --- a/drivers/net/wireless/ti/wl12xx/main.c
47182 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47183 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47184 sizeof(wl->conf.mem));
47185
47186 /* read data preparation is only needed by wl127x */
47187 - wl->ops->prepare_read = wl127x_prepare_read;
47188 + pax_open_kernel();
47189 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47190 + pax_close_kernel();
47191
47192 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47193 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47194 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47195 sizeof(wl->conf.mem));
47196
47197 /* read data preparation is only needed by wl127x */
47198 - wl->ops->prepare_read = wl127x_prepare_read;
47199 + pax_open_kernel();
47200 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47201 + pax_close_kernel();
47202
47203 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47204 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47205 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47206 index ec37b16..7e34d66 100644
47207 --- a/drivers/net/wireless/ti/wl18xx/main.c
47208 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47209 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47210 }
47211
47212 if (!checksum_param) {
47213 - wl18xx_ops.set_rx_csum = NULL;
47214 - wl18xx_ops.init_vif = NULL;
47215 + pax_open_kernel();
47216 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47217 + *(void **)&wl18xx_ops.init_vif = NULL;
47218 + pax_close_kernel();
47219 }
47220
47221 /* Enable 11a Band only if we have 5G antennas */
47222 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47223 index a912dc0..a8225ba 100644
47224 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47225 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47226 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47227 {
47228 struct zd_usb *usb = urb->context;
47229 struct zd_usb_interrupt *intr = &usb->intr;
47230 - int len;
47231 + unsigned int len;
47232 u16 int_num;
47233
47234 ZD_ASSERT(in_interrupt());
47235 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47236 index 683671a..4519fc2 100644
47237 --- a/drivers/nfc/nfcwilink.c
47238 +++ b/drivers/nfc/nfcwilink.c
47239 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47240
47241 static int nfcwilink_probe(struct platform_device *pdev)
47242 {
47243 - static struct nfcwilink *drv;
47244 + struct nfcwilink *drv;
47245 int rc;
47246 __u32 protocols;
47247
47248 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47249 index d93b2b6..ae50401 100644
47250 --- a/drivers/oprofile/buffer_sync.c
47251 +++ b/drivers/oprofile/buffer_sync.c
47252 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47253 if (cookie == NO_COOKIE)
47254 offset = pc;
47255 if (cookie == INVALID_COOKIE) {
47256 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47257 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47258 offset = pc;
47259 }
47260 if (cookie != last_cookie) {
47261 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47262 /* add userspace sample */
47263
47264 if (!mm) {
47265 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47266 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47267 return 0;
47268 }
47269
47270 cookie = lookup_dcookie(mm, s->eip, &offset);
47271
47272 if (cookie == INVALID_COOKIE) {
47273 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47274 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47275 return 0;
47276 }
47277
47278 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47279 /* ignore backtraces if failed to add a sample */
47280 if (state == sb_bt_start) {
47281 state = sb_bt_ignore;
47282 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47283 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47284 }
47285 }
47286 release_mm(mm);
47287 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47288 index c0cc4e7..44d4e54 100644
47289 --- a/drivers/oprofile/event_buffer.c
47290 +++ b/drivers/oprofile/event_buffer.c
47291 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47292 }
47293
47294 if (buffer_pos == buffer_size) {
47295 - atomic_inc(&oprofile_stats.event_lost_overflow);
47296 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47297 return;
47298 }
47299
47300 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47301 index ed2c3ec..deda85a 100644
47302 --- a/drivers/oprofile/oprof.c
47303 +++ b/drivers/oprofile/oprof.c
47304 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47305 if (oprofile_ops.switch_events())
47306 return;
47307
47308 - atomic_inc(&oprofile_stats.multiplex_counter);
47309 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47310 start_switch_worker();
47311 }
47312
47313 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47314 index ee2cfce..7f8f699 100644
47315 --- a/drivers/oprofile/oprofile_files.c
47316 +++ b/drivers/oprofile/oprofile_files.c
47317 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47318
47319 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47320
47321 -static ssize_t timeout_read(struct file *file, char __user *buf,
47322 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47323 size_t count, loff_t *offset)
47324 {
47325 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47326 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47327 index 59659ce..6c860a0 100644
47328 --- a/drivers/oprofile/oprofile_stats.c
47329 +++ b/drivers/oprofile/oprofile_stats.c
47330 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47331 cpu_buf->sample_invalid_eip = 0;
47332 }
47333
47334 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47335 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47336 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47337 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47338 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47339 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47340 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47341 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47342 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47343 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47344 }
47345
47346
47347 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47348 index 1fc622b..8c48fc3 100644
47349 --- a/drivers/oprofile/oprofile_stats.h
47350 +++ b/drivers/oprofile/oprofile_stats.h
47351 @@ -13,11 +13,11 @@
47352 #include <linux/atomic.h>
47353
47354 struct oprofile_stat_struct {
47355 - atomic_t sample_lost_no_mm;
47356 - atomic_t sample_lost_no_mapping;
47357 - atomic_t bt_lost_no_mapping;
47358 - atomic_t event_lost_overflow;
47359 - atomic_t multiplex_counter;
47360 + atomic_unchecked_t sample_lost_no_mm;
47361 + atomic_unchecked_t sample_lost_no_mapping;
47362 + atomic_unchecked_t bt_lost_no_mapping;
47363 + atomic_unchecked_t event_lost_overflow;
47364 + atomic_unchecked_t multiplex_counter;
47365 };
47366
47367 extern struct oprofile_stat_struct oprofile_stats;
47368 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47369 index 3f49345..c750d0b 100644
47370 --- a/drivers/oprofile/oprofilefs.c
47371 +++ b/drivers/oprofile/oprofilefs.c
47372 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47373
47374 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47375 {
47376 - atomic_t *val = file->private_data;
47377 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47378 + atomic_unchecked_t *val = file->private_data;
47379 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47380 }
47381
47382
47383 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47384
47385
47386 int oprofilefs_create_ro_atomic(struct dentry *root,
47387 - char const *name, atomic_t *val)
47388 + char const *name, atomic_unchecked_t *val)
47389 {
47390 return __oprofilefs_create_file(root, name,
47391 &atomic_ro_fops, 0444, val);
47392 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47393 index 61be1d9..dec05d7 100644
47394 --- a/drivers/oprofile/timer_int.c
47395 +++ b/drivers/oprofile/timer_int.c
47396 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47397 return NOTIFY_OK;
47398 }
47399
47400 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47401 +static struct notifier_block oprofile_cpu_notifier = {
47402 .notifier_call = oprofile_cpu_notify,
47403 };
47404
47405 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47406 index 92ed045..62d39bd7 100644
47407 --- a/drivers/parport/procfs.c
47408 +++ b/drivers/parport/procfs.c
47409 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47410
47411 *ppos += len;
47412
47413 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47414 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47415 }
47416
47417 #ifdef CONFIG_PARPORT_1284
47418 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47419
47420 *ppos += len;
47421
47422 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47423 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47424 }
47425 #endif /* IEEE1284.3 support. */
47426
47427 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47428 index 8dcccff..35d701d 100644
47429 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47430 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47431 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47432 goto init_cleanup;
47433 }
47434
47435 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47436 + pax_open_kernel();
47437 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47438 + pax_close_kernel();
47439 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47440
47441 return retval;
47442 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47443 index 7536eef..52dc8fa 100644
47444 --- a/drivers/pci/hotplug/cpcihp_generic.c
47445 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47446 @@ -73,7 +73,6 @@ static u16 port;
47447 static unsigned int enum_bit;
47448 static u8 enum_mask;
47449
47450 -static struct cpci_hp_controller_ops generic_hpc_ops;
47451 static struct cpci_hp_controller generic_hpc;
47452
47453 static int __init validate_parameters(void)
47454 @@ -139,6 +138,10 @@ static int query_enum(void)
47455 return ((value & enum_mask) == enum_mask);
47456 }
47457
47458 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47459 + .query_enum = query_enum,
47460 +};
47461 +
47462 static int __init cpcihp_generic_init(void)
47463 {
47464 int status;
47465 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47466 pci_dev_put(dev);
47467
47468 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47469 - generic_hpc_ops.query_enum = query_enum;
47470 generic_hpc.ops = &generic_hpc_ops;
47471
47472 status = cpci_hp_register_controller(&generic_hpc);
47473 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47474 index e8c4a7c..7046f5c 100644
47475 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47476 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47477 @@ -59,7 +59,6 @@
47478 /* local variables */
47479 static bool debug;
47480 static bool poll;
47481 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47482 static struct cpci_hp_controller zt5550_hpc;
47483
47484 /* Primary cPCI bus bridge device */
47485 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47486 return 0;
47487 }
47488
47489 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47490 + .query_enum = zt5550_hc_query_enum,
47491 +};
47492 +
47493 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47494 {
47495 int status;
47496 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47497 dbg("returned from zt5550_hc_config");
47498
47499 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47500 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47501 zt5550_hpc.ops = &zt5550_hpc_ops;
47502 if(!poll) {
47503 zt5550_hpc.irq = hc_dev->irq;
47504 zt5550_hpc.irq_flags = IRQF_SHARED;
47505 zt5550_hpc.dev_id = hc_dev;
47506
47507 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47508 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47509 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47510 + pax_open_kernel();
47511 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47512 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47513 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47514 + pax_open_kernel();
47515 } else {
47516 info("using ENUM# polling mode");
47517 }
47518 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47519 index 76ba8a1..20ca857 100644
47520 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47521 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47522 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47523
47524 void compaq_nvram_init (void __iomem *rom_start)
47525 {
47526 +
47527 +#ifndef CONFIG_PAX_KERNEXEC
47528 if (rom_start) {
47529 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47530 }
47531 +#endif
47532 +
47533 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47534
47535 /* initialize our int15 lock */
47536 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47537 index cfa92a9..29539c5 100644
47538 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47539 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47540 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47541 return -EINVAL;
47542 }
47543
47544 - slot->ops->owner = owner;
47545 - slot->ops->mod_name = mod_name;
47546 + pax_open_kernel();
47547 + *(struct module **)&slot->ops->owner = owner;
47548 + *(const char **)&slot->ops->mod_name = mod_name;
47549 + pax_close_kernel();
47550
47551 mutex_lock(&pci_hp_mutex);
47552 /*
47553 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47554 index 53b58de..4479896 100644
47555 --- a/drivers/pci/hotplug/pciehp_core.c
47556 +++ b/drivers/pci/hotplug/pciehp_core.c
47557 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47558 struct slot *slot = ctrl->slot;
47559 struct hotplug_slot *hotplug = NULL;
47560 struct hotplug_slot_info *info = NULL;
47561 - struct hotplug_slot_ops *ops = NULL;
47562 + hotplug_slot_ops_no_const *ops = NULL;
47563 char name[SLOT_NAME_SIZE];
47564 int retval = -ENOMEM;
47565
47566 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47567 index 955ab79..d1df9c7 100644
47568 --- a/drivers/pci/msi.c
47569 +++ b/drivers/pci/msi.c
47570 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47571 {
47572 struct attribute **msi_attrs;
47573 struct attribute *msi_attr;
47574 - struct device_attribute *msi_dev_attr;
47575 - struct attribute_group *msi_irq_group;
47576 + device_attribute_no_const *msi_dev_attr;
47577 + attribute_group_no_const *msi_irq_group;
47578 const struct attribute_group **msi_irq_groups;
47579 struct msi_desc *entry;
47580 int ret = -ENOMEM;
47581 @@ -589,7 +589,7 @@ error_attrs:
47582 count = 0;
47583 msi_attr = msi_attrs[count];
47584 while (msi_attr) {
47585 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47586 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47587 kfree(msi_attr->name);
47588 kfree(msi_dev_attr);
47589 ++count;
47590 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47591 index 276ef9c..1d33a36 100644
47592 --- a/drivers/pci/pci-sysfs.c
47593 +++ b/drivers/pci/pci-sysfs.c
47594 @@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47595 {
47596 /* allocate attribute structure, piggyback attribute name */
47597 int name_len = write_combine ? 13 : 10;
47598 - struct bin_attribute *res_attr;
47599 + bin_attribute_no_const *res_attr;
47600 int retval;
47601
47602 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47603 @@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47604 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47605 {
47606 int retval;
47607 - struct bin_attribute *attr;
47608 + bin_attribute_no_const *attr;
47609
47610 /* If the device has VPD, try to expose it in sysfs. */
47611 if (dev->vpd) {
47612 @@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47613 {
47614 int retval;
47615 int rom_size = 0;
47616 - struct bin_attribute *attr;
47617 + bin_attribute_no_const *attr;
47618
47619 if (!sysfs_initialized)
47620 return -EACCES;
47621 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47622 index 4df38df..b6bb7fe 100644
47623 --- a/drivers/pci/pci.h
47624 +++ b/drivers/pci/pci.h
47625 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
47626 struct pci_vpd {
47627 unsigned int len;
47628 const struct pci_vpd_ops *ops;
47629 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47630 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47631 };
47632
47633 int pci_vpd_pci22_init(struct pci_dev *dev);
47634 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47635 index e1e7026..d28dd33 100644
47636 --- a/drivers/pci/pcie/aspm.c
47637 +++ b/drivers/pci/pcie/aspm.c
47638 @@ -27,9 +27,9 @@
47639 #define MODULE_PARAM_PREFIX "pcie_aspm."
47640
47641 /* Note: those are not register definitions */
47642 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47643 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47644 -#define ASPM_STATE_L1 (4) /* L1 state */
47645 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47646 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47647 +#define ASPM_STATE_L1 (4U) /* L1 state */
47648 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47649 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47650
47651 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47652 index 6e34498..9911975 100644
47653 --- a/drivers/pci/probe.c
47654 +++ b/drivers/pci/probe.c
47655 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47656 struct pci_bus_region region, inverted_region;
47657 bool bar_too_big = false, bar_disabled = false;
47658
47659 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47660 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47661
47662 /* No printks while decoding is disabled! */
47663 if (!dev->mmio_always_on) {
47664 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47665 index 46d1378..30e452b 100644
47666 --- a/drivers/pci/proc.c
47667 +++ b/drivers/pci/proc.c
47668 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47669 static int __init pci_proc_init(void)
47670 {
47671 struct pci_dev *dev = NULL;
47672 +
47673 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47674 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47675 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47676 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47677 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47678 +#endif
47679 +#else
47680 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47681 +#endif
47682 proc_create("devices", 0, proc_bus_pci_dir,
47683 &proc_bus_pci_dev_operations);
47684 proc_initialized = 1;
47685 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47686 index 7f3aad0..7d604bb 100644
47687 --- a/drivers/platform/chrome/chromeos_laptop.c
47688 +++ b/drivers/platform/chrome/chromeos_laptop.c
47689 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47690 .callback = chromeos_laptop_dmi_matched, \
47691 .driver_data = (void *)&board_
47692
47693 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47694 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47695 {
47696 .ident = "Samsung Series 5 550",
47697 .matches = {
47698 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47699 index c5e082f..d6307a0 100644
47700 --- a/drivers/platform/x86/asus-wmi.c
47701 +++ b/drivers/platform/x86/asus-wmi.c
47702 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47703 int err;
47704 u32 retval = -1;
47705
47706 +#ifdef CONFIG_GRKERNSEC_KMEM
47707 + return -EPERM;
47708 +#endif
47709 +
47710 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47711
47712 if (err < 0)
47713 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47714 int err;
47715 u32 retval = -1;
47716
47717 +#ifdef CONFIG_GRKERNSEC_KMEM
47718 + return -EPERM;
47719 +#endif
47720 +
47721 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47722 &retval);
47723
47724 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47725 union acpi_object *obj;
47726 acpi_status status;
47727
47728 +#ifdef CONFIG_GRKERNSEC_KMEM
47729 + return -EPERM;
47730 +#endif
47731 +
47732 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47733 1, asus->debug.method_id,
47734 &input, &output);
47735 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47736 index 62f8030..c7f2a45 100644
47737 --- a/drivers/platform/x86/msi-laptop.c
47738 +++ b/drivers/platform/x86/msi-laptop.c
47739 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47740
47741 if (!quirks->ec_read_only) {
47742 /* allow userland write sysfs file */
47743 - dev_attr_bluetooth.store = store_bluetooth;
47744 - dev_attr_wlan.store = store_wlan;
47745 - dev_attr_threeg.store = store_threeg;
47746 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47747 - dev_attr_wlan.attr.mode |= S_IWUSR;
47748 - dev_attr_threeg.attr.mode |= S_IWUSR;
47749 + pax_open_kernel();
47750 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47751 + *(void **)&dev_attr_wlan.store = store_wlan;
47752 + *(void **)&dev_attr_threeg.store = store_threeg;
47753 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47754 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47755 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47756 + pax_close_kernel();
47757 }
47758
47759 /* disable hardware control by fn key */
47760 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47761 index 70222f2..8c8ce66 100644
47762 --- a/drivers/platform/x86/msi-wmi.c
47763 +++ b/drivers/platform/x86/msi-wmi.c
47764 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47765 static void msi_wmi_notify(u32 value, void *context)
47766 {
47767 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47768 - static struct key_entry *key;
47769 + struct key_entry *key;
47770 union acpi_object *obj;
47771 acpi_status status;
47772
47773 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47774 index 8f8551a..3ace3ca 100644
47775 --- a/drivers/platform/x86/sony-laptop.c
47776 +++ b/drivers/platform/x86/sony-laptop.c
47777 @@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47778 }
47779
47780 /* High speed charging function */
47781 -static struct device_attribute *hsc_handle;
47782 +static device_attribute_no_const *hsc_handle;
47783
47784 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47785 struct device_attribute *attr,
47786 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47787 index defb6af..7a5d3d1 100644
47788 --- a/drivers/platform/x86/thinkpad_acpi.c
47789 +++ b/drivers/platform/x86/thinkpad_acpi.c
47790 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47791 return 0;
47792 }
47793
47794 -void static hotkey_mask_warn_incomplete_mask(void)
47795 +static void hotkey_mask_warn_incomplete_mask(void)
47796 {
47797 /* log only what the user can fix... */
47798 const u32 wantedmask = hotkey_driver_mask &
47799 @@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47800 }
47801 }
47802
47803 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47804 - struct tp_nvram_state *newn,
47805 - const u32 event_mask)
47806 -{
47807 -
47808 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47809 do { \
47810 if ((event_mask & (1 << __scancode)) && \
47811 @@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47812 tpacpi_hotkey_send_key(__scancode); \
47813 } while (0)
47814
47815 - void issue_volchange(const unsigned int oldvol,
47816 - const unsigned int newvol)
47817 - {
47818 - unsigned int i = oldvol;
47819 +static void issue_volchange(const unsigned int oldvol,
47820 + const unsigned int newvol,
47821 + const u32 event_mask)
47822 +{
47823 + unsigned int i = oldvol;
47824
47825 - while (i > newvol) {
47826 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47827 - i--;
47828 - }
47829 - while (i < newvol) {
47830 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47831 - i++;
47832 - }
47833 + while (i > newvol) {
47834 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47835 + i--;
47836 }
47837 + while (i < newvol) {
47838 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47839 + i++;
47840 + }
47841 +}
47842
47843 - void issue_brightnesschange(const unsigned int oldbrt,
47844 - const unsigned int newbrt)
47845 - {
47846 - unsigned int i = oldbrt;
47847 +static void issue_brightnesschange(const unsigned int oldbrt,
47848 + const unsigned int newbrt,
47849 + const u32 event_mask)
47850 +{
47851 + unsigned int i = oldbrt;
47852
47853 - while (i > newbrt) {
47854 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47855 - i--;
47856 - }
47857 - while (i < newbrt) {
47858 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47859 - i++;
47860 - }
47861 + while (i > newbrt) {
47862 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47863 + i--;
47864 + }
47865 + while (i < newbrt) {
47866 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47867 + i++;
47868 }
47869 +}
47870
47871 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47872 + struct tp_nvram_state *newn,
47873 + const u32 event_mask)
47874 +{
47875 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47876 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47877 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47878 @@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47879 oldn->volume_level != newn->volume_level) {
47880 /* recently muted, or repeated mute keypress, or
47881 * multiple presses ending in mute */
47882 - issue_volchange(oldn->volume_level, newn->volume_level);
47883 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47884 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47885 }
47886 } else {
47887 @@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47888 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47889 }
47890 if (oldn->volume_level != newn->volume_level) {
47891 - issue_volchange(oldn->volume_level, newn->volume_level);
47892 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47893 } else if (oldn->volume_toggle != newn->volume_toggle) {
47894 /* repeated vol up/down keypress at end of scale ? */
47895 if (newn->volume_level == 0)
47896 @@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47897 /* handle brightness */
47898 if (oldn->brightness_level != newn->brightness_level) {
47899 issue_brightnesschange(oldn->brightness_level,
47900 - newn->brightness_level);
47901 + newn->brightness_level,
47902 + event_mask);
47903 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47904 /* repeated key presses that didn't change state */
47905 if (newn->brightness_level == 0)
47906 @@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47907 && !tp_features.bright_unkfw)
47908 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47909 }
47910 +}
47911
47912 #undef TPACPI_COMPARE_KEY
47913 #undef TPACPI_MAY_SEND_KEY
47914 -}
47915
47916 /*
47917 * Polling driver
47918 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47919 index 769d265..a3a05ca 100644
47920 --- a/drivers/pnp/pnpbios/bioscalls.c
47921 +++ b/drivers/pnp/pnpbios/bioscalls.c
47922 @@ -58,7 +58,7 @@ do { \
47923 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47924 } while(0)
47925
47926 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47927 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47928 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47929
47930 /*
47931 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47932
47933 cpu = get_cpu();
47934 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47935 +
47936 + pax_open_kernel();
47937 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47938 + pax_close_kernel();
47939
47940 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47941 spin_lock_irqsave(&pnp_bios_lock, flags);
47942 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47943 :"memory");
47944 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47945
47946 + pax_open_kernel();
47947 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47948 + pax_close_kernel();
47949 +
47950 put_cpu();
47951
47952 /* If we get here and this is set then the PnP BIOS faulted on us. */
47953 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47954 return status;
47955 }
47956
47957 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47958 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47959 {
47960 int i;
47961
47962 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47963 pnp_bios_callpoint.offset = header->fields.pm16offset;
47964 pnp_bios_callpoint.segment = PNP_CS16;
47965
47966 + pax_open_kernel();
47967 +
47968 for_each_possible_cpu(i) {
47969 struct desc_struct *gdt = get_cpu_gdt_table(i);
47970 if (!gdt)
47971 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47972 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47973 (unsigned long)__va(header->fields.pm16dseg));
47974 }
47975 +
47976 + pax_close_kernel();
47977 }
47978 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47979 index bacddd1..65ea100 100644
47980 --- a/drivers/pnp/resource.c
47981 +++ b/drivers/pnp/resource.c
47982 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47983 return 1;
47984
47985 /* check if the resource is valid */
47986 - if (*irq < 0 || *irq > 15)
47987 + if (*irq > 15)
47988 return 0;
47989
47990 /* check if the resource is reserved */
47991 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47992 return 1;
47993
47994 /* check if the resource is valid */
47995 - if (*dma < 0 || *dma == 4 || *dma > 7)
47996 + if (*dma == 4 || *dma > 7)
47997 return 0;
47998
47999 /* check if the resource is reserved */
48000 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48001 index 0c52e2a..3421ab7 100644
48002 --- a/drivers/power/pda_power.c
48003 +++ b/drivers/power/pda_power.c
48004 @@ -37,7 +37,11 @@ static int polling;
48005
48006 #if IS_ENABLED(CONFIG_USB_PHY)
48007 static struct usb_phy *transceiver;
48008 -static struct notifier_block otg_nb;
48009 +static int otg_handle_notification(struct notifier_block *nb,
48010 + unsigned long event, void *unused);
48011 +static struct notifier_block otg_nb = {
48012 + .notifier_call = otg_handle_notification
48013 +};
48014 #endif
48015
48016 static struct regulator *ac_draw;
48017 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48018
48019 #if IS_ENABLED(CONFIG_USB_PHY)
48020 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48021 - otg_nb.notifier_call = otg_handle_notification;
48022 ret = usb_register_notifier(transceiver, &otg_nb);
48023 if (ret) {
48024 dev_err(dev, "failure to register otg notifier\n");
48025 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48026 index cc439fd..8fa30df 100644
48027 --- a/drivers/power/power_supply.h
48028 +++ b/drivers/power/power_supply.h
48029 @@ -16,12 +16,12 @@ struct power_supply;
48030
48031 #ifdef CONFIG_SYSFS
48032
48033 -extern void power_supply_init_attrs(struct device_type *dev_type);
48034 +extern void power_supply_init_attrs(void);
48035 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48036
48037 #else
48038
48039 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48040 +static inline void power_supply_init_attrs(void) {}
48041 #define power_supply_uevent NULL
48042
48043 #endif /* CONFIG_SYSFS */
48044 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48045 index 2660664..75fcb04 100644
48046 --- a/drivers/power/power_supply_core.c
48047 +++ b/drivers/power/power_supply_core.c
48048 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48049 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48050 EXPORT_SYMBOL_GPL(power_supply_notifier);
48051
48052 -static struct device_type power_supply_dev_type;
48053 +extern const struct attribute_group *power_supply_attr_groups[];
48054 +static struct device_type power_supply_dev_type = {
48055 + .groups = power_supply_attr_groups,
48056 +};
48057
48058 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48059 struct power_supply *supply)
48060 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48061 return PTR_ERR(power_supply_class);
48062
48063 power_supply_class->dev_uevent = power_supply_uevent;
48064 - power_supply_init_attrs(&power_supply_dev_type);
48065 + power_supply_init_attrs();
48066
48067 return 0;
48068 }
48069 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48070 index 44420d1..967126e 100644
48071 --- a/drivers/power/power_supply_sysfs.c
48072 +++ b/drivers/power/power_supply_sysfs.c
48073 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48074 .is_visible = power_supply_attr_is_visible,
48075 };
48076
48077 -static const struct attribute_group *power_supply_attr_groups[] = {
48078 +const struct attribute_group *power_supply_attr_groups[] = {
48079 &power_supply_attr_group,
48080 NULL,
48081 };
48082
48083 -void power_supply_init_attrs(struct device_type *dev_type)
48084 +void power_supply_init_attrs(void)
48085 {
48086 int i;
48087
48088 - dev_type->groups = power_supply_attr_groups;
48089 -
48090 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48091 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48092 }
48093 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48094 index 84419af..268ede8 100644
48095 --- a/drivers/powercap/powercap_sys.c
48096 +++ b/drivers/powercap/powercap_sys.c
48097 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48098 struct device_attribute name_attr;
48099 };
48100
48101 +static ssize_t show_constraint_name(struct device *dev,
48102 + struct device_attribute *dev_attr,
48103 + char *buf);
48104 +
48105 static struct powercap_constraint_attr
48106 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48107 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48108 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48109 + .power_limit_attr = {
48110 + .attr = {
48111 + .name = NULL,
48112 + .mode = S_IWUSR | S_IRUGO
48113 + },
48114 + .show = show_constraint_power_limit_uw,
48115 + .store = store_constraint_power_limit_uw
48116 + },
48117 +
48118 + .time_window_attr = {
48119 + .attr = {
48120 + .name = NULL,
48121 + .mode = S_IWUSR | S_IRUGO
48122 + },
48123 + .show = show_constraint_time_window_us,
48124 + .store = store_constraint_time_window_us
48125 + },
48126 +
48127 + .max_power_attr = {
48128 + .attr = {
48129 + .name = NULL,
48130 + .mode = S_IRUGO
48131 + },
48132 + .show = show_constraint_max_power_uw,
48133 + .store = NULL
48134 + },
48135 +
48136 + .min_power_attr = {
48137 + .attr = {
48138 + .name = NULL,
48139 + .mode = S_IRUGO
48140 + },
48141 + .show = show_constraint_min_power_uw,
48142 + .store = NULL
48143 + },
48144 +
48145 + .max_time_window_attr = {
48146 + .attr = {
48147 + .name = NULL,
48148 + .mode = S_IRUGO
48149 + },
48150 + .show = show_constraint_max_time_window_us,
48151 + .store = NULL
48152 + },
48153 +
48154 + .min_time_window_attr = {
48155 + .attr = {
48156 + .name = NULL,
48157 + .mode = S_IRUGO
48158 + },
48159 + .show = show_constraint_min_time_window_us,
48160 + .store = NULL
48161 + },
48162 +
48163 + .name_attr = {
48164 + .attr = {
48165 + .name = NULL,
48166 + .mode = S_IRUGO
48167 + },
48168 + .show = show_constraint_name,
48169 + .store = NULL
48170 + }
48171 + }
48172 +};
48173
48174 /* A list of powercap control_types */
48175 static LIST_HEAD(powercap_cntrl_list);
48176 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48177 }
48178
48179 static int create_constraint_attribute(int id, const char *name,
48180 - int mode,
48181 - struct device_attribute *dev_attr,
48182 - ssize_t (*show)(struct device *,
48183 - struct device_attribute *, char *),
48184 - ssize_t (*store)(struct device *,
48185 - struct device_attribute *,
48186 - const char *, size_t)
48187 - )
48188 + struct device_attribute *dev_attr)
48189 {
48190 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48191
48192 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48193 - id, name);
48194 - if (!dev_attr->attr.name)
48195 + if (!name)
48196 return -ENOMEM;
48197 - dev_attr->attr.mode = mode;
48198 - dev_attr->show = show;
48199 - dev_attr->store = store;
48200 +
48201 + pax_open_kernel();
48202 + *(const char **)&dev_attr->attr.name = name;
48203 + pax_close_kernel();
48204
48205 return 0;
48206 }
48207 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48208
48209 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48210 ret = create_constraint_attribute(i, "power_limit_uw",
48211 - S_IWUSR | S_IRUGO,
48212 - &constraint_attrs[i].power_limit_attr,
48213 - show_constraint_power_limit_uw,
48214 - store_constraint_power_limit_uw);
48215 + &constraint_attrs[i].power_limit_attr);
48216 if (ret)
48217 goto err_alloc;
48218 ret = create_constraint_attribute(i, "time_window_us",
48219 - S_IWUSR | S_IRUGO,
48220 - &constraint_attrs[i].time_window_attr,
48221 - show_constraint_time_window_us,
48222 - store_constraint_time_window_us);
48223 + &constraint_attrs[i].time_window_attr);
48224 if (ret)
48225 goto err_alloc;
48226 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48227 - &constraint_attrs[i].name_attr,
48228 - show_constraint_name,
48229 - NULL);
48230 + ret = create_constraint_attribute(i, "name",
48231 + &constraint_attrs[i].name_attr);
48232 if (ret)
48233 goto err_alloc;
48234 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48235 - &constraint_attrs[i].max_power_attr,
48236 - show_constraint_max_power_uw,
48237 - NULL);
48238 + ret = create_constraint_attribute(i, "max_power_uw",
48239 + &constraint_attrs[i].max_power_attr);
48240 if (ret)
48241 goto err_alloc;
48242 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48243 - &constraint_attrs[i].min_power_attr,
48244 - show_constraint_min_power_uw,
48245 - NULL);
48246 + ret = create_constraint_attribute(i, "min_power_uw",
48247 + &constraint_attrs[i].min_power_attr);
48248 if (ret)
48249 goto err_alloc;
48250 ret = create_constraint_attribute(i, "max_time_window_us",
48251 - S_IRUGO,
48252 - &constraint_attrs[i].max_time_window_attr,
48253 - show_constraint_max_time_window_us,
48254 - NULL);
48255 + &constraint_attrs[i].max_time_window_attr);
48256 if (ret)
48257 goto err_alloc;
48258 ret = create_constraint_attribute(i, "min_time_window_us",
48259 - S_IRUGO,
48260 - &constraint_attrs[i].min_time_window_attr,
48261 - show_constraint_min_time_window_us,
48262 - NULL);
48263 + &constraint_attrs[i].min_time_window_attr);
48264 if (ret)
48265 goto err_alloc;
48266
48267 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48268 power_zone->zone_dev_attrs[count++] =
48269 &dev_attr_max_energy_range_uj.attr;
48270 if (power_zone->ops->get_energy_uj) {
48271 + pax_open_kernel();
48272 if (power_zone->ops->reset_energy_uj)
48273 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48274 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48275 else
48276 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48277 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48278 + pax_close_kernel();
48279 power_zone->zone_dev_attrs[count++] =
48280 &dev_attr_energy_uj.attr;
48281 }
48282 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48283 index afca1bc..86840b8 100644
48284 --- a/drivers/regulator/core.c
48285 +++ b/drivers/regulator/core.c
48286 @@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48287 {
48288 const struct regulation_constraints *constraints = NULL;
48289 const struct regulator_init_data *init_data;
48290 - static atomic_t regulator_no = ATOMIC_INIT(0);
48291 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48292 struct regulator_dev *rdev;
48293 struct device *dev;
48294 int ret, i;
48295 @@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48296 rdev->dev.of_node = config->of_node;
48297 rdev->dev.parent = dev;
48298 dev_set_name(&rdev->dev, "regulator.%d",
48299 - atomic_inc_return(&regulator_no) - 1);
48300 + atomic_inc_return_unchecked(&regulator_no) - 1);
48301 ret = device_register(&rdev->dev);
48302 if (ret != 0) {
48303 put_device(&rdev->dev);
48304 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48305 index 8d94d3d..653b623 100644
48306 --- a/drivers/regulator/max8660.c
48307 +++ b/drivers/regulator/max8660.c
48308 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48309 max8660->shadow_regs[MAX8660_OVER1] = 5;
48310 } else {
48311 /* Otherwise devices can be toggled via software */
48312 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48313 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48314 + pax_open_kernel();
48315 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48316 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48317 + pax_close_kernel();
48318 }
48319
48320 /*
48321 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48322 index 892aa1e..ebd1b9c 100644
48323 --- a/drivers/regulator/max8973-regulator.c
48324 +++ b/drivers/regulator/max8973-regulator.c
48325 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48326 if (!pdata || !pdata->enable_ext_control) {
48327 max->desc.enable_reg = MAX8973_VOUT;
48328 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48329 - max->ops.enable = regulator_enable_regmap;
48330 - max->ops.disable = regulator_disable_regmap;
48331 - max->ops.is_enabled = regulator_is_enabled_regmap;
48332 + pax_open_kernel();
48333 + *(void **)&max->ops.enable = regulator_enable_regmap;
48334 + *(void **)&max->ops.disable = regulator_disable_regmap;
48335 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48336 + pax_close_kernel();
48337 }
48338
48339 if (pdata) {
48340 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48341 index f374fa5..26f0683 100644
48342 --- a/drivers/regulator/mc13892-regulator.c
48343 +++ b/drivers/regulator/mc13892-regulator.c
48344 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48345 }
48346 mc13xxx_unlock(mc13892);
48347
48348 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48349 + pax_open_kernel();
48350 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48351 = mc13892_vcam_set_mode;
48352 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48353 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48354 = mc13892_vcam_get_mode;
48355 + pax_close_kernel();
48356
48357 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48358 ARRAY_SIZE(mc13892_regulators));
48359 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48360 index cae212f..58a3980 100644
48361 --- a/drivers/rtc/rtc-cmos.c
48362 +++ b/drivers/rtc/rtc-cmos.c
48363 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48364 hpet_rtc_timer_init();
48365
48366 /* export at least the first block of NVRAM */
48367 - nvram.size = address_space - NVRAM_OFFSET;
48368 + pax_open_kernel();
48369 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48370 + pax_close_kernel();
48371 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48372 if (retval < 0) {
48373 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48374 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48375 index d049393..bb20be0 100644
48376 --- a/drivers/rtc/rtc-dev.c
48377 +++ b/drivers/rtc/rtc-dev.c
48378 @@ -16,6 +16,7 @@
48379 #include <linux/module.h>
48380 #include <linux/rtc.h>
48381 #include <linux/sched.h>
48382 +#include <linux/grsecurity.h>
48383 #include "rtc-core.h"
48384
48385 static dev_t rtc_devt;
48386 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48387 if (copy_from_user(&tm, uarg, sizeof(tm)))
48388 return -EFAULT;
48389
48390 + gr_log_timechange();
48391 +
48392 return rtc_set_time(rtc, &tm);
48393
48394 case RTC_PIE_ON:
48395 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48396 index 4e75345..09f8663 100644
48397 --- a/drivers/rtc/rtc-ds1307.c
48398 +++ b/drivers/rtc/rtc-ds1307.c
48399 @@ -107,7 +107,7 @@ struct ds1307 {
48400 u8 offset; /* register's offset */
48401 u8 regs[11];
48402 u16 nvram_offset;
48403 - struct bin_attribute *nvram;
48404 + bin_attribute_no_const *nvram;
48405 enum ds_type type;
48406 unsigned long flags;
48407 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48408 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48409 index 11880c1..b823aa4 100644
48410 --- a/drivers/rtc/rtc-m48t59.c
48411 +++ b/drivers/rtc/rtc-m48t59.c
48412 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48413 if (IS_ERR(m48t59->rtc))
48414 return PTR_ERR(m48t59->rtc);
48415
48416 - m48t59_nvram_attr.size = pdata->offset;
48417 + pax_open_kernel();
48418 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48419 + pax_close_kernel();
48420
48421 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48422 if (ret)
48423 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48424 index 14b5f8d..cc9bd26 100644
48425 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48426 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48427 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48428 for (bit = 0; bit < 8; bit++) {
48429
48430 if ((pci_status[i] & (0x1 << bit)) != 0) {
48431 - static const char *s;
48432 + const char *s;
48433
48434 s = pci_status_strings[bit];
48435 if (i == 7/*TARG*/ && bit == 3)
48436 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48437
48438 for (bit = 0; bit < 8; bit++) {
48439
48440 - if ((split_status[i] & (0x1 << bit)) != 0) {
48441 - static const char *s;
48442 -
48443 - s = split_status_strings[bit];
48444 - printk(s, ahd_name(ahd),
48445 + if ((split_status[i] & (0x1 << bit)) != 0)
48446 + printk(split_status_strings[bit], ahd_name(ahd),
48447 split_status_source[i]);
48448 - }
48449
48450 if (i > 1)
48451 continue;
48452
48453 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48454 - static const char *s;
48455 -
48456 - s = split_status_strings[bit];
48457 - printk(s, ahd_name(ahd), "SG");
48458 - }
48459 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48460 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48461 }
48462 }
48463 /*
48464 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48465 index e693af6..2e525b6 100644
48466 --- a/drivers/scsi/bfa/bfa_fcpim.h
48467 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48468 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48469
48470 struct bfa_itn_s {
48471 bfa_isr_func_t isr;
48472 -};
48473 +} __no_const;
48474
48475 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48476 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48477 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48478 index a3ab5cc..8143622 100644
48479 --- a/drivers/scsi/bfa/bfa_fcs.c
48480 +++ b/drivers/scsi/bfa/bfa_fcs.c
48481 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48482 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48483
48484 static struct bfa_fcs_mod_s fcs_modules[] = {
48485 - { bfa_fcs_port_attach, NULL, NULL },
48486 - { bfa_fcs_uf_attach, NULL, NULL },
48487 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48488 - bfa_fcs_fabric_modexit },
48489 + {
48490 + .attach = bfa_fcs_port_attach,
48491 + .modinit = NULL,
48492 + .modexit = NULL
48493 + },
48494 + {
48495 + .attach = bfa_fcs_uf_attach,
48496 + .modinit = NULL,
48497 + .modexit = NULL
48498 + },
48499 + {
48500 + .attach = bfa_fcs_fabric_attach,
48501 + .modinit = bfa_fcs_fabric_modinit,
48502 + .modexit = bfa_fcs_fabric_modexit
48503 + },
48504 };
48505
48506 /*
48507 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48508 index ff75ef8..2dfe00a 100644
48509 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48510 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48511 @@ -89,15 +89,26 @@ static struct {
48512 void (*offline) (struct bfa_fcs_lport_s *port);
48513 } __port_action[] = {
48514 {
48515 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48516 - bfa_fcs_lport_unknown_offline}, {
48517 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48518 - bfa_fcs_lport_fab_offline}, {
48519 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48520 - bfa_fcs_lport_n2n_offline}, {
48521 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48522 - bfa_fcs_lport_loop_offline},
48523 - };
48524 + .init = bfa_fcs_lport_unknown_init,
48525 + .online = bfa_fcs_lport_unknown_online,
48526 + .offline = bfa_fcs_lport_unknown_offline
48527 + },
48528 + {
48529 + .init = bfa_fcs_lport_fab_init,
48530 + .online = bfa_fcs_lport_fab_online,
48531 + .offline = bfa_fcs_lport_fab_offline
48532 + },
48533 + {
48534 + .init = bfa_fcs_lport_n2n_init,
48535 + .online = bfa_fcs_lport_n2n_online,
48536 + .offline = bfa_fcs_lport_n2n_offline
48537 + },
48538 + {
48539 + .init = bfa_fcs_lport_loop_init,
48540 + .online = bfa_fcs_lport_loop_online,
48541 + .offline = bfa_fcs_lport_loop_offline
48542 + },
48543 +};
48544
48545 /*
48546 * fcs_port_sm FCS logical port state machine
48547 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48548 index 2e28392..9d865b6 100644
48549 --- a/drivers/scsi/bfa/bfa_ioc.h
48550 +++ b/drivers/scsi/bfa/bfa_ioc.h
48551 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48552 bfa_ioc_disable_cbfn_t disable_cbfn;
48553 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48554 bfa_ioc_reset_cbfn_t reset_cbfn;
48555 -};
48556 +} __no_const;
48557
48558 /*
48559 * IOC event notification mechanism.
48560 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48561 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48562 enum bfi_ioc_state fwstate);
48563 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48564 -};
48565 +} __no_const;
48566
48567 /*
48568 * Queue element to wait for room in request queue. FIFO order is
48569 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48570 index a14c784..6de6790 100644
48571 --- a/drivers/scsi/bfa/bfa_modules.h
48572 +++ b/drivers/scsi/bfa/bfa_modules.h
48573 @@ -78,12 +78,12 @@ enum {
48574 \
48575 extern struct bfa_module_s hal_mod_ ## __mod; \
48576 struct bfa_module_s hal_mod_ ## __mod = { \
48577 - bfa_ ## __mod ## _meminfo, \
48578 - bfa_ ## __mod ## _attach, \
48579 - bfa_ ## __mod ## _detach, \
48580 - bfa_ ## __mod ## _start, \
48581 - bfa_ ## __mod ## _stop, \
48582 - bfa_ ## __mod ## _iocdisable, \
48583 + .meminfo = bfa_ ## __mod ## _meminfo, \
48584 + .attach = bfa_ ## __mod ## _attach, \
48585 + .detach = bfa_ ## __mod ## _detach, \
48586 + .start = bfa_ ## __mod ## _start, \
48587 + .stop = bfa_ ## __mod ## _stop, \
48588 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48589 }
48590
48591 #define BFA_CACHELINE_SZ (256)
48592 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48593 index 045c4e1..13de803 100644
48594 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48595 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48596 @@ -33,8 +33,8 @@
48597 */
48598 #include "libfcoe.h"
48599
48600 -static atomic_t ctlr_num;
48601 -static atomic_t fcf_num;
48602 +static atomic_unchecked_t ctlr_num;
48603 +static atomic_unchecked_t fcf_num;
48604
48605 /*
48606 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48607 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48608 if (!ctlr)
48609 goto out;
48610
48611 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48612 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48613 ctlr->f = f;
48614 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48615 INIT_LIST_HEAD(&ctlr->fcfs);
48616 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48617 fcf->dev.parent = &ctlr->dev;
48618 fcf->dev.bus = &fcoe_bus_type;
48619 fcf->dev.type = &fcoe_fcf_device_type;
48620 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48621 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48622 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48623
48624 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48625 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48626 {
48627 int error;
48628
48629 - atomic_set(&ctlr_num, 0);
48630 - atomic_set(&fcf_num, 0);
48631 + atomic_set_unchecked(&ctlr_num, 0);
48632 + atomic_set_unchecked(&fcf_num, 0);
48633
48634 error = bus_register(&fcoe_bus_type);
48635 if (error)
48636 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48637 index f28ea07..34b16d3 100644
48638 --- a/drivers/scsi/hosts.c
48639 +++ b/drivers/scsi/hosts.c
48640 @@ -42,7 +42,7 @@
48641 #include "scsi_logging.h"
48642
48643
48644 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48645 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48646
48647
48648 static void scsi_host_cls_release(struct device *dev)
48649 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48650 * subtract one because we increment first then return, but we need to
48651 * know what the next host number was before increment
48652 */
48653 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48654 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48655 shost->dma_channel = 0xff;
48656
48657 /* These three are default values which can be overridden */
48658 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48659 index 868318a..e07ef3b 100644
48660 --- a/drivers/scsi/hpsa.c
48661 +++ b/drivers/scsi/hpsa.c
48662 @@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48663 unsigned long flags;
48664
48665 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48666 - return h->access.command_completed(h, q);
48667 + return h->access->command_completed(h, q);
48668
48669 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48670 a = rq->head[rq->current_entry];
48671 @@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
48672 while (!list_empty(&h->reqQ)) {
48673 c = list_entry(h->reqQ.next, struct CommandList, list);
48674 /* can't do anything if fifo is full */
48675 - if ((h->access.fifo_full(h))) {
48676 + if ((h->access->fifo_full(h))) {
48677 h->fifo_recently_full = 1;
48678 dev_warn(&h->pdev->dev, "fifo full\n");
48679 break;
48680 @@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
48681
48682 /* Tell the controller execute command */
48683 spin_unlock_irqrestore(&h->lock, flags);
48684 - h->access.submit_command(h, c);
48685 + h->access->submit_command(h, c);
48686 spin_lock_irqsave(&h->lock, flags);
48687 }
48688 spin_unlock_irqrestore(&h->lock, flags);
48689 @@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
48690
48691 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48692 {
48693 - return h->access.command_completed(h, q);
48694 + return h->access->command_completed(h, q);
48695 }
48696
48697 static inline bool interrupt_pending(struct ctlr_info *h)
48698 {
48699 - return h->access.intr_pending(h);
48700 + return h->access->intr_pending(h);
48701 }
48702
48703 static inline long interrupt_not_for_us(struct ctlr_info *h)
48704 {
48705 - return (h->access.intr_pending(h) == 0) ||
48706 + return (h->access->intr_pending(h) == 0) ||
48707 (h->interrupts_enabled == 0);
48708 }
48709
48710 @@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48711 if (prod_index < 0)
48712 return -ENODEV;
48713 h->product_name = products[prod_index].product_name;
48714 - h->access = *(products[prod_index].access);
48715 + h->access = products[prod_index].access;
48716
48717 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48718 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48719 @@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48720 {
48721 unsigned long flags;
48722
48723 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48724 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48725 spin_lock_irqsave(&h->lock, flags);
48726 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48727 spin_unlock_irqrestore(&h->lock, flags);
48728 @@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
48729 }
48730
48731 /* make sure the board interrupts are off */
48732 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48733 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48734
48735 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48736 goto clean2;
48737 @@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
48738 * fake ones to scoop up any residual completions.
48739 */
48740 spin_lock_irqsave(&h->lock, flags);
48741 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48742 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48743 spin_unlock_irqrestore(&h->lock, flags);
48744 free_irqs(h);
48745 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48746 @@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
48747 dev_info(&h->pdev->dev, "Board READY.\n");
48748 dev_info(&h->pdev->dev,
48749 "Waiting for stale completions to drain.\n");
48750 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48751 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48752 msleep(10000);
48753 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48754 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48755
48756 rc = controller_reset_failed(h->cfgtable);
48757 if (rc)
48758 @@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
48759 }
48760
48761 /* Turn the interrupts on so we can service requests */
48762 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48763 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48764
48765 hpsa_hba_inquiry(h);
48766 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48767 @@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48768 * To write all data in the battery backed cache to disks
48769 */
48770 hpsa_flush_cache(h);
48771 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48772 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48773 hpsa_free_irqs_and_disable_msix(h);
48774 }
48775
48776 @@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48777 return;
48778 }
48779 /* Change the access methods to the performant access methods */
48780 - h->access = SA5_performant_access;
48781 + h->access = &SA5_performant_access;
48782 h->transMethod = CFGTBL_Trans_Performant;
48783 }
48784
48785 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48786 index 01c3283..4655219 100644
48787 --- a/drivers/scsi/hpsa.h
48788 +++ b/drivers/scsi/hpsa.h
48789 @@ -79,7 +79,7 @@ struct ctlr_info {
48790 unsigned int msix_vector;
48791 unsigned int msi_vector;
48792 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48793 - struct access_method access;
48794 + struct access_method *access;
48795
48796 /* queue and queue Info */
48797 struct list_head reqQ;
48798 @@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48799 }
48800
48801 static struct access_method SA5_access = {
48802 - SA5_submit_command,
48803 - SA5_intr_mask,
48804 - SA5_fifo_full,
48805 - SA5_intr_pending,
48806 - SA5_completed,
48807 + .submit_command = SA5_submit_command,
48808 + .set_intr_mask = SA5_intr_mask,
48809 + .fifo_full = SA5_fifo_full,
48810 + .intr_pending = SA5_intr_pending,
48811 + .command_completed = SA5_completed,
48812 };
48813
48814 static struct access_method SA5_performant_access = {
48815 - SA5_submit_command,
48816 - SA5_performant_intr_mask,
48817 - SA5_fifo_full,
48818 - SA5_performant_intr_pending,
48819 - SA5_performant_completed,
48820 + .submit_command = SA5_submit_command,
48821 + .set_intr_mask = SA5_performant_intr_mask,
48822 + .fifo_full = SA5_fifo_full,
48823 + .intr_pending = SA5_performant_intr_pending,
48824 + .command_completed = SA5_performant_completed,
48825 };
48826
48827 struct board_type {
48828 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48829 index 1b3a094..068e683 100644
48830 --- a/drivers/scsi/libfc/fc_exch.c
48831 +++ b/drivers/scsi/libfc/fc_exch.c
48832 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48833 u16 pool_max_index;
48834
48835 struct {
48836 - atomic_t no_free_exch;
48837 - atomic_t no_free_exch_xid;
48838 - atomic_t xid_not_found;
48839 - atomic_t xid_busy;
48840 - atomic_t seq_not_found;
48841 - atomic_t non_bls_resp;
48842 + atomic_unchecked_t no_free_exch;
48843 + atomic_unchecked_t no_free_exch_xid;
48844 + atomic_unchecked_t xid_not_found;
48845 + atomic_unchecked_t xid_busy;
48846 + atomic_unchecked_t seq_not_found;
48847 + atomic_unchecked_t non_bls_resp;
48848 } stats;
48849 };
48850
48851 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48852 /* allocate memory for exchange */
48853 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48854 if (!ep) {
48855 - atomic_inc(&mp->stats.no_free_exch);
48856 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48857 goto out;
48858 }
48859 memset(ep, 0, sizeof(*ep));
48860 @@ -874,7 +874,7 @@ out:
48861 return ep;
48862 err:
48863 spin_unlock_bh(&pool->lock);
48864 - atomic_inc(&mp->stats.no_free_exch_xid);
48865 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48866 mempool_free(ep, mp->ep_pool);
48867 return NULL;
48868 }
48869 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48870 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48871 ep = fc_exch_find(mp, xid);
48872 if (!ep) {
48873 - atomic_inc(&mp->stats.xid_not_found);
48874 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48875 reject = FC_RJT_OX_ID;
48876 goto out;
48877 }
48878 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48879 ep = fc_exch_find(mp, xid);
48880 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48881 if (ep) {
48882 - atomic_inc(&mp->stats.xid_busy);
48883 + atomic_inc_unchecked(&mp->stats.xid_busy);
48884 reject = FC_RJT_RX_ID;
48885 goto rel;
48886 }
48887 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48888 }
48889 xid = ep->xid; /* get our XID */
48890 } else if (!ep) {
48891 - atomic_inc(&mp->stats.xid_not_found);
48892 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48893 reject = FC_RJT_RX_ID; /* XID not found */
48894 goto out;
48895 }
48896 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48897 } else {
48898 sp = &ep->seq;
48899 if (sp->id != fh->fh_seq_id) {
48900 - atomic_inc(&mp->stats.seq_not_found);
48901 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48902 if (f_ctl & FC_FC_END_SEQ) {
48903 /*
48904 * Update sequence_id based on incoming last
48905 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48906
48907 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48908 if (!ep) {
48909 - atomic_inc(&mp->stats.xid_not_found);
48910 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48911 goto out;
48912 }
48913 if (ep->esb_stat & ESB_ST_COMPLETE) {
48914 - atomic_inc(&mp->stats.xid_not_found);
48915 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48916 goto rel;
48917 }
48918 if (ep->rxid == FC_XID_UNKNOWN)
48919 ep->rxid = ntohs(fh->fh_rx_id);
48920 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48921 - atomic_inc(&mp->stats.xid_not_found);
48922 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48923 goto rel;
48924 }
48925 if (ep->did != ntoh24(fh->fh_s_id) &&
48926 ep->did != FC_FID_FLOGI) {
48927 - atomic_inc(&mp->stats.xid_not_found);
48928 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48929 goto rel;
48930 }
48931 sof = fr_sof(fp);
48932 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48933 sp->ssb_stat |= SSB_ST_RESP;
48934 sp->id = fh->fh_seq_id;
48935 } else if (sp->id != fh->fh_seq_id) {
48936 - atomic_inc(&mp->stats.seq_not_found);
48937 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48938 goto rel;
48939 }
48940
48941 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48942 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48943
48944 if (!sp)
48945 - atomic_inc(&mp->stats.xid_not_found);
48946 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48947 else
48948 - atomic_inc(&mp->stats.non_bls_resp);
48949 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48950
48951 fc_frame_free(fp);
48952 }
48953 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48954
48955 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48956 mp = ema->mp;
48957 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48958 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48959 st->fc_no_free_exch_xid +=
48960 - atomic_read(&mp->stats.no_free_exch_xid);
48961 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48962 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48963 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48964 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48965 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48966 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48967 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48968 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48969 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48970 }
48971 }
48972 EXPORT_SYMBOL(fc_exch_update_stats);
48973 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48974 index d289583..b745eec 100644
48975 --- a/drivers/scsi/libsas/sas_ata.c
48976 +++ b/drivers/scsi/libsas/sas_ata.c
48977 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48978 .postreset = ata_std_postreset,
48979 .error_handler = ata_std_error_handler,
48980 .post_internal_cmd = sas_ata_post_internal,
48981 - .qc_defer = ata_std_qc_defer,
48982 + .qc_defer = ata_std_qc_defer,
48983 .qc_prep = ata_noop_qc_prep,
48984 .qc_issue = sas_ata_qc_issue,
48985 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48986 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48987 index 4e1b75c..0bbdfa9 100644
48988 --- a/drivers/scsi/lpfc/lpfc.h
48989 +++ b/drivers/scsi/lpfc/lpfc.h
48990 @@ -432,7 +432,7 @@ struct lpfc_vport {
48991 struct dentry *debug_nodelist;
48992 struct dentry *vport_debugfs_root;
48993 struct lpfc_debugfs_trc *disc_trc;
48994 - atomic_t disc_trc_cnt;
48995 + atomic_unchecked_t disc_trc_cnt;
48996 #endif
48997 uint8_t stat_data_enabled;
48998 uint8_t stat_data_blocked;
48999 @@ -865,8 +865,8 @@ struct lpfc_hba {
49000 struct timer_list fabric_block_timer;
49001 unsigned long bit_flags;
49002 #define FABRIC_COMANDS_BLOCKED 0
49003 - atomic_t num_rsrc_err;
49004 - atomic_t num_cmd_success;
49005 + atomic_unchecked_t num_rsrc_err;
49006 + atomic_unchecked_t num_cmd_success;
49007 unsigned long last_rsrc_error_time;
49008 unsigned long last_ramp_down_time;
49009 unsigned long last_ramp_up_time;
49010 @@ -902,7 +902,7 @@ struct lpfc_hba {
49011
49012 struct dentry *debug_slow_ring_trc;
49013 struct lpfc_debugfs_trc *slow_ring_trc;
49014 - atomic_t slow_ring_trc_cnt;
49015 + atomic_unchecked_t slow_ring_trc_cnt;
49016 /* iDiag debugfs sub-directory */
49017 struct dentry *idiag_root;
49018 struct dentry *idiag_pci_cfg;
49019 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49020 index b800cc9..16b6a91 100644
49021 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49022 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49023 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49024
49025 #include <linux/debugfs.h>
49026
49027 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49028 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49029 static unsigned long lpfc_debugfs_start_time = 0L;
49030
49031 /* iDiag */
49032 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49033 lpfc_debugfs_enable = 0;
49034
49035 len = 0;
49036 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49037 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49038 (lpfc_debugfs_max_disc_trc - 1);
49039 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49040 dtp = vport->disc_trc + i;
49041 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49042 lpfc_debugfs_enable = 0;
49043
49044 len = 0;
49045 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49046 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49047 (lpfc_debugfs_max_slow_ring_trc - 1);
49048 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49049 dtp = phba->slow_ring_trc + i;
49050 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49051 !vport || !vport->disc_trc)
49052 return;
49053
49054 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49055 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49056 (lpfc_debugfs_max_disc_trc - 1);
49057 dtp = vport->disc_trc + index;
49058 dtp->fmt = fmt;
49059 dtp->data1 = data1;
49060 dtp->data2 = data2;
49061 dtp->data3 = data3;
49062 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49063 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49064 dtp->jif = jiffies;
49065 #endif
49066 return;
49067 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49068 !phba || !phba->slow_ring_trc)
49069 return;
49070
49071 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49072 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49073 (lpfc_debugfs_max_slow_ring_trc - 1);
49074 dtp = phba->slow_ring_trc + index;
49075 dtp->fmt = fmt;
49076 dtp->data1 = data1;
49077 dtp->data2 = data2;
49078 dtp->data3 = data3;
49079 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49080 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49081 dtp->jif = jiffies;
49082 #endif
49083 return;
49084 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49085 "slow_ring buffer\n");
49086 goto debug_failed;
49087 }
49088 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49089 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49090 memset(phba->slow_ring_trc, 0,
49091 (sizeof(struct lpfc_debugfs_trc) *
49092 lpfc_debugfs_max_slow_ring_trc));
49093 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49094 "buffer\n");
49095 goto debug_failed;
49096 }
49097 - atomic_set(&vport->disc_trc_cnt, 0);
49098 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49099
49100 snprintf(name, sizeof(name), "discovery_trace");
49101 vport->debug_disc_trc =
49102 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49103 index 68c94cc..8c27be5 100644
49104 --- a/drivers/scsi/lpfc/lpfc_init.c
49105 +++ b/drivers/scsi/lpfc/lpfc_init.c
49106 @@ -10949,8 +10949,10 @@ lpfc_init(void)
49107 "misc_register returned with status %d", error);
49108
49109 if (lpfc_enable_npiv) {
49110 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49111 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49112 + pax_open_kernel();
49113 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49114 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49115 + pax_close_kernel();
49116 }
49117 lpfc_transport_template =
49118 fc_attach_transport(&lpfc_transport_functions);
49119 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49120 index b2ede05..aaf482ca 100644
49121 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49122 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49123 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49124 uint32_t evt_posted;
49125
49126 spin_lock_irqsave(&phba->hbalock, flags);
49127 - atomic_inc(&phba->num_rsrc_err);
49128 + atomic_inc_unchecked(&phba->num_rsrc_err);
49129 phba->last_rsrc_error_time = jiffies;
49130
49131 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49132 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49133 unsigned long flags;
49134 struct lpfc_hba *phba = vport->phba;
49135 uint32_t evt_posted;
49136 - atomic_inc(&phba->num_cmd_success);
49137 + atomic_inc_unchecked(&phba->num_cmd_success);
49138
49139 if (vport->cfg_lun_queue_depth <= queue_depth)
49140 return;
49141 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49142 unsigned long num_rsrc_err, num_cmd_success;
49143 int i;
49144
49145 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49146 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49147 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49148 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49149
49150 /*
49151 * The error and success command counters are global per
49152 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49153 }
49154 }
49155 lpfc_destroy_vport_work_array(phba, vports);
49156 - atomic_set(&phba->num_rsrc_err, 0);
49157 - atomic_set(&phba->num_cmd_success, 0);
49158 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49159 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49160 }
49161
49162 /**
49163 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49164 }
49165 }
49166 lpfc_destroy_vport_work_array(phba, vports);
49167 - atomic_set(&phba->num_rsrc_err, 0);
49168 - atomic_set(&phba->num_cmd_success, 0);
49169 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49170 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49171 }
49172
49173 /**
49174 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49175 index 7f0af4f..193ac3e 100644
49176 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49177 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49178 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49179 {
49180 struct scsi_device *sdev = to_scsi_device(dev);
49181 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49182 - static struct _raid_device *raid_device;
49183 + struct _raid_device *raid_device;
49184 unsigned long flags;
49185 Mpi2RaidVolPage0_t vol_pg0;
49186 Mpi2ConfigReply_t mpi_reply;
49187 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49188 {
49189 struct scsi_device *sdev = to_scsi_device(dev);
49190 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49191 - static struct _raid_device *raid_device;
49192 + struct _raid_device *raid_device;
49193 unsigned long flags;
49194 Mpi2RaidVolPage0_t vol_pg0;
49195 Mpi2ConfigReply_t mpi_reply;
49196 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49197 struct fw_event_work *fw_event)
49198 {
49199 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49200 - static struct _raid_device *raid_device;
49201 + struct _raid_device *raid_device;
49202 unsigned long flags;
49203 u16 handle;
49204
49205 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49206 u64 sas_address;
49207 struct _sas_device *sas_device;
49208 struct _sas_node *expander_device;
49209 - static struct _raid_device *raid_device;
49210 + struct _raid_device *raid_device;
49211 u8 retry_count;
49212 unsigned long flags;
49213
49214 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49215 index be8ce54..94ed33a 100644
49216 --- a/drivers/scsi/pmcraid.c
49217 +++ b/drivers/scsi/pmcraid.c
49218 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49219 res->scsi_dev = scsi_dev;
49220 scsi_dev->hostdata = res;
49221 res->change_detected = 0;
49222 - atomic_set(&res->read_failures, 0);
49223 - atomic_set(&res->write_failures, 0);
49224 + atomic_set_unchecked(&res->read_failures, 0);
49225 + atomic_set_unchecked(&res->write_failures, 0);
49226 rc = 0;
49227 }
49228 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49229 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49230
49231 /* If this was a SCSI read/write command keep count of errors */
49232 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49233 - atomic_inc(&res->read_failures);
49234 + atomic_inc_unchecked(&res->read_failures);
49235 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49236 - atomic_inc(&res->write_failures);
49237 + atomic_inc_unchecked(&res->write_failures);
49238
49239 if (!RES_IS_GSCSI(res->cfg_entry) &&
49240 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49241 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49242 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49243 * hrrq_id assigned here in queuecommand
49244 */
49245 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49246 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49247 pinstance->num_hrrq;
49248 cmd->cmd_done = pmcraid_io_done;
49249
49250 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49251 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49252 * hrrq_id assigned here in queuecommand
49253 */
49254 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49255 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49256 pinstance->num_hrrq;
49257
49258 if (request_size) {
49259 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49260
49261 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49262 /* add resources only after host is added into system */
49263 - if (!atomic_read(&pinstance->expose_resources))
49264 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49265 return;
49266
49267 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49268 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49269 init_waitqueue_head(&pinstance->reset_wait_q);
49270
49271 atomic_set(&pinstance->outstanding_cmds, 0);
49272 - atomic_set(&pinstance->last_message_id, 0);
49273 - atomic_set(&pinstance->expose_resources, 0);
49274 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49275 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49276
49277 INIT_LIST_HEAD(&pinstance->free_res_q);
49278 INIT_LIST_HEAD(&pinstance->used_res_q);
49279 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49280 /* Schedule worker thread to handle CCN and take care of adding and
49281 * removing devices to OS
49282 */
49283 - atomic_set(&pinstance->expose_resources, 1);
49284 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49285 schedule_work(&pinstance->worker_q);
49286 return rc;
49287
49288 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49289 index e1d150f..6c6df44 100644
49290 --- a/drivers/scsi/pmcraid.h
49291 +++ b/drivers/scsi/pmcraid.h
49292 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49293 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49294
49295 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49296 - atomic_t last_message_id;
49297 + atomic_unchecked_t last_message_id;
49298
49299 /* configuration table */
49300 struct pmcraid_config_table *cfg_table;
49301 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49302 atomic_t outstanding_cmds;
49303
49304 /* should add/delete resources to mid-layer now ?*/
49305 - atomic_t expose_resources;
49306 + atomic_unchecked_t expose_resources;
49307
49308
49309
49310 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49311 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49312 };
49313 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49314 - atomic_t read_failures; /* count of failed READ commands */
49315 - atomic_t write_failures; /* count of failed WRITE commands */
49316 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49317 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49318
49319 /* To indicate add/delete/modify during CCN */
49320 u8 change_detected;
49321 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49322 index 4a0d7c9..3d658d7 100644
49323 --- a/drivers/scsi/qla2xxx/qla_attr.c
49324 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49325 @@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49326 return 0;
49327 }
49328
49329 -struct fc_function_template qla2xxx_transport_functions = {
49330 +fc_function_template_no_const qla2xxx_transport_functions = {
49331
49332 .show_host_node_name = 1,
49333 .show_host_port_name = 1,
49334 @@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49335 .bsg_timeout = qla24xx_bsg_timeout,
49336 };
49337
49338 -struct fc_function_template qla2xxx_transport_vport_functions = {
49339 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49340
49341 .show_host_node_name = 1,
49342 .show_host_port_name = 1,
49343 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49344 index 1f42662..bf9836c 100644
49345 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49346 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49347 @@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49348 struct device_attribute;
49349 extern struct device_attribute *qla2x00_host_attrs[];
49350 struct fc_function_template;
49351 -extern struct fc_function_template qla2xxx_transport_functions;
49352 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49353 +extern fc_function_template_no_const qla2xxx_transport_functions;
49354 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49355 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49356 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49357 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49358 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49359 index 89a5300..2a459ab 100644
49360 --- a/drivers/scsi/qla2xxx/qla_os.c
49361 +++ b/drivers/scsi/qla2xxx/qla_os.c
49362 @@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49363 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49364 /* Ok, a 64bit DMA mask is applicable. */
49365 ha->flags.enable_64bit_addressing = 1;
49366 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49367 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49368 + pax_open_kernel();
49369 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49370 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49371 + pax_close_kernel();
49372 return;
49373 }
49374 }
49375 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49376 index aa67bb9..06d0e2a 100644
49377 --- a/drivers/scsi/qla4xxx/ql4_def.h
49378 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49379 @@ -303,7 +303,7 @@ struct ddb_entry {
49380 * (4000 only) */
49381 atomic_t relogin_timer; /* Max Time to wait for
49382 * relogin to complete */
49383 - atomic_t relogin_retry_count; /* Num of times relogin has been
49384 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49385 * retried */
49386 uint32_t default_time2wait; /* Default Min time between
49387 * relogins (+aens) */
49388 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49389 index c21adc3..1b4155f 100644
49390 --- a/drivers/scsi/qla4xxx/ql4_os.c
49391 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49392 @@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49393 */
49394 if (!iscsi_is_session_online(cls_sess)) {
49395 /* Reset retry relogin timer */
49396 - atomic_inc(&ddb_entry->relogin_retry_count);
49397 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49398 DEBUG2(ql4_printk(KERN_INFO, ha,
49399 "%s: index[%d] relogin timed out-retrying"
49400 " relogin (%d), retry (%d)\n", __func__,
49401 ddb_entry->fw_ddb_index,
49402 - atomic_read(&ddb_entry->relogin_retry_count),
49403 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49404 ddb_entry->default_time2wait + 4));
49405 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49406 atomic_set(&ddb_entry->retry_relogin_timer,
49407 @@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49408
49409 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49410 atomic_set(&ddb_entry->relogin_timer, 0);
49411 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49412 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49413 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49414 ddb_entry->default_relogin_timeout =
49415 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49416 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49417 index d8afec8..3ec7152 100644
49418 --- a/drivers/scsi/scsi.c
49419 +++ b/drivers/scsi/scsi.c
49420 @@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49421 struct Scsi_Host *host = cmd->device->host;
49422 int rtn = 0;
49423
49424 - atomic_inc(&cmd->device->iorequest_cnt);
49425 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49426
49427 /* check if the device is still usable */
49428 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49429 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49430 index 62ec84b..93159d8 100644
49431 --- a/drivers/scsi/scsi_lib.c
49432 +++ b/drivers/scsi/scsi_lib.c
49433 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49434 shost = sdev->host;
49435 scsi_init_cmd_errh(cmd);
49436 cmd->result = DID_NO_CONNECT << 16;
49437 - atomic_inc(&cmd->device->iorequest_cnt);
49438 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49439
49440 /*
49441 * SCSI request completion path will do scsi_device_unbusy(),
49442 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49443
49444 INIT_LIST_HEAD(&cmd->eh_entry);
49445
49446 - atomic_inc(&cmd->device->iodone_cnt);
49447 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49448 if (cmd->result)
49449 - atomic_inc(&cmd->device->ioerr_cnt);
49450 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49451
49452 disposition = scsi_decide_disposition(cmd);
49453 if (disposition != SUCCESS &&
49454 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49455 index 9117d0b..d289a7a 100644
49456 --- a/drivers/scsi/scsi_sysfs.c
49457 +++ b/drivers/scsi/scsi_sysfs.c
49458 @@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49459 char *buf) \
49460 { \
49461 struct scsi_device *sdev = to_scsi_device(dev); \
49462 - unsigned long long count = atomic_read(&sdev->field); \
49463 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49464 return snprintf(buf, 20, "0x%llx\n", count); \
49465 } \
49466 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49467 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49468 index 84a1fdf..693b0d6 100644
49469 --- a/drivers/scsi/scsi_tgt_lib.c
49470 +++ b/drivers/scsi/scsi_tgt_lib.c
49471 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49472 int err;
49473
49474 dprintk("%lx %u\n", uaddr, len);
49475 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49476 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49477 if (err) {
49478 /*
49479 * TODO: need to fixup sg_tablesize, max_segment_size,
49480 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49481 index 4628fd5..a94a1c2 100644
49482 --- a/drivers/scsi/scsi_transport_fc.c
49483 +++ b/drivers/scsi/scsi_transport_fc.c
49484 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49485 * Netlink Infrastructure
49486 */
49487
49488 -static atomic_t fc_event_seq;
49489 +static atomic_unchecked_t fc_event_seq;
49490
49491 /**
49492 * fc_get_event_number - Obtain the next sequential FC event number
49493 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49494 u32
49495 fc_get_event_number(void)
49496 {
49497 - return atomic_add_return(1, &fc_event_seq);
49498 + return atomic_add_return_unchecked(1, &fc_event_seq);
49499 }
49500 EXPORT_SYMBOL(fc_get_event_number);
49501
49502 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49503 {
49504 int error;
49505
49506 - atomic_set(&fc_event_seq, 0);
49507 + atomic_set_unchecked(&fc_event_seq, 0);
49508
49509 error = transport_class_register(&fc_host_class);
49510 if (error)
49511 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49512 char *cp;
49513
49514 *val = simple_strtoul(buf, &cp, 0);
49515 - if ((*cp && (*cp != '\n')) || (*val < 0))
49516 + if (*cp && (*cp != '\n'))
49517 return -EINVAL;
49518 /*
49519 * Check for overflow; dev_loss_tmo is u32
49520 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49521 index fd8ffe6..fd0bebf 100644
49522 --- a/drivers/scsi/scsi_transport_iscsi.c
49523 +++ b/drivers/scsi/scsi_transport_iscsi.c
49524 @@ -79,7 +79,7 @@ struct iscsi_internal {
49525 struct transport_container session_cont;
49526 };
49527
49528 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49529 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49530 static struct workqueue_struct *iscsi_eh_timer_workq;
49531
49532 static DEFINE_IDA(iscsi_sess_ida);
49533 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49534 int err;
49535
49536 ihost = shost->shost_data;
49537 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49538 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49539
49540 if (target_id == ISCSI_MAX_TARGET) {
49541 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49542 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49543 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49544 ISCSI_TRANSPORT_VERSION);
49545
49546 - atomic_set(&iscsi_session_nr, 0);
49547 + atomic_set_unchecked(&iscsi_session_nr, 0);
49548
49549 err = class_register(&iscsi_transport_class);
49550 if (err)
49551 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49552 index d47ffc8..30f46a9 100644
49553 --- a/drivers/scsi/scsi_transport_srp.c
49554 +++ b/drivers/scsi/scsi_transport_srp.c
49555 @@ -36,7 +36,7 @@
49556 #include "scsi_transport_srp_internal.h"
49557
49558 struct srp_host_attrs {
49559 - atomic_t next_port_id;
49560 + atomic_unchecked_t next_port_id;
49561 };
49562 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49563
49564 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49565 struct Scsi_Host *shost = dev_to_shost(dev);
49566 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49567
49568 - atomic_set(&srp_host->next_port_id, 0);
49569 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49570 return 0;
49571 }
49572
49573 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49574 rport_fast_io_fail_timedout);
49575 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49576
49577 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49578 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49579 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49580
49581 transport_setup_device(&rport->dev);
49582 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49583 index 36d1a23..3f33303 100644
49584 --- a/drivers/scsi/sd.c
49585 +++ b/drivers/scsi/sd.c
49586 @@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
49587 sdkp->disk = gd;
49588 sdkp->index = index;
49589 atomic_set(&sdkp->openers, 0);
49590 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49591 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49592
49593 if (!sdp->request_queue->rq_timeout) {
49594 if (sdp->type != TYPE_MOD)
49595 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49596 index df5e961..df6b97f 100644
49597 --- a/drivers/scsi/sg.c
49598 +++ b/drivers/scsi/sg.c
49599 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49600 sdp->disk->disk_name,
49601 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49602 NULL,
49603 - (char *)arg);
49604 + (char __user *)arg);
49605 case BLKTRACESTART:
49606 return blk_trace_startstop(sdp->device->request_queue, 1);
49607 case BLKTRACESTOP:
49608 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49609 index d0b28bb..a263613 100644
49610 --- a/drivers/spi/spi.c
49611 +++ b/drivers/spi/spi.c
49612 @@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
49613 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49614
49615 /* portable code must never pass more than 32 bytes */
49616 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49617 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49618
49619 static u8 *buf;
49620
49621 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49622 index 2c61783..4d49e4e 100644
49623 --- a/drivers/staging/android/timed_output.c
49624 +++ b/drivers/staging/android/timed_output.c
49625 @@ -25,7 +25,7 @@
49626 #include "timed_output.h"
49627
49628 static struct class *timed_output_class;
49629 -static atomic_t device_count;
49630 +static atomic_unchecked_t device_count;
49631
49632 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49633 char *buf)
49634 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49635 timed_output_class = class_create(THIS_MODULE, "timed_output");
49636 if (IS_ERR(timed_output_class))
49637 return PTR_ERR(timed_output_class);
49638 - atomic_set(&device_count, 0);
49639 + atomic_set_unchecked(&device_count, 0);
49640 timed_output_class->dev_groups = timed_output_groups;
49641 }
49642
49643 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49644 if (ret < 0)
49645 return ret;
49646
49647 - tdev->index = atomic_inc_return(&device_count);
49648 + tdev->index = atomic_inc_return_unchecked(&device_count);
49649 tdev->dev = device_create(timed_output_class, NULL,
49650 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49651 if (IS_ERR(tdev->dev))
49652 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49653 index fe47cd3..19a1bd1 100644
49654 --- a/drivers/staging/gdm724x/gdm_tty.c
49655 +++ b/drivers/staging/gdm724x/gdm_tty.c
49656 @@ -44,7 +44,7 @@
49657 #define gdm_tty_send_control(n, r, v, d, l) (\
49658 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49659
49660 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49661 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49662
49663 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49664 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49665 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49666 index 236ed66..dd9cd74 100644
49667 --- a/drivers/staging/imx-drm/imx-drm-core.c
49668 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49669 @@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49670 goto err_busy;
49671 }
49672
49673 - if (imxdrm->drm->open_count) {
49674 + if (local_read(&imxdrm->drm->open_count)) {
49675 ret = -EBUSY;
49676 goto err_busy;
49677 }
49678 @@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49679
49680 mutex_lock(&imxdrm->mutex);
49681
49682 - if (imxdrm->drm->open_count) {
49683 + if (local_read(&imxdrm->drm->open_count)) {
49684 ret = -EBUSY;
49685 goto err_busy;
49686 }
49687 @@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49688
49689 mutex_lock(&imxdrm->mutex);
49690
49691 - if (imxdrm->drm->open_count) {
49692 + if (local_read(&imxdrm->drm->open_count)) {
49693 ret = -EBUSY;
49694 goto err_busy;
49695 }
49696 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49697 index 3f8020c..649fded 100644
49698 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49699 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49700 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49701 return 0;
49702 }
49703
49704 -sfw_test_client_ops_t brw_test_client;
49705 -void brw_init_test_client(void)
49706 -{
49707 - brw_test_client.tso_init = brw_client_init;
49708 - brw_test_client.tso_fini = brw_client_fini;
49709 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49710 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49711 +sfw_test_client_ops_t brw_test_client = {
49712 + .tso_init = brw_client_init,
49713 + .tso_fini = brw_client_fini,
49714 + .tso_prep_rpc = brw_client_prep_rpc,
49715 + .tso_done_rpc = brw_client_done_rpc,
49716 };
49717
49718 srpc_service_t brw_test_service;
49719 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49720 index 050723a..fa6fdf1 100644
49721 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49722 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49723 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49724
49725 extern sfw_test_client_ops_t ping_test_client;
49726 extern srpc_service_t ping_test_service;
49727 -extern void ping_init_test_client(void);
49728 extern void ping_init_test_service(void);
49729
49730 extern sfw_test_client_ops_t brw_test_client;
49731 extern srpc_service_t brw_test_service;
49732 -extern void brw_init_test_client(void);
49733 extern void brw_init_test_service(void);
49734
49735
49736 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49737 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49738 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49739
49740 - brw_init_test_client();
49741 brw_init_test_service();
49742 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49743 LASSERT (rc == 0);
49744
49745 - ping_init_test_client();
49746 ping_init_test_service();
49747 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49748 LASSERT (rc == 0);
49749 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49750 index 750cac4..e4d751f 100644
49751 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49752 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49753 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49754 return 0;
49755 }
49756
49757 -sfw_test_client_ops_t ping_test_client;
49758 -void ping_init_test_client(void)
49759 -{
49760 - ping_test_client.tso_init = ping_client_init;
49761 - ping_test_client.tso_fini = ping_client_fini;
49762 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49763 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49764 -}
49765 +sfw_test_client_ops_t ping_test_client = {
49766 + .tso_init = ping_client_init,
49767 + .tso_fini = ping_client_fini,
49768 + .tso_prep_rpc = ping_client_prep_rpc,
49769 + .tso_done_rpc = ping_client_done_rpc,
49770 +};
49771
49772 srpc_service_t ping_test_service;
49773 void ping_init_test_service(void)
49774 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49775 index ec4bb5e..740c6dd 100644
49776 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49777 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49778 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49779 ldlm_completion_callback lcs_completion;
49780 ldlm_blocking_callback lcs_blocking;
49781 ldlm_glimpse_callback lcs_glimpse;
49782 -};
49783 +} __no_const;
49784
49785 /* ldlm_lockd.c */
49786 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49787 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49788 index c3470ce..2bef527 100644
49789 --- a/drivers/staging/lustre/lustre/include/obd.h
49790 +++ b/drivers/staging/lustre/lustre/include/obd.h
49791 @@ -1426,7 +1426,7 @@ struct md_ops {
49792 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49793 * wrapper function in include/linux/obd_class.h.
49794 */
49795 -};
49796 +} __no_const;
49797
49798 struct lsm_operations {
49799 void (*lsm_free)(struct lov_stripe_md *);
49800 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49801 index c9aae13..60ea292 100644
49802 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49803 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49804 @@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49805 int added = (mode == LCK_NL);
49806 int overlaps = 0;
49807 int splitted = 0;
49808 - const struct ldlm_callback_suite null_cbs = { NULL };
49809 + const struct ldlm_callback_suite null_cbs = { };
49810
49811 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49812 LPU64" end "LPU64"\n", *flags,
49813 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49814 index e947b91..f408990 100644
49815 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49816 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49817 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49818 int LL_PROC_PROTO(proc_console_max_delay_cs)
49819 {
49820 int rc, max_delay_cs;
49821 - ctl_table_t dummy = *table;
49822 + ctl_table_no_const dummy = *table;
49823 cfs_duration_t d;
49824
49825 dummy.data = &max_delay_cs;
49826 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49827 int LL_PROC_PROTO(proc_console_min_delay_cs)
49828 {
49829 int rc, min_delay_cs;
49830 - ctl_table_t dummy = *table;
49831 + ctl_table_no_const dummy = *table;
49832 cfs_duration_t d;
49833
49834 dummy.data = &min_delay_cs;
49835 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49836 int LL_PROC_PROTO(proc_console_backoff)
49837 {
49838 int rc, backoff;
49839 - ctl_table_t dummy = *table;
49840 + ctl_table_no_const dummy = *table;
49841
49842 dummy.data = &backoff;
49843 dummy.proc_handler = &proc_dointvec;
49844 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49845 index 24ae26d..9d09cab 100644
49846 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49847 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49848 @@ -313,11 +313,11 @@ out:
49849
49850
49851 struct cfs_psdev_ops libcfs_psdev_ops = {
49852 - libcfs_psdev_open,
49853 - libcfs_psdev_release,
49854 - NULL,
49855 - NULL,
49856 - libcfs_ioctl
49857 + .p_open = libcfs_psdev_open,
49858 + .p_close = libcfs_psdev_release,
49859 + .p_read = NULL,
49860 + .p_write = NULL,
49861 + .p_ioctl = libcfs_ioctl
49862 };
49863
49864 extern int insert_proc(void);
49865 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49866 index 52b7731..d604da0 100644
49867 --- a/drivers/staging/lustre/lustre/llite/dir.c
49868 +++ b/drivers/staging/lustre/lustre/llite/dir.c
49869 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49870 int mode;
49871 int err;
49872
49873 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49874 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49875 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49876 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49877 lump);
49878 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49879 index 480b7c4..6846324 100644
49880 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49881 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49882 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49883
49884 static int solo_sysfs_init(struct solo_dev *solo_dev)
49885 {
49886 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49887 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49888 struct device *dev = &solo_dev->dev;
49889 const char *driver;
49890 int i;
49891 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49892 index 1db18c7..35e6afc 100644
49893 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49894 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49895 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49896
49897 int solo_g723_init(struct solo_dev *solo_dev)
49898 {
49899 - static struct snd_device_ops ops = { NULL };
49900 + static struct snd_device_ops ops = { };
49901 struct snd_card *card;
49902 struct snd_kcontrol_new kctl;
49903 char name[32];
49904 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49905 index 7f2f247..d999137 100644
49906 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49907 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49908 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49909
49910 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49911 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49912 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49913 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49914 if (p2m_id < 0)
49915 p2m_id = -p2m_id;
49916 }
49917 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49918 index 8964f8b..36eb087 100644
49919 --- a/drivers/staging/media/solo6x10/solo6x10.h
49920 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49921 @@ -237,7 +237,7 @@ struct solo_dev {
49922
49923 /* P2M DMA Engine */
49924 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49925 - atomic_t p2m_count;
49926 + atomic_unchecked_t p2m_count;
49927 int p2m_jiffies;
49928 unsigned int p2m_timeouts;
49929
49930 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49931 index a0f4868..139f1fb 100644
49932 --- a/drivers/staging/octeon/ethernet-rx.c
49933 +++ b/drivers/staging/octeon/ethernet-rx.c
49934 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49935 /* Increment RX stats for virtual ports */
49936 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49937 #ifdef CONFIG_64BIT
49938 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49939 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49940 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49941 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49942 #else
49943 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49944 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49945 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49946 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49947 #endif
49948 }
49949 netif_receive_skb(skb);
49950 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49951 dev->name);
49952 */
49953 #ifdef CONFIG_64BIT
49954 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49955 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49956 #else
49957 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49958 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49959 #endif
49960 dev_kfree_skb_irq(skb);
49961 }
49962 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49963 index 089dc4b..c9a687e 100644
49964 --- a/drivers/staging/octeon/ethernet.c
49965 +++ b/drivers/staging/octeon/ethernet.c
49966 @@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49967 * since the RX tasklet also increments it.
49968 */
49969 #ifdef CONFIG_64BIT
49970 - atomic64_add(rx_status.dropped_packets,
49971 - (atomic64_t *)&priv->stats.rx_dropped);
49972 + atomic64_add_unchecked(rx_status.dropped_packets,
49973 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49974 #else
49975 - atomic_add(rx_status.dropped_packets,
49976 - (atomic_t *)&priv->stats.rx_dropped);
49977 + atomic_add_unchecked(rx_status.dropped_packets,
49978 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49979 #endif
49980 }
49981
49982 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49983 index c274b34..f84de76 100644
49984 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49985 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49986 @@ -271,7 +271,7 @@ struct hal_ops {
49987 s32 (*c2h_handler)(struct adapter *padapter,
49988 struct c2h_evt_hdr *c2h_evt);
49989 c2h_id_filter c2h_id_filter_ccx;
49990 -};
49991 +} __no_const;
49992
49993 enum rt_eeprom_type {
49994 EEPROM_93C46,
49995 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49996 index 3d1dfcc..ff5620a 100644
49997 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49998 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49999 @@ -126,7 +126,7 @@ struct _io_ops {
50000 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50001 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50002 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50003 -};
50004 +} __no_const;
50005
50006 struct io_req {
50007 struct list_head list;
50008 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50009 index dc23395..cf7e9b1 100644
50010 --- a/drivers/staging/rtl8712/rtl871x_io.h
50011 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50012 @@ -108,7 +108,7 @@ struct _io_ops {
50013 u8 *pmem);
50014 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50015 u8 *pmem);
50016 -};
50017 +} __no_const;
50018
50019 struct io_req {
50020 struct list_head list;
50021 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50022 index 1f5088b..0e59820 100644
50023 --- a/drivers/staging/sbe-2t3e3/netdev.c
50024 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50025 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50026 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50027
50028 if (rlen)
50029 - if (copy_to_user(data, &resp, rlen))
50030 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50031 return -EFAULT;
50032
50033 return 0;
50034 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50035 index a863a98..d272795 100644
50036 --- a/drivers/staging/usbip/vhci.h
50037 +++ b/drivers/staging/usbip/vhci.h
50038 @@ -83,7 +83,7 @@ struct vhci_hcd {
50039 unsigned resuming:1;
50040 unsigned long re_timeout;
50041
50042 - atomic_t seqnum;
50043 + atomic_unchecked_t seqnum;
50044
50045 /*
50046 * NOTE:
50047 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50048 index 72391ef..7c6717a 100644
50049 --- a/drivers/staging/usbip/vhci_hcd.c
50050 +++ b/drivers/staging/usbip/vhci_hcd.c
50051 @@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50052
50053 spin_lock(&vdev->priv_lock);
50054
50055 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50056 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50057 if (priv->seqnum == 0xffff)
50058 dev_info(&urb->dev->dev, "seqnum max\n");
50059
50060 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50061 return -ENOMEM;
50062 }
50063
50064 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50065 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50066 if (unlink->seqnum == 0xffff)
50067 pr_info("seqnum max\n");
50068
50069 @@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50070 vdev->rhport = rhport;
50071 }
50072
50073 - atomic_set(&vhci->seqnum, 0);
50074 + atomic_set_unchecked(&vhci->seqnum, 0);
50075 spin_lock_init(&vhci->lock);
50076
50077 hcd->power_budget = 0; /* no limit */
50078 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50079 index d07fcb5..358e1e1 100644
50080 --- a/drivers/staging/usbip/vhci_rx.c
50081 +++ b/drivers/staging/usbip/vhci_rx.c
50082 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50083 if (!urb) {
50084 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50085 pr_info("max seqnum %d\n",
50086 - atomic_read(&the_controller->seqnum));
50087 + atomic_read_unchecked(&the_controller->seqnum));
50088 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50089 return;
50090 }
50091 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50092 index 6eecd53..29317c6 100644
50093 --- a/drivers/staging/vt6655/hostap.c
50094 +++ b/drivers/staging/vt6655/hostap.c
50095 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50096 *
50097 */
50098
50099 +static net_device_ops_no_const apdev_netdev_ops;
50100 +
50101 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50102 {
50103 PSDevice apdev_priv;
50104 struct net_device *dev = pDevice->dev;
50105 int ret;
50106 - const struct net_device_ops apdev_netdev_ops = {
50107 - .ndo_start_xmit = pDevice->tx_80211,
50108 - };
50109
50110 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50111
50112 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50113 *apdev_priv = *pDevice;
50114 eth_hw_addr_inherit(pDevice->apdev, dev);
50115
50116 + /* only half broken now */
50117 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50118 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50119
50120 pDevice->apdev->type = ARPHRD_IEEE80211;
50121 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50122 index 67ba48b..24e602f 100644
50123 --- a/drivers/staging/vt6656/hostap.c
50124 +++ b/drivers/staging/vt6656/hostap.c
50125 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50126 *
50127 */
50128
50129 +static net_device_ops_no_const apdev_netdev_ops;
50130 +
50131 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50132 {
50133 struct vnt_private *apdev_priv;
50134 struct net_device *dev = pDevice->dev;
50135 int ret;
50136 - const struct net_device_ops apdev_netdev_ops = {
50137 - .ndo_start_xmit = pDevice->tx_80211,
50138 - };
50139
50140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50141
50142 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50143 *apdev_priv = *pDevice;
50144 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50145
50146 + /* only half broken now */
50147 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50148 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50149
50150 pDevice->apdev->type = ARPHRD_IEEE80211;
50151 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50152 index 24884ca..26c8220 100644
50153 --- a/drivers/target/sbp/sbp_target.c
50154 +++ b/drivers/target/sbp/sbp_target.c
50155 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50156
50157 #define SESSION_MAINTENANCE_INTERVAL HZ
50158
50159 -static atomic_t login_id = ATOMIC_INIT(0);
50160 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50161
50162 static void session_maintenance_work(struct work_struct *);
50163 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50164 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50165 login->lun = se_lun;
50166 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50167 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50168 - login->login_id = atomic_inc_return(&login_id);
50169 + login->login_id = atomic_inc_return_unchecked(&login_id);
50170
50171 login->tgt_agt = sbp_target_agent_register(login);
50172 if (IS_ERR(login->tgt_agt)) {
50173 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50174 index 65001e1..2ebfbb9 100644
50175 --- a/drivers/target/target_core_device.c
50176 +++ b/drivers/target/target_core_device.c
50177 @@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50178 spin_lock_init(&dev->se_tmr_lock);
50179 spin_lock_init(&dev->qf_cmd_lock);
50180 sema_init(&dev->caw_sem, 1);
50181 - atomic_set(&dev->dev_ordered_id, 0);
50182 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50183 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50184 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50185 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50186 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50187 index 2956250..b10f722 100644
50188 --- a/drivers/target/target_core_transport.c
50189 +++ b/drivers/target/target_core_transport.c
50190 @@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50191 * Used to determine when ORDERED commands should go from
50192 * Dormant to Active status.
50193 */
50194 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50195 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50196 smp_mb__after_atomic_inc();
50197 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50198 cmd->se_ordered_id, cmd->sam_task_attr,
50199 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50200 index 04b1be7..5eff86d 100644
50201 --- a/drivers/thermal/of-thermal.c
50202 +++ b/drivers/thermal/of-thermal.c
50203 @@ -30,6 +30,7 @@
50204 #include <linux/err.h>
50205 #include <linux/export.h>
50206 #include <linux/string.h>
50207 +#include <linux/mm.h>
50208
50209 #include "thermal_core.h"
50210
50211 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50212 tz->get_trend = get_trend;
50213 tz->sensor_data = data;
50214
50215 - tzd->ops->get_temp = of_thermal_get_temp;
50216 - tzd->ops->get_trend = of_thermal_get_trend;
50217 + pax_open_kernel();
50218 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50219 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50220 + pax_close_kernel();
50221 mutex_unlock(&tzd->lock);
50222
50223 return tzd;
50224 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50225 return;
50226
50227 mutex_lock(&tzd->lock);
50228 - tzd->ops->get_temp = NULL;
50229 - tzd->ops->get_trend = NULL;
50230 + pax_open_kernel();
50231 + *(void **)&tzd->ops->get_temp = NULL;
50232 + *(void **)&tzd->ops->get_trend = NULL;
50233 + pax_close_kernel();
50234
50235 tz->get_temp = NULL;
50236 tz->get_trend = NULL;
50237 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50238 index a57bb5a..1f727d33 100644
50239 --- a/drivers/tty/cyclades.c
50240 +++ b/drivers/tty/cyclades.c
50241 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50242 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50243 info->port.count);
50244 #endif
50245 - info->port.count++;
50246 + atomic_inc(&info->port.count);
50247 #ifdef CY_DEBUG_COUNT
50248 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50249 - current->pid, info->port.count);
50250 + current->pid, atomic_read(&info->port.count));
50251 #endif
50252
50253 /*
50254 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50255 for (j = 0; j < cy_card[i].nports; j++) {
50256 info = &cy_card[i].ports[j];
50257
50258 - if (info->port.count) {
50259 + if (atomic_read(&info->port.count)) {
50260 /* XXX is the ldisc num worth this? */
50261 struct tty_struct *tty;
50262 struct tty_ldisc *ld;
50263 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50264 index 50b4688..e1e8125 100644
50265 --- a/drivers/tty/hvc/hvc_console.c
50266 +++ b/drivers/tty/hvc/hvc_console.c
50267 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50268
50269 spin_lock_irqsave(&hp->port.lock, flags);
50270 /* Check and then increment for fast path open. */
50271 - if (hp->port.count++ > 0) {
50272 + if (atomic_inc_return(&hp->port.count) > 1) {
50273 spin_unlock_irqrestore(&hp->port.lock, flags);
50274 hvc_kick();
50275 return 0;
50276 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50277
50278 spin_lock_irqsave(&hp->port.lock, flags);
50279
50280 - if (--hp->port.count == 0) {
50281 + if (atomic_dec_return(&hp->port.count) == 0) {
50282 spin_unlock_irqrestore(&hp->port.lock, flags);
50283 /* We are done with the tty pointer now. */
50284 tty_port_tty_set(&hp->port, NULL);
50285 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50286 */
50287 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50288 } else {
50289 - if (hp->port.count < 0)
50290 + if (atomic_read(&hp->port.count) < 0)
50291 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50292 - hp->vtermno, hp->port.count);
50293 + hp->vtermno, atomic_read(&hp->port.count));
50294 spin_unlock_irqrestore(&hp->port.lock, flags);
50295 }
50296 }
50297 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50298 * open->hangup case this can be called after the final close so prevent
50299 * that from happening for now.
50300 */
50301 - if (hp->port.count <= 0) {
50302 + if (atomic_read(&hp->port.count) <= 0) {
50303 spin_unlock_irqrestore(&hp->port.lock, flags);
50304 return;
50305 }
50306
50307 - hp->port.count = 0;
50308 + atomic_set(&hp->port.count, 0);
50309 spin_unlock_irqrestore(&hp->port.lock, flags);
50310 tty_port_tty_set(&hp->port, NULL);
50311
50312 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50313 return -EPIPE;
50314
50315 /* FIXME what's this (unprotected) check for? */
50316 - if (hp->port.count <= 0)
50317 + if (atomic_read(&hp->port.count) <= 0)
50318 return -EIO;
50319
50320 spin_lock_irqsave(&hp->lock, flags);
50321 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50322 index 81e939e..95ead10 100644
50323 --- a/drivers/tty/hvc/hvcs.c
50324 +++ b/drivers/tty/hvc/hvcs.c
50325 @@ -83,6 +83,7 @@
50326 #include <asm/hvcserver.h>
50327 #include <asm/uaccess.h>
50328 #include <asm/vio.h>
50329 +#include <asm/local.h>
50330
50331 /*
50332 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50333 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50334
50335 spin_lock_irqsave(&hvcsd->lock, flags);
50336
50337 - if (hvcsd->port.count > 0) {
50338 + if (atomic_read(&hvcsd->port.count) > 0) {
50339 spin_unlock_irqrestore(&hvcsd->lock, flags);
50340 printk(KERN_INFO "HVCS: vterm state unchanged. "
50341 "The hvcs device node is still in use.\n");
50342 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50343 }
50344 }
50345
50346 - hvcsd->port.count = 0;
50347 + atomic_set(&hvcsd->port.count, 0);
50348 hvcsd->port.tty = tty;
50349 tty->driver_data = hvcsd;
50350
50351 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50352 unsigned long flags;
50353
50354 spin_lock_irqsave(&hvcsd->lock, flags);
50355 - hvcsd->port.count++;
50356 + atomic_inc(&hvcsd->port.count);
50357 hvcsd->todo_mask |= HVCS_SCHED_READ;
50358 spin_unlock_irqrestore(&hvcsd->lock, flags);
50359
50360 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50361 hvcsd = tty->driver_data;
50362
50363 spin_lock_irqsave(&hvcsd->lock, flags);
50364 - if (--hvcsd->port.count == 0) {
50365 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50366
50367 vio_disable_interrupts(hvcsd->vdev);
50368
50369 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50370
50371 free_irq(irq, hvcsd);
50372 return;
50373 - } else if (hvcsd->port.count < 0) {
50374 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50375 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50376 " is missmanaged.\n",
50377 - hvcsd->vdev->unit_address, hvcsd->port.count);
50378 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50379 }
50380
50381 spin_unlock_irqrestore(&hvcsd->lock, flags);
50382 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50383
50384 spin_lock_irqsave(&hvcsd->lock, flags);
50385 /* Preserve this so that we know how many kref refs to put */
50386 - temp_open_count = hvcsd->port.count;
50387 + temp_open_count = atomic_read(&hvcsd->port.count);
50388
50389 /*
50390 * Don't kref put inside the spinlock because the destruction
50391 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50392 tty->driver_data = NULL;
50393 hvcsd->port.tty = NULL;
50394
50395 - hvcsd->port.count = 0;
50396 + atomic_set(&hvcsd->port.count, 0);
50397
50398 /* This will drop any buffered data on the floor which is OK in a hangup
50399 * scenario. */
50400 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50401 * the middle of a write operation? This is a crummy place to do this
50402 * but we want to keep it all in the spinlock.
50403 */
50404 - if (hvcsd->port.count <= 0) {
50405 + if (atomic_read(&hvcsd->port.count) <= 0) {
50406 spin_unlock_irqrestore(&hvcsd->lock, flags);
50407 return -ENODEV;
50408 }
50409 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50410 {
50411 struct hvcs_struct *hvcsd = tty->driver_data;
50412
50413 - if (!hvcsd || hvcsd->port.count <= 0)
50414 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50415 return 0;
50416
50417 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50418 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50419 index 4190199..06d5bfa 100644
50420 --- a/drivers/tty/hvc/hvsi.c
50421 +++ b/drivers/tty/hvc/hvsi.c
50422 @@ -85,7 +85,7 @@ struct hvsi_struct {
50423 int n_outbuf;
50424 uint32_t vtermno;
50425 uint32_t virq;
50426 - atomic_t seqno; /* HVSI packet sequence number */
50427 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50428 uint16_t mctrl;
50429 uint8_t state; /* HVSI protocol state */
50430 uint8_t flags;
50431 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50432
50433 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50434 packet.hdr.len = sizeof(struct hvsi_query_response);
50435 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50436 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50437 packet.verb = VSV_SEND_VERSION_NUMBER;
50438 packet.u.version = HVSI_VERSION;
50439 packet.query_seqno = query_seqno+1;
50440 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50441
50442 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50443 packet.hdr.len = sizeof(struct hvsi_query);
50444 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50445 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50446 packet.verb = verb;
50447
50448 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50449 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50450 int wrote;
50451
50452 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50453 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50454 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50455 packet.hdr.len = sizeof(struct hvsi_control);
50456 packet.verb = VSV_SET_MODEM_CTL;
50457 packet.mask = HVSI_TSDTR;
50458 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50459 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50460
50461 packet.hdr.type = VS_DATA_PACKET_HEADER;
50462 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50463 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50464 packet.hdr.len = count + sizeof(struct hvsi_header);
50465 memcpy(&packet.data, buf, count);
50466
50467 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50468 struct hvsi_control packet __ALIGNED__;
50469
50470 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50471 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50472 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50473 packet.hdr.len = 6;
50474 packet.verb = VSV_CLOSE_PROTOCOL;
50475
50476 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50477
50478 tty_port_tty_set(&hp->port, tty);
50479 spin_lock_irqsave(&hp->lock, flags);
50480 - hp->port.count++;
50481 + atomic_inc(&hp->port.count);
50482 atomic_set(&hp->seqno, 0);
50483 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50484 spin_unlock_irqrestore(&hp->lock, flags);
50485 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50486
50487 spin_lock_irqsave(&hp->lock, flags);
50488
50489 - if (--hp->port.count == 0) {
50490 + if (atomic_dec_return(&hp->port.count) == 0) {
50491 tty_port_tty_set(&hp->port, NULL);
50492 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50493
50494 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50495
50496 spin_lock_irqsave(&hp->lock, flags);
50497 }
50498 - } else if (hp->port.count < 0)
50499 + } else if (atomic_read(&hp->port.count) < 0)
50500 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50501 - hp - hvsi_ports, hp->port.count);
50502 + hp - hvsi_ports, atomic_read(&hp->port.count));
50503
50504 spin_unlock_irqrestore(&hp->lock, flags);
50505 }
50506 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50507 tty_port_tty_set(&hp->port, NULL);
50508
50509 spin_lock_irqsave(&hp->lock, flags);
50510 - hp->port.count = 0;
50511 + atomic_set(&hp->port.count, 0);
50512 hp->n_outbuf = 0;
50513 spin_unlock_irqrestore(&hp->lock, flags);
50514 }
50515 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50516 index 7ae6c29..05c6dba 100644
50517 --- a/drivers/tty/hvc/hvsi_lib.c
50518 +++ b/drivers/tty/hvc/hvsi_lib.c
50519 @@ -8,7 +8,7 @@
50520
50521 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50522 {
50523 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50524 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50525
50526 /* Assumes that always succeeds, works in practice */
50527 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50528 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50529
50530 /* Reset state */
50531 pv->established = 0;
50532 - atomic_set(&pv->seqno, 0);
50533 + atomic_set_unchecked(&pv->seqno, 0);
50534
50535 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50536
50537 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50538 index 17ee3bf..8d2520d 100644
50539 --- a/drivers/tty/ipwireless/tty.c
50540 +++ b/drivers/tty/ipwireless/tty.c
50541 @@ -28,6 +28,7 @@
50542 #include <linux/tty_driver.h>
50543 #include <linux/tty_flip.h>
50544 #include <linux/uaccess.h>
50545 +#include <asm/local.h>
50546
50547 #include "tty.h"
50548 #include "network.h"
50549 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50550 mutex_unlock(&tty->ipw_tty_mutex);
50551 return -ENODEV;
50552 }
50553 - if (tty->port.count == 0)
50554 + if (atomic_read(&tty->port.count) == 0)
50555 tty->tx_bytes_queued = 0;
50556
50557 - tty->port.count++;
50558 + atomic_inc(&tty->port.count);
50559
50560 tty->port.tty = linux_tty;
50561 linux_tty->driver_data = tty;
50562 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50563
50564 static void do_ipw_close(struct ipw_tty *tty)
50565 {
50566 - tty->port.count--;
50567 -
50568 - if (tty->port.count == 0) {
50569 + if (atomic_dec_return(&tty->port.count) == 0) {
50570 struct tty_struct *linux_tty = tty->port.tty;
50571
50572 if (linux_tty != NULL) {
50573 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50574 return;
50575
50576 mutex_lock(&tty->ipw_tty_mutex);
50577 - if (tty->port.count == 0) {
50578 + if (atomic_read(&tty->port.count) == 0) {
50579 mutex_unlock(&tty->ipw_tty_mutex);
50580 return;
50581 }
50582 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50583
50584 mutex_lock(&tty->ipw_tty_mutex);
50585
50586 - if (!tty->port.count) {
50587 + if (!atomic_read(&tty->port.count)) {
50588 mutex_unlock(&tty->ipw_tty_mutex);
50589 return;
50590 }
50591 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50592 return -ENODEV;
50593
50594 mutex_lock(&tty->ipw_tty_mutex);
50595 - if (!tty->port.count) {
50596 + if (!atomic_read(&tty->port.count)) {
50597 mutex_unlock(&tty->ipw_tty_mutex);
50598 return -EINVAL;
50599 }
50600 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50601 if (!tty)
50602 return -ENODEV;
50603
50604 - if (!tty->port.count)
50605 + if (!atomic_read(&tty->port.count))
50606 return -EINVAL;
50607
50608 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50609 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50610 if (!tty)
50611 return 0;
50612
50613 - if (!tty->port.count)
50614 + if (!atomic_read(&tty->port.count))
50615 return 0;
50616
50617 return tty->tx_bytes_queued;
50618 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50619 if (!tty)
50620 return -ENODEV;
50621
50622 - if (!tty->port.count)
50623 + if (!atomic_read(&tty->port.count))
50624 return -EINVAL;
50625
50626 return get_control_lines(tty);
50627 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50628 if (!tty)
50629 return -ENODEV;
50630
50631 - if (!tty->port.count)
50632 + if (!atomic_read(&tty->port.count))
50633 return -EINVAL;
50634
50635 return set_control_lines(tty, set, clear);
50636 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50637 if (!tty)
50638 return -ENODEV;
50639
50640 - if (!tty->port.count)
50641 + if (!atomic_read(&tty->port.count))
50642 return -EINVAL;
50643
50644 /* FIXME: Exactly how is the tty object locked here .. */
50645 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50646 * are gone */
50647 mutex_lock(&ttyj->ipw_tty_mutex);
50648 }
50649 - while (ttyj->port.count)
50650 + while (atomic_read(&ttyj->port.count))
50651 do_ipw_close(ttyj);
50652 ipwireless_disassociate_network_ttys(network,
50653 ttyj->channel_idx);
50654 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50655 index 1deaca4..c8582d4 100644
50656 --- a/drivers/tty/moxa.c
50657 +++ b/drivers/tty/moxa.c
50658 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50659 }
50660
50661 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50662 - ch->port.count++;
50663 + atomic_inc(&ch->port.count);
50664 tty->driver_data = ch;
50665 tty_port_tty_set(&ch->port, tty);
50666 mutex_lock(&ch->port.mutex);
50667 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50668 index 2ebe47b..3205833 100644
50669 --- a/drivers/tty/n_gsm.c
50670 +++ b/drivers/tty/n_gsm.c
50671 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50672 spin_lock_init(&dlci->lock);
50673 mutex_init(&dlci->mutex);
50674 dlci->fifo = &dlci->_fifo;
50675 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50676 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50677 kfree(dlci);
50678 return NULL;
50679 }
50680 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50681 struct gsm_dlci *dlci = tty->driver_data;
50682 struct tty_port *port = &dlci->port;
50683
50684 - port->count++;
50685 + atomic_inc(&port->count);
50686 tty_port_tty_set(port, tty);
50687
50688 dlci->modem_rx = 0;
50689 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50690 index d15624c..e512bdb 100644
50691 --- a/drivers/tty/n_tty.c
50692 +++ b/drivers/tty/n_tty.c
50693 @@ -115,7 +115,7 @@ struct n_tty_data {
50694 int minimum_to_wake;
50695
50696 /* consumer-published */
50697 - size_t read_tail;
50698 + size_t read_tail __intentional_overflow(-1);
50699 size_t line_start;
50700
50701 /* protected by output lock */
50702 @@ -2515,6 +2515,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50703 {
50704 *ops = tty_ldisc_N_TTY;
50705 ops->owner = NULL;
50706 - ops->refcount = ops->flags = 0;
50707 + atomic_set(&ops->refcount, 0);
50708 + ops->flags = 0;
50709 }
50710 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50711 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50712 index 25c9bc7..24077b7 100644
50713 --- a/drivers/tty/pty.c
50714 +++ b/drivers/tty/pty.c
50715 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50716 panic("Couldn't register Unix98 pts driver");
50717
50718 /* Now create the /dev/ptmx special device */
50719 + pax_open_kernel();
50720 tty_default_fops(&ptmx_fops);
50721 - ptmx_fops.open = ptmx_open;
50722 + *(void **)&ptmx_fops.open = ptmx_open;
50723 + pax_close_kernel();
50724
50725 cdev_init(&ptmx_cdev, &ptmx_fops);
50726 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50727 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50728 index 383c4c7..d408e21 100644
50729 --- a/drivers/tty/rocket.c
50730 +++ b/drivers/tty/rocket.c
50731 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50732 tty->driver_data = info;
50733 tty_port_tty_set(port, tty);
50734
50735 - if (port->count++ == 0) {
50736 + if (atomic_inc_return(&port->count) == 1) {
50737 atomic_inc(&rp_num_ports_open);
50738
50739 #ifdef ROCKET_DEBUG_OPEN
50740 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50741 #endif
50742 }
50743 #ifdef ROCKET_DEBUG_OPEN
50744 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50745 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50746 #endif
50747
50748 /*
50749 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50750 spin_unlock_irqrestore(&info->port.lock, flags);
50751 return;
50752 }
50753 - if (info->port.count)
50754 + if (atomic_read(&info->port.count))
50755 atomic_dec(&rp_num_ports_open);
50756 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50757 spin_unlock_irqrestore(&info->port.lock, flags);
50758 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50759 index 1274499..f541382 100644
50760 --- a/drivers/tty/serial/ioc4_serial.c
50761 +++ b/drivers/tty/serial/ioc4_serial.c
50762 @@ -437,7 +437,7 @@ struct ioc4_soft {
50763 } is_intr_info[MAX_IOC4_INTR_ENTS];
50764
50765 /* Number of entries active in the above array */
50766 - atomic_t is_num_intrs;
50767 + atomic_unchecked_t is_num_intrs;
50768 } is_intr_type[IOC4_NUM_INTR_TYPES];
50769
50770 /* is_ir_lock must be held while
50771 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50772 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50773 || (type == IOC4_OTHER_INTR_TYPE)));
50774
50775 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50776 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50777 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50778
50779 /* Save off the lower level interrupt handler */
50780 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50781
50782 soft = arg;
50783 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50784 - num_intrs = (int)atomic_read(
50785 + num_intrs = (int)atomic_read_unchecked(
50786 &soft->is_intr_type[intr_type].is_num_intrs);
50787
50788 this_mir = this_ir = pending_intrs(soft, intr_type);
50789 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50790 index a260cde..6b2b5ce 100644
50791 --- a/drivers/tty/serial/kgdboc.c
50792 +++ b/drivers/tty/serial/kgdboc.c
50793 @@ -24,8 +24,9 @@
50794 #define MAX_CONFIG_LEN 40
50795
50796 static struct kgdb_io kgdboc_io_ops;
50797 +static struct kgdb_io kgdboc_io_ops_console;
50798
50799 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50800 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50801 static int configured = -1;
50802
50803 static char config[MAX_CONFIG_LEN];
50804 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50805 kgdboc_unregister_kbd();
50806 if (configured == 1)
50807 kgdb_unregister_io_module(&kgdboc_io_ops);
50808 + else if (configured == 2)
50809 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50810 }
50811
50812 static int configure_kgdboc(void)
50813 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50814 int err;
50815 char *cptr = config;
50816 struct console *cons;
50817 + int is_console = 0;
50818
50819 err = kgdboc_option_setup(config);
50820 if (err || !strlen(config) || isspace(config[0]))
50821 goto noconfig;
50822
50823 err = -ENODEV;
50824 - kgdboc_io_ops.is_console = 0;
50825 kgdb_tty_driver = NULL;
50826
50827 kgdboc_use_kms = 0;
50828 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50829 int idx;
50830 if (cons->device && cons->device(cons, &idx) == p &&
50831 idx == tty_line) {
50832 - kgdboc_io_ops.is_console = 1;
50833 + is_console = 1;
50834 break;
50835 }
50836 cons = cons->next;
50837 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50838 kgdb_tty_line = tty_line;
50839
50840 do_register:
50841 - err = kgdb_register_io_module(&kgdboc_io_ops);
50842 + if (is_console) {
50843 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50844 + configured = 2;
50845 + } else {
50846 + err = kgdb_register_io_module(&kgdboc_io_ops);
50847 + configured = 1;
50848 + }
50849 if (err)
50850 goto noconfig;
50851
50852 @@ -205,8 +214,6 @@ do_register:
50853 if (err)
50854 goto nmi_con_failed;
50855
50856 - configured = 1;
50857 -
50858 return 0;
50859
50860 nmi_con_failed:
50861 @@ -223,7 +230,7 @@ noconfig:
50862 static int __init init_kgdboc(void)
50863 {
50864 /* Already configured? */
50865 - if (configured == 1)
50866 + if (configured >= 1)
50867 return 0;
50868
50869 return configure_kgdboc();
50870 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50871 if (config[len - 1] == '\n')
50872 config[len - 1] = '\0';
50873
50874 - if (configured == 1)
50875 + if (configured >= 1)
50876 cleanup_kgdboc();
50877
50878 /* Go and configure with the new params. */
50879 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50880 .post_exception = kgdboc_post_exp_handler,
50881 };
50882
50883 +static struct kgdb_io kgdboc_io_ops_console = {
50884 + .name = "kgdboc",
50885 + .read_char = kgdboc_get_char,
50886 + .write_char = kgdboc_put_char,
50887 + .pre_exception = kgdboc_pre_exp_handler,
50888 + .post_exception = kgdboc_post_exp_handler,
50889 + .is_console = 1
50890 +};
50891 +
50892 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50893 /* This is only available if kgdboc is a built in for early debugging */
50894 static int __init kgdboc_early_init(char *opt)
50895 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50896 index b5d779c..3622cfe 100644
50897 --- a/drivers/tty/serial/msm_serial.c
50898 +++ b/drivers/tty/serial/msm_serial.c
50899 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50900 .cons = MSM_CONSOLE,
50901 };
50902
50903 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50904 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50905
50906 static const struct of_device_id msm_uartdm_table[] = {
50907 { .compatible = "qcom,msm-uartdm" },
50908 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50909 int irq;
50910
50911 if (pdev->id == -1)
50912 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50913 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50914
50915 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50916 return -ENXIO;
50917 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50918 index 9cd706d..6ff2de7 100644
50919 --- a/drivers/tty/serial/samsung.c
50920 +++ b/drivers/tty/serial/samsung.c
50921 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50922 }
50923 }
50924
50925 +static int s3c64xx_serial_startup(struct uart_port *port);
50926 static int s3c24xx_serial_startup(struct uart_port *port)
50927 {
50928 struct s3c24xx_uart_port *ourport = to_ourport(port);
50929 int ret;
50930
50931 + /* Startup sequence is different for s3c64xx and higher SoC's */
50932 + if (s3c24xx_serial_has_interrupt_mask(port))
50933 + return s3c64xx_serial_startup(port);
50934 +
50935 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50936 port->mapbase, port->membase);
50937
50938 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50939 /* setup info for port */
50940 port->dev = &platdev->dev;
50941
50942 - /* Startup sequence is different for s3c64xx and higher SoC's */
50943 - if (s3c24xx_serial_has_interrupt_mask(port))
50944 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50945 -
50946 port->uartclk = 1;
50947
50948 if (cfg->uart_flags & UPF_CONS_FLOW) {
50949 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50950 index ece2049..fba2524 100644
50951 --- a/drivers/tty/serial/serial_core.c
50952 +++ b/drivers/tty/serial/serial_core.c
50953 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50954 uart_flush_buffer(tty);
50955 uart_shutdown(tty, state);
50956 spin_lock_irqsave(&port->lock, flags);
50957 - port->count = 0;
50958 + atomic_set(&port->count, 0);
50959 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50960 spin_unlock_irqrestore(&port->lock, flags);
50961 tty_port_tty_set(port, NULL);
50962 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50963 goto end;
50964 }
50965
50966 - port->count++;
50967 + atomic_inc(&port->count);
50968 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50969 retval = -ENXIO;
50970 goto err_dec_count;
50971 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50972 /*
50973 * Make sure the device is in D0 state.
50974 */
50975 - if (port->count == 1)
50976 + if (atomic_read(&port->count) == 1)
50977 uart_change_pm(state, UART_PM_STATE_ON);
50978
50979 /*
50980 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50981 end:
50982 return retval;
50983 err_dec_count:
50984 - port->count--;
50985 + atomic_inc(&port->count);
50986 mutex_unlock(&port->mutex);
50987 goto end;
50988 }
50989 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50990 index 5ae14b4..2c1288f 100644
50991 --- a/drivers/tty/synclink.c
50992 +++ b/drivers/tty/synclink.c
50993 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50994
50995 if (debug_level >= DEBUG_LEVEL_INFO)
50996 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50997 - __FILE__,__LINE__, info->device_name, info->port.count);
50998 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50999
51000 if (tty_port_close_start(&info->port, tty, filp) == 0)
51001 goto cleanup;
51002 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51003 cleanup:
51004 if (debug_level >= DEBUG_LEVEL_INFO)
51005 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51006 - tty->driver->name, info->port.count);
51007 + tty->driver->name, atomic_read(&info->port.count));
51008
51009 } /* end of mgsl_close() */
51010
51011 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51012
51013 mgsl_flush_buffer(tty);
51014 shutdown(info);
51015 -
51016 - info->port.count = 0;
51017 +
51018 + atomic_set(&info->port.count, 0);
51019 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51020 info->port.tty = NULL;
51021
51022 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51023
51024 if (debug_level >= DEBUG_LEVEL_INFO)
51025 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51026 - __FILE__,__LINE__, tty->driver->name, port->count );
51027 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51028
51029 spin_lock_irqsave(&info->irq_spinlock, flags);
51030 if (!tty_hung_up_p(filp)) {
51031 extra_count = true;
51032 - port->count--;
51033 + atomic_dec(&port->count);
51034 }
51035 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51036 port->blocked_open++;
51037 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51038
51039 if (debug_level >= DEBUG_LEVEL_INFO)
51040 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51041 - __FILE__,__LINE__, tty->driver->name, port->count );
51042 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51043
51044 tty_unlock(tty);
51045 schedule();
51046 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51047
51048 /* FIXME: Racy on hangup during close wait */
51049 if (extra_count)
51050 - port->count++;
51051 + atomic_inc(&port->count);
51052 port->blocked_open--;
51053
51054 if (debug_level >= DEBUG_LEVEL_INFO)
51055 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51056 - __FILE__,__LINE__, tty->driver->name, port->count );
51057 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51058
51059 if (!retval)
51060 port->flags |= ASYNC_NORMAL_ACTIVE;
51061 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51062
51063 if (debug_level >= DEBUG_LEVEL_INFO)
51064 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51065 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51066 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51067
51068 /* If port is closing, signal caller to try again */
51069 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51070 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51071 spin_unlock_irqrestore(&info->netlock, flags);
51072 goto cleanup;
51073 }
51074 - info->port.count++;
51075 + atomic_inc(&info->port.count);
51076 spin_unlock_irqrestore(&info->netlock, flags);
51077
51078 - if (info->port.count == 1) {
51079 + if (atomic_read(&info->port.count) == 1) {
51080 /* 1st open on this device, init hardware */
51081 retval = startup(info);
51082 if (retval < 0)
51083 @@ -3446,8 +3446,8 @@ cleanup:
51084 if (retval) {
51085 if (tty->count == 1)
51086 info->port.tty = NULL; /* tty layer will release tty struct */
51087 - if(info->port.count)
51088 - info->port.count--;
51089 + if (atomic_read(&info->port.count))
51090 + atomic_dec(&info->port.count);
51091 }
51092
51093 return retval;
51094 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51095 unsigned short new_crctype;
51096
51097 /* return error if TTY interface open */
51098 - if (info->port.count)
51099 + if (atomic_read(&info->port.count))
51100 return -EBUSY;
51101
51102 switch (encoding)
51103 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51104
51105 /* arbitrate between network and tty opens */
51106 spin_lock_irqsave(&info->netlock, flags);
51107 - if (info->port.count != 0 || info->netcount != 0) {
51108 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51109 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51110 spin_unlock_irqrestore(&info->netlock, flags);
51111 return -EBUSY;
51112 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51113 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51114
51115 /* return error if TTY interface open */
51116 - if (info->port.count)
51117 + if (atomic_read(&info->port.count))
51118 return -EBUSY;
51119
51120 if (cmd != SIOCWANDEV)
51121 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51122 index c359a91..959fc26 100644
51123 --- a/drivers/tty/synclink_gt.c
51124 +++ b/drivers/tty/synclink_gt.c
51125 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51126 tty->driver_data = info;
51127 info->port.tty = tty;
51128
51129 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51130 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51131
51132 /* If port is closing, signal caller to try again */
51133 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51134 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51135 mutex_unlock(&info->port.mutex);
51136 goto cleanup;
51137 }
51138 - info->port.count++;
51139 + atomic_inc(&info->port.count);
51140 spin_unlock_irqrestore(&info->netlock, flags);
51141
51142 - if (info->port.count == 1) {
51143 + if (atomic_read(&info->port.count) == 1) {
51144 /* 1st open on this device, init hardware */
51145 retval = startup(info);
51146 if (retval < 0) {
51147 @@ -715,8 +715,8 @@ cleanup:
51148 if (retval) {
51149 if (tty->count == 1)
51150 info->port.tty = NULL; /* tty layer will release tty struct */
51151 - if(info->port.count)
51152 - info->port.count--;
51153 + if(atomic_read(&info->port.count))
51154 + atomic_dec(&info->port.count);
51155 }
51156
51157 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51158 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51159
51160 if (sanity_check(info, tty->name, "close"))
51161 return;
51162 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51163 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51164
51165 if (tty_port_close_start(&info->port, tty, filp) == 0)
51166 goto cleanup;
51167 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51168 tty_port_close_end(&info->port, tty);
51169 info->port.tty = NULL;
51170 cleanup:
51171 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51172 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51173 }
51174
51175 static void hangup(struct tty_struct *tty)
51176 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51177 shutdown(info);
51178
51179 spin_lock_irqsave(&info->port.lock, flags);
51180 - info->port.count = 0;
51181 + atomic_set(&info->port.count, 0);
51182 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51183 info->port.tty = NULL;
51184 spin_unlock_irqrestore(&info->port.lock, flags);
51185 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51186 unsigned short new_crctype;
51187
51188 /* return error if TTY interface open */
51189 - if (info->port.count)
51190 + if (atomic_read(&info->port.count))
51191 return -EBUSY;
51192
51193 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51194 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51195
51196 /* arbitrate between network and tty opens */
51197 spin_lock_irqsave(&info->netlock, flags);
51198 - if (info->port.count != 0 || info->netcount != 0) {
51199 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51200 DBGINFO(("%s hdlc_open busy\n", dev->name));
51201 spin_unlock_irqrestore(&info->netlock, flags);
51202 return -EBUSY;
51203 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51204 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51205
51206 /* return error if TTY interface open */
51207 - if (info->port.count)
51208 + if (atomic_read(&info->port.count))
51209 return -EBUSY;
51210
51211 if (cmd != SIOCWANDEV)
51212 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51213 if (port == NULL)
51214 continue;
51215 spin_lock(&port->lock);
51216 - if ((port->port.count || port->netcount) &&
51217 + if ((atomic_read(&port->port.count) || port->netcount) &&
51218 port->pending_bh && !port->bh_running &&
51219 !port->bh_requested) {
51220 DBGISR(("%s bh queued\n", port->device_name));
51221 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51222 spin_lock_irqsave(&info->lock, flags);
51223 if (!tty_hung_up_p(filp)) {
51224 extra_count = true;
51225 - port->count--;
51226 + atomic_dec(&port->count);
51227 }
51228 spin_unlock_irqrestore(&info->lock, flags);
51229 port->blocked_open++;
51230 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51231 remove_wait_queue(&port->open_wait, &wait);
51232
51233 if (extra_count)
51234 - port->count++;
51235 + atomic_inc(&port->count);
51236 port->blocked_open--;
51237
51238 if (!retval)
51239 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51240 index 144202e..4ccb07d 100644
51241 --- a/drivers/tty/synclinkmp.c
51242 +++ b/drivers/tty/synclinkmp.c
51243 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51244
51245 if (debug_level >= DEBUG_LEVEL_INFO)
51246 printk("%s(%d):%s open(), old ref count = %d\n",
51247 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51248 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51249
51250 /* If port is closing, signal caller to try again */
51251 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51252 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51253 spin_unlock_irqrestore(&info->netlock, flags);
51254 goto cleanup;
51255 }
51256 - info->port.count++;
51257 + atomic_inc(&info->port.count);
51258 spin_unlock_irqrestore(&info->netlock, flags);
51259
51260 - if (info->port.count == 1) {
51261 + if (atomic_read(&info->port.count) == 1) {
51262 /* 1st open on this device, init hardware */
51263 retval = startup(info);
51264 if (retval < 0)
51265 @@ -796,8 +796,8 @@ cleanup:
51266 if (retval) {
51267 if (tty->count == 1)
51268 info->port.tty = NULL; /* tty layer will release tty struct */
51269 - if(info->port.count)
51270 - info->port.count--;
51271 + if(atomic_read(&info->port.count))
51272 + atomic_dec(&info->port.count);
51273 }
51274
51275 return retval;
51276 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51277
51278 if (debug_level >= DEBUG_LEVEL_INFO)
51279 printk("%s(%d):%s close() entry, count=%d\n",
51280 - __FILE__,__LINE__, info->device_name, info->port.count);
51281 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51282
51283 if (tty_port_close_start(&info->port, tty, filp) == 0)
51284 goto cleanup;
51285 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51286 cleanup:
51287 if (debug_level >= DEBUG_LEVEL_INFO)
51288 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51289 - tty->driver->name, info->port.count);
51290 + tty->driver->name, atomic_read(&info->port.count));
51291 }
51292
51293 /* Called by tty_hangup() when a hangup is signaled.
51294 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51295 shutdown(info);
51296
51297 spin_lock_irqsave(&info->port.lock, flags);
51298 - info->port.count = 0;
51299 + atomic_set(&info->port.count, 0);
51300 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51301 info->port.tty = NULL;
51302 spin_unlock_irqrestore(&info->port.lock, flags);
51303 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51304 unsigned short new_crctype;
51305
51306 /* return error if TTY interface open */
51307 - if (info->port.count)
51308 + if (atomic_read(&info->port.count))
51309 return -EBUSY;
51310
51311 switch (encoding)
51312 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51313
51314 /* arbitrate between network and tty opens */
51315 spin_lock_irqsave(&info->netlock, flags);
51316 - if (info->port.count != 0 || info->netcount != 0) {
51317 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51318 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51319 spin_unlock_irqrestore(&info->netlock, flags);
51320 return -EBUSY;
51321 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51322 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51323
51324 /* return error if TTY interface open */
51325 - if (info->port.count)
51326 + if (atomic_read(&info->port.count))
51327 return -EBUSY;
51328
51329 if (cmd != SIOCWANDEV)
51330 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51331 * do not request bottom half processing if the
51332 * device is not open in a normal mode.
51333 */
51334 - if ( port && (port->port.count || port->netcount) &&
51335 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51336 port->pending_bh && !port->bh_running &&
51337 !port->bh_requested ) {
51338 if ( debug_level >= DEBUG_LEVEL_ISR )
51339 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51340
51341 if (debug_level >= DEBUG_LEVEL_INFO)
51342 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51343 - __FILE__,__LINE__, tty->driver->name, port->count );
51344 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51345
51346 spin_lock_irqsave(&info->lock, flags);
51347 if (!tty_hung_up_p(filp)) {
51348 extra_count = true;
51349 - port->count--;
51350 + atomic_dec(&port->count);
51351 }
51352 spin_unlock_irqrestore(&info->lock, flags);
51353 port->blocked_open++;
51354 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51355
51356 if (debug_level >= DEBUG_LEVEL_INFO)
51357 printk("%s(%d):%s block_til_ready() count=%d\n",
51358 - __FILE__,__LINE__, tty->driver->name, port->count );
51359 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51360
51361 tty_unlock(tty);
51362 schedule();
51363 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51364 remove_wait_queue(&port->open_wait, &wait);
51365
51366 if (extra_count)
51367 - port->count++;
51368 + atomic_inc(&port->count);
51369 port->blocked_open--;
51370
51371 if (debug_level >= DEBUG_LEVEL_INFO)
51372 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51373 - __FILE__,__LINE__, tty->driver->name, port->count );
51374 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51375
51376 if (!retval)
51377 port->flags |= ASYNC_NORMAL_ACTIVE;
51378 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51379 index ce396ec..04a37be 100644
51380 --- a/drivers/tty/sysrq.c
51381 +++ b/drivers/tty/sysrq.c
51382 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51383 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51384 size_t count, loff_t *ppos)
51385 {
51386 - if (count) {
51387 + if (count && capable(CAP_SYS_ADMIN)) {
51388 char c;
51389
51390 if (get_user(c, buf))
51391 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51392 index d3448a9..28e8db0 100644
51393 --- a/drivers/tty/tty_io.c
51394 +++ b/drivers/tty/tty_io.c
51395 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51396
51397 void tty_default_fops(struct file_operations *fops)
51398 {
51399 - *fops = tty_fops;
51400 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51401 }
51402
51403 /*
51404 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51405 index 2d822aa..a566234 100644
51406 --- a/drivers/tty/tty_ldisc.c
51407 +++ b/drivers/tty/tty_ldisc.c
51408 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51409 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51410 tty_ldiscs[disc] = new_ldisc;
51411 new_ldisc->num = disc;
51412 - new_ldisc->refcount = 0;
51413 + atomic_set(&new_ldisc->refcount, 0);
51414 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51415
51416 return ret;
51417 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51418 return -EINVAL;
51419
51420 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51421 - if (tty_ldiscs[disc]->refcount)
51422 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51423 ret = -EBUSY;
51424 else
51425 tty_ldiscs[disc] = NULL;
51426 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51427 if (ldops) {
51428 ret = ERR_PTR(-EAGAIN);
51429 if (try_module_get(ldops->owner)) {
51430 - ldops->refcount++;
51431 + atomic_inc(&ldops->refcount);
51432 ret = ldops;
51433 }
51434 }
51435 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51436 unsigned long flags;
51437
51438 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51439 - ldops->refcount--;
51440 + atomic_dec(&ldops->refcount);
51441 module_put(ldops->owner);
51442 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51443 }
51444 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51445 index 3f746c8..2f2fcaa 100644
51446 --- a/drivers/tty/tty_port.c
51447 +++ b/drivers/tty/tty_port.c
51448 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51449 unsigned long flags;
51450
51451 spin_lock_irqsave(&port->lock, flags);
51452 - port->count = 0;
51453 + atomic_set(&port->count, 0);
51454 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51455 tty = port->tty;
51456 if (tty)
51457 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51458 /* The port lock protects the port counts */
51459 spin_lock_irqsave(&port->lock, flags);
51460 if (!tty_hung_up_p(filp))
51461 - port->count--;
51462 + atomic_dec(&port->count);
51463 port->blocked_open++;
51464 spin_unlock_irqrestore(&port->lock, flags);
51465
51466 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51467 we must not mess that up further */
51468 spin_lock_irqsave(&port->lock, flags);
51469 if (!tty_hung_up_p(filp))
51470 - port->count++;
51471 + atomic_inc(&port->count);
51472 port->blocked_open--;
51473 if (retval == 0)
51474 port->flags |= ASYNC_NORMAL_ACTIVE;
51475 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51476 return 0;
51477 }
51478
51479 - if (tty->count == 1 && port->count != 1) {
51480 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51481 printk(KERN_WARNING
51482 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51483 - port->count);
51484 - port->count = 1;
51485 + atomic_read(&port->count));
51486 + atomic_set(&port->count, 1);
51487 }
51488 - if (--port->count < 0) {
51489 + if (atomic_dec_return(&port->count) < 0) {
51490 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51491 - port->count);
51492 - port->count = 0;
51493 + atomic_read(&port->count));
51494 + atomic_set(&port->count, 0);
51495 }
51496
51497 - if (port->count) {
51498 + if (atomic_read(&port->count)) {
51499 spin_unlock_irqrestore(&port->lock, flags);
51500 return 0;
51501 }
51502 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51503 {
51504 spin_lock_irq(&port->lock);
51505 if (!tty_hung_up_p(filp))
51506 - ++port->count;
51507 + atomic_inc(&port->count);
51508 spin_unlock_irq(&port->lock);
51509 tty_port_tty_set(port, tty);
51510
51511 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51512 index d0e3a44..5f8b754 100644
51513 --- a/drivers/tty/vt/keyboard.c
51514 +++ b/drivers/tty/vt/keyboard.c
51515 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51516 kbd->kbdmode == VC_OFF) &&
51517 value != KVAL(K_SAK))
51518 return; /* SAK is allowed even in raw mode */
51519 +
51520 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51521 + {
51522 + void *func = fn_handler[value];
51523 + if (func == fn_show_state || func == fn_show_ptregs ||
51524 + func == fn_show_mem)
51525 + return;
51526 + }
51527 +#endif
51528 +
51529 fn_handler[value](vc);
51530 }
51531
51532 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51533 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51534 return -EFAULT;
51535
51536 - if (!capable(CAP_SYS_TTY_CONFIG))
51537 - perm = 0;
51538 -
51539 switch (cmd) {
51540 case KDGKBENT:
51541 /* Ensure another thread doesn't free it under us */
51542 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51543 spin_unlock_irqrestore(&kbd_event_lock, flags);
51544 return put_user(val, &user_kbe->kb_value);
51545 case KDSKBENT:
51546 + if (!capable(CAP_SYS_TTY_CONFIG))
51547 + perm = 0;
51548 +
51549 if (!perm)
51550 return -EPERM;
51551 if (!i && v == K_NOSUCHMAP) {
51552 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51553 int i, j, k;
51554 int ret;
51555
51556 - if (!capable(CAP_SYS_TTY_CONFIG))
51557 - perm = 0;
51558 -
51559 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51560 if (!kbs) {
51561 ret = -ENOMEM;
51562 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51563 kfree(kbs);
51564 return ((p && *p) ? -EOVERFLOW : 0);
51565 case KDSKBSENT:
51566 + if (!capable(CAP_SYS_TTY_CONFIG))
51567 + perm = 0;
51568 +
51569 if (!perm) {
51570 ret = -EPERM;
51571 goto reterr;
51572 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51573 index a673e5b..36e5d32 100644
51574 --- a/drivers/uio/uio.c
51575 +++ b/drivers/uio/uio.c
51576 @@ -25,6 +25,7 @@
51577 #include <linux/kobject.h>
51578 #include <linux/cdev.h>
51579 #include <linux/uio_driver.h>
51580 +#include <asm/local.h>
51581
51582 #define UIO_MAX_DEVICES (1U << MINORBITS)
51583
51584 @@ -32,7 +33,7 @@ struct uio_device {
51585 struct module *owner;
51586 struct device *dev;
51587 int minor;
51588 - atomic_t event;
51589 + atomic_unchecked_t event;
51590 struct fasync_struct *async_queue;
51591 wait_queue_head_t wait;
51592 struct uio_info *info;
51593 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51594 struct device_attribute *attr, char *buf)
51595 {
51596 struct uio_device *idev = dev_get_drvdata(dev);
51597 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51598 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51599 }
51600 static DEVICE_ATTR_RO(event);
51601
51602 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51603 {
51604 struct uio_device *idev = info->uio_dev;
51605
51606 - atomic_inc(&idev->event);
51607 + atomic_inc_unchecked(&idev->event);
51608 wake_up_interruptible(&idev->wait);
51609 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51610 }
51611 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51612 }
51613
51614 listener->dev = idev;
51615 - listener->event_count = atomic_read(&idev->event);
51616 + listener->event_count = atomic_read_unchecked(&idev->event);
51617 filep->private_data = listener;
51618
51619 if (idev->info->open) {
51620 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51621 return -EIO;
51622
51623 poll_wait(filep, &idev->wait, wait);
51624 - if (listener->event_count != atomic_read(&idev->event))
51625 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51626 return POLLIN | POLLRDNORM;
51627 return 0;
51628 }
51629 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51630 do {
51631 set_current_state(TASK_INTERRUPTIBLE);
51632
51633 - event_count = atomic_read(&idev->event);
51634 + event_count = atomic_read_unchecked(&idev->event);
51635 if (event_count != listener->event_count) {
51636 if (copy_to_user(buf, &event_count, count))
51637 retval = -EFAULT;
51638 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51639 static int uio_find_mem_index(struct vm_area_struct *vma)
51640 {
51641 struct uio_device *idev = vma->vm_private_data;
51642 + unsigned long size;
51643
51644 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51645 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51646 + size = idev->info->mem[vma->vm_pgoff].size;
51647 + if (size == 0)
51648 + return -1;
51649 + if (vma->vm_end - vma->vm_start > size)
51650 return -1;
51651 return (int)vma->vm_pgoff;
51652 }
51653 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51654 idev->owner = owner;
51655 idev->info = info;
51656 init_waitqueue_head(&idev->wait);
51657 - atomic_set(&idev->event, 0);
51658 + atomic_set_unchecked(&idev->event, 0);
51659
51660 ret = uio_get_minor(idev);
51661 if (ret)
51662 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51663 index 813d4d3..a71934f 100644
51664 --- a/drivers/usb/atm/cxacru.c
51665 +++ b/drivers/usb/atm/cxacru.c
51666 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51667 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51668 if (ret < 2)
51669 return -EINVAL;
51670 - if (index < 0 || index > 0x7f)
51671 + if (index > 0x7f)
51672 return -EINVAL;
51673 pos += tmp;
51674
51675 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51676 index dada014..1d0d517 100644
51677 --- a/drivers/usb/atm/usbatm.c
51678 +++ b/drivers/usb/atm/usbatm.c
51679 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51680 if (printk_ratelimit())
51681 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51682 __func__, vpi, vci);
51683 - atomic_inc(&vcc->stats->rx_err);
51684 + atomic_inc_unchecked(&vcc->stats->rx_err);
51685 return;
51686 }
51687
51688 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51689 if (length > ATM_MAX_AAL5_PDU) {
51690 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51691 __func__, length, vcc);
51692 - atomic_inc(&vcc->stats->rx_err);
51693 + atomic_inc_unchecked(&vcc->stats->rx_err);
51694 goto out;
51695 }
51696
51697 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51698 if (sarb->len < pdu_length) {
51699 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51700 __func__, pdu_length, sarb->len, vcc);
51701 - atomic_inc(&vcc->stats->rx_err);
51702 + atomic_inc_unchecked(&vcc->stats->rx_err);
51703 goto out;
51704 }
51705
51706 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51707 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51708 __func__, vcc);
51709 - atomic_inc(&vcc->stats->rx_err);
51710 + atomic_inc_unchecked(&vcc->stats->rx_err);
51711 goto out;
51712 }
51713
51714 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51715 if (printk_ratelimit())
51716 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51717 __func__, length);
51718 - atomic_inc(&vcc->stats->rx_drop);
51719 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51720 goto out;
51721 }
51722
51723 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51724
51725 vcc->push(vcc, skb);
51726
51727 - atomic_inc(&vcc->stats->rx);
51728 + atomic_inc_unchecked(&vcc->stats->rx);
51729 out:
51730 skb_trim(sarb, 0);
51731 }
51732 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51733 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51734
51735 usbatm_pop(vcc, skb);
51736 - atomic_inc(&vcc->stats->tx);
51737 + atomic_inc_unchecked(&vcc->stats->tx);
51738
51739 skb = skb_dequeue(&instance->sndqueue);
51740 }
51741 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51742 if (!left--)
51743 return sprintf(page,
51744 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51745 - atomic_read(&atm_dev->stats.aal5.tx),
51746 - atomic_read(&atm_dev->stats.aal5.tx_err),
51747 - atomic_read(&atm_dev->stats.aal5.rx),
51748 - atomic_read(&atm_dev->stats.aal5.rx_err),
51749 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51750 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51751 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51752 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51753 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51754 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51755
51756 if (!left--) {
51757 if (instance->disconnected)
51758 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51759 index 2a3bbdf..91d72cf 100644
51760 --- a/drivers/usb/core/devices.c
51761 +++ b/drivers/usb/core/devices.c
51762 @@ -126,7 +126,7 @@ static const char format_endpt[] =
51763 * time it gets called.
51764 */
51765 static struct device_connect_event {
51766 - atomic_t count;
51767 + atomic_unchecked_t count;
51768 wait_queue_head_t wait;
51769 } device_event = {
51770 .count = ATOMIC_INIT(1),
51771 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51772
51773 void usbfs_conn_disc_event(void)
51774 {
51775 - atomic_add(2, &device_event.count);
51776 + atomic_add_unchecked(2, &device_event.count);
51777 wake_up(&device_event.wait);
51778 }
51779
51780 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51781
51782 poll_wait(file, &device_event.wait, wait);
51783
51784 - event_count = atomic_read(&device_event.count);
51785 + event_count = atomic_read_unchecked(&device_event.count);
51786 if (file->f_version != event_count) {
51787 file->f_version = event_count;
51788 return POLLIN | POLLRDNORM;
51789 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51790 index 90e18f6..5eeda46 100644
51791 --- a/drivers/usb/core/devio.c
51792 +++ b/drivers/usb/core/devio.c
51793 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51794 struct dev_state *ps = file->private_data;
51795 struct usb_device *dev = ps->dev;
51796 ssize_t ret = 0;
51797 - unsigned len;
51798 + size_t len;
51799 loff_t pos;
51800 int i;
51801
51802 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51803 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51804 struct usb_config_descriptor *config =
51805 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51806 - unsigned int length = le16_to_cpu(config->wTotalLength);
51807 + size_t length = le16_to_cpu(config->wTotalLength);
51808
51809 if (*ppos < pos + length) {
51810
51811 /* The descriptor may claim to be longer than it
51812 * really is. Here is the actual allocated length. */
51813 - unsigned alloclen =
51814 + size_t alloclen =
51815 le16_to_cpu(dev->config[i].desc.wTotalLength);
51816
51817 - len = length - (*ppos - pos);
51818 + len = length + pos - *ppos;
51819 if (len > nbytes)
51820 len = nbytes;
51821
51822 /* Simply don't write (skip over) unallocated parts */
51823 if (alloclen > (*ppos - pos)) {
51824 - alloclen -= (*ppos - pos);
51825 + alloclen = alloclen + pos - *ppos;
51826 if (copy_to_user(buf,
51827 dev->rawdescriptors[i] + (*ppos - pos),
51828 min(len, alloclen))) {
51829 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51830 index 2518c32..1c201bb 100644
51831 --- a/drivers/usb/core/hcd.c
51832 +++ b/drivers/usb/core/hcd.c
51833 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51834 */
51835 usb_get_urb(urb);
51836 atomic_inc(&urb->use_count);
51837 - atomic_inc(&urb->dev->urbnum);
51838 + atomic_inc_unchecked(&urb->dev->urbnum);
51839 usbmon_urb_submit(&hcd->self, urb);
51840
51841 /* NOTE requirements on root-hub callers (usbfs and the hub
51842 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51843 urb->hcpriv = NULL;
51844 INIT_LIST_HEAD(&urb->urb_list);
51845 atomic_dec(&urb->use_count);
51846 - atomic_dec(&urb->dev->urbnum);
51847 + atomic_dec_unchecked(&urb->dev->urbnum);
51848 if (atomic_read(&urb->reject))
51849 wake_up(&usb_kill_urb_queue);
51850 usb_put_urb(urb);
51851 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51852 index 64ea219..dbc1780 100644
51853 --- a/drivers/usb/core/hub.c
51854 +++ b/drivers/usb/core/hub.c
51855 @@ -27,6 +27,7 @@
51856 #include <linux/freezer.h>
51857 #include <linux/random.h>
51858 #include <linux/pm_qos.h>
51859 +#include <linux/grsecurity.h>
51860
51861 #include <asm/uaccess.h>
51862 #include <asm/byteorder.h>
51863 @@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51864 goto done;
51865 return;
51866 }
51867 +
51868 + if (gr_handle_new_usb())
51869 + goto done;
51870 +
51871 if (hub_is_superspeed(hub->hdev))
51872 unit_load = 150;
51873 else
51874 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51875 index f829a1a..e6c334a 100644
51876 --- a/drivers/usb/core/message.c
51877 +++ b/drivers/usb/core/message.c
51878 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51879 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51880 * error number.
51881 */
51882 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51883 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51884 __u8 requesttype, __u16 value, __u16 index, void *data,
51885 __u16 size, int timeout)
51886 {
51887 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51888 * If successful, 0. Otherwise a negative error number. The number of actual
51889 * bytes transferred will be stored in the @actual_length paramater.
51890 */
51891 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51892 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51893 void *data, int len, int *actual_length, int timeout)
51894 {
51895 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51896 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51897 * bytes transferred will be stored in the @actual_length parameter.
51898 *
51899 */
51900 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51901 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51902 void *data, int len, int *actual_length, int timeout)
51903 {
51904 struct urb *urb;
51905 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51906 index 1236c60..d47a51c 100644
51907 --- a/drivers/usb/core/sysfs.c
51908 +++ b/drivers/usb/core/sysfs.c
51909 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51910 struct usb_device *udev;
51911
51912 udev = to_usb_device(dev);
51913 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51914 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51915 }
51916 static DEVICE_ATTR_RO(urbnum);
51917
51918 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51919 index 4d11449..f4ccabf 100644
51920 --- a/drivers/usb/core/usb.c
51921 +++ b/drivers/usb/core/usb.c
51922 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51923 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51924 dev->state = USB_STATE_ATTACHED;
51925 dev->lpm_disable_count = 1;
51926 - atomic_set(&dev->urbnum, 0);
51927 + atomic_set_unchecked(&dev->urbnum, 0);
51928
51929 INIT_LIST_HEAD(&dev->ep0.urb_list);
51930 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51931 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51932 index 2da0a5a..4870e09 100644
51933 --- a/drivers/usb/dwc3/gadget.c
51934 +++ b/drivers/usb/dwc3/gadget.c
51935 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51936 if (!usb_endpoint_xfer_isoc(desc))
51937 return 0;
51938
51939 - memset(&trb_link, 0, sizeof(trb_link));
51940 -
51941 /* Link TRB for ISOC. The HWO bit is never reset */
51942 trb_st_hw = &dep->trb_pool[0];
51943
51944 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51945 index 8cfc319..4868255 100644
51946 --- a/drivers/usb/early/ehci-dbgp.c
51947 +++ b/drivers/usb/early/ehci-dbgp.c
51948 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51949
51950 #ifdef CONFIG_KGDB
51951 static struct kgdb_io kgdbdbgp_io_ops;
51952 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51953 +static struct kgdb_io kgdbdbgp_io_ops_console;
51954 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51955 #else
51956 #define dbgp_kgdb_mode (0)
51957 #endif
51958 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51959 .write_char = kgdbdbgp_write_char,
51960 };
51961
51962 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51963 + .name = "kgdbdbgp",
51964 + .read_char = kgdbdbgp_read_char,
51965 + .write_char = kgdbdbgp_write_char,
51966 + .is_console = 1
51967 +};
51968 +
51969 static int kgdbdbgp_wait_time;
51970
51971 static int __init kgdbdbgp_parse_config(char *str)
51972 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51973 ptr++;
51974 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51975 }
51976 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51977 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51978 + if (early_dbgp_console.index != -1)
51979 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51980 + else
51981 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51982
51983 return 0;
51984 }
51985 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
51986 index 2b4c82d..06a8ee6 100644
51987 --- a/drivers/usb/gadget/f_uac1.c
51988 +++ b/drivers/usb/gadget/f_uac1.c
51989 @@ -13,6 +13,7 @@
51990 #include <linux/kernel.h>
51991 #include <linux/device.h>
51992 #include <linux/atomic.h>
51993 +#include <linux/module.h>
51994
51995 #include "u_uac1.h"
51996
51997 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51998 index ad0aca8..8ff84865 100644
51999 --- a/drivers/usb/gadget/u_serial.c
52000 +++ b/drivers/usb/gadget/u_serial.c
52001 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52002 spin_lock_irq(&port->port_lock);
52003
52004 /* already open? Great. */
52005 - if (port->port.count) {
52006 + if (atomic_read(&port->port.count)) {
52007 status = 0;
52008 - port->port.count++;
52009 + atomic_inc(&port->port.count);
52010
52011 /* currently opening/closing? wait ... */
52012 } else if (port->openclose) {
52013 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52014 tty->driver_data = port;
52015 port->port.tty = tty;
52016
52017 - port->port.count = 1;
52018 + atomic_set(&port->port.count, 1);
52019 port->openclose = false;
52020
52021 /* if connected, start the I/O stream */
52022 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52023
52024 spin_lock_irq(&port->port_lock);
52025
52026 - if (port->port.count != 1) {
52027 - if (port->port.count == 0)
52028 + if (atomic_read(&port->port.count) != 1) {
52029 + if (atomic_read(&port->port.count) == 0)
52030 WARN_ON(1);
52031 else
52032 - --port->port.count;
52033 + atomic_dec(&port->port.count);
52034 goto exit;
52035 }
52036
52037 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52038 * and sleep if necessary
52039 */
52040 port->openclose = true;
52041 - port->port.count = 0;
52042 + atomic_set(&port->port.count, 0);
52043
52044 gser = port->port_usb;
52045 if (gser && gser->disconnect)
52046 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52047 int cond;
52048
52049 spin_lock_irq(&port->port_lock);
52050 - cond = (port->port.count == 0) && !port->openclose;
52051 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52052 spin_unlock_irq(&port->port_lock);
52053 return cond;
52054 }
52055 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52056 /* if it's already open, start I/O ... and notify the serial
52057 * protocol about open/close status (connect/disconnect).
52058 */
52059 - if (port->port.count) {
52060 + if (atomic_read(&port->port.count)) {
52061 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52062 gs_start_io(port);
52063 if (gser->connect)
52064 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52065
52066 port->port_usb = NULL;
52067 gser->ioport = NULL;
52068 - if (port->port.count > 0 || port->openclose) {
52069 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52070 wake_up_interruptible(&port->drain_wait);
52071 if (port->port.tty)
52072 tty_hangup(port->port.tty);
52073 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52074
52075 /* finally, free any unused/unusable I/O buffers */
52076 spin_lock_irqsave(&port->port_lock, flags);
52077 - if (port->port.count == 0 && !port->openclose)
52078 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52079 gs_buf_free(&port->port_write_buf);
52080 gs_free_requests(gser->out, &port->read_pool, NULL);
52081 gs_free_requests(gser->out, &port->read_queue, NULL);
52082 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52083 index 7a55fea..cc0ed4f 100644
52084 --- a/drivers/usb/gadget/u_uac1.c
52085 +++ b/drivers/usb/gadget/u_uac1.c
52086 @@ -16,6 +16,7 @@
52087 #include <linux/ctype.h>
52088 #include <linux/random.h>
52089 #include <linux/syscalls.h>
52090 +#include <linux/module.h>
52091
52092 #include "u_uac1.h"
52093
52094 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52095 index 7ae0c4d..35521b7 100644
52096 --- a/drivers/usb/host/ehci-hub.c
52097 +++ b/drivers/usb/host/ehci-hub.c
52098 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52099 urb->transfer_flags = URB_DIR_IN;
52100 usb_get_urb(urb);
52101 atomic_inc(&urb->use_count);
52102 - atomic_inc(&urb->dev->urbnum);
52103 + atomic_inc_unchecked(&urb->dev->urbnum);
52104 urb->setup_dma = dma_map_single(
52105 hcd->self.controller,
52106 urb->setup_packet,
52107 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52108 urb->status = -EINPROGRESS;
52109 usb_get_urb(urb);
52110 atomic_inc(&urb->use_count);
52111 - atomic_inc(&urb->dev->urbnum);
52112 + atomic_inc_unchecked(&urb->dev->urbnum);
52113 retval = submit_single_step_set_feature(hcd, urb, 0);
52114 if (!retval && !wait_for_completion_timeout(&done,
52115 msecs_to_jiffies(2000))) {
52116 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52117 index ba6a5d6..f88f7f3 100644
52118 --- a/drivers/usb/misc/appledisplay.c
52119 +++ b/drivers/usb/misc/appledisplay.c
52120 @@ -83,7 +83,7 @@ struct appledisplay {
52121 spinlock_t lock;
52122 };
52123
52124 -static atomic_t count_displays = ATOMIC_INIT(0);
52125 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52126 static struct workqueue_struct *wq;
52127
52128 static void appledisplay_complete(struct urb *urb)
52129 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52130
52131 /* Register backlight device */
52132 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52133 - atomic_inc_return(&count_displays) - 1);
52134 + atomic_inc_return_unchecked(&count_displays) - 1);
52135 memset(&props, 0, sizeof(struct backlight_properties));
52136 props.type = BACKLIGHT_RAW;
52137 props.max_brightness = 0xff;
52138 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52139 index 8d7fc48..01c4986 100644
52140 --- a/drivers/usb/serial/console.c
52141 +++ b/drivers/usb/serial/console.c
52142 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52143
52144 info->port = port;
52145
52146 - ++port->port.count;
52147 + atomic_inc(&port->port.count);
52148 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52149 if (serial->type->set_termios) {
52150 /*
52151 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52152 }
52153 /* Now that any required fake tty operations are completed restore
52154 * the tty port count */
52155 - --port->port.count;
52156 + atomic_dec(&port->port.count);
52157 /* The console is special in terms of closing the device so
52158 * indicate this port is now acting as a system console. */
52159 port->port.console = 1;
52160 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52161 free_tty:
52162 kfree(tty);
52163 reset_open_count:
52164 - port->port.count = 0;
52165 + atomic_set(&port->port.count, 0);
52166 usb_autopm_put_interface(serial->interface);
52167 error_get_interface:
52168 usb_serial_put(serial);
52169 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52170 static void usb_console_write(struct console *co,
52171 const char *buf, unsigned count)
52172 {
52173 - static struct usbcons_info *info = &usbcons_info;
52174 + struct usbcons_info *info = &usbcons_info;
52175 struct usb_serial_port *port = info->port;
52176 struct usb_serial *serial;
52177 int retval = -ENODEV;
52178 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52179 index 75f70f0..d467e1a 100644
52180 --- a/drivers/usb/storage/usb.h
52181 +++ b/drivers/usb/storage/usb.h
52182 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52183 __u8 useProtocol;
52184 __u8 useTransport;
52185 int (*initFunction)(struct us_data *);
52186 -};
52187 +} __do_const;
52188
52189
52190 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52191 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52192 index a2ef84b..aa7c2b8 100644
52193 --- a/drivers/usb/wusbcore/wa-hc.h
52194 +++ b/drivers/usb/wusbcore/wa-hc.h
52195 @@ -225,7 +225,7 @@ struct wahc {
52196 spinlock_t xfer_list_lock;
52197 struct work_struct xfer_enqueue_work;
52198 struct work_struct xfer_error_work;
52199 - atomic_t xfer_id_count;
52200 + atomic_unchecked_t xfer_id_count;
52201
52202 kernel_ulong_t quirks;
52203 };
52204 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52205 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52206 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52207 wa->dto_in_use = 0;
52208 - atomic_set(&wa->xfer_id_count, 1);
52209 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52210 }
52211
52212 /**
52213 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52214 index 3cd96e9..bd7c58d 100644
52215 --- a/drivers/usb/wusbcore/wa-xfer.c
52216 +++ b/drivers/usb/wusbcore/wa-xfer.c
52217 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52218 */
52219 static void wa_xfer_id_init(struct wa_xfer *xfer)
52220 {
52221 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52222 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52223 }
52224
52225 /* Return the xfer's ID. */
52226 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52227 index 21271d8..45b55a0 100644
52228 --- a/drivers/vfio/vfio.c
52229 +++ b/drivers/vfio/vfio.c
52230 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52231 return 0;
52232
52233 /* TODO Prevent device auto probing */
52234 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52235 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52236 iommu_group_id(group->iommu_group));
52237
52238 return 0;
52239 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52240 index 5174eba..451e6bc 100644
52241 --- a/drivers/vhost/vringh.c
52242 +++ b/drivers/vhost/vringh.c
52243 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52244 /* Userspace access helpers: in this case, addresses are really userspace. */
52245 static inline int getu16_user(u16 *val, const u16 *p)
52246 {
52247 - return get_user(*val, (__force u16 __user *)p);
52248 + return get_user(*val, (u16 __force_user *)p);
52249 }
52250
52251 static inline int putu16_user(u16 *p, u16 val)
52252 {
52253 - return put_user(val, (__force u16 __user *)p);
52254 + return put_user(val, (u16 __force_user *)p);
52255 }
52256
52257 static inline int copydesc_user(void *dst, const void *src, size_t len)
52258 {
52259 - return copy_from_user(dst, (__force void __user *)src, len) ?
52260 + return copy_from_user(dst, (void __force_user *)src, len) ?
52261 -EFAULT : 0;
52262 }
52263
52264 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52265 const struct vring_used_elem *src,
52266 unsigned int num)
52267 {
52268 - return copy_to_user((__force void __user *)dst, src,
52269 + return copy_to_user((void __force_user *)dst, src,
52270 sizeof(*dst) * num) ? -EFAULT : 0;
52271 }
52272
52273 static inline int xfer_from_user(void *src, void *dst, size_t len)
52274 {
52275 - return copy_from_user(dst, (__force void __user *)src, len) ?
52276 + return copy_from_user(dst, (void __force_user *)src, len) ?
52277 -EFAULT : 0;
52278 }
52279
52280 static inline int xfer_to_user(void *dst, void *src, size_t len)
52281 {
52282 - return copy_to_user((__force void __user *)dst, src, len) ?
52283 + return copy_to_user((void __force_user *)dst, src, len) ?
52284 -EFAULT : 0;
52285 }
52286
52287 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52288 vrh->last_used_idx = 0;
52289 vrh->vring.num = num;
52290 /* vring expects kernel addresses, but only used via accessors. */
52291 - vrh->vring.desc = (__force struct vring_desc *)desc;
52292 - vrh->vring.avail = (__force struct vring_avail *)avail;
52293 - vrh->vring.used = (__force struct vring_used *)used;
52294 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52295 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52296 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52297 return 0;
52298 }
52299 EXPORT_SYMBOL(vringh_init_user);
52300 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52301
52302 static inline int putu16_kern(u16 *p, u16 val)
52303 {
52304 - ACCESS_ONCE(*p) = val;
52305 + ACCESS_ONCE_RW(*p) = val;
52306 return 0;
52307 }
52308
52309 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52310 index 1b0b233..6f34c2c 100644
52311 --- a/drivers/video/arcfb.c
52312 +++ b/drivers/video/arcfb.c
52313 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52314 return -ENOSPC;
52315
52316 err = 0;
52317 - if ((count + p) > fbmemlength) {
52318 + if (count > (fbmemlength - p)) {
52319 count = fbmemlength - p;
52320 err = -ENOSPC;
52321 }
52322 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52323 index 52108be..c7c110d 100644
52324 --- a/drivers/video/aty/aty128fb.c
52325 +++ b/drivers/video/aty/aty128fb.c
52326 @@ -149,7 +149,7 @@ enum {
52327 };
52328
52329 /* Must match above enum */
52330 -static char * const r128_family[] = {
52331 +static const char * const r128_family[] = {
52332 "AGP",
52333 "PCI",
52334 "PRO AGP",
52335 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52336 index 28fafbf..ae91651 100644
52337 --- a/drivers/video/aty/atyfb_base.c
52338 +++ b/drivers/video/aty/atyfb_base.c
52339 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52340 par->accel_flags = var->accel_flags; /* hack */
52341
52342 if (var->accel_flags) {
52343 - info->fbops->fb_sync = atyfb_sync;
52344 + pax_open_kernel();
52345 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52346 + pax_close_kernel();
52347 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52348 } else {
52349 - info->fbops->fb_sync = NULL;
52350 + pax_open_kernel();
52351 + *(void **)&info->fbops->fb_sync = NULL;
52352 + pax_close_kernel();
52353 info->flags |= FBINFO_HWACCEL_DISABLED;
52354 }
52355
52356 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52357 index 95ec042..e6affdd 100644
52358 --- a/drivers/video/aty/mach64_cursor.c
52359 +++ b/drivers/video/aty/mach64_cursor.c
52360 @@ -7,6 +7,7 @@
52361 #include <linux/string.h>
52362
52363 #include <asm/io.h>
52364 +#include <asm/pgtable.h>
52365
52366 #ifdef __sparc__
52367 #include <asm/fbio.h>
52368 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52369 info->sprite.buf_align = 16; /* and 64 lines tall. */
52370 info->sprite.flags = FB_PIXMAP_IO;
52371
52372 - info->fbops->fb_cursor = atyfb_cursor;
52373 + pax_open_kernel();
52374 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52375 + pax_close_kernel();
52376
52377 return 0;
52378 }
52379 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52380 index 84a110a..96312c3 100644
52381 --- a/drivers/video/backlight/kb3886_bl.c
52382 +++ b/drivers/video/backlight/kb3886_bl.c
52383 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52384 static unsigned long kb3886bl_flags;
52385 #define KB3886BL_SUSPENDED 0x01
52386
52387 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52388 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52389 {
52390 .ident = "Sahara Touch-iT",
52391 .matches = {
52392 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52393 index 900aa4e..6d49418 100644
52394 --- a/drivers/video/fb_defio.c
52395 +++ b/drivers/video/fb_defio.c
52396 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52397
52398 BUG_ON(!fbdefio);
52399 mutex_init(&fbdefio->lock);
52400 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52401 + pax_open_kernel();
52402 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52403 + pax_close_kernel();
52404 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52405 INIT_LIST_HEAD(&fbdefio->pagelist);
52406 if (fbdefio->delay == 0) /* set a default of 1 s */
52407 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52408 page->mapping = NULL;
52409 }
52410
52411 - info->fbops->fb_mmap = NULL;
52412 + *(void **)&info->fbops->fb_mmap = NULL;
52413 mutex_destroy(&fbdefio->lock);
52414 }
52415 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52416 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52417 index 7309ac7..be3c49c 100644
52418 --- a/drivers/video/fbmem.c
52419 +++ b/drivers/video/fbmem.c
52420 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52421 image->dx += image->width + 8;
52422 }
52423 } else if (rotate == FB_ROTATE_UD) {
52424 - for (x = 0; x < num && image->dx >= 0; x++) {
52425 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52426 info->fbops->fb_imageblit(info, image);
52427 image->dx -= image->width + 8;
52428 }
52429 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52430 image->dy += image->height + 8;
52431 }
52432 } else if (rotate == FB_ROTATE_CCW) {
52433 - for (x = 0; x < num && image->dy >= 0; x++) {
52434 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52435 info->fbops->fb_imageblit(info, image);
52436 image->dy -= image->height + 8;
52437 }
52438 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52439 return -EFAULT;
52440 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52441 return -EINVAL;
52442 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52443 + if (con2fb.framebuffer >= FB_MAX)
52444 return -EINVAL;
52445 if (!registered_fb[con2fb.framebuffer])
52446 request_module("fb%d", con2fb.framebuffer);
52447 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52448 __u32 data;
52449 int err;
52450
52451 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52452 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52453
52454 data = (__u32) (unsigned long) fix->smem_start;
52455 err |= put_user(data, &fix32->smem_start);
52456 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52457 index 130708f..cdac1a9 100644
52458 --- a/drivers/video/hyperv_fb.c
52459 +++ b/drivers/video/hyperv_fb.c
52460 @@ -233,7 +233,7 @@ static uint screen_fb_size;
52461 static inline int synthvid_send(struct hv_device *hdev,
52462 struct synthvid_msg *msg)
52463 {
52464 - static atomic64_t request_id = ATOMIC64_INIT(0);
52465 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52466 int ret;
52467
52468 msg->pipe_hdr.type = PIPE_MSG_DATA;
52469 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52470
52471 ret = vmbus_sendpacket(hdev->channel, msg,
52472 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52473 - atomic64_inc_return(&request_id),
52474 + atomic64_inc_return_unchecked(&request_id),
52475 VM_PKT_DATA_INBAND, 0);
52476
52477 if (ret)
52478 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52479 index 7672d2e..b56437f 100644
52480 --- a/drivers/video/i810/i810_accel.c
52481 +++ b/drivers/video/i810/i810_accel.c
52482 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52483 }
52484 }
52485 printk("ringbuffer lockup!!!\n");
52486 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52487 i810_report_error(mmio);
52488 par->dev_flags |= LOCKUP;
52489 info->pixmap.scan_align = 1;
52490 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52491 index 3c14e43..2630570 100644
52492 --- a/drivers/video/logo/logo_linux_clut224.ppm
52493 +++ b/drivers/video/logo/logo_linux_clut224.ppm
52494 @@ -2,1603 +2,1123 @@ P3
52495 # Standard 224-color Linux logo
52496 80 80
52497 255
52498 - 0 0 0 0 0 0 0 0 0 0 0 0
52499 - 0 0 0 0 0 0 0 0 0 0 0 0
52500 - 0 0 0 0 0 0 0 0 0 0 0 0
52501 - 0 0 0 0 0 0 0 0 0 0 0 0
52502 - 0 0 0 0 0 0 0 0 0 0 0 0
52503 - 0 0 0 0 0 0 0 0 0 0 0 0
52504 - 0 0 0 0 0 0 0 0 0 0 0 0
52505 - 0 0 0 0 0 0 0 0 0 0 0 0
52506 - 0 0 0 0 0 0 0 0 0 0 0 0
52507 - 6 6 6 6 6 6 10 10 10 10 10 10
52508 - 10 10 10 6 6 6 6 6 6 6 6 6
52509 - 0 0 0 0 0 0 0 0 0 0 0 0
52510 - 0 0 0 0 0 0 0 0 0 0 0 0
52511 - 0 0 0 0 0 0 0 0 0 0 0 0
52512 - 0 0 0 0 0 0 0 0 0 0 0 0
52513 - 0 0 0 0 0 0 0 0 0 0 0 0
52514 - 0 0 0 0 0 0 0 0 0 0 0 0
52515 - 0 0 0 0 0 0 0 0 0 0 0 0
52516 - 0 0 0 0 0 0 0 0 0 0 0 0
52517 - 0 0 0 0 0 0 0 0 0 0 0 0
52518 - 0 0 0 0 0 0 0 0 0 0 0 0
52519 - 0 0 0 0 0 0 0 0 0 0 0 0
52520 - 0 0 0 0 0 0 0 0 0 0 0 0
52521 - 0 0 0 0 0 0 0 0 0 0 0 0
52522 - 0 0 0 0 0 0 0 0 0 0 0 0
52523 - 0 0 0 0 0 0 0 0 0 0 0 0
52524 - 0 0 0 0 0 0 0 0 0 0 0 0
52525 - 0 0 0 0 0 0 0 0 0 0 0 0
52526 - 0 0 0 6 6 6 10 10 10 14 14 14
52527 - 22 22 22 26 26 26 30 30 30 34 34 34
52528 - 30 30 30 30 30 30 26 26 26 18 18 18
52529 - 14 14 14 10 10 10 6 6 6 0 0 0
52530 - 0 0 0 0 0 0 0 0 0 0 0 0
52531 - 0 0 0 0 0 0 0 0 0 0 0 0
52532 - 0 0 0 0 0 0 0 0 0 0 0 0
52533 - 0 0 0 0 0 0 0 0 0 0 0 0
52534 - 0 0 0 0 0 0 0 0 0 0 0 0
52535 - 0 0 0 0 0 0 0 0 0 0 0 0
52536 - 0 0 0 0 0 0 0 0 0 0 0 0
52537 - 0 0 0 0 0 0 0 0 0 0 0 0
52538 - 0 0 0 0 0 0 0 0 0 0 0 0
52539 - 0 0 0 0 0 1 0 0 1 0 0 0
52540 - 0 0 0 0 0 0 0 0 0 0 0 0
52541 - 0 0 0 0 0 0 0 0 0 0 0 0
52542 - 0 0 0 0 0 0 0 0 0 0 0 0
52543 - 0 0 0 0 0 0 0 0 0 0 0 0
52544 - 0 0 0 0 0 0 0 0 0 0 0 0
52545 - 0 0 0 0 0 0 0 0 0 0 0 0
52546 - 6 6 6 14 14 14 26 26 26 42 42 42
52547 - 54 54 54 66 66 66 78 78 78 78 78 78
52548 - 78 78 78 74 74 74 66 66 66 54 54 54
52549 - 42 42 42 26 26 26 18 18 18 10 10 10
52550 - 6 6 6 0 0 0 0 0 0 0 0 0
52551 - 0 0 0 0 0 0 0 0 0 0 0 0
52552 - 0 0 0 0 0 0 0 0 0 0 0 0
52553 - 0 0 0 0 0 0 0 0 0 0 0 0
52554 - 0 0 0 0 0 0 0 0 0 0 0 0
52555 - 0 0 0 0 0 0 0 0 0 0 0 0
52556 - 0 0 0 0 0 0 0 0 0 0 0 0
52557 - 0 0 0 0 0 0 0 0 0 0 0 0
52558 - 0 0 0 0 0 0 0 0 0 0 0 0
52559 - 0 0 1 0 0 0 0 0 0 0 0 0
52560 - 0 0 0 0 0 0 0 0 0 0 0 0
52561 - 0 0 0 0 0 0 0 0 0 0 0 0
52562 - 0 0 0 0 0 0 0 0 0 0 0 0
52563 - 0 0 0 0 0 0 0 0 0 0 0 0
52564 - 0 0 0 0 0 0 0 0 0 0 0 0
52565 - 0 0 0 0 0 0 0 0 0 10 10 10
52566 - 22 22 22 42 42 42 66 66 66 86 86 86
52567 - 66 66 66 38 38 38 38 38 38 22 22 22
52568 - 26 26 26 34 34 34 54 54 54 66 66 66
52569 - 86 86 86 70 70 70 46 46 46 26 26 26
52570 - 14 14 14 6 6 6 0 0 0 0 0 0
52571 - 0 0 0 0 0 0 0 0 0 0 0 0
52572 - 0 0 0 0 0 0 0 0 0 0 0 0
52573 - 0 0 0 0 0 0 0 0 0 0 0 0
52574 - 0 0 0 0 0 0 0 0 0 0 0 0
52575 - 0 0 0 0 0 0 0 0 0 0 0 0
52576 - 0 0 0 0 0 0 0 0 0 0 0 0
52577 - 0 0 0 0 0 0 0 0 0 0 0 0
52578 - 0 0 0 0 0 0 0 0 0 0 0 0
52579 - 0 0 1 0 0 1 0 0 1 0 0 0
52580 - 0 0 0 0 0 0 0 0 0 0 0 0
52581 - 0 0 0 0 0 0 0 0 0 0 0 0
52582 - 0 0 0 0 0 0 0 0 0 0 0 0
52583 - 0 0 0 0 0 0 0 0 0 0 0 0
52584 - 0 0 0 0 0 0 0 0 0 0 0 0
52585 - 0 0 0 0 0 0 10 10 10 26 26 26
52586 - 50 50 50 82 82 82 58 58 58 6 6 6
52587 - 2 2 6 2 2 6 2 2 6 2 2 6
52588 - 2 2 6 2 2 6 2 2 6 2 2 6
52589 - 6 6 6 54 54 54 86 86 86 66 66 66
52590 - 38 38 38 18 18 18 6 6 6 0 0 0
52591 - 0 0 0 0 0 0 0 0 0 0 0 0
52592 - 0 0 0 0 0 0 0 0 0 0 0 0
52593 - 0 0 0 0 0 0 0 0 0 0 0 0
52594 - 0 0 0 0 0 0 0 0 0 0 0 0
52595 - 0 0 0 0 0 0 0 0 0 0 0 0
52596 - 0 0 0 0 0 0 0 0 0 0 0 0
52597 - 0 0 0 0 0 0 0 0 0 0 0 0
52598 - 0 0 0 0 0 0 0 0 0 0 0 0
52599 - 0 0 0 0 0 0 0 0 0 0 0 0
52600 - 0 0 0 0 0 0 0 0 0 0 0 0
52601 - 0 0 0 0 0 0 0 0 0 0 0 0
52602 - 0 0 0 0 0 0 0 0 0 0 0 0
52603 - 0 0 0 0 0 0 0 0 0 0 0 0
52604 - 0 0 0 0 0 0 0 0 0 0 0 0
52605 - 0 0 0 6 6 6 22 22 22 50 50 50
52606 - 78 78 78 34 34 34 2 2 6 2 2 6
52607 - 2 2 6 2 2 6 2 2 6 2 2 6
52608 - 2 2 6 2 2 6 2 2 6 2 2 6
52609 - 2 2 6 2 2 6 6 6 6 70 70 70
52610 - 78 78 78 46 46 46 22 22 22 6 6 6
52611 - 0 0 0 0 0 0 0 0 0 0 0 0
52612 - 0 0 0 0 0 0 0 0 0 0 0 0
52613 - 0 0 0 0 0 0 0 0 0 0 0 0
52614 - 0 0 0 0 0 0 0 0 0 0 0 0
52615 - 0 0 0 0 0 0 0 0 0 0 0 0
52616 - 0 0 0 0 0 0 0 0 0 0 0 0
52617 - 0 0 0 0 0 0 0 0 0 0 0 0
52618 - 0 0 0 0 0 0 0 0 0 0 0 0
52619 - 0 0 1 0 0 1 0 0 1 0 0 0
52620 - 0 0 0 0 0 0 0 0 0 0 0 0
52621 - 0 0 0 0 0 0 0 0 0 0 0 0
52622 - 0 0 0 0 0 0 0 0 0 0 0 0
52623 - 0 0 0 0 0 0 0 0 0 0 0 0
52624 - 0 0 0 0 0 0 0 0 0 0 0 0
52625 - 6 6 6 18 18 18 42 42 42 82 82 82
52626 - 26 26 26 2 2 6 2 2 6 2 2 6
52627 - 2 2 6 2 2 6 2 2 6 2 2 6
52628 - 2 2 6 2 2 6 2 2 6 14 14 14
52629 - 46 46 46 34 34 34 6 6 6 2 2 6
52630 - 42 42 42 78 78 78 42 42 42 18 18 18
52631 - 6 6 6 0 0 0 0 0 0 0 0 0
52632 - 0 0 0 0 0 0 0 0 0 0 0 0
52633 - 0 0 0 0 0 0 0 0 0 0 0 0
52634 - 0 0 0 0 0 0 0 0 0 0 0 0
52635 - 0 0 0 0 0 0 0 0 0 0 0 0
52636 - 0 0 0 0 0 0 0 0 0 0 0 0
52637 - 0 0 0 0 0 0 0 0 0 0 0 0
52638 - 0 0 0 0 0 0 0 0 0 0 0 0
52639 - 0 0 1 0 0 0 0 0 1 0 0 0
52640 - 0 0 0 0 0 0 0 0 0 0 0 0
52641 - 0 0 0 0 0 0 0 0 0 0 0 0
52642 - 0 0 0 0 0 0 0 0 0 0 0 0
52643 - 0 0 0 0 0 0 0 0 0 0 0 0
52644 - 0 0 0 0 0 0 0 0 0 0 0 0
52645 - 10 10 10 30 30 30 66 66 66 58 58 58
52646 - 2 2 6 2 2 6 2 2 6 2 2 6
52647 - 2 2 6 2 2 6 2 2 6 2 2 6
52648 - 2 2 6 2 2 6 2 2 6 26 26 26
52649 - 86 86 86 101 101 101 46 46 46 10 10 10
52650 - 2 2 6 58 58 58 70 70 70 34 34 34
52651 - 10 10 10 0 0 0 0 0 0 0 0 0
52652 - 0 0 0 0 0 0 0 0 0 0 0 0
52653 - 0 0 0 0 0 0 0 0 0 0 0 0
52654 - 0 0 0 0 0 0 0 0 0 0 0 0
52655 - 0 0 0 0 0 0 0 0 0 0 0 0
52656 - 0 0 0 0 0 0 0 0 0 0 0 0
52657 - 0 0 0 0 0 0 0 0 0 0 0 0
52658 - 0 0 0 0 0 0 0 0 0 0 0 0
52659 - 0 0 1 0 0 1 0 0 1 0 0 0
52660 - 0 0 0 0 0 0 0 0 0 0 0 0
52661 - 0 0 0 0 0 0 0 0 0 0 0 0
52662 - 0 0 0 0 0 0 0 0 0 0 0 0
52663 - 0 0 0 0 0 0 0 0 0 0 0 0
52664 - 0 0 0 0 0 0 0 0 0 0 0 0
52665 - 14 14 14 42 42 42 86 86 86 10 10 10
52666 - 2 2 6 2 2 6 2 2 6 2 2 6
52667 - 2 2 6 2 2 6 2 2 6 2 2 6
52668 - 2 2 6 2 2 6 2 2 6 30 30 30
52669 - 94 94 94 94 94 94 58 58 58 26 26 26
52670 - 2 2 6 6 6 6 78 78 78 54 54 54
52671 - 22 22 22 6 6 6 0 0 0 0 0 0
52672 - 0 0 0 0 0 0 0 0 0 0 0 0
52673 - 0 0 0 0 0 0 0 0 0 0 0 0
52674 - 0 0 0 0 0 0 0 0 0 0 0 0
52675 - 0 0 0 0 0 0 0 0 0 0 0 0
52676 - 0 0 0 0 0 0 0 0 0 0 0 0
52677 - 0 0 0 0 0 0 0 0 0 0 0 0
52678 - 0 0 0 0 0 0 0 0 0 0 0 0
52679 - 0 0 0 0 0 0 0 0 0 0 0 0
52680 - 0 0 0 0 0 0 0 0 0 0 0 0
52681 - 0 0 0 0 0 0 0 0 0 0 0 0
52682 - 0 0 0 0 0 0 0 0 0 0 0 0
52683 - 0 0 0 0 0 0 0 0 0 0 0 0
52684 - 0 0 0 0 0 0 0 0 0 6 6 6
52685 - 22 22 22 62 62 62 62 62 62 2 2 6
52686 - 2 2 6 2 2 6 2 2 6 2 2 6
52687 - 2 2 6 2 2 6 2 2 6 2 2 6
52688 - 2 2 6 2 2 6 2 2 6 26 26 26
52689 - 54 54 54 38 38 38 18 18 18 10 10 10
52690 - 2 2 6 2 2 6 34 34 34 82 82 82
52691 - 38 38 38 14 14 14 0 0 0 0 0 0
52692 - 0 0 0 0 0 0 0 0 0 0 0 0
52693 - 0 0 0 0 0 0 0 0 0 0 0 0
52694 - 0 0 0 0 0 0 0 0 0 0 0 0
52695 - 0 0 0 0 0 0 0 0 0 0 0 0
52696 - 0 0 0 0 0 0 0 0 0 0 0 0
52697 - 0 0 0 0 0 0 0 0 0 0 0 0
52698 - 0 0 0 0 0 0 0 0 0 0 0 0
52699 - 0 0 0 0 0 1 0 0 1 0 0 0
52700 - 0 0 0 0 0 0 0 0 0 0 0 0
52701 - 0 0 0 0 0 0 0 0 0 0 0 0
52702 - 0 0 0 0 0 0 0 0 0 0 0 0
52703 - 0 0 0 0 0 0 0 0 0 0 0 0
52704 - 0 0 0 0 0 0 0 0 0 6 6 6
52705 - 30 30 30 78 78 78 30 30 30 2 2 6
52706 - 2 2 6 2 2 6 2 2 6 2 2 6
52707 - 2 2 6 2 2 6 2 2 6 2 2 6
52708 - 2 2 6 2 2 6 2 2 6 10 10 10
52709 - 10 10 10 2 2 6 2 2 6 2 2 6
52710 - 2 2 6 2 2 6 2 2 6 78 78 78
52711 - 50 50 50 18 18 18 6 6 6 0 0 0
52712 - 0 0 0 0 0 0 0 0 0 0 0 0
52713 - 0 0 0 0 0 0 0 0 0 0 0 0
52714 - 0 0 0 0 0 0 0 0 0 0 0 0
52715 - 0 0 0 0 0 0 0 0 0 0 0 0
52716 - 0 0 0 0 0 0 0 0 0 0 0 0
52717 - 0 0 0 0 0 0 0 0 0 0 0 0
52718 - 0 0 0 0 0 0 0 0 0 0 0 0
52719 - 0 0 1 0 0 0 0 0 0 0 0 0
52720 - 0 0 0 0 0 0 0 0 0 0 0 0
52721 - 0 0 0 0 0 0 0 0 0 0 0 0
52722 - 0 0 0 0 0 0 0 0 0 0 0 0
52723 - 0 0 0 0 0 0 0 0 0 0 0 0
52724 - 0 0 0 0 0 0 0 0 0 10 10 10
52725 - 38 38 38 86 86 86 14 14 14 2 2 6
52726 - 2 2 6 2 2 6 2 2 6 2 2 6
52727 - 2 2 6 2 2 6 2 2 6 2 2 6
52728 - 2 2 6 2 2 6 2 2 6 2 2 6
52729 - 2 2 6 2 2 6 2 2 6 2 2 6
52730 - 2 2 6 2 2 6 2 2 6 54 54 54
52731 - 66 66 66 26 26 26 6 6 6 0 0 0
52732 - 0 0 0 0 0 0 0 0 0 0 0 0
52733 - 0 0 0 0 0 0 0 0 0 0 0 0
52734 - 0 0 0 0 0 0 0 0 0 0 0 0
52735 - 0 0 0 0 0 0 0 0 0 0 0 0
52736 - 0 0 0 0 0 0 0 0 0 0 0 0
52737 - 0 0 0 0 0 0 0 0 0 0 0 0
52738 - 0 0 0 0 0 0 0 0 0 0 0 0
52739 - 0 0 0 0 0 1 0 0 1 0 0 0
52740 - 0 0 0 0 0 0 0 0 0 0 0 0
52741 - 0 0 0 0 0 0 0 0 0 0 0 0
52742 - 0 0 0 0 0 0 0 0 0 0 0 0
52743 - 0 0 0 0 0 0 0 0 0 0 0 0
52744 - 0 0 0 0 0 0 0 0 0 14 14 14
52745 - 42 42 42 82 82 82 2 2 6 2 2 6
52746 - 2 2 6 6 6 6 10 10 10 2 2 6
52747 - 2 2 6 2 2 6 2 2 6 2 2 6
52748 - 2 2 6 2 2 6 2 2 6 6 6 6
52749 - 14 14 14 10 10 10 2 2 6 2 2 6
52750 - 2 2 6 2 2 6 2 2 6 18 18 18
52751 - 82 82 82 34 34 34 10 10 10 0 0 0
52752 - 0 0 0 0 0 0 0 0 0 0 0 0
52753 - 0 0 0 0 0 0 0 0 0 0 0 0
52754 - 0 0 0 0 0 0 0 0 0 0 0 0
52755 - 0 0 0 0 0 0 0 0 0 0 0 0
52756 - 0 0 0 0 0 0 0 0 0 0 0 0
52757 - 0 0 0 0 0 0 0 0 0 0 0 0
52758 - 0 0 0 0 0 0 0 0 0 0 0 0
52759 - 0 0 1 0 0 0 0 0 0 0 0 0
52760 - 0 0 0 0 0 0 0 0 0 0 0 0
52761 - 0 0 0 0 0 0 0 0 0 0 0 0
52762 - 0 0 0 0 0 0 0 0 0 0 0 0
52763 - 0 0 0 0 0 0 0 0 0 0 0 0
52764 - 0 0 0 0 0 0 0 0 0 14 14 14
52765 - 46 46 46 86 86 86 2 2 6 2 2 6
52766 - 6 6 6 6 6 6 22 22 22 34 34 34
52767 - 6 6 6 2 2 6 2 2 6 2 2 6
52768 - 2 2 6 2 2 6 18 18 18 34 34 34
52769 - 10 10 10 50 50 50 22 22 22 2 2 6
52770 - 2 2 6 2 2 6 2 2 6 10 10 10
52771 - 86 86 86 42 42 42 14 14 14 0 0 0
52772 - 0 0 0 0 0 0 0 0 0 0 0 0
52773 - 0 0 0 0 0 0 0 0 0 0 0 0
52774 - 0 0 0 0 0 0 0 0 0 0 0 0
52775 - 0 0 0 0 0 0 0 0 0 0 0 0
52776 - 0 0 0 0 0 0 0 0 0 0 0 0
52777 - 0 0 0 0 0 0 0 0 0 0 0 0
52778 - 0 0 0 0 0 0 0 0 0 0 0 0
52779 - 0 0 1 0 0 1 0 0 1 0 0 0
52780 - 0 0 0 0 0 0 0 0 0 0 0 0
52781 - 0 0 0 0 0 0 0 0 0 0 0 0
52782 - 0 0 0 0 0 0 0 0 0 0 0 0
52783 - 0 0 0 0 0 0 0 0 0 0 0 0
52784 - 0 0 0 0 0 0 0 0 0 14 14 14
52785 - 46 46 46 86 86 86 2 2 6 2 2 6
52786 - 38 38 38 116 116 116 94 94 94 22 22 22
52787 - 22 22 22 2 2 6 2 2 6 2 2 6
52788 - 14 14 14 86 86 86 138 138 138 162 162 162
52789 -154 154 154 38 38 38 26 26 26 6 6 6
52790 - 2 2 6 2 2 6 2 2 6 2 2 6
52791 - 86 86 86 46 46 46 14 14 14 0 0 0
52792 - 0 0 0 0 0 0 0 0 0 0 0 0
52793 - 0 0 0 0 0 0 0 0 0 0 0 0
52794 - 0 0 0 0 0 0 0 0 0 0 0 0
52795 - 0 0 0 0 0 0 0 0 0 0 0 0
52796 - 0 0 0 0 0 0 0 0 0 0 0 0
52797 - 0 0 0 0 0 0 0 0 0 0 0 0
52798 - 0 0 0 0 0 0 0 0 0 0 0 0
52799 - 0 0 0 0 0 0 0 0 0 0 0 0
52800 - 0 0 0 0 0 0 0 0 0 0 0 0
52801 - 0 0 0 0 0 0 0 0 0 0 0 0
52802 - 0 0 0 0 0 0 0 0 0 0 0 0
52803 - 0 0 0 0 0 0 0 0 0 0 0 0
52804 - 0 0 0 0 0 0 0 0 0 14 14 14
52805 - 46 46 46 86 86 86 2 2 6 14 14 14
52806 -134 134 134 198 198 198 195 195 195 116 116 116
52807 - 10 10 10 2 2 6 2 2 6 6 6 6
52808 -101 98 89 187 187 187 210 210 210 218 218 218
52809 -214 214 214 134 134 134 14 14 14 6 6 6
52810 - 2 2 6 2 2 6 2 2 6 2 2 6
52811 - 86 86 86 50 50 50 18 18 18 6 6 6
52812 - 0 0 0 0 0 0 0 0 0 0 0 0
52813 - 0 0 0 0 0 0 0 0 0 0 0 0
52814 - 0 0 0 0 0 0 0 0 0 0 0 0
52815 - 0 0 0 0 0 0 0 0 0 0 0 0
52816 - 0 0 0 0 0 0 0 0 0 0 0 0
52817 - 0 0 0 0 0 0 0 0 0 0 0 0
52818 - 0 0 0 0 0 0 0 0 1 0 0 0
52819 - 0 0 1 0 0 1 0 0 1 0 0 0
52820 - 0 0 0 0 0 0 0 0 0 0 0 0
52821 - 0 0 0 0 0 0 0 0 0 0 0 0
52822 - 0 0 0 0 0 0 0 0 0 0 0 0
52823 - 0 0 0 0 0 0 0 0 0 0 0 0
52824 - 0 0 0 0 0 0 0 0 0 14 14 14
52825 - 46 46 46 86 86 86 2 2 6 54 54 54
52826 -218 218 218 195 195 195 226 226 226 246 246 246
52827 - 58 58 58 2 2 6 2 2 6 30 30 30
52828 -210 210 210 253 253 253 174 174 174 123 123 123
52829 -221 221 221 234 234 234 74 74 74 2 2 6
52830 - 2 2 6 2 2 6 2 2 6 2 2 6
52831 - 70 70 70 58 58 58 22 22 22 6 6 6
52832 - 0 0 0 0 0 0 0 0 0 0 0 0
52833 - 0 0 0 0 0 0 0 0 0 0 0 0
52834 - 0 0 0 0 0 0 0 0 0 0 0 0
52835 - 0 0 0 0 0 0 0 0 0 0 0 0
52836 - 0 0 0 0 0 0 0 0 0 0 0 0
52837 - 0 0 0 0 0 0 0 0 0 0 0 0
52838 - 0 0 0 0 0 0 0 0 0 0 0 0
52839 - 0 0 0 0 0 0 0 0 0 0 0 0
52840 - 0 0 0 0 0 0 0 0 0 0 0 0
52841 - 0 0 0 0 0 0 0 0 0 0 0 0
52842 - 0 0 0 0 0 0 0 0 0 0 0 0
52843 - 0 0 0 0 0 0 0 0 0 0 0 0
52844 - 0 0 0 0 0 0 0 0 0 14 14 14
52845 - 46 46 46 82 82 82 2 2 6 106 106 106
52846 -170 170 170 26 26 26 86 86 86 226 226 226
52847 -123 123 123 10 10 10 14 14 14 46 46 46
52848 -231 231 231 190 190 190 6 6 6 70 70 70
52849 - 90 90 90 238 238 238 158 158 158 2 2 6
52850 - 2 2 6 2 2 6 2 2 6 2 2 6
52851 - 70 70 70 58 58 58 22 22 22 6 6 6
52852 - 0 0 0 0 0 0 0 0 0 0 0 0
52853 - 0 0 0 0 0 0 0 0 0 0 0 0
52854 - 0 0 0 0 0 0 0 0 0 0 0 0
52855 - 0 0 0 0 0 0 0 0 0 0 0 0
52856 - 0 0 0 0 0 0 0 0 0 0 0 0
52857 - 0 0 0 0 0 0 0 0 0 0 0 0
52858 - 0 0 0 0 0 0 0 0 1 0 0 0
52859 - 0 0 1 0 0 1 0 0 1 0 0 0
52860 - 0 0 0 0 0 0 0 0 0 0 0 0
52861 - 0 0 0 0 0 0 0 0 0 0 0 0
52862 - 0 0 0 0 0 0 0 0 0 0 0 0
52863 - 0 0 0 0 0 0 0 0 0 0 0 0
52864 - 0 0 0 0 0 0 0 0 0 14 14 14
52865 - 42 42 42 86 86 86 6 6 6 116 116 116
52866 -106 106 106 6 6 6 70 70 70 149 149 149
52867 -128 128 128 18 18 18 38 38 38 54 54 54
52868 -221 221 221 106 106 106 2 2 6 14 14 14
52869 - 46 46 46 190 190 190 198 198 198 2 2 6
52870 - 2 2 6 2 2 6 2 2 6 2 2 6
52871 - 74 74 74 62 62 62 22 22 22 6 6 6
52872 - 0 0 0 0 0 0 0 0 0 0 0 0
52873 - 0 0 0 0 0 0 0 0 0 0 0 0
52874 - 0 0 0 0 0 0 0 0 0 0 0 0
52875 - 0 0 0 0 0 0 0 0 0 0 0 0
52876 - 0 0 0 0 0 0 0 0 0 0 0 0
52877 - 0 0 0 0 0 0 0 0 0 0 0 0
52878 - 0 0 0 0 0 0 0 0 1 0 0 0
52879 - 0 0 1 0 0 0 0 0 1 0 0 0
52880 - 0 0 0 0 0 0 0 0 0 0 0 0
52881 - 0 0 0 0 0 0 0 0 0 0 0 0
52882 - 0 0 0 0 0 0 0 0 0 0 0 0
52883 - 0 0 0 0 0 0 0 0 0 0 0 0
52884 - 0 0 0 0 0 0 0 0 0 14 14 14
52885 - 42 42 42 94 94 94 14 14 14 101 101 101
52886 -128 128 128 2 2 6 18 18 18 116 116 116
52887 -118 98 46 121 92 8 121 92 8 98 78 10
52888 -162 162 162 106 106 106 2 2 6 2 2 6
52889 - 2 2 6 195 195 195 195 195 195 6 6 6
52890 - 2 2 6 2 2 6 2 2 6 2 2 6
52891 - 74 74 74 62 62 62 22 22 22 6 6 6
52892 - 0 0 0 0 0 0 0 0 0 0 0 0
52893 - 0 0 0 0 0 0 0 0 0 0 0 0
52894 - 0 0 0 0 0 0 0 0 0 0 0 0
52895 - 0 0 0 0 0 0 0 0 0 0 0 0
52896 - 0 0 0 0 0 0 0 0 0 0 0 0
52897 - 0 0 0 0 0 0 0 0 0 0 0 0
52898 - 0 0 0 0 0 0 0 0 1 0 0 1
52899 - 0 0 1 0 0 0 0 0 1 0 0 0
52900 - 0 0 0 0 0 0 0 0 0 0 0 0
52901 - 0 0 0 0 0 0 0 0 0 0 0 0
52902 - 0 0 0 0 0 0 0 0 0 0 0 0
52903 - 0 0 0 0 0 0 0 0 0 0 0 0
52904 - 0 0 0 0 0 0 0 0 0 10 10 10
52905 - 38 38 38 90 90 90 14 14 14 58 58 58
52906 -210 210 210 26 26 26 54 38 6 154 114 10
52907 -226 170 11 236 186 11 225 175 15 184 144 12
52908 -215 174 15 175 146 61 37 26 9 2 2 6
52909 - 70 70 70 246 246 246 138 138 138 2 2 6
52910 - 2 2 6 2 2 6 2 2 6 2 2 6
52911 - 70 70 70 66 66 66 26 26 26 6 6 6
52912 - 0 0 0 0 0 0 0 0 0 0 0 0
52913 - 0 0 0 0 0 0 0 0 0 0 0 0
52914 - 0 0 0 0 0 0 0 0 0 0 0 0
52915 - 0 0 0 0 0 0 0 0 0 0 0 0
52916 - 0 0 0 0 0 0 0 0 0 0 0 0
52917 - 0 0 0 0 0 0 0 0 0 0 0 0
52918 - 0 0 0 0 0 0 0 0 0 0 0 0
52919 - 0 0 0 0 0 0 0 0 0 0 0 0
52920 - 0 0 0 0 0 0 0 0 0 0 0 0
52921 - 0 0 0 0 0 0 0 0 0 0 0 0
52922 - 0 0 0 0 0 0 0 0 0 0 0 0
52923 - 0 0 0 0 0 0 0 0 0 0 0 0
52924 - 0 0 0 0 0 0 0 0 0 10 10 10
52925 - 38 38 38 86 86 86 14 14 14 10 10 10
52926 -195 195 195 188 164 115 192 133 9 225 175 15
52927 -239 182 13 234 190 10 232 195 16 232 200 30
52928 -245 207 45 241 208 19 232 195 16 184 144 12
52929 -218 194 134 211 206 186 42 42 42 2 2 6
52930 - 2 2 6 2 2 6 2 2 6 2 2 6
52931 - 50 50 50 74 74 74 30 30 30 6 6 6
52932 - 0 0 0 0 0 0 0 0 0 0 0 0
52933 - 0 0 0 0 0 0 0 0 0 0 0 0
52934 - 0 0 0 0 0 0 0 0 0 0 0 0
52935 - 0 0 0 0 0 0 0 0 0 0 0 0
52936 - 0 0 0 0 0 0 0 0 0 0 0 0
52937 - 0 0 0 0 0 0 0 0 0 0 0 0
52938 - 0 0 0 0 0 0 0 0 0 0 0 0
52939 - 0 0 0 0 0 0 0 0 0 0 0 0
52940 - 0 0 0 0 0 0 0 0 0 0 0 0
52941 - 0 0 0 0 0 0 0 0 0 0 0 0
52942 - 0 0 0 0 0 0 0 0 0 0 0 0
52943 - 0 0 0 0 0 0 0 0 0 0 0 0
52944 - 0 0 0 0 0 0 0 0 0 10 10 10
52945 - 34 34 34 86 86 86 14 14 14 2 2 6
52946 -121 87 25 192 133 9 219 162 10 239 182 13
52947 -236 186 11 232 195 16 241 208 19 244 214 54
52948 -246 218 60 246 218 38 246 215 20 241 208 19
52949 -241 208 19 226 184 13 121 87 25 2 2 6
52950 - 2 2 6 2 2 6 2 2 6 2 2 6
52951 - 50 50 50 82 82 82 34 34 34 10 10 10
52952 - 0 0 0 0 0 0 0 0 0 0 0 0
52953 - 0 0 0 0 0 0 0 0 0 0 0 0
52954 - 0 0 0 0 0 0 0 0 0 0 0 0
52955 - 0 0 0 0 0 0 0 0 0 0 0 0
52956 - 0 0 0 0 0 0 0 0 0 0 0 0
52957 - 0 0 0 0 0 0 0 0 0 0 0 0
52958 - 0 0 0 0 0 0 0 0 0 0 0 0
52959 - 0 0 0 0 0 0 0 0 0 0 0 0
52960 - 0 0 0 0 0 0 0 0 0 0 0 0
52961 - 0 0 0 0 0 0 0 0 0 0 0 0
52962 - 0 0 0 0 0 0 0 0 0 0 0 0
52963 - 0 0 0 0 0 0 0 0 0 0 0 0
52964 - 0 0 0 0 0 0 0 0 0 10 10 10
52965 - 34 34 34 82 82 82 30 30 30 61 42 6
52966 -180 123 7 206 145 10 230 174 11 239 182 13
52967 -234 190 10 238 202 15 241 208 19 246 218 74
52968 -246 218 38 246 215 20 246 215 20 246 215 20
52969 -226 184 13 215 174 15 184 144 12 6 6 6
52970 - 2 2 6 2 2 6 2 2 6 2 2 6
52971 - 26 26 26 94 94 94 42 42 42 14 14 14
52972 - 0 0 0 0 0 0 0 0 0 0 0 0
52973 - 0 0 0 0 0 0 0 0 0 0 0 0
52974 - 0 0 0 0 0 0 0 0 0 0 0 0
52975 - 0 0 0 0 0 0 0 0 0 0 0 0
52976 - 0 0 0 0 0 0 0 0 0 0 0 0
52977 - 0 0 0 0 0 0 0 0 0 0 0 0
52978 - 0 0 0 0 0 0 0 0 0 0 0 0
52979 - 0 0 0 0 0 0 0 0 0 0 0 0
52980 - 0 0 0 0 0 0 0 0 0 0 0 0
52981 - 0 0 0 0 0 0 0 0 0 0 0 0
52982 - 0 0 0 0 0 0 0 0 0 0 0 0
52983 - 0 0 0 0 0 0 0 0 0 0 0 0
52984 - 0 0 0 0 0 0 0 0 0 10 10 10
52985 - 30 30 30 78 78 78 50 50 50 104 69 6
52986 -192 133 9 216 158 10 236 178 12 236 186 11
52987 -232 195 16 241 208 19 244 214 54 245 215 43
52988 -246 215 20 246 215 20 241 208 19 198 155 10
52989 -200 144 11 216 158 10 156 118 10 2 2 6
52990 - 2 2 6 2 2 6 2 2 6 2 2 6
52991 - 6 6 6 90 90 90 54 54 54 18 18 18
52992 - 6 6 6 0 0 0 0 0 0 0 0 0
52993 - 0 0 0 0 0 0 0 0 0 0 0 0
52994 - 0 0 0 0 0 0 0 0 0 0 0 0
52995 - 0 0 0 0 0 0 0 0 0 0 0 0
52996 - 0 0 0 0 0 0 0 0 0 0 0 0
52997 - 0 0 0 0 0 0 0 0 0 0 0 0
52998 - 0 0 0 0 0 0 0 0 0 0 0 0
52999 - 0 0 0 0 0 0 0 0 0 0 0 0
53000 - 0 0 0 0 0 0 0 0 0 0 0 0
53001 - 0 0 0 0 0 0 0 0 0 0 0 0
53002 - 0 0 0 0 0 0 0 0 0 0 0 0
53003 - 0 0 0 0 0 0 0 0 0 0 0 0
53004 - 0 0 0 0 0 0 0 0 0 10 10 10
53005 - 30 30 30 78 78 78 46 46 46 22 22 22
53006 -137 92 6 210 162 10 239 182 13 238 190 10
53007 -238 202 15 241 208 19 246 215 20 246 215 20
53008 -241 208 19 203 166 17 185 133 11 210 150 10
53009 -216 158 10 210 150 10 102 78 10 2 2 6
53010 - 6 6 6 54 54 54 14 14 14 2 2 6
53011 - 2 2 6 62 62 62 74 74 74 30 30 30
53012 - 10 10 10 0 0 0 0 0 0 0 0 0
53013 - 0 0 0 0 0 0 0 0 0 0 0 0
53014 - 0 0 0 0 0 0 0 0 0 0 0 0
53015 - 0 0 0 0 0 0 0 0 0 0 0 0
53016 - 0 0 0 0 0 0 0 0 0 0 0 0
53017 - 0 0 0 0 0 0 0 0 0 0 0 0
53018 - 0 0 0 0 0 0 0 0 0 0 0 0
53019 - 0 0 0 0 0 0 0 0 0 0 0 0
53020 - 0 0 0 0 0 0 0 0 0 0 0 0
53021 - 0 0 0 0 0 0 0 0 0 0 0 0
53022 - 0 0 0 0 0 0 0 0 0 0 0 0
53023 - 0 0 0 0 0 0 0 0 0 0 0 0
53024 - 0 0 0 0 0 0 0 0 0 10 10 10
53025 - 34 34 34 78 78 78 50 50 50 6 6 6
53026 - 94 70 30 139 102 15 190 146 13 226 184 13
53027 -232 200 30 232 195 16 215 174 15 190 146 13
53028 -168 122 10 192 133 9 210 150 10 213 154 11
53029 -202 150 34 182 157 106 101 98 89 2 2 6
53030 - 2 2 6 78 78 78 116 116 116 58 58 58
53031 - 2 2 6 22 22 22 90 90 90 46 46 46
53032 - 18 18 18 6 6 6 0 0 0 0 0 0
53033 - 0 0 0 0 0 0 0 0 0 0 0 0
53034 - 0 0 0 0 0 0 0 0 0 0 0 0
53035 - 0 0 0 0 0 0 0 0 0 0 0 0
53036 - 0 0 0 0 0 0 0 0 0 0 0 0
53037 - 0 0 0 0 0 0 0 0 0 0 0 0
53038 - 0 0 0 0 0 0 0 0 0 0 0 0
53039 - 0 0 0 0 0 0 0 0 0 0 0 0
53040 - 0 0 0 0 0 0 0 0 0 0 0 0
53041 - 0 0 0 0 0 0 0 0 0 0 0 0
53042 - 0 0 0 0 0 0 0 0 0 0 0 0
53043 - 0 0 0 0 0 0 0 0 0 0 0 0
53044 - 0 0 0 0 0 0 0 0 0 10 10 10
53045 - 38 38 38 86 86 86 50 50 50 6 6 6
53046 -128 128 128 174 154 114 156 107 11 168 122 10
53047 -198 155 10 184 144 12 197 138 11 200 144 11
53048 -206 145 10 206 145 10 197 138 11 188 164 115
53049 -195 195 195 198 198 198 174 174 174 14 14 14
53050 - 2 2 6 22 22 22 116 116 116 116 116 116
53051 - 22 22 22 2 2 6 74 74 74 70 70 70
53052 - 30 30 30 10 10 10 0 0 0 0 0 0
53053 - 0 0 0 0 0 0 0 0 0 0 0 0
53054 - 0 0 0 0 0 0 0 0 0 0 0 0
53055 - 0 0 0 0 0 0 0 0 0 0 0 0
53056 - 0 0 0 0 0 0 0 0 0 0 0 0
53057 - 0 0 0 0 0 0 0 0 0 0 0 0
53058 - 0 0 0 0 0 0 0 0 0 0 0 0
53059 - 0 0 0 0 0 0 0 0 0 0 0 0
53060 - 0 0 0 0 0 0 0 0 0 0 0 0
53061 - 0 0 0 0 0 0 0 0 0 0 0 0
53062 - 0 0 0 0 0 0 0 0 0 0 0 0
53063 - 0 0 0 0 0 0 0 0 0 0 0 0
53064 - 0 0 0 0 0 0 6 6 6 18 18 18
53065 - 50 50 50 101 101 101 26 26 26 10 10 10
53066 -138 138 138 190 190 190 174 154 114 156 107 11
53067 -197 138 11 200 144 11 197 138 11 192 133 9
53068 -180 123 7 190 142 34 190 178 144 187 187 187
53069 -202 202 202 221 221 221 214 214 214 66 66 66
53070 - 2 2 6 2 2 6 50 50 50 62 62 62
53071 - 6 6 6 2 2 6 10 10 10 90 90 90
53072 - 50 50 50 18 18 18 6 6 6 0 0 0
53073 - 0 0 0 0 0 0 0 0 0 0 0 0
53074 - 0 0 0 0 0 0 0 0 0 0 0 0
53075 - 0 0 0 0 0 0 0 0 0 0 0 0
53076 - 0 0 0 0 0 0 0 0 0 0 0 0
53077 - 0 0 0 0 0 0 0 0 0 0 0 0
53078 - 0 0 0 0 0 0 0 0 0 0 0 0
53079 - 0 0 0 0 0 0 0 0 0 0 0 0
53080 - 0 0 0 0 0 0 0 0 0 0 0 0
53081 - 0 0 0 0 0 0 0 0 0 0 0 0
53082 - 0 0 0 0 0 0 0 0 0 0 0 0
53083 - 0 0 0 0 0 0 0 0 0 0 0 0
53084 - 0 0 0 0 0 0 10 10 10 34 34 34
53085 - 74 74 74 74 74 74 2 2 6 6 6 6
53086 -144 144 144 198 198 198 190 190 190 178 166 146
53087 -154 121 60 156 107 11 156 107 11 168 124 44
53088 -174 154 114 187 187 187 190 190 190 210 210 210
53089 -246 246 246 253 253 253 253 253 253 182 182 182
53090 - 6 6 6 2 2 6 2 2 6 2 2 6
53091 - 2 2 6 2 2 6 2 2 6 62 62 62
53092 - 74 74 74 34 34 34 14 14 14 0 0 0
53093 - 0 0 0 0 0 0 0 0 0 0 0 0
53094 - 0 0 0 0 0 0 0 0 0 0 0 0
53095 - 0 0 0 0 0 0 0 0 0 0 0 0
53096 - 0 0 0 0 0 0 0 0 0 0 0 0
53097 - 0 0 0 0 0 0 0 0 0 0 0 0
53098 - 0 0 0 0 0 0 0 0 0 0 0 0
53099 - 0 0 0 0 0 0 0 0 0 0 0 0
53100 - 0 0 0 0 0 0 0 0 0 0 0 0
53101 - 0 0 0 0 0 0 0 0 0 0 0 0
53102 - 0 0 0 0 0 0 0 0 0 0 0 0
53103 - 0 0 0 0 0 0 0 0 0 0 0 0
53104 - 0 0 0 10 10 10 22 22 22 54 54 54
53105 - 94 94 94 18 18 18 2 2 6 46 46 46
53106 -234 234 234 221 221 221 190 190 190 190 190 190
53107 -190 190 190 187 187 187 187 187 187 190 190 190
53108 -190 190 190 195 195 195 214 214 214 242 242 242
53109 -253 253 253 253 253 253 253 253 253 253 253 253
53110 - 82 82 82 2 2 6 2 2 6 2 2 6
53111 - 2 2 6 2 2 6 2 2 6 14 14 14
53112 - 86 86 86 54 54 54 22 22 22 6 6 6
53113 - 0 0 0 0 0 0 0 0 0 0 0 0
53114 - 0 0 0 0 0 0 0 0 0 0 0 0
53115 - 0 0 0 0 0 0 0 0 0 0 0 0
53116 - 0 0 0 0 0 0 0 0 0 0 0 0
53117 - 0 0 0 0 0 0 0 0 0 0 0 0
53118 - 0 0 0 0 0 0 0 0 0 0 0 0
53119 - 0 0 0 0 0 0 0 0 0 0 0 0
53120 - 0 0 0 0 0 0 0 0 0 0 0 0
53121 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 18 18 18 46 46 46 90 90 90
53125 - 46 46 46 18 18 18 6 6 6 182 182 182
53126 -253 253 253 246 246 246 206 206 206 190 190 190
53127 -190 190 190 190 190 190 190 190 190 190 190 190
53128 -206 206 206 231 231 231 250 250 250 253 253 253
53129 -253 253 253 253 253 253 253 253 253 253 253 253
53130 -202 202 202 14 14 14 2 2 6 2 2 6
53131 - 2 2 6 2 2 6 2 2 6 2 2 6
53132 - 42 42 42 86 86 86 42 42 42 18 18 18
53133 - 6 6 6 0 0 0 0 0 0 0 0 0
53134 - 0 0 0 0 0 0 0 0 0 0 0 0
53135 - 0 0 0 0 0 0 0 0 0 0 0 0
53136 - 0 0 0 0 0 0 0 0 0 0 0 0
53137 - 0 0 0 0 0 0 0 0 0 0 0 0
53138 - 0 0 0 0 0 0 0 0 0 0 0 0
53139 - 0 0 0 0 0 0 0 0 0 0 0 0
53140 - 0 0 0 0 0 0 0 0 0 0 0 0
53141 - 0 0 0 0 0 0 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 6 6 6
53144 - 14 14 14 38 38 38 74 74 74 66 66 66
53145 - 2 2 6 6 6 6 90 90 90 250 250 250
53146 -253 253 253 253 253 253 238 238 238 198 198 198
53147 -190 190 190 190 190 190 195 195 195 221 221 221
53148 -246 246 246 253 253 253 253 253 253 253 253 253
53149 -253 253 253 253 253 253 253 253 253 253 253 253
53150 -253 253 253 82 82 82 2 2 6 2 2 6
53151 - 2 2 6 2 2 6 2 2 6 2 2 6
53152 - 2 2 6 78 78 78 70 70 70 34 34 34
53153 - 14 14 14 6 6 6 0 0 0 0 0 0
53154 - 0 0 0 0 0 0 0 0 0 0 0 0
53155 - 0 0 0 0 0 0 0 0 0 0 0 0
53156 - 0 0 0 0 0 0 0 0 0 0 0 0
53157 - 0 0 0 0 0 0 0 0 0 0 0 0
53158 - 0 0 0 0 0 0 0 0 0 0 0 0
53159 - 0 0 0 0 0 0 0 0 0 0 0 0
53160 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
53164 - 34 34 34 66 66 66 78 78 78 6 6 6
53165 - 2 2 6 18 18 18 218 218 218 253 253 253
53166 -253 253 253 253 253 253 253 253 253 246 246 246
53167 -226 226 226 231 231 231 246 246 246 253 253 253
53168 -253 253 253 253 253 253 253 253 253 253 253 253
53169 -253 253 253 253 253 253 253 253 253 253 253 253
53170 -253 253 253 178 178 178 2 2 6 2 2 6
53171 - 2 2 6 2 2 6 2 2 6 2 2 6
53172 - 2 2 6 18 18 18 90 90 90 62 62 62
53173 - 30 30 30 10 10 10 0 0 0 0 0 0
53174 - 0 0 0 0 0 0 0 0 0 0 0 0
53175 - 0 0 0 0 0 0 0 0 0 0 0 0
53176 - 0 0 0 0 0 0 0 0 0 0 0 0
53177 - 0 0 0 0 0 0 0 0 0 0 0 0
53178 - 0 0 0 0 0 0 0 0 0 0 0 0
53179 - 0 0 0 0 0 0 0 0 0 0 0 0
53180 - 0 0 0 0 0 0 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 10 10 10 26 26 26
53184 - 58 58 58 90 90 90 18 18 18 2 2 6
53185 - 2 2 6 110 110 110 253 253 253 253 253 253
53186 -253 253 253 253 253 253 253 253 253 253 253 253
53187 -250 250 250 253 253 253 253 253 253 253 253 253
53188 -253 253 253 253 253 253 253 253 253 253 253 253
53189 -253 253 253 253 253 253 253 253 253 253 253 253
53190 -253 253 253 231 231 231 18 18 18 2 2 6
53191 - 2 2 6 2 2 6 2 2 6 2 2 6
53192 - 2 2 6 2 2 6 18 18 18 94 94 94
53193 - 54 54 54 26 26 26 10 10 10 0 0 0
53194 - 0 0 0 0 0 0 0 0 0 0 0 0
53195 - 0 0 0 0 0 0 0 0 0 0 0 0
53196 - 0 0 0 0 0 0 0 0 0 0 0 0
53197 - 0 0 0 0 0 0 0 0 0 0 0 0
53198 - 0 0 0 0 0 0 0 0 0 0 0 0
53199 - 0 0 0 0 0 0 0 0 0 0 0 0
53200 - 0 0 0 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 6 6 6 22 22 22 50 50 50
53204 - 90 90 90 26 26 26 2 2 6 2 2 6
53205 - 14 14 14 195 195 195 250 250 250 253 253 253
53206 -253 253 253 253 253 253 253 253 253 253 253 253
53207 -253 253 253 253 253 253 253 253 253 253 253 253
53208 -253 253 253 253 253 253 253 253 253 253 253 253
53209 -253 253 253 253 253 253 253 253 253 253 253 253
53210 -250 250 250 242 242 242 54 54 54 2 2 6
53211 - 2 2 6 2 2 6 2 2 6 2 2 6
53212 - 2 2 6 2 2 6 2 2 6 38 38 38
53213 - 86 86 86 50 50 50 22 22 22 6 6 6
53214 - 0 0 0 0 0 0 0 0 0 0 0 0
53215 - 0 0 0 0 0 0 0 0 0 0 0 0
53216 - 0 0 0 0 0 0 0 0 0 0 0 0
53217 - 0 0 0 0 0 0 0 0 0 0 0 0
53218 - 0 0 0 0 0 0 0 0 0 0 0 0
53219 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 14 14 14 38 38 38 82 82 82
53224 - 34 34 34 2 2 6 2 2 6 2 2 6
53225 - 42 42 42 195 195 195 246 246 246 253 253 253
53226 -253 253 253 253 253 253 253 253 253 250 250 250
53227 -242 242 242 242 242 242 250 250 250 253 253 253
53228 -253 253 253 253 253 253 253 253 253 253 253 253
53229 -253 253 253 250 250 250 246 246 246 238 238 238
53230 -226 226 226 231 231 231 101 101 101 6 6 6
53231 - 2 2 6 2 2 6 2 2 6 2 2 6
53232 - 2 2 6 2 2 6 2 2 6 2 2 6
53233 - 38 38 38 82 82 82 42 42 42 14 14 14
53234 - 6 6 6 0 0 0 0 0 0 0 0 0
53235 - 0 0 0 0 0 0 0 0 0 0 0 0
53236 - 0 0 0 0 0 0 0 0 0 0 0 0
53237 - 0 0 0 0 0 0 0 0 0 0 0 0
53238 - 0 0 0 0 0 0 0 0 0 0 0 0
53239 - 0 0 0 0 0 0 0 0 0 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 - 10 10 10 26 26 26 62 62 62 66 66 66
53244 - 2 2 6 2 2 6 2 2 6 6 6 6
53245 - 70 70 70 170 170 170 206 206 206 234 234 234
53246 -246 246 246 250 250 250 250 250 250 238 238 238
53247 -226 226 226 231 231 231 238 238 238 250 250 250
53248 -250 250 250 250 250 250 246 246 246 231 231 231
53249 -214 214 214 206 206 206 202 202 202 202 202 202
53250 -198 198 198 202 202 202 182 182 182 18 18 18
53251 - 2 2 6 2 2 6 2 2 6 2 2 6
53252 - 2 2 6 2 2 6 2 2 6 2 2 6
53253 - 2 2 6 62 62 62 66 66 66 30 30 30
53254 - 10 10 10 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 0 0 0 0 0 0 0 0 0
53257 - 0 0 0 0 0 0 0 0 0 0 0 0
53258 - 0 0 0 0 0 0 0 0 0 0 0 0
53259 - 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
53264 - 2 2 6 2 2 6 2 2 6 10 10 10
53265 - 94 94 94 182 182 182 218 218 218 242 242 242
53266 -250 250 250 253 253 253 253 253 253 250 250 250
53267 -234 234 234 253 253 253 253 253 253 253 253 253
53268 -253 253 253 253 253 253 253 253 253 246 246 246
53269 -238 238 238 226 226 226 210 210 210 202 202 202
53270 -195 195 195 195 195 195 210 210 210 158 158 158
53271 - 6 6 6 14 14 14 50 50 50 14 14 14
53272 - 2 2 6 2 2 6 2 2 6 2 2 6
53273 - 2 2 6 6 6 6 86 86 86 46 46 46
53274 - 18 18 18 6 6 6 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 0 0 0
53277 - 0 0 0 0 0 0 0 0 0 0 0 0
53278 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
53283 - 22 22 22 54 54 54 70 70 70 2 2 6
53284 - 2 2 6 10 10 10 2 2 6 22 22 22
53285 -166 166 166 231 231 231 250 250 250 253 253 253
53286 -253 253 253 253 253 253 253 253 253 250 250 250
53287 -242 242 242 253 253 253 253 253 253 253 253 253
53288 -253 253 253 253 253 253 253 253 253 253 253 253
53289 -253 253 253 253 253 253 253 253 253 246 246 246
53290 -231 231 231 206 206 206 198 198 198 226 226 226
53291 - 94 94 94 2 2 6 6 6 6 38 38 38
53292 - 30 30 30 2 2 6 2 2 6 2 2 6
53293 - 2 2 6 2 2 6 62 62 62 66 66 66
53294 - 26 26 26 10 10 10 0 0 0 0 0 0
53295 - 0 0 0 0 0 0 0 0 0 0 0 0
53296 - 0 0 0 0 0 0 0 0 0 0 0 0
53297 - 0 0 0 0 0 0 0 0 0 0 0 0
53298 - 0 0 0 0 0 0 0 0 0 0 0 0
53299 - 0 0 0 0 0 0 0 0 0 0 0 0
53300 - 0 0 0 0 0 0 0 0 0 0 0 0
53301 - 0 0 0 0 0 0 0 0 0 0 0 0
53302 - 0 0 0 0 0 0 0 0 0 10 10 10
53303 - 30 30 30 74 74 74 50 50 50 2 2 6
53304 - 26 26 26 26 26 26 2 2 6 106 106 106
53305 -238 238 238 253 253 253 253 253 253 253 253 253
53306 -253 253 253 253 253 253 253 253 253 253 253 253
53307 -253 253 253 253 253 253 253 253 253 253 253 253
53308 -253 253 253 253 253 253 253 253 253 253 253 253
53309 -253 253 253 253 253 253 253 253 253 253 253 253
53310 -253 253 253 246 246 246 218 218 218 202 202 202
53311 -210 210 210 14 14 14 2 2 6 2 2 6
53312 - 30 30 30 22 22 22 2 2 6 2 2 6
53313 - 2 2 6 2 2 6 18 18 18 86 86 86
53314 - 42 42 42 14 14 14 0 0 0 0 0 0
53315 - 0 0 0 0 0 0 0 0 0 0 0 0
53316 - 0 0 0 0 0 0 0 0 0 0 0 0
53317 - 0 0 0 0 0 0 0 0 0 0 0 0
53318 - 0 0 0 0 0 0 0 0 0 0 0 0
53319 - 0 0 0 0 0 0 0 0 0 0 0 0
53320 - 0 0 0 0 0 0 0 0 0 0 0 0
53321 - 0 0 0 0 0 0 0 0 0 0 0 0
53322 - 0 0 0 0 0 0 0 0 0 14 14 14
53323 - 42 42 42 90 90 90 22 22 22 2 2 6
53324 - 42 42 42 2 2 6 18 18 18 218 218 218
53325 -253 253 253 253 253 253 253 253 253 253 253 253
53326 -253 253 253 253 253 253 253 253 253 253 253 253
53327 -253 253 253 253 253 253 253 253 253 253 253 253
53328 -253 253 253 253 253 253 253 253 253 253 253 253
53329 -253 253 253 253 253 253 253 253 253 253 253 253
53330 -253 253 253 253 253 253 250 250 250 221 221 221
53331 -218 218 218 101 101 101 2 2 6 14 14 14
53332 - 18 18 18 38 38 38 10 10 10 2 2 6
53333 - 2 2 6 2 2 6 2 2 6 78 78 78
53334 - 58 58 58 22 22 22 6 6 6 0 0 0
53335 - 0 0 0 0 0 0 0 0 0 0 0 0
53336 - 0 0 0 0 0 0 0 0 0 0 0 0
53337 - 0 0 0 0 0 0 0 0 0 0 0 0
53338 - 0 0 0 0 0 0 0 0 0 0 0 0
53339 - 0 0 0 0 0 0 0 0 0 0 0 0
53340 - 0 0 0 0 0 0 0 0 0 0 0 0
53341 - 0 0 0 0 0 0 0 0 0 0 0 0
53342 - 0 0 0 0 0 0 6 6 6 18 18 18
53343 - 54 54 54 82 82 82 2 2 6 26 26 26
53344 - 22 22 22 2 2 6 123 123 123 253 253 253
53345 -253 253 253 253 253 253 253 253 253 253 253 253
53346 -253 253 253 253 253 253 253 253 253 253 253 253
53347 -253 253 253 253 253 253 253 253 253 253 253 253
53348 -253 253 253 253 253 253 253 253 253 253 253 253
53349 -253 253 253 253 253 253 253 253 253 253 253 253
53350 -253 253 253 253 253 253 253 253 253 250 250 250
53351 -238 238 238 198 198 198 6 6 6 38 38 38
53352 - 58 58 58 26 26 26 38 38 38 2 2 6
53353 - 2 2 6 2 2 6 2 2 6 46 46 46
53354 - 78 78 78 30 30 30 10 10 10 0 0 0
53355 - 0 0 0 0 0 0 0 0 0 0 0 0
53356 - 0 0 0 0 0 0 0 0 0 0 0 0
53357 - 0 0 0 0 0 0 0 0 0 0 0 0
53358 - 0 0 0 0 0 0 0 0 0 0 0 0
53359 - 0 0 0 0 0 0 0 0 0 0 0 0
53360 - 0 0 0 0 0 0 0 0 0 0 0 0
53361 - 0 0 0 0 0 0 0 0 0 0 0 0
53362 - 0 0 0 0 0 0 10 10 10 30 30 30
53363 - 74 74 74 58 58 58 2 2 6 42 42 42
53364 - 2 2 6 22 22 22 231 231 231 253 253 253
53365 -253 253 253 253 253 253 253 253 253 253 253 253
53366 -253 253 253 253 253 253 253 253 253 250 250 250
53367 -253 253 253 253 253 253 253 253 253 253 253 253
53368 -253 253 253 253 253 253 253 253 253 253 253 253
53369 -253 253 253 253 253 253 253 253 253 253 253 253
53370 -253 253 253 253 253 253 253 253 253 253 253 253
53371 -253 253 253 246 246 246 46 46 46 38 38 38
53372 - 42 42 42 14 14 14 38 38 38 14 14 14
53373 - 2 2 6 2 2 6 2 2 6 6 6 6
53374 - 86 86 86 46 46 46 14 14 14 0 0 0
53375 - 0 0 0 0 0 0 0 0 0 0 0 0
53376 - 0 0 0 0 0 0 0 0 0 0 0 0
53377 - 0 0 0 0 0 0 0 0 0 0 0 0
53378 - 0 0 0 0 0 0 0 0 0 0 0 0
53379 - 0 0 0 0 0 0 0 0 0 0 0 0
53380 - 0 0 0 0 0 0 0 0 0 0 0 0
53381 - 0 0 0 0 0 0 0 0 0 0 0 0
53382 - 0 0 0 6 6 6 14 14 14 42 42 42
53383 - 90 90 90 18 18 18 18 18 18 26 26 26
53384 - 2 2 6 116 116 116 253 253 253 253 253 253
53385 -253 253 253 253 253 253 253 253 253 253 253 253
53386 -253 253 253 253 253 253 250 250 250 238 238 238
53387 -253 253 253 253 253 253 253 253 253 253 253 253
53388 -253 253 253 253 253 253 253 253 253 253 253 253
53389 -253 253 253 253 253 253 253 253 253 253 253 253
53390 -253 253 253 253 253 253 253 253 253 253 253 253
53391 -253 253 253 253 253 253 94 94 94 6 6 6
53392 - 2 2 6 2 2 6 10 10 10 34 34 34
53393 - 2 2 6 2 2 6 2 2 6 2 2 6
53394 - 74 74 74 58 58 58 22 22 22 6 6 6
53395 - 0 0 0 0 0 0 0 0 0 0 0 0
53396 - 0 0 0 0 0 0 0 0 0 0 0 0
53397 - 0 0 0 0 0 0 0 0 0 0 0 0
53398 - 0 0 0 0 0 0 0 0 0 0 0 0
53399 - 0 0 0 0 0 0 0 0 0 0 0 0
53400 - 0 0 0 0 0 0 0 0 0 0 0 0
53401 - 0 0 0 0 0 0 0 0 0 0 0 0
53402 - 0 0 0 10 10 10 26 26 26 66 66 66
53403 - 82 82 82 2 2 6 38 38 38 6 6 6
53404 - 14 14 14 210 210 210 253 253 253 253 253 253
53405 -253 253 253 253 253 253 253 253 253 253 253 253
53406 -253 253 253 253 253 253 246 246 246 242 242 242
53407 -253 253 253 253 253 253 253 253 253 253 253 253
53408 -253 253 253 253 253 253 253 253 253 253 253 253
53409 -253 253 253 253 253 253 253 253 253 253 253 253
53410 -253 253 253 253 253 253 253 253 253 253 253 253
53411 -253 253 253 253 253 253 144 144 144 2 2 6
53412 - 2 2 6 2 2 6 2 2 6 46 46 46
53413 - 2 2 6 2 2 6 2 2 6 2 2 6
53414 - 42 42 42 74 74 74 30 30 30 10 10 10
53415 - 0 0 0 0 0 0 0 0 0 0 0 0
53416 - 0 0 0 0 0 0 0 0 0 0 0 0
53417 - 0 0 0 0 0 0 0 0 0 0 0 0
53418 - 0 0 0 0 0 0 0 0 0 0 0 0
53419 - 0 0 0 0 0 0 0 0 0 0 0 0
53420 - 0 0 0 0 0 0 0 0 0 0 0 0
53421 - 0 0 0 0 0 0 0 0 0 0 0 0
53422 - 6 6 6 14 14 14 42 42 42 90 90 90
53423 - 26 26 26 6 6 6 42 42 42 2 2 6
53424 - 74 74 74 250 250 250 253 253 253 253 253 253
53425 -253 253 253 253 253 253 253 253 253 253 253 253
53426 -253 253 253 253 253 253 242 242 242 242 242 242
53427 -253 253 253 253 253 253 253 253 253 253 253 253
53428 -253 253 253 253 253 253 253 253 253 253 253 253
53429 -253 253 253 253 253 253 253 253 253 253 253 253
53430 -253 253 253 253 253 253 253 253 253 253 253 253
53431 -253 253 253 253 253 253 182 182 182 2 2 6
53432 - 2 2 6 2 2 6 2 2 6 46 46 46
53433 - 2 2 6 2 2 6 2 2 6 2 2 6
53434 - 10 10 10 86 86 86 38 38 38 10 10 10
53435 - 0 0 0 0 0 0 0 0 0 0 0 0
53436 - 0 0 0 0 0 0 0 0 0 0 0 0
53437 - 0 0 0 0 0 0 0 0 0 0 0 0
53438 - 0 0 0 0 0 0 0 0 0 0 0 0
53439 - 0 0 0 0 0 0 0 0 0 0 0 0
53440 - 0 0 0 0 0 0 0 0 0 0 0 0
53441 - 0 0 0 0 0 0 0 0 0 0 0 0
53442 - 10 10 10 26 26 26 66 66 66 82 82 82
53443 - 2 2 6 22 22 22 18 18 18 2 2 6
53444 -149 149 149 253 253 253 253 253 253 253 253 253
53445 -253 253 253 253 253 253 253 253 253 253 253 253
53446 -253 253 253 253 253 253 234 234 234 242 242 242
53447 -253 253 253 253 253 253 253 253 253 253 253 253
53448 -253 253 253 253 253 253 253 253 253 253 253 253
53449 -253 253 253 253 253 253 253 253 253 253 253 253
53450 -253 253 253 253 253 253 253 253 253 253 253 253
53451 -253 253 253 253 253 253 206 206 206 2 2 6
53452 - 2 2 6 2 2 6 2 2 6 38 38 38
53453 - 2 2 6 2 2 6 2 2 6 2 2 6
53454 - 6 6 6 86 86 86 46 46 46 14 14 14
53455 - 0 0 0 0 0 0 0 0 0 0 0 0
53456 - 0 0 0 0 0 0 0 0 0 0 0 0
53457 - 0 0 0 0 0 0 0 0 0 0 0 0
53458 - 0 0 0 0 0 0 0 0 0 0 0 0
53459 - 0 0 0 0 0 0 0 0 0 0 0 0
53460 - 0 0 0 0 0 0 0 0 0 0 0 0
53461 - 0 0 0 0 0 0 0 0 0 6 6 6
53462 - 18 18 18 46 46 46 86 86 86 18 18 18
53463 - 2 2 6 34 34 34 10 10 10 6 6 6
53464 -210 210 210 253 253 253 253 253 253 253 253 253
53465 -253 253 253 253 253 253 253 253 253 253 253 253
53466 -253 253 253 253 253 253 234 234 234 242 242 242
53467 -253 253 253 253 253 253 253 253 253 253 253 253
53468 -253 253 253 253 253 253 253 253 253 253 253 253
53469 -253 253 253 253 253 253 253 253 253 253 253 253
53470 -253 253 253 253 253 253 253 253 253 253 253 253
53471 -253 253 253 253 253 253 221 221 221 6 6 6
53472 - 2 2 6 2 2 6 6 6 6 30 30 30
53473 - 2 2 6 2 2 6 2 2 6 2 2 6
53474 - 2 2 6 82 82 82 54 54 54 18 18 18
53475 - 6 6 6 0 0 0 0 0 0 0 0 0
53476 - 0 0 0 0 0 0 0 0 0 0 0 0
53477 - 0 0 0 0 0 0 0 0 0 0 0 0
53478 - 0 0 0 0 0 0 0 0 0 0 0 0
53479 - 0 0 0 0 0 0 0 0 0 0 0 0
53480 - 0 0 0 0 0 0 0 0 0 0 0 0
53481 - 0 0 0 0 0 0 0 0 0 10 10 10
53482 - 26 26 26 66 66 66 62 62 62 2 2 6
53483 - 2 2 6 38 38 38 10 10 10 26 26 26
53484 -238 238 238 253 253 253 253 253 253 253 253 253
53485 -253 253 253 253 253 253 253 253 253 253 253 253
53486 -253 253 253 253 253 253 231 231 231 238 238 238
53487 -253 253 253 253 253 253 253 253 253 253 253 253
53488 -253 253 253 253 253 253 253 253 253 253 253 253
53489 -253 253 253 253 253 253 253 253 253 253 253 253
53490 -253 253 253 253 253 253 253 253 253 253 253 253
53491 -253 253 253 253 253 253 231 231 231 6 6 6
53492 - 2 2 6 2 2 6 10 10 10 30 30 30
53493 - 2 2 6 2 2 6 2 2 6 2 2 6
53494 - 2 2 6 66 66 66 58 58 58 22 22 22
53495 - 6 6 6 0 0 0 0 0 0 0 0 0
53496 - 0 0 0 0 0 0 0 0 0 0 0 0
53497 - 0 0 0 0 0 0 0 0 0 0 0 0
53498 - 0 0 0 0 0 0 0 0 0 0 0 0
53499 - 0 0 0 0 0 0 0 0 0 0 0 0
53500 - 0 0 0 0 0 0 0 0 0 0 0 0
53501 - 0 0 0 0 0 0 0 0 0 10 10 10
53502 - 38 38 38 78 78 78 6 6 6 2 2 6
53503 - 2 2 6 46 46 46 14 14 14 42 42 42
53504 -246 246 246 253 253 253 253 253 253 253 253 253
53505 -253 253 253 253 253 253 253 253 253 253 253 253
53506 -253 253 253 253 253 253 231 231 231 242 242 242
53507 -253 253 253 253 253 253 253 253 253 253 253 253
53508 -253 253 253 253 253 253 253 253 253 253 253 253
53509 -253 253 253 253 253 253 253 253 253 253 253 253
53510 -253 253 253 253 253 253 253 253 253 253 253 253
53511 -253 253 253 253 253 253 234 234 234 10 10 10
53512 - 2 2 6 2 2 6 22 22 22 14 14 14
53513 - 2 2 6 2 2 6 2 2 6 2 2 6
53514 - 2 2 6 66 66 66 62 62 62 22 22 22
53515 - 6 6 6 0 0 0 0 0 0 0 0 0
53516 - 0 0 0 0 0 0 0 0 0 0 0 0
53517 - 0 0 0 0 0 0 0 0 0 0 0 0
53518 - 0 0 0 0 0 0 0 0 0 0 0 0
53519 - 0 0 0 0 0 0 0 0 0 0 0 0
53520 - 0 0 0 0 0 0 0 0 0 0 0 0
53521 - 0 0 0 0 0 0 6 6 6 18 18 18
53522 - 50 50 50 74 74 74 2 2 6 2 2 6
53523 - 14 14 14 70 70 70 34 34 34 62 62 62
53524 -250 250 250 253 253 253 253 253 253 253 253 253
53525 -253 253 253 253 253 253 253 253 253 253 253 253
53526 -253 253 253 253 253 253 231 231 231 246 246 246
53527 -253 253 253 253 253 253 253 253 253 253 253 253
53528 -253 253 253 253 253 253 253 253 253 253 253 253
53529 -253 253 253 253 253 253 253 253 253 253 253 253
53530 -253 253 253 253 253 253 253 253 253 253 253 253
53531 -253 253 253 253 253 253 234 234 234 14 14 14
53532 - 2 2 6 2 2 6 30 30 30 2 2 6
53533 - 2 2 6 2 2 6 2 2 6 2 2 6
53534 - 2 2 6 66 66 66 62 62 62 22 22 22
53535 - 6 6 6 0 0 0 0 0 0 0 0 0
53536 - 0 0 0 0 0 0 0 0 0 0 0 0
53537 - 0 0 0 0 0 0 0 0 0 0 0 0
53538 - 0 0 0 0 0 0 0 0 0 0 0 0
53539 - 0 0 0 0 0 0 0 0 0 0 0 0
53540 - 0 0 0 0 0 0 0 0 0 0 0 0
53541 - 0 0 0 0 0 0 6 6 6 18 18 18
53542 - 54 54 54 62 62 62 2 2 6 2 2 6
53543 - 2 2 6 30 30 30 46 46 46 70 70 70
53544 -250 250 250 253 253 253 253 253 253 253 253 253
53545 -253 253 253 253 253 253 253 253 253 253 253 253
53546 -253 253 253 253 253 253 231 231 231 246 246 246
53547 -253 253 253 253 253 253 253 253 253 253 253 253
53548 -253 253 253 253 253 253 253 253 253 253 253 253
53549 -253 253 253 253 253 253 253 253 253 253 253 253
53550 -253 253 253 253 253 253 253 253 253 253 253 253
53551 -253 253 253 253 253 253 226 226 226 10 10 10
53552 - 2 2 6 6 6 6 30 30 30 2 2 6
53553 - 2 2 6 2 2 6 2 2 6 2 2 6
53554 - 2 2 6 66 66 66 58 58 58 22 22 22
53555 - 6 6 6 0 0 0 0 0 0 0 0 0
53556 - 0 0 0 0 0 0 0 0 0 0 0 0
53557 - 0 0 0 0 0 0 0 0 0 0 0 0
53558 - 0 0 0 0 0 0 0 0 0 0 0 0
53559 - 0 0 0 0 0 0 0 0 0 0 0 0
53560 - 0 0 0 0 0 0 0 0 0 0 0 0
53561 - 0 0 0 0 0 0 6 6 6 22 22 22
53562 - 58 58 58 62 62 62 2 2 6 2 2 6
53563 - 2 2 6 2 2 6 30 30 30 78 78 78
53564 -250 250 250 253 253 253 253 253 253 253 253 253
53565 -253 253 253 253 253 253 253 253 253 253 253 253
53566 -253 253 253 253 253 253 231 231 231 246 246 246
53567 -253 253 253 253 253 253 253 253 253 253 253 253
53568 -253 253 253 253 253 253 253 253 253 253 253 253
53569 -253 253 253 253 253 253 253 253 253 253 253 253
53570 -253 253 253 253 253 253 253 253 253 253 253 253
53571 -253 253 253 253 253 253 206 206 206 2 2 6
53572 - 22 22 22 34 34 34 18 14 6 22 22 22
53573 - 26 26 26 18 18 18 6 6 6 2 2 6
53574 - 2 2 6 82 82 82 54 54 54 18 18 18
53575 - 6 6 6 0 0 0 0 0 0 0 0 0
53576 - 0 0 0 0 0 0 0 0 0 0 0 0
53577 - 0 0 0 0 0 0 0 0 0 0 0 0
53578 - 0 0 0 0 0 0 0 0 0 0 0 0
53579 - 0 0 0 0 0 0 0 0 0 0 0 0
53580 - 0 0 0 0 0 0 0 0 0 0 0 0
53581 - 0 0 0 0 0 0 6 6 6 26 26 26
53582 - 62 62 62 106 106 106 74 54 14 185 133 11
53583 -210 162 10 121 92 8 6 6 6 62 62 62
53584 -238 238 238 253 253 253 253 253 253 253 253 253
53585 -253 253 253 253 253 253 253 253 253 253 253 253
53586 -253 253 253 253 253 253 231 231 231 246 246 246
53587 -253 253 253 253 253 253 253 253 253 253 253 253
53588 -253 253 253 253 253 253 253 253 253 253 253 253
53589 -253 253 253 253 253 253 253 253 253 253 253 253
53590 -253 253 253 253 253 253 253 253 253 253 253 253
53591 -253 253 253 253 253 253 158 158 158 18 18 18
53592 - 14 14 14 2 2 6 2 2 6 2 2 6
53593 - 6 6 6 18 18 18 66 66 66 38 38 38
53594 - 6 6 6 94 94 94 50 50 50 18 18 18
53595 - 6 6 6 0 0 0 0 0 0 0 0 0
53596 - 0 0 0 0 0 0 0 0 0 0 0 0
53597 - 0 0 0 0 0 0 0 0 0 0 0 0
53598 - 0 0 0 0 0 0 0 0 0 0 0 0
53599 - 0 0 0 0 0 0 0 0 0 0 0 0
53600 - 0 0 0 0 0 0 0 0 0 6 6 6
53601 - 10 10 10 10 10 10 18 18 18 38 38 38
53602 - 78 78 78 142 134 106 216 158 10 242 186 14
53603 -246 190 14 246 190 14 156 118 10 10 10 10
53604 - 90 90 90 238 238 238 253 253 253 253 253 253
53605 -253 253 253 253 253 253 253 253 253 253 253 253
53606 -253 253 253 253 253 253 231 231 231 250 250 250
53607 -253 253 253 253 253 253 253 253 253 253 253 253
53608 -253 253 253 253 253 253 253 253 253 253 253 253
53609 -253 253 253 253 253 253 253 253 253 253 253 253
53610 -253 253 253 253 253 253 253 253 253 246 230 190
53611 -238 204 91 238 204 91 181 142 44 37 26 9
53612 - 2 2 6 2 2 6 2 2 6 2 2 6
53613 - 2 2 6 2 2 6 38 38 38 46 46 46
53614 - 26 26 26 106 106 106 54 54 54 18 18 18
53615 - 6 6 6 0 0 0 0 0 0 0 0 0
53616 - 0 0 0 0 0 0 0 0 0 0 0 0
53617 - 0 0 0 0 0 0 0 0 0 0 0 0
53618 - 0 0 0 0 0 0 0 0 0 0 0 0
53619 - 0 0 0 0 0 0 0 0 0 0 0 0
53620 - 0 0 0 6 6 6 14 14 14 22 22 22
53621 - 30 30 30 38 38 38 50 50 50 70 70 70
53622 -106 106 106 190 142 34 226 170 11 242 186 14
53623 -246 190 14 246 190 14 246 190 14 154 114 10
53624 - 6 6 6 74 74 74 226 226 226 253 253 253
53625 -253 253 253 253 253 253 253 253 253 253 253 253
53626 -253 253 253 253 253 253 231 231 231 250 250 250
53627 -253 253 253 253 253 253 253 253 253 253 253 253
53628 -253 253 253 253 253 253 253 253 253 253 253 253
53629 -253 253 253 253 253 253 253 253 253 253 253 253
53630 -253 253 253 253 253 253 253 253 253 228 184 62
53631 -241 196 14 241 208 19 232 195 16 38 30 10
53632 - 2 2 6 2 2 6 2 2 6 2 2 6
53633 - 2 2 6 6 6 6 30 30 30 26 26 26
53634 -203 166 17 154 142 90 66 66 66 26 26 26
53635 - 6 6 6 0 0 0 0 0 0 0 0 0
53636 - 0 0 0 0 0 0 0 0 0 0 0 0
53637 - 0 0 0 0 0 0 0 0 0 0 0 0
53638 - 0 0 0 0 0 0 0 0 0 0 0 0
53639 - 0 0 0 0 0 0 0 0 0 0 0 0
53640 - 6 6 6 18 18 18 38 38 38 58 58 58
53641 - 78 78 78 86 86 86 101 101 101 123 123 123
53642 -175 146 61 210 150 10 234 174 13 246 186 14
53643 -246 190 14 246 190 14 246 190 14 238 190 10
53644 -102 78 10 2 2 6 46 46 46 198 198 198
53645 -253 253 253 253 253 253 253 253 253 253 253 253
53646 -253 253 253 253 253 253 234 234 234 242 242 242
53647 -253 253 253 253 253 253 253 253 253 253 253 253
53648 -253 253 253 253 253 253 253 253 253 253 253 253
53649 -253 253 253 253 253 253 253 253 253 253 253 253
53650 -253 253 253 253 253 253 253 253 253 224 178 62
53651 -242 186 14 241 196 14 210 166 10 22 18 6
53652 - 2 2 6 2 2 6 2 2 6 2 2 6
53653 - 2 2 6 2 2 6 6 6 6 121 92 8
53654 -238 202 15 232 195 16 82 82 82 34 34 34
53655 - 10 10 10 0 0 0 0 0 0 0 0 0
53656 - 0 0 0 0 0 0 0 0 0 0 0 0
53657 - 0 0 0 0 0 0 0 0 0 0 0 0
53658 - 0 0 0 0 0 0 0 0 0 0 0 0
53659 - 0 0 0 0 0 0 0 0 0 0 0 0
53660 - 14 14 14 38 38 38 70 70 70 154 122 46
53661 -190 142 34 200 144 11 197 138 11 197 138 11
53662 -213 154 11 226 170 11 242 186 14 246 190 14
53663 -246 190 14 246 190 14 246 190 14 246 190 14
53664 -225 175 15 46 32 6 2 2 6 22 22 22
53665 -158 158 158 250 250 250 253 253 253 253 253 253
53666 -253 253 253 253 253 253 253 253 253 253 253 253
53667 -253 253 253 253 253 253 253 253 253 253 253 253
53668 -253 253 253 253 253 253 253 253 253 253 253 253
53669 -253 253 253 253 253 253 253 253 253 253 253 253
53670 -253 253 253 250 250 250 242 242 242 224 178 62
53671 -239 182 13 236 186 11 213 154 11 46 32 6
53672 - 2 2 6 2 2 6 2 2 6 2 2 6
53673 - 2 2 6 2 2 6 61 42 6 225 175 15
53674 -238 190 10 236 186 11 112 100 78 42 42 42
53675 - 14 14 14 0 0 0 0 0 0 0 0 0
53676 - 0 0 0 0 0 0 0 0 0 0 0 0
53677 - 0 0 0 0 0 0 0 0 0 0 0 0
53678 - 0 0 0 0 0 0 0 0 0 0 0 0
53679 - 0 0 0 0 0 0 0 0 0 6 6 6
53680 - 22 22 22 54 54 54 154 122 46 213 154 11
53681 -226 170 11 230 174 11 226 170 11 226 170 11
53682 -236 178 12 242 186 14 246 190 14 246 190 14
53683 -246 190 14 246 190 14 246 190 14 246 190 14
53684 -241 196 14 184 144 12 10 10 10 2 2 6
53685 - 6 6 6 116 116 116 242 242 242 253 253 253
53686 -253 253 253 253 253 253 253 253 253 253 253 253
53687 -253 253 253 253 253 253 253 253 253 253 253 253
53688 -253 253 253 253 253 253 253 253 253 253 253 253
53689 -253 253 253 253 253 253 253 253 253 253 253 253
53690 -253 253 253 231 231 231 198 198 198 214 170 54
53691 -236 178 12 236 178 12 210 150 10 137 92 6
53692 - 18 14 6 2 2 6 2 2 6 2 2 6
53693 - 6 6 6 70 47 6 200 144 11 236 178 12
53694 -239 182 13 239 182 13 124 112 88 58 58 58
53695 - 22 22 22 6 6 6 0 0 0 0 0 0
53696 - 0 0 0 0 0 0 0 0 0 0 0 0
53697 - 0 0 0 0 0 0 0 0 0 0 0 0
53698 - 0 0 0 0 0 0 0 0 0 0 0 0
53699 - 0 0 0 0 0 0 0 0 0 10 10 10
53700 - 30 30 30 70 70 70 180 133 36 226 170 11
53701 -239 182 13 242 186 14 242 186 14 246 186 14
53702 -246 190 14 246 190 14 246 190 14 246 190 14
53703 -246 190 14 246 190 14 246 190 14 246 190 14
53704 -246 190 14 232 195 16 98 70 6 2 2 6
53705 - 2 2 6 2 2 6 66 66 66 221 221 221
53706 -253 253 253 253 253 253 253 253 253 253 253 253
53707 -253 253 253 253 253 253 253 253 253 253 253 253
53708 -253 253 253 253 253 253 253 253 253 253 253 253
53709 -253 253 253 253 253 253 253 253 253 253 253 253
53710 -253 253 253 206 206 206 198 198 198 214 166 58
53711 -230 174 11 230 174 11 216 158 10 192 133 9
53712 -163 110 8 116 81 8 102 78 10 116 81 8
53713 -167 114 7 197 138 11 226 170 11 239 182 13
53714 -242 186 14 242 186 14 162 146 94 78 78 78
53715 - 34 34 34 14 14 14 6 6 6 0 0 0
53716 - 0 0 0 0 0 0 0 0 0 0 0 0
53717 - 0 0 0 0 0 0 0 0 0 0 0 0
53718 - 0 0 0 0 0 0 0 0 0 0 0 0
53719 - 0 0 0 0 0 0 0 0 0 6 6 6
53720 - 30 30 30 78 78 78 190 142 34 226 170 11
53721 -239 182 13 246 190 14 246 190 14 246 190 14
53722 -246 190 14 246 190 14 246 190 14 246 190 14
53723 -246 190 14 246 190 14 246 190 14 246 190 14
53724 -246 190 14 241 196 14 203 166 17 22 18 6
53725 - 2 2 6 2 2 6 2 2 6 38 38 38
53726 -218 218 218 253 253 253 253 253 253 253 253 253
53727 -253 253 253 253 253 253 253 253 253 253 253 253
53728 -253 253 253 253 253 253 253 253 253 253 253 253
53729 -253 253 253 253 253 253 253 253 253 253 253 253
53730 -250 250 250 206 206 206 198 198 198 202 162 69
53731 -226 170 11 236 178 12 224 166 10 210 150 10
53732 -200 144 11 197 138 11 192 133 9 197 138 11
53733 -210 150 10 226 170 11 242 186 14 246 190 14
53734 -246 190 14 246 186 14 225 175 15 124 112 88
53735 - 62 62 62 30 30 30 14 14 14 6 6 6
53736 - 0 0 0 0 0 0 0 0 0 0 0 0
53737 - 0 0 0 0 0 0 0 0 0 0 0 0
53738 - 0 0 0 0 0 0 0 0 0 0 0 0
53739 - 0 0 0 0 0 0 0 0 0 10 10 10
53740 - 30 30 30 78 78 78 174 135 50 224 166 10
53741 -239 182 13 246 190 14 246 190 14 246 190 14
53742 -246 190 14 246 190 14 246 190 14 246 190 14
53743 -246 190 14 246 190 14 246 190 14 246 190 14
53744 -246 190 14 246 190 14 241 196 14 139 102 15
53745 - 2 2 6 2 2 6 2 2 6 2 2 6
53746 - 78 78 78 250 250 250 253 253 253 253 253 253
53747 -253 253 253 253 253 253 253 253 253 253 253 253
53748 -253 253 253 253 253 253 253 253 253 253 253 253
53749 -253 253 253 253 253 253 253 253 253 253 253 253
53750 -250 250 250 214 214 214 198 198 198 190 150 46
53751 -219 162 10 236 178 12 234 174 13 224 166 10
53752 -216 158 10 213 154 11 213 154 11 216 158 10
53753 -226 170 11 239 182 13 246 190 14 246 190 14
53754 -246 190 14 246 190 14 242 186 14 206 162 42
53755 -101 101 101 58 58 58 30 30 30 14 14 14
53756 - 6 6 6 0 0 0 0 0 0 0 0 0
53757 - 0 0 0 0 0 0 0 0 0 0 0 0
53758 - 0 0 0 0 0 0 0 0 0 0 0 0
53759 - 0 0 0 0 0 0 0 0 0 10 10 10
53760 - 30 30 30 74 74 74 174 135 50 216 158 10
53761 -236 178 12 246 190 14 246 190 14 246 190 14
53762 -246 190 14 246 190 14 246 190 14 246 190 14
53763 -246 190 14 246 190 14 246 190 14 246 190 14
53764 -246 190 14 246 190 14 241 196 14 226 184 13
53765 - 61 42 6 2 2 6 2 2 6 2 2 6
53766 - 22 22 22 238 238 238 253 253 253 253 253 253
53767 -253 253 253 253 253 253 253 253 253 253 253 253
53768 -253 253 253 253 253 253 253 253 253 253 253 253
53769 -253 253 253 253 253 253 253 253 253 253 253 253
53770 -253 253 253 226 226 226 187 187 187 180 133 36
53771 -216 158 10 236 178 12 239 182 13 236 178 12
53772 -230 174 11 226 170 11 226 170 11 230 174 11
53773 -236 178 12 242 186 14 246 190 14 246 190 14
53774 -246 190 14 246 190 14 246 186 14 239 182 13
53775 -206 162 42 106 106 106 66 66 66 34 34 34
53776 - 14 14 14 6 6 6 0 0 0 0 0 0
53777 - 0 0 0 0 0 0 0 0 0 0 0 0
53778 - 0 0 0 0 0 0 0 0 0 0 0 0
53779 - 0 0 0 0 0 0 0 0 0 6 6 6
53780 - 26 26 26 70 70 70 163 133 67 213 154 11
53781 -236 178 12 246 190 14 246 190 14 246 190 14
53782 -246 190 14 246 190 14 246 190 14 246 190 14
53783 -246 190 14 246 190 14 246 190 14 246 190 14
53784 -246 190 14 246 190 14 246 190 14 241 196 14
53785 -190 146 13 18 14 6 2 2 6 2 2 6
53786 - 46 46 46 246 246 246 253 253 253 253 253 253
53787 -253 253 253 253 253 253 253 253 253 253 253 253
53788 -253 253 253 253 253 253 253 253 253 253 253 253
53789 -253 253 253 253 253 253 253 253 253 253 253 253
53790 -253 253 253 221 221 221 86 86 86 156 107 11
53791 -216 158 10 236 178 12 242 186 14 246 186 14
53792 -242 186 14 239 182 13 239 182 13 242 186 14
53793 -242 186 14 246 186 14 246 190 14 246 190 14
53794 -246 190 14 246 190 14 246 190 14 246 190 14
53795 -242 186 14 225 175 15 142 122 72 66 66 66
53796 - 30 30 30 10 10 10 0 0 0 0 0 0
53797 - 0 0 0 0 0 0 0 0 0 0 0 0
53798 - 0 0 0 0 0 0 0 0 0 0 0 0
53799 - 0 0 0 0 0 0 0 0 0 6 6 6
53800 - 26 26 26 70 70 70 163 133 67 210 150 10
53801 -236 178 12 246 190 14 246 190 14 246 190 14
53802 -246 190 14 246 190 14 246 190 14 246 190 14
53803 -246 190 14 246 190 14 246 190 14 246 190 14
53804 -246 190 14 246 190 14 246 190 14 246 190 14
53805 -232 195 16 121 92 8 34 34 34 106 106 106
53806 -221 221 221 253 253 253 253 253 253 253 253 253
53807 -253 253 253 253 253 253 253 253 253 253 253 253
53808 -253 253 253 253 253 253 253 253 253 253 253 253
53809 -253 253 253 253 253 253 253 253 253 253 253 253
53810 -242 242 242 82 82 82 18 14 6 163 110 8
53811 -216 158 10 236 178 12 242 186 14 246 190 14
53812 -246 190 14 246 190 14 246 190 14 246 190 14
53813 -246 190 14 246 190 14 246 190 14 246 190 14
53814 -246 190 14 246 190 14 246 190 14 246 190 14
53815 -246 190 14 246 190 14 242 186 14 163 133 67
53816 - 46 46 46 18 18 18 6 6 6 0 0 0
53817 - 0 0 0 0 0 0 0 0 0 0 0 0
53818 - 0 0 0 0 0 0 0 0 0 0 0 0
53819 - 0 0 0 0 0 0 0 0 0 10 10 10
53820 - 30 30 30 78 78 78 163 133 67 210 150 10
53821 -236 178 12 246 186 14 246 190 14 246 190 14
53822 -246 190 14 246 190 14 246 190 14 246 190 14
53823 -246 190 14 246 190 14 246 190 14 246 190 14
53824 -246 190 14 246 190 14 246 190 14 246 190 14
53825 -241 196 14 215 174 15 190 178 144 253 253 253
53826 -253 253 253 253 253 253 253 253 253 253 253 253
53827 -253 253 253 253 253 253 253 253 253 253 253 253
53828 -253 253 253 253 253 253 253 253 253 253 253 253
53829 -253 253 253 253 253 253 253 253 253 218 218 218
53830 - 58 58 58 2 2 6 22 18 6 167 114 7
53831 -216 158 10 236 178 12 246 186 14 246 190 14
53832 -246 190 14 246 190 14 246 190 14 246 190 14
53833 -246 190 14 246 190 14 246 190 14 246 190 14
53834 -246 190 14 246 190 14 246 190 14 246 190 14
53835 -246 190 14 246 186 14 242 186 14 190 150 46
53836 - 54 54 54 22 22 22 6 6 6 0 0 0
53837 - 0 0 0 0 0 0 0 0 0 0 0 0
53838 - 0 0 0 0 0 0 0 0 0 0 0 0
53839 - 0 0 0 0 0 0 0 0 0 14 14 14
53840 - 38 38 38 86 86 86 180 133 36 213 154 11
53841 -236 178 12 246 186 14 246 190 14 246 190 14
53842 -246 190 14 246 190 14 246 190 14 246 190 14
53843 -246 190 14 246 190 14 246 190 14 246 190 14
53844 -246 190 14 246 190 14 246 190 14 246 190 14
53845 -246 190 14 232 195 16 190 146 13 214 214 214
53846 -253 253 253 253 253 253 253 253 253 253 253 253
53847 -253 253 253 253 253 253 253 253 253 253 253 253
53848 -253 253 253 253 253 253 253 253 253 253 253 253
53849 -253 253 253 250 250 250 170 170 170 26 26 26
53850 - 2 2 6 2 2 6 37 26 9 163 110 8
53851 -219 162 10 239 182 13 246 186 14 246 190 14
53852 -246 190 14 246 190 14 246 190 14 246 190 14
53853 -246 190 14 246 190 14 246 190 14 246 190 14
53854 -246 190 14 246 190 14 246 190 14 246 190 14
53855 -246 186 14 236 178 12 224 166 10 142 122 72
53856 - 46 46 46 18 18 18 6 6 6 0 0 0
53857 - 0 0 0 0 0 0 0 0 0 0 0 0
53858 - 0 0 0 0 0 0 0 0 0 0 0 0
53859 - 0 0 0 0 0 0 6 6 6 18 18 18
53860 - 50 50 50 109 106 95 192 133 9 224 166 10
53861 -242 186 14 246 190 14 246 190 14 246 190 14
53862 -246 190 14 246 190 14 246 190 14 246 190 14
53863 -246 190 14 246 190 14 246 190 14 246 190 14
53864 -246 190 14 246 190 14 246 190 14 246 190 14
53865 -242 186 14 226 184 13 210 162 10 142 110 46
53866 -226 226 226 253 253 253 253 253 253 253 253 253
53867 -253 253 253 253 253 253 253 253 253 253 253 253
53868 -253 253 253 253 253 253 253 253 253 253 253 253
53869 -198 198 198 66 66 66 2 2 6 2 2 6
53870 - 2 2 6 2 2 6 50 34 6 156 107 11
53871 -219 162 10 239 182 13 246 186 14 246 190 14
53872 -246 190 14 246 190 14 246 190 14 246 190 14
53873 -246 190 14 246 190 14 246 190 14 246 190 14
53874 -246 190 14 246 190 14 246 190 14 242 186 14
53875 -234 174 13 213 154 11 154 122 46 66 66 66
53876 - 30 30 30 10 10 10 0 0 0 0 0 0
53877 - 0 0 0 0 0 0 0 0 0 0 0 0
53878 - 0 0 0 0 0 0 0 0 0 0 0 0
53879 - 0 0 0 0 0 0 6 6 6 22 22 22
53880 - 58 58 58 154 121 60 206 145 10 234 174 13
53881 -242 186 14 246 186 14 246 190 14 246 190 14
53882 -246 190 14 246 190 14 246 190 14 246 190 14
53883 -246 190 14 246 190 14 246 190 14 246 190 14
53884 -246 190 14 246 190 14 246 190 14 246 190 14
53885 -246 186 14 236 178 12 210 162 10 163 110 8
53886 - 61 42 6 138 138 138 218 218 218 250 250 250
53887 -253 253 253 253 253 253 253 253 253 250 250 250
53888 -242 242 242 210 210 210 144 144 144 66 66 66
53889 - 6 6 6 2 2 6 2 2 6 2 2 6
53890 - 2 2 6 2 2 6 61 42 6 163 110 8
53891 -216 158 10 236 178 12 246 190 14 246 190 14
53892 -246 190 14 246 190 14 246 190 14 246 190 14
53893 -246 190 14 246 190 14 246 190 14 246 190 14
53894 -246 190 14 239 182 13 230 174 11 216 158 10
53895 -190 142 34 124 112 88 70 70 70 38 38 38
53896 - 18 18 18 6 6 6 0 0 0 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 0 0 0 0 0 0 0 0 0 0 0 0
53899 - 0 0 0 0 0 0 6 6 6 22 22 22
53900 - 62 62 62 168 124 44 206 145 10 224 166 10
53901 -236 178 12 239 182 13 242 186 14 242 186 14
53902 -246 186 14 246 190 14 246 190 14 246 190 14
53903 -246 190 14 246 190 14 246 190 14 246 190 14
53904 -246 190 14 246 190 14 246 190 14 246 190 14
53905 -246 190 14 236 178 12 216 158 10 175 118 6
53906 - 80 54 7 2 2 6 6 6 6 30 30 30
53907 - 54 54 54 62 62 62 50 50 50 38 38 38
53908 - 14 14 14 2 2 6 2 2 6 2 2 6
53909 - 2 2 6 2 2 6 2 2 6 2 2 6
53910 - 2 2 6 6 6 6 80 54 7 167 114 7
53911 -213 154 11 236 178 12 246 190 14 246 190 14
53912 -246 190 14 246 190 14 246 190 14 246 190 14
53913 -246 190 14 242 186 14 239 182 13 239 182 13
53914 -230 174 11 210 150 10 174 135 50 124 112 88
53915 - 82 82 82 54 54 54 34 34 34 18 18 18
53916 - 6 6 6 0 0 0 0 0 0 0 0 0
53917 - 0 0 0 0 0 0 0 0 0 0 0 0
53918 - 0 0 0 0 0 0 0 0 0 0 0 0
53919 - 0 0 0 0 0 0 6 6 6 18 18 18
53920 - 50 50 50 158 118 36 192 133 9 200 144 11
53921 -216 158 10 219 162 10 224 166 10 226 170 11
53922 -230 174 11 236 178 12 239 182 13 239 182 13
53923 -242 186 14 246 186 14 246 190 14 246 190 14
53924 -246 190 14 246 190 14 246 190 14 246 190 14
53925 -246 186 14 230 174 11 210 150 10 163 110 8
53926 -104 69 6 10 10 10 2 2 6 2 2 6
53927 - 2 2 6 2 2 6 2 2 6 2 2 6
53928 - 2 2 6 2 2 6 2 2 6 2 2 6
53929 - 2 2 6 2 2 6 2 2 6 2 2 6
53930 - 2 2 6 6 6 6 91 60 6 167 114 7
53931 -206 145 10 230 174 11 242 186 14 246 190 14
53932 -246 190 14 246 190 14 246 186 14 242 186 14
53933 -239 182 13 230 174 11 224 166 10 213 154 11
53934 -180 133 36 124 112 88 86 86 86 58 58 58
53935 - 38 38 38 22 22 22 10 10 10 6 6 6
53936 - 0 0 0 0 0 0 0 0 0 0 0 0
53937 - 0 0 0 0 0 0 0 0 0 0 0 0
53938 - 0 0 0 0 0 0 0 0 0 0 0 0
53939 - 0 0 0 0 0 0 0 0 0 14 14 14
53940 - 34 34 34 70 70 70 138 110 50 158 118 36
53941 -167 114 7 180 123 7 192 133 9 197 138 11
53942 -200 144 11 206 145 10 213 154 11 219 162 10
53943 -224 166 10 230 174 11 239 182 13 242 186 14
53944 -246 186 14 246 186 14 246 186 14 246 186 14
53945 -239 182 13 216 158 10 185 133 11 152 99 6
53946 -104 69 6 18 14 6 2 2 6 2 2 6
53947 - 2 2 6 2 2 6 2 2 6 2 2 6
53948 - 2 2 6 2 2 6 2 2 6 2 2 6
53949 - 2 2 6 2 2 6 2 2 6 2 2 6
53950 - 2 2 6 6 6 6 80 54 7 152 99 6
53951 -192 133 9 219 162 10 236 178 12 239 182 13
53952 -246 186 14 242 186 14 239 182 13 236 178 12
53953 -224 166 10 206 145 10 192 133 9 154 121 60
53954 - 94 94 94 62 62 62 42 42 42 22 22 22
53955 - 14 14 14 6 6 6 0 0 0 0 0 0
53956 - 0 0 0 0 0 0 0 0 0 0 0 0
53957 - 0 0 0 0 0 0 0 0 0 0 0 0
53958 - 0 0 0 0 0 0 0 0 0 0 0 0
53959 - 0 0 0 0 0 0 0 0 0 6 6 6
53960 - 18 18 18 34 34 34 58 58 58 78 78 78
53961 -101 98 89 124 112 88 142 110 46 156 107 11
53962 -163 110 8 167 114 7 175 118 6 180 123 7
53963 -185 133 11 197 138 11 210 150 10 219 162 10
53964 -226 170 11 236 178 12 236 178 12 234 174 13
53965 -219 162 10 197 138 11 163 110 8 130 83 6
53966 - 91 60 6 10 10 10 2 2 6 2 2 6
53967 - 18 18 18 38 38 38 38 38 38 38 38 38
53968 - 38 38 38 38 38 38 38 38 38 38 38 38
53969 - 38 38 38 38 38 38 26 26 26 2 2 6
53970 - 2 2 6 6 6 6 70 47 6 137 92 6
53971 -175 118 6 200 144 11 219 162 10 230 174 11
53972 -234 174 13 230 174 11 219 162 10 210 150 10
53973 -192 133 9 163 110 8 124 112 88 82 82 82
53974 - 50 50 50 30 30 30 14 14 14 6 6 6
53975 - 0 0 0 0 0 0 0 0 0 0 0 0
53976 - 0 0 0 0 0 0 0 0 0 0 0 0
53977 - 0 0 0 0 0 0 0 0 0 0 0 0
53978 - 0 0 0 0 0 0 0 0 0 0 0 0
53979 - 0 0 0 0 0 0 0 0 0 0 0 0
53980 - 6 6 6 14 14 14 22 22 22 34 34 34
53981 - 42 42 42 58 58 58 74 74 74 86 86 86
53982 -101 98 89 122 102 70 130 98 46 121 87 25
53983 -137 92 6 152 99 6 163 110 8 180 123 7
53984 -185 133 11 197 138 11 206 145 10 200 144 11
53985 -180 123 7 156 107 11 130 83 6 104 69 6
53986 - 50 34 6 54 54 54 110 110 110 101 98 89
53987 - 86 86 86 82 82 82 78 78 78 78 78 78
53988 - 78 78 78 78 78 78 78 78 78 78 78 78
53989 - 78 78 78 82 82 82 86 86 86 94 94 94
53990 -106 106 106 101 101 101 86 66 34 124 80 6
53991 -156 107 11 180 123 7 192 133 9 200 144 11
53992 -206 145 10 200 144 11 192 133 9 175 118 6
53993 -139 102 15 109 106 95 70 70 70 42 42 42
53994 - 22 22 22 10 10 10 0 0 0 0 0 0
53995 - 0 0 0 0 0 0 0 0 0 0 0 0
53996 - 0 0 0 0 0 0 0 0 0 0 0 0
53997 - 0 0 0 0 0 0 0 0 0 0 0 0
53998 - 0 0 0 0 0 0 0 0 0 0 0 0
53999 - 0 0 0 0 0 0 0 0 0 0 0 0
54000 - 0 0 0 0 0 0 6 6 6 10 10 10
54001 - 14 14 14 22 22 22 30 30 30 38 38 38
54002 - 50 50 50 62 62 62 74 74 74 90 90 90
54003 -101 98 89 112 100 78 121 87 25 124 80 6
54004 -137 92 6 152 99 6 152 99 6 152 99 6
54005 -138 86 6 124 80 6 98 70 6 86 66 30
54006 -101 98 89 82 82 82 58 58 58 46 46 46
54007 - 38 38 38 34 34 34 34 34 34 34 34 34
54008 - 34 34 34 34 34 34 34 34 34 34 34 34
54009 - 34 34 34 34 34 34 38 38 38 42 42 42
54010 - 54 54 54 82 82 82 94 86 76 91 60 6
54011 -134 86 6 156 107 11 167 114 7 175 118 6
54012 -175 118 6 167 114 7 152 99 6 121 87 25
54013 -101 98 89 62 62 62 34 34 34 18 18 18
54014 - 6 6 6 0 0 0 0 0 0 0 0 0
54015 - 0 0 0 0 0 0 0 0 0 0 0 0
54016 - 0 0 0 0 0 0 0 0 0 0 0 0
54017 - 0 0 0 0 0 0 0 0 0 0 0 0
54018 - 0 0 0 0 0 0 0 0 0 0 0 0
54019 - 0 0 0 0 0 0 0 0 0 0 0 0
54020 - 0 0 0 0 0 0 0 0 0 0 0 0
54021 - 0 0 0 6 6 6 6 6 6 10 10 10
54022 - 18 18 18 22 22 22 30 30 30 42 42 42
54023 - 50 50 50 66 66 66 86 86 86 101 98 89
54024 -106 86 58 98 70 6 104 69 6 104 69 6
54025 -104 69 6 91 60 6 82 62 34 90 90 90
54026 - 62 62 62 38 38 38 22 22 22 14 14 14
54027 - 10 10 10 10 10 10 10 10 10 10 10 10
54028 - 10 10 10 10 10 10 6 6 6 10 10 10
54029 - 10 10 10 10 10 10 10 10 10 14 14 14
54030 - 22 22 22 42 42 42 70 70 70 89 81 66
54031 - 80 54 7 104 69 6 124 80 6 137 92 6
54032 -134 86 6 116 81 8 100 82 52 86 86 86
54033 - 58 58 58 30 30 30 14 14 14 6 6 6
54034 - 0 0 0 0 0 0 0 0 0 0 0 0
54035 - 0 0 0 0 0 0 0 0 0 0 0 0
54036 - 0 0 0 0 0 0 0 0 0 0 0 0
54037 - 0 0 0 0 0 0 0 0 0 0 0 0
54038 - 0 0 0 0 0 0 0 0 0 0 0 0
54039 - 0 0 0 0 0 0 0 0 0 0 0 0
54040 - 0 0 0 0 0 0 0 0 0 0 0 0
54041 - 0 0 0 0 0 0 0 0 0 0 0 0
54042 - 0 0 0 6 6 6 10 10 10 14 14 14
54043 - 18 18 18 26 26 26 38 38 38 54 54 54
54044 - 70 70 70 86 86 86 94 86 76 89 81 66
54045 - 89 81 66 86 86 86 74 74 74 50 50 50
54046 - 30 30 30 14 14 14 6 6 6 0 0 0
54047 - 0 0 0 0 0 0 0 0 0 0 0 0
54048 - 0 0 0 0 0 0 0 0 0 0 0 0
54049 - 0 0 0 0 0 0 0 0 0 0 0 0
54050 - 6 6 6 18 18 18 34 34 34 58 58 58
54051 - 82 82 82 89 81 66 89 81 66 89 81 66
54052 - 94 86 66 94 86 76 74 74 74 50 50 50
54053 - 26 26 26 14 14 14 6 6 6 0 0 0
54054 - 0 0 0 0 0 0 0 0 0 0 0 0
54055 - 0 0 0 0 0 0 0 0 0 0 0 0
54056 - 0 0 0 0 0 0 0 0 0 0 0 0
54057 - 0 0 0 0 0 0 0 0 0 0 0 0
54058 - 0 0 0 0 0 0 0 0 0 0 0 0
54059 - 0 0 0 0 0 0 0 0 0 0 0 0
54060 - 0 0 0 0 0 0 0 0 0 0 0 0
54061 - 0 0 0 0 0 0 0 0 0 0 0 0
54062 - 0 0 0 0 0 0 0 0 0 0 0 0
54063 - 6 6 6 6 6 6 14 14 14 18 18 18
54064 - 30 30 30 38 38 38 46 46 46 54 54 54
54065 - 50 50 50 42 42 42 30 30 30 18 18 18
54066 - 10 10 10 0 0 0 0 0 0 0 0 0
54067 - 0 0 0 0 0 0 0 0 0 0 0 0
54068 - 0 0 0 0 0 0 0 0 0 0 0 0
54069 - 0 0 0 0 0 0 0 0 0 0 0 0
54070 - 0 0 0 6 6 6 14 14 14 26 26 26
54071 - 38 38 38 50 50 50 58 58 58 58 58 58
54072 - 54 54 54 42 42 42 30 30 30 18 18 18
54073 - 10 10 10 0 0 0 0 0 0 0 0 0
54074 - 0 0 0 0 0 0 0 0 0 0 0 0
54075 - 0 0 0 0 0 0 0 0 0 0 0 0
54076 - 0 0 0 0 0 0 0 0 0 0 0 0
54077 - 0 0 0 0 0 0 0 0 0 0 0 0
54078 - 0 0 0 0 0 0 0 0 0 0 0 0
54079 - 0 0 0 0 0 0 0 0 0 0 0 0
54080 - 0 0 0 0 0 0 0 0 0 0 0 0
54081 - 0 0 0 0 0 0 0 0 0 0 0 0
54082 - 0 0 0 0 0 0 0 0 0 0 0 0
54083 - 0 0 0 0 0 0 0 0 0 6 6 6
54084 - 6 6 6 10 10 10 14 14 14 18 18 18
54085 - 18 18 18 14 14 14 10 10 10 6 6 6
54086 - 0 0 0 0 0 0 0 0 0 0 0 0
54087 - 0 0 0 0 0 0 0 0 0 0 0 0
54088 - 0 0 0 0 0 0 0 0 0 0 0 0
54089 - 0 0 0 0 0 0 0 0 0 0 0 0
54090 - 0 0 0 0 0 0 0 0 0 6 6 6
54091 - 14 14 14 18 18 18 22 22 22 22 22 22
54092 - 18 18 18 14 14 14 10 10 10 6 6 6
54093 - 0 0 0 0 0 0 0 0 0 0 0 0
54094 - 0 0 0 0 0 0 0 0 0 0 0 0
54095 - 0 0 0 0 0 0 0 0 0 0 0 0
54096 - 0 0 0 0 0 0 0 0 0 0 0 0
54097 - 0 0 0 0 0 0 0 0 0 0 0 0
54098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54111 +4 4 4 4 4 4
54112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54125 +4 4 4 4 4 4
54126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54139 +4 4 4 4 4 4
54140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54153 +4 4 4 4 4 4
54154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54167 +4 4 4 4 4 4
54168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54174 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54181 +4 4 4 4 4 4
54182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54186 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54187 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54188 +4 4 4 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 1 1 1 0 0 0
54192 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54193 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54195 +4 4 4 4 4 4
54196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54200 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54201 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54202 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
54206 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54207 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54208 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54209 +4 4 4 4 4 4
54210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54214 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54215 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54216 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
54220 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54221 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54222 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54223 +4 4 4 4 4 4
54224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54227 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54228 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54229 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54230 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
54233 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54234 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54235 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54236 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54237 +4 4 4 4 4 4
54238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54241 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54242 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54243 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54244 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54245 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54246 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54247 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54248 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54249 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54250 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54251 +4 4 4 4 4 4
54252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54255 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54256 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54257 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54258 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54259 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54260 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54261 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54262 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54263 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54264 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54265 +4 4 4 4 4 4
54266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54268 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54269 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54270 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54271 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54272 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54273 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54274 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54275 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54276 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54277 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54278 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54279 +4 4 4 4 4 4
54280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54282 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54283 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54284 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54285 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54286 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54287 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54288 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54289 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54290 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54291 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54292 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54293 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54296 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54297 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54298 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54299 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54300 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54301 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54302 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54303 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54304 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54305 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54306 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54307 +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 4 4 4 4 4 4 4 4 4 4 4 4
54310 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54311 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54312 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54313 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54314 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54315 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54316 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54317 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54318 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54319 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54320 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54321 +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 4 4 4 3 3 3 0 0 0
54324 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54325 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54326 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54327 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54328 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54329 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54330 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54331 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54332 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54333 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54334 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54335 +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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54338 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54339 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54340 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54341 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54342 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54343 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54344 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54345 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54346 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54347 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54348 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54349 +0 0 0 4 4 4
54350 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54351 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54352 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54353 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54354 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54355 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54356 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54357 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54358 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54359 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54360 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54361 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54362 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54363 +2 0 0 0 0 0
54364 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54365 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54366 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54367 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54368 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54369 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54370 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54371 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54372 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54373 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54374 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54375 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54376 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54377 +37 38 37 0 0 0
54378 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54379 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54380 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54381 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54382 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54383 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54384 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54385 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54386 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54387 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54388 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54389 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54390 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54391 +85 115 134 4 0 0
54392 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54393 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54394 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54395 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54396 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54397 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54398 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54399 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54400 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54401 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54402 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54403 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54404 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54405 +60 73 81 4 0 0
54406 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54407 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54408 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54409 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54410 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54411 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54412 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54413 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54414 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54415 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54416 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54417 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54418 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54419 +16 19 21 4 0 0
54420 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54421 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54422 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54423 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54424 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54425 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54426 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54427 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54428 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54429 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54430 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54431 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54432 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54433 +4 0 0 4 3 3
54434 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54435 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54436 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54438 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54439 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54440 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54441 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54442 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54443 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54444 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54445 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54446 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54447 +3 2 2 4 4 4
54448 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54449 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54450 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54451 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54452 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54453 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54454 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54455 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54456 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54457 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54458 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54459 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54460 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54461 +4 4 4 4 4 4
54462 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54463 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54464 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54465 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54466 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54467 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54468 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54469 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54470 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54471 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54472 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54473 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54474 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54475 +4 4 4 4 4 4
54476 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54477 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54478 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54479 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54480 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54481 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54482 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54483 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54484 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54485 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54486 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54487 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54488 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54489 +5 5 5 5 5 5
54490 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54491 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54492 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54493 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54494 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54495 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54496 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54497 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54498 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54499 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54500 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54501 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54502 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54503 +5 5 5 4 4 4
54504 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54505 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54506 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54507 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54508 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54509 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54510 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54511 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54512 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54513 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54514 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54515 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54517 +4 4 4 4 4 4
54518 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54519 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54520 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54521 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54522 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54523 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54524 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54525 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54526 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54527 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54528 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54529 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54531 +4 4 4 4 4 4
54532 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54533 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54534 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54535 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54536 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54537 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54538 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54539 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54540 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54541 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54542 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54545 +4 4 4 4 4 4
54546 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54547 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54548 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54549 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54550 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54551 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54552 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54553 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54554 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54555 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54556 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54559 +4 4 4 4 4 4
54560 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54561 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54562 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54563 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54564 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54565 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54566 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54567 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54568 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54569 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54570 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54573 +4 4 4 4 4 4
54574 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54575 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54576 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54577 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54578 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54579 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54580 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54581 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54582 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54583 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54584 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54587 +4 4 4 4 4 4
54588 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54589 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54590 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54591 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54592 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54593 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54594 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54595 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54596 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54597 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54598 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54601 +4 4 4 4 4 4
54602 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54603 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54604 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54605 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54606 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54607 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54608 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54609 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54610 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54611 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54612 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54615 +4 4 4 4 4 4
54616 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54617 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54618 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54619 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54620 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54621 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54622 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54623 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54624 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54625 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54626 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54629 +4 4 4 4 4 4
54630 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54631 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54632 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54633 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54634 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54635 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54636 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54637 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54638 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54639 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54640 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54643 +4 4 4 4 4 4
54644 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54645 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54646 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54647 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54648 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54649 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54650 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54651 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54652 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54653 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54654 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54657 +4 4 4 4 4 4
54658 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54659 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54660 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54661 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54662 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54663 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54664 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54665 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54666 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54667 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54668 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54671 +4 4 4 4 4 4
54672 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54673 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54674 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54675 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54676 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54677 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54678 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54679 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54680 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54681 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54682 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685 +4 4 4 4 4 4
54686 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54687 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54688 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54689 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54690 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54691 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54692 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54693 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54694 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54695 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54696 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699 +4 4 4 4 4 4
54700 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54701 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54702 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54703 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54704 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54705 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54706 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54707 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54708 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54709 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54710 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713 +4 4 4 4 4 4
54714 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54715 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54716 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54717 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54718 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54719 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54720 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54721 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54722 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54723 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54724 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727 +4 4 4 4 4 4
54728 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54729 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54730 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54731 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54732 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54733 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54734 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54735 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54736 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54737 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54738 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741 +4 4 4 4 4 4
54742 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54743 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54744 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54745 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54746 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54747 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54748 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54749 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54750 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54751 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54752 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755 +4 4 4 4 4 4
54756 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54757 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54758 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54759 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54760 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54761 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54762 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54763 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54764 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54765 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54766 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54769 +4 4 4 4 4 4
54770 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54771 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54772 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54773 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54774 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54775 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54776 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54777 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54778 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54779 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54780 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783 +4 4 4 4 4 4
54784 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54785 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54786 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54787 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54788 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54789 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54790 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54791 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54792 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54793 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54794 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54797 +4 4 4 4 4 4
54798 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54799 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54800 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54801 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54802 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54803 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54804 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54805 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54806 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54807 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54808 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54811 +4 4 4 4 4 4
54812 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54813 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54814 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54815 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54816 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54817 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54818 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54819 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54820 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54821 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54822 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54825 +4 4 4 4 4 4
54826 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54827 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54828 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54829 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54830 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54831 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54832 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54833 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54834 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54835 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54836 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54839 +4 4 4 4 4 4
54840 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54841 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54842 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54843 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54844 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54845 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54846 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54847 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54848 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54849 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54850 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54853 +4 4 4 4 4 4
54854 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54855 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54856 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54857 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54858 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54859 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54860 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54861 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54862 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54863 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54864 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54867 +4 4 4 4 4 4
54868 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54869 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54870 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54871 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54872 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54873 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54874 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54875 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54876 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54877 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54878 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54881 +4 4 4 4 4 4
54882 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54883 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54884 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54885 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54886 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54887 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54888 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54889 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54890 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54891 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54892 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54895 +4 4 4 4 4 4
54896 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54897 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54898 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54899 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54900 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54901 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54902 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54903 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54904 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54905 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54906 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54909 +4 4 4 4 4 4
54910 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54911 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54912 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54913 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54914 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54915 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54916 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54917 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54918 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54919 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54923 +4 4 4 4 4 4
54924 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54925 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54926 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54927 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54928 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54929 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54930 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54931 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54932 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54933 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54937 +4 4 4 4 4 4
54938 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54939 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54940 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54941 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54942 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54943 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54944 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54945 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54946 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54947 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54951 +4 4 4 4 4 4
54952 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54953 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54954 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54955 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54956 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54957 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54958 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54959 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54960 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54961 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54965 +4 4 4 4 4 4
54966 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54967 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54968 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54969 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54970 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54971 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54972 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54973 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54974 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54979 +4 4 4 4 4 4
54980 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54981 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54982 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54983 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54984 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54985 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54986 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54987 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54988 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54993 +4 4 4 4 4 4
54994 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54995 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54996 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54997 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54998 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54999 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55000 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55001 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55002 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55007 +4 4 4 4 4 4
55008 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55009 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55010 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55011 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55012 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55013 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55014 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55015 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55021 +4 4 4 4 4 4
55022 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55023 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55024 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55025 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55026 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55027 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55028 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55029 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55035 +4 4 4 4 4 4
55036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55037 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55038 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55039 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55040 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55041 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55042 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55043 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55049 +4 4 4 4 4 4
55050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55051 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55052 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55053 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55054 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55055 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55056 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55057 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55063 +4 4 4 4 4 4
55064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55065 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55066 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55067 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55068 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55069 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55070 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55071 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55077 +4 4 4 4 4 4
55078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55080 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55081 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55082 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55083 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55084 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55085 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55091 +4 4 4 4 4 4
55092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55095 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55096 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55097 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55098 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55105 +4 4 4 4 4 4
55106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55109 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55110 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55111 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55112 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55119 +4 4 4 4 4 4
55120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55123 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55124 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55125 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55126 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55133 +4 4 4 4 4 4
55134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55137 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55138 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55139 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55140 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55147 +4 4 4 4 4 4
55148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55152 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55153 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55154 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55161 +4 4 4 4 4 4
55162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55166 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55167 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55168 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55175 +4 4 4 4 4 4
55176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55180 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55181 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55182 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55189 +4 4 4 4 4 4
55190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55195 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55203 +4 4 4 4 4 4
55204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55209 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55217 +4 4 4 4 4 4
55218 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55219 index a01147f..5d896f8 100644
55220 --- a/drivers/video/matrox/matroxfb_DAC1064.c
55221 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
55222 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55223
55224 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55225 struct matrox_switch matrox_mystique = {
55226 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55227 + .preinit = MGA1064_preinit,
55228 + .reset = MGA1064_reset,
55229 + .init = MGA1064_init,
55230 + .restore = MGA1064_restore,
55231 };
55232 EXPORT_SYMBOL(matrox_mystique);
55233 #endif
55234
55235 #ifdef CONFIG_FB_MATROX_G
55236 struct matrox_switch matrox_G100 = {
55237 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55238 + .preinit = MGAG100_preinit,
55239 + .reset = MGAG100_reset,
55240 + .init = MGAG100_init,
55241 + .restore = MGAG100_restore,
55242 };
55243 EXPORT_SYMBOL(matrox_G100);
55244 #endif
55245 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55246 index 195ad7c..09743fc 100644
55247 --- a/drivers/video/matrox/matroxfb_Ti3026.c
55248 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
55249 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55250 }
55251
55252 struct matrox_switch matrox_millennium = {
55253 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55254 + .preinit = Ti3026_preinit,
55255 + .reset = Ti3026_reset,
55256 + .init = Ti3026_init,
55257 + .restore = Ti3026_restore
55258 };
55259 EXPORT_SYMBOL(matrox_millennium);
55260 #endif
55261 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55262 index fe92eed..106e085 100644
55263 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
55264 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55265 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55266 struct mb862xxfb_par *par = info->par;
55267
55268 if (info->var.bits_per_pixel == 32) {
55269 - info->fbops->fb_fillrect = cfb_fillrect;
55270 - info->fbops->fb_copyarea = cfb_copyarea;
55271 - info->fbops->fb_imageblit = cfb_imageblit;
55272 + pax_open_kernel();
55273 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55274 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55275 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55276 + pax_close_kernel();
55277 } else {
55278 outreg(disp, GC_L0EM, 3);
55279 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55280 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55281 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55282 + pax_open_kernel();
55283 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55284 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55285 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55286 + pax_close_kernel();
55287 }
55288 outreg(draw, GDC_REG_DRAW_BASE, 0);
55289 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55290 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55291 index def0412..fed6529 100644
55292 --- a/drivers/video/nvidia/nvidia.c
55293 +++ b/drivers/video/nvidia/nvidia.c
55294 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55295 info->fix.line_length = (info->var.xres_virtual *
55296 info->var.bits_per_pixel) >> 3;
55297 if (info->var.accel_flags) {
55298 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55299 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55300 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55301 - info->fbops->fb_sync = nvidiafb_sync;
55302 + pax_open_kernel();
55303 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55304 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55305 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55306 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55307 + pax_close_kernel();
55308 info->pixmap.scan_align = 4;
55309 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55310 info->flags |= FBINFO_READS_FAST;
55311 NVResetGraphics(info);
55312 } else {
55313 - info->fbops->fb_imageblit = cfb_imageblit;
55314 - info->fbops->fb_fillrect = cfb_fillrect;
55315 - info->fbops->fb_copyarea = cfb_copyarea;
55316 - info->fbops->fb_sync = NULL;
55317 + pax_open_kernel();
55318 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55319 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55320 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55321 + *(void **)&info->fbops->fb_sync = NULL;
55322 + pax_close_kernel();
55323 info->pixmap.scan_align = 1;
55324 info->flags |= FBINFO_HWACCEL_DISABLED;
55325 info->flags &= ~FBINFO_READS_FAST;
55326 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55327 info->pixmap.size = 8 * 1024;
55328 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55329
55330 - if (!hwcur)
55331 - info->fbops->fb_cursor = NULL;
55332 + if (!hwcur) {
55333 + pax_open_kernel();
55334 + *(void **)&info->fbops->fb_cursor = NULL;
55335 + pax_close_kernel();
55336 + }
55337
55338 info->var.accel_flags = (!noaccel);
55339
55340 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55341 index 669a81f..e216d76 100644
55342 --- a/drivers/video/omap2/dss/display.c
55343 +++ b/drivers/video/omap2/dss/display.c
55344 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55345 snprintf(dssdev->alias, sizeof(dssdev->alias),
55346 "display%d", disp_num_counter++);
55347
55348 + pax_open_kernel();
55349 if (drv && drv->get_resolution == NULL)
55350 - drv->get_resolution = omapdss_default_get_resolution;
55351 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55352 if (drv && drv->get_recommended_bpp == NULL)
55353 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55354 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55355 if (drv && drv->get_timings == NULL)
55356 - drv->get_timings = omapdss_default_get_timings;
55357 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55358 + pax_close_kernel();
55359
55360 mutex_lock(&panel_list_mutex);
55361 list_add_tail(&dssdev->panel_list, &panel_list);
55362 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55363 index 83433cb..71e9b98 100644
55364 --- a/drivers/video/s1d13xxxfb.c
55365 +++ b/drivers/video/s1d13xxxfb.c
55366 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55367
55368 switch(prod_id) {
55369 case S1D13506_PROD_ID: /* activate acceleration */
55370 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55371 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55372 + pax_open_kernel();
55373 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55374 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55375 + pax_close_kernel();
55376 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55377 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55378 break;
55379 diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55380 index 2bcc84a..29dd1ea 100644
55381 --- a/drivers/video/sh_mobile_lcdcfb.c
55382 +++ b/drivers/video/sh_mobile_lcdcfb.c
55383 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55384 }
55385
55386 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55387 - lcdc_sys_write_index,
55388 - lcdc_sys_write_data,
55389 - lcdc_sys_read_data,
55390 + .write_index = lcdc_sys_write_index,
55391 + .write_data = lcdc_sys_write_data,
55392 + .read_data = lcdc_sys_read_data,
55393 };
55394
55395 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55396 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55397 index d513ed6..90b0de9 100644
55398 --- a/drivers/video/smscufx.c
55399 +++ b/drivers/video/smscufx.c
55400 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55401 fb_deferred_io_cleanup(info);
55402 kfree(info->fbdefio);
55403 info->fbdefio = NULL;
55404 - info->fbops->fb_mmap = ufx_ops_mmap;
55405 + pax_open_kernel();
55406 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55407 + pax_close_kernel();
55408 }
55409
55410 pr_debug("released /dev/fb%d user=%d count=%d",
55411 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55412 index 77b890e..458e666 100644
55413 --- a/drivers/video/udlfb.c
55414 +++ b/drivers/video/udlfb.c
55415 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55416 dlfb_urb_completion(urb);
55417
55418 error:
55419 - atomic_add(bytes_sent, &dev->bytes_sent);
55420 - atomic_add(bytes_identical, &dev->bytes_identical);
55421 - atomic_add(width*height*2, &dev->bytes_rendered);
55422 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55423 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55424 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55425 end_cycles = get_cycles();
55426 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55427 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55428 >> 10)), /* Kcycles */
55429 &dev->cpu_kcycles_used);
55430
55431 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55432 dlfb_urb_completion(urb);
55433
55434 error:
55435 - atomic_add(bytes_sent, &dev->bytes_sent);
55436 - atomic_add(bytes_identical, &dev->bytes_identical);
55437 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55438 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55439 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55440 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55441 end_cycles = get_cycles();
55442 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55443 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55444 >> 10)), /* Kcycles */
55445 &dev->cpu_kcycles_used);
55446 }
55447 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55448 fb_deferred_io_cleanup(info);
55449 kfree(info->fbdefio);
55450 info->fbdefio = NULL;
55451 - info->fbops->fb_mmap = dlfb_ops_mmap;
55452 + pax_open_kernel();
55453 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55454 + pax_close_kernel();
55455 }
55456
55457 pr_warn("released /dev/fb%d user=%d count=%d\n",
55458 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55459 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55460 struct dlfb_data *dev = fb_info->par;
55461 return snprintf(buf, PAGE_SIZE, "%u\n",
55462 - atomic_read(&dev->bytes_rendered));
55463 + atomic_read_unchecked(&dev->bytes_rendered));
55464 }
55465
55466 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55467 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55468 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55469 struct dlfb_data *dev = fb_info->par;
55470 return snprintf(buf, PAGE_SIZE, "%u\n",
55471 - atomic_read(&dev->bytes_identical));
55472 + atomic_read_unchecked(&dev->bytes_identical));
55473 }
55474
55475 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55476 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55477 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55478 struct dlfb_data *dev = fb_info->par;
55479 return snprintf(buf, PAGE_SIZE, "%u\n",
55480 - atomic_read(&dev->bytes_sent));
55481 + atomic_read_unchecked(&dev->bytes_sent));
55482 }
55483
55484 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55485 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55486 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55487 struct dlfb_data *dev = fb_info->par;
55488 return snprintf(buf, PAGE_SIZE, "%u\n",
55489 - atomic_read(&dev->cpu_kcycles_used));
55490 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55491 }
55492
55493 static ssize_t edid_show(
55494 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55495 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55496 struct dlfb_data *dev = fb_info->par;
55497
55498 - atomic_set(&dev->bytes_rendered, 0);
55499 - atomic_set(&dev->bytes_identical, 0);
55500 - atomic_set(&dev->bytes_sent, 0);
55501 - atomic_set(&dev->cpu_kcycles_used, 0);
55502 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55503 + atomic_set_unchecked(&dev->bytes_identical, 0);
55504 + atomic_set_unchecked(&dev->bytes_sent, 0);
55505 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55506
55507 return count;
55508 }
55509 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55510 index 256fba7..6e75516 100644
55511 --- a/drivers/video/uvesafb.c
55512 +++ b/drivers/video/uvesafb.c
55513 @@ -19,6 +19,7 @@
55514 #include <linux/io.h>
55515 #include <linux/mutex.h>
55516 #include <linux/slab.h>
55517 +#include <linux/moduleloader.h>
55518 #include <video/edid.h>
55519 #include <video/uvesafb.h>
55520 #ifdef CONFIG_X86
55521 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55522 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55523 par->pmi_setpal = par->ypan = 0;
55524 } else {
55525 +
55526 +#ifdef CONFIG_PAX_KERNEXEC
55527 +#ifdef CONFIG_MODULES
55528 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55529 +#endif
55530 + if (!par->pmi_code) {
55531 + par->pmi_setpal = par->ypan = 0;
55532 + return 0;
55533 + }
55534 +#endif
55535 +
55536 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55537 + task->t.regs.edi);
55538 +
55539 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55540 + pax_open_kernel();
55541 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55542 + pax_close_kernel();
55543 +
55544 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55545 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55546 +#else
55547 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55548 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55549 +#endif
55550 +
55551 printk(KERN_INFO "uvesafb: protected mode interface info at "
55552 "%04x:%04x\n",
55553 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55554 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55555 par->ypan = ypan;
55556
55557 if (par->pmi_setpal || par->ypan) {
55558 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55559 if (__supported_pte_mask & _PAGE_NX) {
55560 par->pmi_setpal = par->ypan = 0;
55561 printk(KERN_WARNING "uvesafb: NX protection is active, "
55562 "better not use the PMI.\n");
55563 - } else {
55564 + } else
55565 +#endif
55566 uvesafb_vbe_getpmi(task, par);
55567 - }
55568 }
55569 #else
55570 /* The protected mode interface is not available on non-x86. */
55571 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55572 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55573
55574 /* Disable blanking if the user requested so. */
55575 - if (!blank)
55576 - info->fbops->fb_blank = NULL;
55577 + if (!blank) {
55578 + pax_open_kernel();
55579 + *(void **)&info->fbops->fb_blank = NULL;
55580 + pax_close_kernel();
55581 + }
55582
55583 /*
55584 * Find out how much IO memory is required for the mode with
55585 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55586 info->flags = FBINFO_FLAG_DEFAULT |
55587 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55588
55589 - if (!par->ypan)
55590 - info->fbops->fb_pan_display = NULL;
55591 + if (!par->ypan) {
55592 + pax_open_kernel();
55593 + *(void **)&info->fbops->fb_pan_display = NULL;
55594 + pax_close_kernel();
55595 + }
55596 }
55597
55598 static void uvesafb_init_mtrr(struct fb_info *info)
55599 @@ -1792,6 +1822,11 @@ out_mode:
55600 out:
55601 kfree(par->vbe_modes);
55602
55603 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55604 + if (par->pmi_code)
55605 + module_free_exec(NULL, par->pmi_code);
55606 +#endif
55607 +
55608 framebuffer_release(info);
55609 return err;
55610 }
55611 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55612 kfree(par->vbe_modes);
55613 kfree(par->vbe_state_orig);
55614 kfree(par->vbe_state_saved);
55615 +
55616 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55617 + if (par->pmi_code)
55618 + module_free_exec(NULL, par->pmi_code);
55619 +#endif
55620 +
55621 }
55622
55623 framebuffer_release(info);
55624 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55625 index 1c7da3b..56ea0bd 100644
55626 --- a/drivers/video/vesafb.c
55627 +++ b/drivers/video/vesafb.c
55628 @@ -9,6 +9,7 @@
55629 */
55630
55631 #include <linux/module.h>
55632 +#include <linux/moduleloader.h>
55633 #include <linux/kernel.h>
55634 #include <linux/errno.h>
55635 #include <linux/string.h>
55636 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55637 static int vram_total; /* Set total amount of memory */
55638 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55639 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55640 -static void (*pmi_start)(void) __read_mostly;
55641 -static void (*pmi_pal) (void) __read_mostly;
55642 +static void (*pmi_start)(void) __read_only;
55643 +static void (*pmi_pal) (void) __read_only;
55644 static int depth __read_mostly;
55645 static int vga_compat __read_mostly;
55646 /* --------------------------------------------------------------------- */
55647 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55648 unsigned int size_remap;
55649 unsigned int size_total;
55650 char *option = NULL;
55651 + void *pmi_code = NULL;
55652
55653 /* ignore error return of fb_get_options */
55654 fb_get_options("vesafb", &option);
55655 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55656 size_remap = size_total;
55657 vesafb_fix.smem_len = size_remap;
55658
55659 -#ifndef __i386__
55660 - screen_info.vesapm_seg = 0;
55661 -#endif
55662 -
55663 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55664 printk(KERN_WARNING
55665 "vesafb: cannot reserve video memory at 0x%lx\n",
55666 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55667 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55668 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55669
55670 +#ifdef __i386__
55671 +
55672 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55673 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55674 + if (!pmi_code)
55675 +#elif !defined(CONFIG_PAX_KERNEXEC)
55676 + if (0)
55677 +#endif
55678 +
55679 +#endif
55680 + screen_info.vesapm_seg = 0;
55681 +
55682 if (screen_info.vesapm_seg) {
55683 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55684 - screen_info.vesapm_seg,screen_info.vesapm_off);
55685 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55686 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55687 }
55688
55689 if (screen_info.vesapm_seg < 0xc000)
55690 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55691
55692 if (ypan || pmi_setpal) {
55693 unsigned short *pmi_base;
55694 +
55695 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55696 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55697 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55698 +
55699 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55700 + pax_open_kernel();
55701 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55702 +#else
55703 + pmi_code = pmi_base;
55704 +#endif
55705 +
55706 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55707 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55708 +
55709 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55710 + pmi_start = ktva_ktla(pmi_start);
55711 + pmi_pal = ktva_ktla(pmi_pal);
55712 + pax_close_kernel();
55713 +#endif
55714 +
55715 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55716 if (pmi_base[3]) {
55717 printk(KERN_INFO "vesafb: pmi: ports = ");
55718 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55719 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55720 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55721
55722 - if (!ypan)
55723 - info->fbops->fb_pan_display = NULL;
55724 + if (!ypan) {
55725 + pax_open_kernel();
55726 + *(void **)&info->fbops->fb_pan_display = NULL;
55727 + pax_close_kernel();
55728 + }
55729
55730 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55731 err = -ENOMEM;
55732 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55733 fb_info(info, "%s frame buffer device\n", info->fix.id);
55734 return 0;
55735 err:
55736 +
55737 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55738 + module_free_exec(NULL, pmi_code);
55739 +#endif
55740 +
55741 if (info->screen_base)
55742 iounmap(info->screen_base);
55743 framebuffer_release(info);
55744 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55745 index 88714ae..16c2e11 100644
55746 --- a/drivers/video/via/via_clock.h
55747 +++ b/drivers/video/via/via_clock.h
55748 @@ -56,7 +56,7 @@ struct via_clock {
55749
55750 void (*set_engine_pll_state)(u8 state);
55751 void (*set_engine_pll)(struct via_pll_config config);
55752 -};
55753 +} __no_const;
55754
55755
55756 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55757 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55758 index fef20db..d28b1ab 100644
55759 --- a/drivers/xen/xenfs/xenstored.c
55760 +++ b/drivers/xen/xenfs/xenstored.c
55761 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55762 static int xsd_kva_open(struct inode *inode, struct file *file)
55763 {
55764 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55765 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55766 + NULL);
55767 +#else
55768 xen_store_interface);
55769 +#endif
55770 +
55771 if (!file->private_data)
55772 return -ENOMEM;
55773 return 0;
55774 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55775 index c71e886..61d3d44b 100644
55776 --- a/fs/9p/vfs_addr.c
55777 +++ b/fs/9p/vfs_addr.c
55778 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55779
55780 retval = v9fs_file_write_internal(inode,
55781 v9inode->writeback_fid,
55782 - (__force const char __user *)buffer,
55783 + (const char __force_user *)buffer,
55784 len, &offset, 0);
55785 if (retval > 0)
55786 retval = 0;
55787 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55788 index bb7991c..481e21a 100644
55789 --- a/fs/9p/vfs_inode.c
55790 +++ b/fs/9p/vfs_inode.c
55791 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55792 void
55793 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55794 {
55795 - char *s = nd_get_link(nd);
55796 + const char *s = nd_get_link(nd);
55797
55798 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55799 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55800 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55801 index 370b24c..ff0be7b 100644
55802 --- a/fs/Kconfig.binfmt
55803 +++ b/fs/Kconfig.binfmt
55804 @@ -103,7 +103,7 @@ config HAVE_AOUT
55805
55806 config BINFMT_AOUT
55807 tristate "Kernel support for a.out and ECOFF binaries"
55808 - depends on HAVE_AOUT
55809 + depends on HAVE_AOUT && BROKEN
55810 ---help---
55811 A.out (Assembler.OUTput) is a set of formats for libraries and
55812 executables used in the earliest versions of UNIX. Linux used
55813 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55814 index ce25d75..dc09eeb 100644
55815 --- a/fs/afs/inode.c
55816 +++ b/fs/afs/inode.c
55817 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55818 struct afs_vnode *vnode;
55819 struct super_block *sb;
55820 struct inode *inode;
55821 - static atomic_t afs_autocell_ino;
55822 + static atomic_unchecked_t afs_autocell_ino;
55823
55824 _enter("{%x:%u},%*.*s,",
55825 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55826 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55827 data.fid.unique = 0;
55828 data.fid.vnode = 0;
55829
55830 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55831 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55832 afs_iget5_autocell_test, afs_iget5_set,
55833 &data);
55834 if (!inode) {
55835 diff --git a/fs/aio.c b/fs/aio.c
55836 index 062a5f6..e5618e0 100644
55837 --- a/fs/aio.c
55838 +++ b/fs/aio.c
55839 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55840 size += sizeof(struct io_event) * nr_events;
55841
55842 nr_pages = PFN_UP(size);
55843 - if (nr_pages < 0)
55844 + if (nr_pages <= 0)
55845 return -EINVAL;
55846
55847 file = aio_private_file(ctx, nr_pages);
55848 diff --git a/fs/attr.c b/fs/attr.c
55849 index 5d4e59d..fd02418 100644
55850 --- a/fs/attr.c
55851 +++ b/fs/attr.c
55852 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55853 unsigned long limit;
55854
55855 limit = rlimit(RLIMIT_FSIZE);
55856 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55857 if (limit != RLIM_INFINITY && offset > limit)
55858 goto out_sig;
55859 if (offset > inode->i_sb->s_maxbytes)
55860 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55861 index 116fd38..c04182da 100644
55862 --- a/fs/autofs4/waitq.c
55863 +++ b/fs/autofs4/waitq.c
55864 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55865 {
55866 unsigned long sigpipe, flags;
55867 mm_segment_t fs;
55868 - const char *data = (const char *)addr;
55869 + const char __user *data = (const char __force_user *)addr;
55870 ssize_t wr = 0;
55871
55872 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55873 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55874 return 1;
55875 }
55876
55877 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55878 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55879 +#endif
55880 +
55881 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55882 enum autofs_notify notify)
55883 {
55884 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55885
55886 /* If this is a direct mount request create a dummy name */
55887 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55888 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55889 + /* this name does get written to userland via autofs4_write() */
55890 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55891 +#else
55892 qstr.len = sprintf(name, "%p", dentry);
55893 +#endif
55894 else {
55895 qstr.len = autofs4_getpath(sbi, dentry, &name);
55896 if (!qstr.len) {
55897 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55898 index 2722387..56059b5 100644
55899 --- a/fs/befs/endian.h
55900 +++ b/fs/befs/endian.h
55901 @@ -11,7 +11,7 @@
55902
55903 #include <asm/byteorder.h>
55904
55905 -static inline u64
55906 +static inline u64 __intentional_overflow(-1)
55907 fs64_to_cpu(const struct super_block *sb, fs64 n)
55908 {
55909 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55910 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55911 return (__force fs64)cpu_to_be64(n);
55912 }
55913
55914 -static inline u32
55915 +static inline u32 __intentional_overflow(-1)
55916 fs32_to_cpu(const struct super_block *sb, fs32 n)
55917 {
55918 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55919 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55920 return (__force fs32)cpu_to_be32(n);
55921 }
55922
55923 -static inline u16
55924 +static inline u16 __intentional_overflow(-1)
55925 fs16_to_cpu(const struct super_block *sb, fs16 n)
55926 {
55927 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55928 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55929 index ca0ba15..0fa3257 100644
55930 --- a/fs/binfmt_aout.c
55931 +++ b/fs/binfmt_aout.c
55932 @@ -16,6 +16,7 @@
55933 #include <linux/string.h>
55934 #include <linux/fs.h>
55935 #include <linux/file.h>
55936 +#include <linux/security.h>
55937 #include <linux/stat.h>
55938 #include <linux/fcntl.h>
55939 #include <linux/ptrace.h>
55940 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55941 #endif
55942 # define START_STACK(u) ((void __user *)u.start_stack)
55943
55944 + memset(&dump, 0, sizeof(dump));
55945 +
55946 fs = get_fs();
55947 set_fs(KERNEL_DS);
55948 has_dumped = 1;
55949 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55950
55951 /* If the size of the dump file exceeds the rlimit, then see what would happen
55952 if we wrote the stack, but not the data area. */
55953 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55954 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55955 dump.u_dsize = 0;
55956
55957 /* Make sure we have enough room to write the stack and data areas. */
55958 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55959 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55960 dump.u_ssize = 0;
55961
55962 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55963 rlim = rlimit(RLIMIT_DATA);
55964 if (rlim >= RLIM_INFINITY)
55965 rlim = ~0;
55966 +
55967 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55968 if (ex.a_data + ex.a_bss > rlim)
55969 return -ENOMEM;
55970
55971 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55972
55973 install_exec_creds(bprm);
55974
55975 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55976 + current->mm->pax_flags = 0UL;
55977 +#endif
55978 +
55979 +#ifdef CONFIG_PAX_PAGEEXEC
55980 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55981 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55982 +
55983 +#ifdef CONFIG_PAX_EMUTRAMP
55984 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55985 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55986 +#endif
55987 +
55988 +#ifdef CONFIG_PAX_MPROTECT
55989 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55990 + current->mm->pax_flags |= MF_PAX_MPROTECT;
55991 +#endif
55992 +
55993 + }
55994 +#endif
55995 +
55996 if (N_MAGIC(ex) == OMAGIC) {
55997 unsigned long text_addr, map_size;
55998 loff_t pos;
55999 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56000 }
56001
56002 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56003 - PROT_READ | PROT_WRITE | PROT_EXEC,
56004 + PROT_READ | PROT_WRITE,
56005 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56006 fd_offset + ex.a_text);
56007 if (error != N_DATADDR(ex)) {
56008 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56009 index 67be295..83e2f86 100644
56010 --- a/fs/binfmt_elf.c
56011 +++ b/fs/binfmt_elf.c
56012 @@ -34,6 +34,7 @@
56013 #include <linux/utsname.h>
56014 #include <linux/coredump.h>
56015 #include <linux/sched.h>
56016 +#include <linux/xattr.h>
56017 #include <asm/uaccess.h>
56018 #include <asm/param.h>
56019 #include <asm/page.h>
56020 @@ -48,7 +49,7 @@
56021 static int load_elf_binary(struct linux_binprm *bprm);
56022 static int load_elf_library(struct file *);
56023 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56024 - int, int, unsigned long);
56025 + int, int, unsigned long) __intentional_overflow(-1);
56026
56027 /*
56028 * If we don't support core dumping, then supply a NULL so we
56029 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56030 #define elf_core_dump NULL
56031 #endif
56032
56033 +#ifdef CONFIG_PAX_MPROTECT
56034 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56035 +#endif
56036 +
56037 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56038 +static void elf_handle_mmap(struct file *file);
56039 +#endif
56040 +
56041 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56042 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56043 #else
56044 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56045 .load_binary = load_elf_binary,
56046 .load_shlib = load_elf_library,
56047 .core_dump = elf_core_dump,
56048 +
56049 +#ifdef CONFIG_PAX_MPROTECT
56050 + .handle_mprotect= elf_handle_mprotect,
56051 +#endif
56052 +
56053 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56054 + .handle_mmap = elf_handle_mmap,
56055 +#endif
56056 +
56057 .min_coredump = ELF_EXEC_PAGESIZE,
56058 };
56059
56060 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56061
56062 static int set_brk(unsigned long start, unsigned long end)
56063 {
56064 + unsigned long e = end;
56065 +
56066 start = ELF_PAGEALIGN(start);
56067 end = ELF_PAGEALIGN(end);
56068 if (end > start) {
56069 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56070 if (BAD_ADDR(addr))
56071 return addr;
56072 }
56073 - current->mm->start_brk = current->mm->brk = end;
56074 + current->mm->start_brk = current->mm->brk = e;
56075 return 0;
56076 }
56077
56078 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56079 elf_addr_t __user *u_rand_bytes;
56080 const char *k_platform = ELF_PLATFORM;
56081 const char *k_base_platform = ELF_BASE_PLATFORM;
56082 - unsigned char k_rand_bytes[16];
56083 + u32 k_rand_bytes[4];
56084 int items;
56085 elf_addr_t *elf_info;
56086 int ei_index = 0;
56087 const struct cred *cred = current_cred();
56088 struct vm_area_struct *vma;
56089 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56090
56091 /*
56092 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56093 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56094 * Generate 16 random bytes for userspace PRNG seeding.
56095 */
56096 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56097 - u_rand_bytes = (elf_addr_t __user *)
56098 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56099 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56100 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56101 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56102 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56103 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56104 + u_rand_bytes = (elf_addr_t __user *) p;
56105 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56106 return -EFAULT;
56107
56108 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56109 return -EFAULT;
56110 current->mm->env_end = p;
56111
56112 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56113 +
56114 /* Put the elf_info on the stack in the right place. */
56115 sp = (elf_addr_t __user *)envp + 1;
56116 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56117 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56118 return -EFAULT;
56119 return 0;
56120 }
56121 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56122 an ELF header */
56123
56124 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56125 - struct file *interpreter, unsigned long *interp_map_addr,
56126 - unsigned long no_base)
56127 + struct file *interpreter, unsigned long no_base)
56128 {
56129 struct elf_phdr *elf_phdata;
56130 struct elf_phdr *eppnt;
56131 - unsigned long load_addr = 0;
56132 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56133 int load_addr_set = 0;
56134 unsigned long last_bss = 0, elf_bss = 0;
56135 - unsigned long error = ~0UL;
56136 + unsigned long error = -EINVAL;
56137 unsigned long total_size;
56138 int retval, i, size;
56139
56140 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56141 goto out_close;
56142 }
56143
56144 +#ifdef CONFIG_PAX_SEGMEXEC
56145 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56146 + pax_task_size = SEGMEXEC_TASK_SIZE;
56147 +#endif
56148 +
56149 eppnt = elf_phdata;
56150 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56151 if (eppnt->p_type == PT_LOAD) {
56152 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56153 map_addr = elf_map(interpreter, load_addr + vaddr,
56154 eppnt, elf_prot, elf_type, total_size);
56155 total_size = 0;
56156 - if (!*interp_map_addr)
56157 - *interp_map_addr = map_addr;
56158 error = map_addr;
56159 if (BAD_ADDR(map_addr))
56160 goto out_close;
56161 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56162 k = load_addr + eppnt->p_vaddr;
56163 if (BAD_ADDR(k) ||
56164 eppnt->p_filesz > eppnt->p_memsz ||
56165 - eppnt->p_memsz > TASK_SIZE ||
56166 - TASK_SIZE - eppnt->p_memsz < k) {
56167 + eppnt->p_memsz > pax_task_size ||
56168 + pax_task_size - eppnt->p_memsz < k) {
56169 error = -ENOMEM;
56170 goto out_close;
56171 }
56172 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56173 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56174
56175 /* Map the last of the bss segment */
56176 - error = vm_brk(elf_bss, last_bss - elf_bss);
56177 - if (BAD_ADDR(error))
56178 - goto out_close;
56179 + if (last_bss > elf_bss) {
56180 + error = vm_brk(elf_bss, last_bss - elf_bss);
56181 + if (BAD_ADDR(error))
56182 + goto out_close;
56183 + }
56184 }
56185
56186 error = load_addr;
56187 @@ -538,6 +569,336 @@ out:
56188 return error;
56189 }
56190
56191 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56192 +#ifdef CONFIG_PAX_SOFTMODE
56193 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56194 +{
56195 + unsigned long pax_flags = 0UL;
56196 +
56197 +#ifdef CONFIG_PAX_PAGEEXEC
56198 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56199 + pax_flags |= MF_PAX_PAGEEXEC;
56200 +#endif
56201 +
56202 +#ifdef CONFIG_PAX_SEGMEXEC
56203 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56204 + pax_flags |= MF_PAX_SEGMEXEC;
56205 +#endif
56206 +
56207 +#ifdef CONFIG_PAX_EMUTRAMP
56208 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56209 + pax_flags |= MF_PAX_EMUTRAMP;
56210 +#endif
56211 +
56212 +#ifdef CONFIG_PAX_MPROTECT
56213 + if (elf_phdata->p_flags & PF_MPROTECT)
56214 + pax_flags |= MF_PAX_MPROTECT;
56215 +#endif
56216 +
56217 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56218 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56219 + pax_flags |= MF_PAX_RANDMMAP;
56220 +#endif
56221 +
56222 + return pax_flags;
56223 +}
56224 +#endif
56225 +
56226 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56227 +{
56228 + unsigned long pax_flags = 0UL;
56229 +
56230 +#ifdef CONFIG_PAX_PAGEEXEC
56231 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56232 + pax_flags |= MF_PAX_PAGEEXEC;
56233 +#endif
56234 +
56235 +#ifdef CONFIG_PAX_SEGMEXEC
56236 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56237 + pax_flags |= MF_PAX_SEGMEXEC;
56238 +#endif
56239 +
56240 +#ifdef CONFIG_PAX_EMUTRAMP
56241 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56242 + pax_flags |= MF_PAX_EMUTRAMP;
56243 +#endif
56244 +
56245 +#ifdef CONFIG_PAX_MPROTECT
56246 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56247 + pax_flags |= MF_PAX_MPROTECT;
56248 +#endif
56249 +
56250 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56251 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56252 + pax_flags |= MF_PAX_RANDMMAP;
56253 +#endif
56254 +
56255 + return pax_flags;
56256 +}
56257 +#endif
56258 +
56259 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56260 +#ifdef CONFIG_PAX_SOFTMODE
56261 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56262 +{
56263 + unsigned long pax_flags = 0UL;
56264 +
56265 +#ifdef CONFIG_PAX_PAGEEXEC
56266 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56267 + pax_flags |= MF_PAX_PAGEEXEC;
56268 +#endif
56269 +
56270 +#ifdef CONFIG_PAX_SEGMEXEC
56271 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56272 + pax_flags |= MF_PAX_SEGMEXEC;
56273 +#endif
56274 +
56275 +#ifdef CONFIG_PAX_EMUTRAMP
56276 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56277 + pax_flags |= MF_PAX_EMUTRAMP;
56278 +#endif
56279 +
56280 +#ifdef CONFIG_PAX_MPROTECT
56281 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56282 + pax_flags |= MF_PAX_MPROTECT;
56283 +#endif
56284 +
56285 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56286 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56287 + pax_flags |= MF_PAX_RANDMMAP;
56288 +#endif
56289 +
56290 + return pax_flags;
56291 +}
56292 +#endif
56293 +
56294 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56295 +{
56296 + unsigned long pax_flags = 0UL;
56297 +
56298 +#ifdef CONFIG_PAX_PAGEEXEC
56299 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56300 + pax_flags |= MF_PAX_PAGEEXEC;
56301 +#endif
56302 +
56303 +#ifdef CONFIG_PAX_SEGMEXEC
56304 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56305 + pax_flags |= MF_PAX_SEGMEXEC;
56306 +#endif
56307 +
56308 +#ifdef CONFIG_PAX_EMUTRAMP
56309 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56310 + pax_flags |= MF_PAX_EMUTRAMP;
56311 +#endif
56312 +
56313 +#ifdef CONFIG_PAX_MPROTECT
56314 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56315 + pax_flags |= MF_PAX_MPROTECT;
56316 +#endif
56317 +
56318 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56319 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56320 + pax_flags |= MF_PAX_RANDMMAP;
56321 +#endif
56322 +
56323 + return pax_flags;
56324 +}
56325 +#endif
56326 +
56327 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56328 +static unsigned long pax_parse_defaults(void)
56329 +{
56330 + unsigned long pax_flags = 0UL;
56331 +
56332 +#ifdef CONFIG_PAX_SOFTMODE
56333 + if (pax_softmode)
56334 + return pax_flags;
56335 +#endif
56336 +
56337 +#ifdef CONFIG_PAX_PAGEEXEC
56338 + pax_flags |= MF_PAX_PAGEEXEC;
56339 +#endif
56340 +
56341 +#ifdef CONFIG_PAX_SEGMEXEC
56342 + pax_flags |= MF_PAX_SEGMEXEC;
56343 +#endif
56344 +
56345 +#ifdef CONFIG_PAX_MPROTECT
56346 + pax_flags |= MF_PAX_MPROTECT;
56347 +#endif
56348 +
56349 +#ifdef CONFIG_PAX_RANDMMAP
56350 + if (randomize_va_space)
56351 + pax_flags |= MF_PAX_RANDMMAP;
56352 +#endif
56353 +
56354 + return pax_flags;
56355 +}
56356 +
56357 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56358 +{
56359 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56360 +
56361 +#ifdef CONFIG_PAX_EI_PAX
56362 +
56363 +#ifdef CONFIG_PAX_SOFTMODE
56364 + if (pax_softmode)
56365 + return pax_flags;
56366 +#endif
56367 +
56368 + pax_flags = 0UL;
56369 +
56370 +#ifdef CONFIG_PAX_PAGEEXEC
56371 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56372 + pax_flags |= MF_PAX_PAGEEXEC;
56373 +#endif
56374 +
56375 +#ifdef CONFIG_PAX_SEGMEXEC
56376 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56377 + pax_flags |= MF_PAX_SEGMEXEC;
56378 +#endif
56379 +
56380 +#ifdef CONFIG_PAX_EMUTRAMP
56381 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56382 + pax_flags |= MF_PAX_EMUTRAMP;
56383 +#endif
56384 +
56385 +#ifdef CONFIG_PAX_MPROTECT
56386 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56387 + pax_flags |= MF_PAX_MPROTECT;
56388 +#endif
56389 +
56390 +#ifdef CONFIG_PAX_ASLR
56391 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56392 + pax_flags |= MF_PAX_RANDMMAP;
56393 +#endif
56394 +
56395 +#endif
56396 +
56397 + return pax_flags;
56398 +
56399 +}
56400 +
56401 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56402 +{
56403 +
56404 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56405 + unsigned long i;
56406 +
56407 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56408 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56409 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56410 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56411 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56412 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56413 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56414 + return PAX_PARSE_FLAGS_FALLBACK;
56415 +
56416 +#ifdef CONFIG_PAX_SOFTMODE
56417 + if (pax_softmode)
56418 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56419 + else
56420 +#endif
56421 +
56422 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56423 + break;
56424 + }
56425 +#endif
56426 +
56427 + return PAX_PARSE_FLAGS_FALLBACK;
56428 +}
56429 +
56430 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56431 +{
56432 +
56433 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56434 + ssize_t xattr_size, i;
56435 + unsigned char xattr_value[sizeof("pemrs") - 1];
56436 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56437 +
56438 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56439 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56440 + return PAX_PARSE_FLAGS_FALLBACK;
56441 +
56442 + for (i = 0; i < xattr_size; i++)
56443 + switch (xattr_value[i]) {
56444 + default:
56445 + return PAX_PARSE_FLAGS_FALLBACK;
56446 +
56447 +#define parse_flag(option1, option2, flag) \
56448 + case option1: \
56449 + if (pax_flags_hardmode & MF_PAX_##flag) \
56450 + return PAX_PARSE_FLAGS_FALLBACK;\
56451 + pax_flags_hardmode |= MF_PAX_##flag; \
56452 + break; \
56453 + case option2: \
56454 + if (pax_flags_softmode & MF_PAX_##flag) \
56455 + return PAX_PARSE_FLAGS_FALLBACK;\
56456 + pax_flags_softmode |= MF_PAX_##flag; \
56457 + break;
56458 +
56459 + parse_flag('p', 'P', PAGEEXEC);
56460 + parse_flag('e', 'E', EMUTRAMP);
56461 + parse_flag('m', 'M', MPROTECT);
56462 + parse_flag('r', 'R', RANDMMAP);
56463 + parse_flag('s', 'S', SEGMEXEC);
56464 +
56465 +#undef parse_flag
56466 + }
56467 +
56468 + if (pax_flags_hardmode & pax_flags_softmode)
56469 + return PAX_PARSE_FLAGS_FALLBACK;
56470 +
56471 +#ifdef CONFIG_PAX_SOFTMODE
56472 + if (pax_softmode)
56473 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56474 + else
56475 +#endif
56476 +
56477 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56478 +#else
56479 + return PAX_PARSE_FLAGS_FALLBACK;
56480 +#endif
56481 +
56482 +}
56483 +
56484 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56485 +{
56486 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56487 +
56488 + pax_flags = pax_parse_defaults();
56489 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56490 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56491 + xattr_pax_flags = pax_parse_xattr_pax(file);
56492 +
56493 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56494 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56495 + pt_pax_flags != xattr_pax_flags)
56496 + return -EINVAL;
56497 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56498 + pax_flags = xattr_pax_flags;
56499 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56500 + pax_flags = pt_pax_flags;
56501 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56502 + pax_flags = ei_pax_flags;
56503 +
56504 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56505 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56506 + if ((__supported_pte_mask & _PAGE_NX))
56507 + pax_flags &= ~MF_PAX_SEGMEXEC;
56508 + else
56509 + pax_flags &= ~MF_PAX_PAGEEXEC;
56510 + }
56511 +#endif
56512 +
56513 + if (0 > pax_check_flags(&pax_flags))
56514 + return -EINVAL;
56515 +
56516 + current->mm->pax_flags = pax_flags;
56517 + return 0;
56518 +}
56519 +#endif
56520 +
56521 /*
56522 * These are the functions used to load ELF style executables and shared
56523 * libraries. There is no binary dependent code anywhere else.
56524 @@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56525 {
56526 unsigned int random_variable = 0;
56527
56528 +#ifdef CONFIG_PAX_RANDUSTACK
56529 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56530 + return stack_top - current->mm->delta_stack;
56531 +#endif
56532 +
56533 if ((current->flags & PF_RANDOMIZE) &&
56534 !(current->personality & ADDR_NO_RANDOMIZE)) {
56535 random_variable = get_random_int() & STACK_RND_MASK;
56536 @@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56537 unsigned long load_addr = 0, load_bias = 0;
56538 int load_addr_set = 0;
56539 char * elf_interpreter = NULL;
56540 - unsigned long error;
56541 + unsigned long error = 0;
56542 struct elf_phdr *elf_ppnt, *elf_phdata;
56543 unsigned long elf_bss, elf_brk;
56544 int retval, i;
56545 @@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56546 unsigned long start_code, end_code, start_data, end_data;
56547 unsigned long reloc_func_desc __maybe_unused = 0;
56548 int executable_stack = EXSTACK_DEFAULT;
56549 - unsigned long def_flags = 0;
56550 struct pt_regs *regs = current_pt_regs();
56551 struct {
56552 struct elfhdr elf_ex;
56553 struct elfhdr interp_elf_ex;
56554 } *loc;
56555 + unsigned long pax_task_size;
56556
56557 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56558 if (!loc) {
56559 @@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56560 goto out_free_dentry;
56561
56562 /* OK, This is the point of no return */
56563 - current->mm->def_flags = def_flags;
56564 + current->mm->def_flags = 0;
56565
56566 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56567 may depend on the personality. */
56568 SET_PERSONALITY(loc->elf_ex);
56569 +
56570 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56571 + current->mm->pax_flags = 0UL;
56572 +#endif
56573 +
56574 +#ifdef CONFIG_PAX_DLRESOLVE
56575 + current->mm->call_dl_resolve = 0UL;
56576 +#endif
56577 +
56578 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56579 + current->mm->call_syscall = 0UL;
56580 +#endif
56581 +
56582 +#ifdef CONFIG_PAX_ASLR
56583 + current->mm->delta_mmap = 0UL;
56584 + current->mm->delta_stack = 0UL;
56585 +#endif
56586 +
56587 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56588 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56589 + send_sig(SIGKILL, current, 0);
56590 + goto out_free_dentry;
56591 + }
56592 +#endif
56593 +
56594 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56595 + pax_set_initial_flags(bprm);
56596 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56597 + if (pax_set_initial_flags_func)
56598 + (pax_set_initial_flags_func)(bprm);
56599 +#endif
56600 +
56601 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56602 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56603 + current->mm->context.user_cs_limit = PAGE_SIZE;
56604 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56605 + }
56606 +#endif
56607 +
56608 +#ifdef CONFIG_PAX_SEGMEXEC
56609 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56610 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56611 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56612 + pax_task_size = SEGMEXEC_TASK_SIZE;
56613 + current->mm->def_flags |= VM_NOHUGEPAGE;
56614 + } else
56615 +#endif
56616 +
56617 + pax_task_size = TASK_SIZE;
56618 +
56619 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56620 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56621 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56622 + put_cpu();
56623 + }
56624 +#endif
56625 +
56626 +#ifdef CONFIG_PAX_ASLR
56627 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56628 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56629 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56630 + }
56631 +#endif
56632 +
56633 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56634 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56635 + executable_stack = EXSTACK_DISABLE_X;
56636 + current->personality &= ~READ_IMPLIES_EXEC;
56637 + } else
56638 +#endif
56639 +
56640 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56641 current->personality |= READ_IMPLIES_EXEC;
56642
56643 @@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56644 #else
56645 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56646 #endif
56647 +
56648 +#ifdef CONFIG_PAX_RANDMMAP
56649 + /* PaX: randomize base address at the default exe base if requested */
56650 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56651 +#ifdef CONFIG_SPARC64
56652 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56653 +#else
56654 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56655 +#endif
56656 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56657 + elf_flags |= MAP_FIXED;
56658 + }
56659 +#endif
56660 +
56661 }
56662
56663 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56664 @@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56665 * allowed task size. Note that p_filesz must always be
56666 * <= p_memsz so it is only necessary to check p_memsz.
56667 */
56668 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56669 - elf_ppnt->p_memsz > TASK_SIZE ||
56670 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56671 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56672 + elf_ppnt->p_memsz > pax_task_size ||
56673 + pax_task_size - elf_ppnt->p_memsz < k) {
56674 /* set_brk can never work. Avoid overflows. */
56675 send_sig(SIGKILL, current, 0);
56676 retval = -EINVAL;
56677 @@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56678 goto out_free_dentry;
56679 }
56680 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56681 - send_sig(SIGSEGV, current, 0);
56682 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56683 - goto out_free_dentry;
56684 + /*
56685 + * This bss-zeroing can fail if the ELF
56686 + * file specifies odd protections. So
56687 + * we don't check the return value
56688 + */
56689 }
56690
56691 +#ifdef CONFIG_PAX_RANDMMAP
56692 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56693 + unsigned long start, size, flags;
56694 + vm_flags_t vm_flags;
56695 +
56696 + start = ELF_PAGEALIGN(elf_brk);
56697 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56698 + flags = MAP_FIXED | MAP_PRIVATE;
56699 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56700 +
56701 + down_write(&current->mm->mmap_sem);
56702 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56703 + retval = -ENOMEM;
56704 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56705 +// if (current->personality & ADDR_NO_RANDOMIZE)
56706 +// vm_flags |= VM_READ | VM_MAYREAD;
56707 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56708 + retval = IS_ERR_VALUE(start) ? start : 0;
56709 + }
56710 + up_write(&current->mm->mmap_sem);
56711 + if (retval == 0)
56712 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56713 + if (retval < 0) {
56714 + send_sig(SIGKILL, current, 0);
56715 + goto out_free_dentry;
56716 + }
56717 + }
56718 +#endif
56719 +
56720 if (elf_interpreter) {
56721 - unsigned long interp_map_addr = 0;
56722 -
56723 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56724 interpreter,
56725 - &interp_map_addr,
56726 load_bias);
56727 if (!IS_ERR((void *)elf_entry)) {
56728 /*
56729 @@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56730 * Decide what to dump of a segment, part, all or none.
56731 */
56732 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56733 - unsigned long mm_flags)
56734 + unsigned long mm_flags, long signr)
56735 {
56736 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56737
56738 @@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56739 if (vma->vm_file == NULL)
56740 return 0;
56741
56742 - if (FILTER(MAPPED_PRIVATE))
56743 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56744 goto whole;
56745
56746 /*
56747 @@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56748 {
56749 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56750 int i = 0;
56751 - do
56752 + do {
56753 i += 2;
56754 - while (auxv[i - 2] != AT_NULL);
56755 + } while (auxv[i - 2] != AT_NULL);
56756 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56757 }
56758
56759 @@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56760 {
56761 mm_segment_t old_fs = get_fs();
56762 set_fs(KERNEL_DS);
56763 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56764 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56765 set_fs(old_fs);
56766 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56767 }
56768 @@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56769 }
56770
56771 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56772 - unsigned long mm_flags)
56773 + struct coredump_params *cprm)
56774 {
56775 struct vm_area_struct *vma;
56776 size_t size = 0;
56777
56778 for (vma = first_vma(current, gate_vma); vma != NULL;
56779 vma = next_vma(vma, gate_vma))
56780 - size += vma_dump_size(vma, mm_flags);
56781 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56782 return size;
56783 }
56784
56785 @@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56786
56787 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56788
56789 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56790 + offset += elf_core_vma_data_size(gate_vma, cprm);
56791 offset += elf_core_extra_data_size();
56792 e_shoff = offset;
56793
56794 @@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56795 phdr.p_offset = offset;
56796 phdr.p_vaddr = vma->vm_start;
56797 phdr.p_paddr = 0;
56798 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56799 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56800 phdr.p_memsz = vma->vm_end - vma->vm_start;
56801 offset += phdr.p_filesz;
56802 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56803 @@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56804 unsigned long addr;
56805 unsigned long end;
56806
56807 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56808 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56809
56810 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56811 struct page *page;
56812 @@ -2199,6 +2678,167 @@ out:
56813
56814 #endif /* CONFIG_ELF_CORE */
56815
56816 +#ifdef CONFIG_PAX_MPROTECT
56817 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
56818 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56819 + * we'll remove VM_MAYWRITE for good on RELRO segments.
56820 + *
56821 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56822 + * basis because we want to allow the common case and not the special ones.
56823 + */
56824 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56825 +{
56826 + struct elfhdr elf_h;
56827 + struct elf_phdr elf_p;
56828 + unsigned long i;
56829 + unsigned long oldflags;
56830 + bool is_textrel_rw, is_textrel_rx, is_relro;
56831 +
56832 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56833 + return;
56834 +
56835 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56836 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56837 +
56838 +#ifdef CONFIG_PAX_ELFRELOCS
56839 + /* possible TEXTREL */
56840 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56841 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56842 +#else
56843 + is_textrel_rw = false;
56844 + is_textrel_rx = false;
56845 +#endif
56846 +
56847 + /* possible RELRO */
56848 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56849 +
56850 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56851 + return;
56852 +
56853 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56854 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56855 +
56856 +#ifdef CONFIG_PAX_ETEXECRELOCS
56857 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56858 +#else
56859 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56860 +#endif
56861 +
56862 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56863 + !elf_check_arch(&elf_h) ||
56864 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56865 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56866 + return;
56867 +
56868 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56869 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56870 + return;
56871 + switch (elf_p.p_type) {
56872 + case PT_DYNAMIC:
56873 + if (!is_textrel_rw && !is_textrel_rx)
56874 + continue;
56875 + i = 0UL;
56876 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56877 + elf_dyn dyn;
56878 +
56879 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56880 + break;
56881 + if (dyn.d_tag == DT_NULL)
56882 + break;
56883 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56884 + gr_log_textrel(vma);
56885 + if (is_textrel_rw)
56886 + vma->vm_flags |= VM_MAYWRITE;
56887 + else
56888 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56889 + vma->vm_flags &= ~VM_MAYWRITE;
56890 + break;
56891 + }
56892 + i++;
56893 + }
56894 + is_textrel_rw = false;
56895 + is_textrel_rx = false;
56896 + continue;
56897 +
56898 + case PT_GNU_RELRO:
56899 + if (!is_relro)
56900 + continue;
56901 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56902 + vma->vm_flags &= ~VM_MAYWRITE;
56903 + is_relro = false;
56904 + continue;
56905 +
56906 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56907 + case PT_PAX_FLAGS: {
56908 + const char *msg_mprotect = "", *msg_emutramp = "";
56909 + char *buffer_lib, *buffer_exe;
56910 +
56911 + if (elf_p.p_flags & PF_NOMPROTECT)
56912 + msg_mprotect = "MPROTECT disabled";
56913 +
56914 +#ifdef CONFIG_PAX_EMUTRAMP
56915 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56916 + msg_emutramp = "EMUTRAMP enabled";
56917 +#endif
56918 +
56919 + if (!msg_mprotect[0] && !msg_emutramp[0])
56920 + continue;
56921 +
56922 + if (!printk_ratelimit())
56923 + continue;
56924 +
56925 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56926 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56927 + if (buffer_lib && buffer_exe) {
56928 + char *path_lib, *path_exe;
56929 +
56930 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56931 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56932 +
56933 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56934 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56935 +
56936 + }
56937 + free_page((unsigned long)buffer_exe);
56938 + free_page((unsigned long)buffer_lib);
56939 + continue;
56940 + }
56941 +#endif
56942 +
56943 + }
56944 + }
56945 +}
56946 +#endif
56947 +
56948 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56949 +
56950 +extern int grsec_enable_log_rwxmaps;
56951 +
56952 +static void elf_handle_mmap(struct file *file)
56953 +{
56954 + struct elfhdr elf_h;
56955 + struct elf_phdr elf_p;
56956 + unsigned long i;
56957 +
56958 + if (!grsec_enable_log_rwxmaps)
56959 + return;
56960 +
56961 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56962 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56963 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56964 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56965 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56966 + return;
56967 +
56968 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56969 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56970 + return;
56971 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56972 + gr_log_ptgnustack(file);
56973 + }
56974 +}
56975 +#endif
56976 +
56977 static int __init init_elf_binfmt(void)
56978 {
56979 register_binfmt(&elf_format);
56980 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56981 index d50bbe5..af3b649 100644
56982 --- a/fs/binfmt_flat.c
56983 +++ b/fs/binfmt_flat.c
56984 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56985 realdatastart = (unsigned long) -ENOMEM;
56986 printk("Unable to allocate RAM for process data, errno %d\n",
56987 (int)-realdatastart);
56988 + down_write(&current->mm->mmap_sem);
56989 vm_munmap(textpos, text_len);
56990 + up_write(&current->mm->mmap_sem);
56991 ret = realdatastart;
56992 goto err;
56993 }
56994 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56995 }
56996 if (IS_ERR_VALUE(result)) {
56997 printk("Unable to read data+bss, errno %d\n", (int)-result);
56998 + down_write(&current->mm->mmap_sem);
56999 vm_munmap(textpos, text_len);
57000 vm_munmap(realdatastart, len);
57001 + up_write(&current->mm->mmap_sem);
57002 ret = result;
57003 goto err;
57004 }
57005 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
57006 }
57007 if (IS_ERR_VALUE(result)) {
57008 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
57009 + down_write(&current->mm->mmap_sem);
57010 vm_munmap(textpos, text_len + data_len + extra +
57011 MAX_SHARED_LIBS * sizeof(unsigned long));
57012 + up_write(&current->mm->mmap_sem);
57013 ret = result;
57014 goto err;
57015 }
57016 diff --git a/fs/bio.c b/fs/bio.c
57017 index 8754e7b..0669094 100644
57018 --- a/fs/bio.c
57019 +++ b/fs/bio.c
57020 @@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57021 /*
57022 * Overflow, abort
57023 */
57024 - if (end < start)
57025 + if (end < start || end - start > INT_MAX - nr_pages)
57026 return ERR_PTR(-EINVAL);
57027
57028 nr_pages += end - start;
57029 @@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57030 /*
57031 * Overflow, abort
57032 */
57033 - if (end < start)
57034 + if (end < start || end - start > INT_MAX - nr_pages)
57035 return ERR_PTR(-EINVAL);
57036
57037 nr_pages += end - start;
57038 @@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57039 const int read = bio_data_dir(bio) == READ;
57040 struct bio_map_data *bmd = bio->bi_private;
57041 int i;
57042 - char *p = bmd->sgvecs[0].iov_base;
57043 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57044
57045 bio_for_each_segment_all(bvec, bio, i) {
57046 char *addr = page_address(bvec->bv_page);
57047 diff --git a/fs/block_dev.c b/fs/block_dev.c
57048 index 1e86823..8e34695 100644
57049 --- a/fs/block_dev.c
57050 +++ b/fs/block_dev.c
57051 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57052 else if (bdev->bd_contains == bdev)
57053 return true; /* is a whole device which isn't held */
57054
57055 - else if (whole->bd_holder == bd_may_claim)
57056 + else if (whole->bd_holder == (void *)bd_may_claim)
57057 return true; /* is a partition of a device that is being partitioned */
57058 else if (whole->bd_holder != NULL)
57059 return false; /* is a partition of a held device */
57060 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57061 index cbd3a7d..c6a2881 100644
57062 --- a/fs/btrfs/ctree.c
57063 +++ b/fs/btrfs/ctree.c
57064 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57065 free_extent_buffer(buf);
57066 add_root_to_dirty_list(root);
57067 } else {
57068 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57069 - parent_start = parent->start;
57070 - else
57071 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57072 + if (parent)
57073 + parent_start = parent->start;
57074 + else
57075 + parent_start = 0;
57076 + } else
57077 parent_start = 0;
57078
57079 WARN_ON(trans->transid != btrfs_header_generation(parent));
57080 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57081 index 451b00c..a2cccee 100644
57082 --- a/fs/btrfs/delayed-inode.c
57083 +++ b/fs/btrfs/delayed-inode.c
57084 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57085
57086 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57087 {
57088 - int seq = atomic_inc_return(&delayed_root->items_seq);
57089 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57090 if ((atomic_dec_return(&delayed_root->items) <
57091 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57092 waitqueue_active(&delayed_root->wait))
57093 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57094
57095 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57096 {
57097 - int val = atomic_read(&delayed_root->items_seq);
57098 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57099
57100 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57101 return 1;
57102 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57103 int seq;
57104 int ret;
57105
57106 - seq = atomic_read(&delayed_root->items_seq);
57107 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57108
57109 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57110 if (ret)
57111 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57112 index f70119f..ab5894d 100644
57113 --- a/fs/btrfs/delayed-inode.h
57114 +++ b/fs/btrfs/delayed-inode.h
57115 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57116 */
57117 struct list_head prepare_list;
57118 atomic_t items; /* for delayed items */
57119 - atomic_t items_seq; /* for delayed items */
57120 + atomic_unchecked_t items_seq; /* for delayed items */
57121 int nodes; /* for delayed nodes */
57122 wait_queue_head_t wait;
57123 };
57124 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57125 struct btrfs_delayed_root *delayed_root)
57126 {
57127 atomic_set(&delayed_root->items, 0);
57128 - atomic_set(&delayed_root->items_seq, 0);
57129 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57130 delayed_root->nodes = 0;
57131 spin_lock_init(&delayed_root->lock);
57132 init_waitqueue_head(&delayed_root->wait);
57133 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57134 index a6d8efa..2f062cf 100644
57135 --- a/fs/btrfs/ioctl.c
57136 +++ b/fs/btrfs/ioctl.c
57137 @@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57138 for (i = 0; i < num_types; i++) {
57139 struct btrfs_space_info *tmp;
57140
57141 + /* Don't copy in more than we allocated */
57142 if (!slot_count)
57143 break;
57144
57145 + slot_count--;
57146 +
57147 info = NULL;
57148 rcu_read_lock();
57149 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57150 @@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57151 memcpy(dest, &space, sizeof(space));
57152 dest++;
57153 space_args.total_spaces++;
57154 - slot_count--;
57155 }
57156 - if (!slot_count)
57157 - break;
57158 }
57159 up_read(&info->groups_sem);
57160 }
57161 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57162 index d04db81..96e54f1 100644
57163 --- a/fs/btrfs/super.c
57164 +++ b/fs/btrfs/super.c
57165 @@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57166 function, line, errstr);
57167 return;
57168 }
57169 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57170 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57171 /* Wake up anybody who may be waiting on this transaction */
57172 wake_up(&root->fs_info->transaction_wait);
57173 wake_up(&root->fs_info->transaction_blocked_wait);
57174 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57175 index 865f4cf..f321e86 100644
57176 --- a/fs/btrfs/sysfs.c
57177 +++ b/fs/btrfs/sysfs.c
57178 @@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57179 for (set = 0; set < FEAT_MAX; set++) {
57180 int i;
57181 struct attribute *attrs[2];
57182 - struct attribute_group agroup = {
57183 + attribute_group_no_const agroup = {
57184 .name = "features",
57185 .attrs = attrs,
57186 };
57187 diff --git a/fs/buffer.c b/fs/buffer.c
57188 index 27265a8..289f488 100644
57189 --- a/fs/buffer.c
57190 +++ b/fs/buffer.c
57191 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57192 bh_cachep = kmem_cache_create("buffer_head",
57193 sizeof(struct buffer_head), 0,
57194 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57195 - SLAB_MEM_SPREAD),
57196 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57197 NULL);
57198
57199 /*
57200 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57201 index 622f469..e8d2d55 100644
57202 --- a/fs/cachefiles/bind.c
57203 +++ b/fs/cachefiles/bind.c
57204 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57205 args);
57206
57207 /* start by checking things over */
57208 - ASSERT(cache->fstop_percent >= 0 &&
57209 - cache->fstop_percent < cache->fcull_percent &&
57210 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57211 cache->fcull_percent < cache->frun_percent &&
57212 cache->frun_percent < 100);
57213
57214 - ASSERT(cache->bstop_percent >= 0 &&
57215 - cache->bstop_percent < cache->bcull_percent &&
57216 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57217 cache->bcull_percent < cache->brun_percent &&
57218 cache->brun_percent < 100);
57219
57220 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57221 index 0a1467b..6a53245 100644
57222 --- a/fs/cachefiles/daemon.c
57223 +++ b/fs/cachefiles/daemon.c
57224 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57225 if (n > buflen)
57226 return -EMSGSIZE;
57227
57228 - if (copy_to_user(_buffer, buffer, n) != 0)
57229 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57230 return -EFAULT;
57231
57232 return n;
57233 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57234 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57235 return -EIO;
57236
57237 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57238 + if (datalen > PAGE_SIZE - 1)
57239 return -EOPNOTSUPP;
57240
57241 /* drag the command string into the kernel so we can parse it */
57242 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57243 if (args[0] != '%' || args[1] != '\0')
57244 return -EINVAL;
57245
57246 - if (fstop < 0 || fstop >= cache->fcull_percent)
57247 + if (fstop >= cache->fcull_percent)
57248 return cachefiles_daemon_range_error(cache, args);
57249
57250 cache->fstop_percent = fstop;
57251 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57252 if (args[0] != '%' || args[1] != '\0')
57253 return -EINVAL;
57254
57255 - if (bstop < 0 || bstop >= cache->bcull_percent)
57256 + if (bstop >= cache->bcull_percent)
57257 return cachefiles_daemon_range_error(cache, args);
57258
57259 cache->bstop_percent = bstop;
57260 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57261 index 5349473..d6c0b93 100644
57262 --- a/fs/cachefiles/internal.h
57263 +++ b/fs/cachefiles/internal.h
57264 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57265 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57266 struct rb_root active_nodes; /* active nodes (can't be culled) */
57267 rwlock_t active_lock; /* lock for active_nodes */
57268 - atomic_t gravecounter; /* graveyard uniquifier */
57269 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57270 unsigned frun_percent; /* when to stop culling (% files) */
57271 unsigned fcull_percent; /* when to start culling (% files) */
57272 unsigned fstop_percent; /* when to stop allocating (% files) */
57273 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57274 * proc.c
57275 */
57276 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57277 -extern atomic_t cachefiles_lookup_histogram[HZ];
57278 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57279 -extern atomic_t cachefiles_create_histogram[HZ];
57280 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57281 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57282 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57283
57284 extern int __init cachefiles_proc_init(void);
57285 extern void cachefiles_proc_cleanup(void);
57286 static inline
57287 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57288 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57289 {
57290 unsigned long jif = jiffies - start_jif;
57291 if (jif >= HZ)
57292 jif = HZ - 1;
57293 - atomic_inc(&histogram[jif]);
57294 + atomic_inc_unchecked(&histogram[jif]);
57295 }
57296
57297 #else
57298 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57299 index ca65f39..48921e3 100644
57300 --- a/fs/cachefiles/namei.c
57301 +++ b/fs/cachefiles/namei.c
57302 @@ -317,7 +317,7 @@ try_again:
57303 /* first step is to make up a grave dentry in the graveyard */
57304 sprintf(nbuffer, "%08x%08x",
57305 (uint32_t) get_seconds(),
57306 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57307 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57308
57309 /* do the multiway lock magic */
57310 trap = lock_rename(cache->graveyard, dir);
57311 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57312 index eccd339..4c1d995 100644
57313 --- a/fs/cachefiles/proc.c
57314 +++ b/fs/cachefiles/proc.c
57315 @@ -14,9 +14,9 @@
57316 #include <linux/seq_file.h>
57317 #include "internal.h"
57318
57319 -atomic_t cachefiles_lookup_histogram[HZ];
57320 -atomic_t cachefiles_mkdir_histogram[HZ];
57321 -atomic_t cachefiles_create_histogram[HZ];
57322 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57323 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57324 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57325
57326 /*
57327 * display the latency histogram
57328 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57329 return 0;
57330 default:
57331 index = (unsigned long) v - 3;
57332 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57333 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57334 - z = atomic_read(&cachefiles_create_histogram[index]);
57335 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57336 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57337 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57338 if (x == 0 && y == 0 && z == 0)
57339 return 0;
57340
57341 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57342 index ebaff36..7e3ea26 100644
57343 --- a/fs/cachefiles/rdwr.c
57344 +++ b/fs/cachefiles/rdwr.c
57345 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57346 old_fs = get_fs();
57347 set_fs(KERNEL_DS);
57348 ret = file->f_op->write(
57349 - file, (const void __user *) data, len, &pos);
57350 + file, (const void __force_user *) data, len, &pos);
57351 set_fs(old_fs);
57352 kunmap(page);
57353 file_end_write(file);
57354 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57355 index 45eda6d..9126f7f 100644
57356 --- a/fs/ceph/dir.c
57357 +++ b/fs/ceph/dir.c
57358 @@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57359 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57360 struct ceph_mds_client *mdsc = fsc->mdsc;
57361 unsigned frag = fpos_frag(ctx->pos);
57362 - int off = fpos_off(ctx->pos);
57363 + unsigned int off = fpos_off(ctx->pos);
57364 int err;
57365 u32 ftype;
57366 struct ceph_mds_reply_info_parsed *rinfo;
57367 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57368 index 10a4ccb..92dbc5e 100644
57369 --- a/fs/ceph/super.c
57370 +++ b/fs/ceph/super.c
57371 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57372 /*
57373 * construct our own bdi so we can control readahead, etc.
57374 */
57375 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57376 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57377
57378 static int ceph_register_bdi(struct super_block *sb,
57379 struct ceph_fs_client *fsc)
57380 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57381 default_backing_dev_info.ra_pages;
57382
57383 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57384 - atomic_long_inc_return(&bdi_seq));
57385 + atomic_long_inc_return_unchecked(&bdi_seq));
57386 if (!err)
57387 sb->s_bdi = &fsc->backing_dev_info;
57388 return err;
57389 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57390 index f3ac415..3d2420c 100644
57391 --- a/fs/cifs/cifs_debug.c
57392 +++ b/fs/cifs/cifs_debug.c
57393 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57394
57395 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57396 #ifdef CONFIG_CIFS_STATS2
57397 - atomic_set(&totBufAllocCount, 0);
57398 - atomic_set(&totSmBufAllocCount, 0);
57399 + atomic_set_unchecked(&totBufAllocCount, 0);
57400 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57401 #endif /* CONFIG_CIFS_STATS2 */
57402 spin_lock(&cifs_tcp_ses_lock);
57403 list_for_each(tmp1, &cifs_tcp_ses_list) {
57404 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57405 tcon = list_entry(tmp3,
57406 struct cifs_tcon,
57407 tcon_list);
57408 - atomic_set(&tcon->num_smbs_sent, 0);
57409 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57410 if (server->ops->clear_stats)
57411 server->ops->clear_stats(tcon);
57412 }
57413 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57414 smBufAllocCount.counter, cifs_min_small);
57415 #ifdef CONFIG_CIFS_STATS2
57416 seq_printf(m, "Total Large %d Small %d Allocations\n",
57417 - atomic_read(&totBufAllocCount),
57418 - atomic_read(&totSmBufAllocCount));
57419 + atomic_read_unchecked(&totBufAllocCount),
57420 + atomic_read_unchecked(&totSmBufAllocCount));
57421 #endif /* CONFIG_CIFS_STATS2 */
57422
57423 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57424 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57425 if (tcon->need_reconnect)
57426 seq_puts(m, "\tDISCONNECTED ");
57427 seq_printf(m, "\nSMBs: %d",
57428 - atomic_read(&tcon->num_smbs_sent));
57429 + atomic_read_unchecked(&tcon->num_smbs_sent));
57430 if (server->ops->print_stats)
57431 server->ops->print_stats(m, tcon);
57432 }
57433 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57434 index 849f613..eae6dec 100644
57435 --- a/fs/cifs/cifsfs.c
57436 +++ b/fs/cifs/cifsfs.c
57437 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57438 */
57439 cifs_req_cachep = kmem_cache_create("cifs_request",
57440 CIFSMaxBufSize + max_hdr_size, 0,
57441 - SLAB_HWCACHE_ALIGN, NULL);
57442 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57443 if (cifs_req_cachep == NULL)
57444 return -ENOMEM;
57445
57446 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57447 efficient to alloc 1 per page off the slab compared to 17K (5page)
57448 alloc of large cifs buffers even when page debugging is on */
57449 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57450 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57451 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57452 NULL);
57453 if (cifs_sm_req_cachep == NULL) {
57454 mempool_destroy(cifs_req_poolp);
57455 @@ -1168,8 +1168,8 @@ init_cifs(void)
57456 atomic_set(&bufAllocCount, 0);
57457 atomic_set(&smBufAllocCount, 0);
57458 #ifdef CONFIG_CIFS_STATS2
57459 - atomic_set(&totBufAllocCount, 0);
57460 - atomic_set(&totSmBufAllocCount, 0);
57461 + atomic_set_unchecked(&totBufAllocCount, 0);
57462 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57463 #endif /* CONFIG_CIFS_STATS2 */
57464
57465 atomic_set(&midCount, 0);
57466 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57467 index c0f3718..6afed7d 100644
57468 --- a/fs/cifs/cifsglob.h
57469 +++ b/fs/cifs/cifsglob.h
57470 @@ -804,35 +804,35 @@ struct cifs_tcon {
57471 __u16 Flags; /* optional support bits */
57472 enum statusEnum tidStatus;
57473 #ifdef CONFIG_CIFS_STATS
57474 - atomic_t num_smbs_sent;
57475 + atomic_unchecked_t num_smbs_sent;
57476 union {
57477 struct {
57478 - atomic_t num_writes;
57479 - atomic_t num_reads;
57480 - atomic_t num_flushes;
57481 - atomic_t num_oplock_brks;
57482 - atomic_t num_opens;
57483 - atomic_t num_closes;
57484 - atomic_t num_deletes;
57485 - atomic_t num_mkdirs;
57486 - atomic_t num_posixopens;
57487 - atomic_t num_posixmkdirs;
57488 - atomic_t num_rmdirs;
57489 - atomic_t num_renames;
57490 - atomic_t num_t2renames;
57491 - atomic_t num_ffirst;
57492 - atomic_t num_fnext;
57493 - atomic_t num_fclose;
57494 - atomic_t num_hardlinks;
57495 - atomic_t num_symlinks;
57496 - atomic_t num_locks;
57497 - atomic_t num_acl_get;
57498 - atomic_t num_acl_set;
57499 + atomic_unchecked_t num_writes;
57500 + atomic_unchecked_t num_reads;
57501 + atomic_unchecked_t num_flushes;
57502 + atomic_unchecked_t num_oplock_brks;
57503 + atomic_unchecked_t num_opens;
57504 + atomic_unchecked_t num_closes;
57505 + atomic_unchecked_t num_deletes;
57506 + atomic_unchecked_t num_mkdirs;
57507 + atomic_unchecked_t num_posixopens;
57508 + atomic_unchecked_t num_posixmkdirs;
57509 + atomic_unchecked_t num_rmdirs;
57510 + atomic_unchecked_t num_renames;
57511 + atomic_unchecked_t num_t2renames;
57512 + atomic_unchecked_t num_ffirst;
57513 + atomic_unchecked_t num_fnext;
57514 + atomic_unchecked_t num_fclose;
57515 + atomic_unchecked_t num_hardlinks;
57516 + atomic_unchecked_t num_symlinks;
57517 + atomic_unchecked_t num_locks;
57518 + atomic_unchecked_t num_acl_get;
57519 + atomic_unchecked_t num_acl_set;
57520 } cifs_stats;
57521 #ifdef CONFIG_CIFS_SMB2
57522 struct {
57523 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57524 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57525 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57526 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57527 } smb2_stats;
57528 #endif /* CONFIG_CIFS_SMB2 */
57529 } stats;
57530 @@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
57531 }
57532
57533 #ifdef CONFIG_CIFS_STATS
57534 -#define cifs_stats_inc atomic_inc
57535 +#define cifs_stats_inc atomic_inc_unchecked
57536
57537 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57538 unsigned int bytes)
57539 @@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57540 /* Various Debug counters */
57541 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57542 #ifdef CONFIG_CIFS_STATS2
57543 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57544 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57545 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57546 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57547 #endif
57548 GLOBAL_EXTERN atomic_t smBufAllocCount;
57549 GLOBAL_EXTERN atomic_t midCount;
57550 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57551 index 834fce7..8a314b5 100644
57552 --- a/fs/cifs/file.c
57553 +++ b/fs/cifs/file.c
57554 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57555 index = mapping->writeback_index; /* Start from prev offset */
57556 end = -1;
57557 } else {
57558 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57559 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57560 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57561 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57562 range_whole = true;
57563 + index = 0;
57564 + end = ULONG_MAX;
57565 + } else {
57566 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57567 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57568 + }
57569 scanned = true;
57570 }
57571 retry:
57572 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57573 index 2f9f379..43f8025 100644
57574 --- a/fs/cifs/misc.c
57575 +++ b/fs/cifs/misc.c
57576 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57577 memset(ret_buf, 0, buf_size + 3);
57578 atomic_inc(&bufAllocCount);
57579 #ifdef CONFIG_CIFS_STATS2
57580 - atomic_inc(&totBufAllocCount);
57581 + atomic_inc_unchecked(&totBufAllocCount);
57582 #endif /* CONFIG_CIFS_STATS2 */
57583 }
57584
57585 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57586 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57587 atomic_inc(&smBufAllocCount);
57588 #ifdef CONFIG_CIFS_STATS2
57589 - atomic_inc(&totSmBufAllocCount);
57590 + atomic_inc_unchecked(&totSmBufAllocCount);
57591 #endif /* CONFIG_CIFS_STATS2 */
57592
57593 }
57594 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57595 index 526fb89..ecdbf5a 100644
57596 --- a/fs/cifs/smb1ops.c
57597 +++ b/fs/cifs/smb1ops.c
57598 @@ -616,27 +616,27 @@ static void
57599 cifs_clear_stats(struct cifs_tcon *tcon)
57600 {
57601 #ifdef CONFIG_CIFS_STATS
57602 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57603 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57604 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57605 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57606 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57607 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57608 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57609 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57610 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57611 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57612 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57613 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57614 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57615 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57616 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57617 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57618 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57619 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57620 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57621 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57622 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57623 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57624 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57625 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57626 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57627 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57628 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57629 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57630 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57631 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57632 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57633 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57634 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57635 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57636 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57637 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57638 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57639 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57640 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57641 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57642 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57643 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57644 #endif
57645 }
57646
57647 @@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57648 {
57649 #ifdef CONFIG_CIFS_STATS
57650 seq_printf(m, " Oplocks breaks: %d",
57651 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57652 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57653 seq_printf(m, "\nReads: %d Bytes: %llu",
57654 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57655 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57656 (long long)(tcon->bytes_read));
57657 seq_printf(m, "\nWrites: %d Bytes: %llu",
57658 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57659 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57660 (long long)(tcon->bytes_written));
57661 seq_printf(m, "\nFlushes: %d",
57662 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57663 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57664 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57665 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57666 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57667 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57668 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57669 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57670 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57671 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57672 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57673 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57674 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57675 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57676 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57677 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57678 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57679 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57680 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57681 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57682 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57683 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57684 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57685 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57686 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57687 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57688 seq_printf(m, "\nRenames: %d T2 Renames %d",
57689 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57690 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57691 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57692 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57693 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57694 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57695 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57696 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57697 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57698 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57699 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57700 #endif
57701 }
57702
57703 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57704 index 192f51a..539307e 100644
57705 --- a/fs/cifs/smb2ops.c
57706 +++ b/fs/cifs/smb2ops.c
57707 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57708 #ifdef CONFIG_CIFS_STATS
57709 int i;
57710 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57711 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57712 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57713 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57714 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57715 }
57716 #endif
57717 }
57718 @@ -405,65 +405,65 @@ static void
57719 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57720 {
57721 #ifdef CONFIG_CIFS_STATS
57722 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57723 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57724 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57725 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57726 seq_printf(m, "\nNegotiates: %d sent %d failed",
57727 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57728 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57729 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57730 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57731 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57732 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57733 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57734 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57735 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57736 seq_printf(m, "\nLogoffs: %d sent %d failed",
57737 - atomic_read(&sent[SMB2_LOGOFF_HE]),
57738 - atomic_read(&failed[SMB2_LOGOFF_HE]));
57739 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57740 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57741 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57742 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57743 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57744 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57745 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57746 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57747 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57748 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57749 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57750 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57751 seq_printf(m, "\nCreates: %d sent %d failed",
57752 - atomic_read(&sent[SMB2_CREATE_HE]),
57753 - atomic_read(&failed[SMB2_CREATE_HE]));
57754 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57755 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57756 seq_printf(m, "\nCloses: %d sent %d failed",
57757 - atomic_read(&sent[SMB2_CLOSE_HE]),
57758 - atomic_read(&failed[SMB2_CLOSE_HE]));
57759 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57760 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57761 seq_printf(m, "\nFlushes: %d sent %d failed",
57762 - atomic_read(&sent[SMB2_FLUSH_HE]),
57763 - atomic_read(&failed[SMB2_FLUSH_HE]));
57764 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57765 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57766 seq_printf(m, "\nReads: %d sent %d failed",
57767 - atomic_read(&sent[SMB2_READ_HE]),
57768 - atomic_read(&failed[SMB2_READ_HE]));
57769 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
57770 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
57771 seq_printf(m, "\nWrites: %d sent %d failed",
57772 - atomic_read(&sent[SMB2_WRITE_HE]),
57773 - atomic_read(&failed[SMB2_WRITE_HE]));
57774 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57775 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57776 seq_printf(m, "\nLocks: %d sent %d failed",
57777 - atomic_read(&sent[SMB2_LOCK_HE]),
57778 - atomic_read(&failed[SMB2_LOCK_HE]));
57779 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57780 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57781 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57782 - atomic_read(&sent[SMB2_IOCTL_HE]),
57783 - atomic_read(&failed[SMB2_IOCTL_HE]));
57784 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57785 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57786 seq_printf(m, "\nCancels: %d sent %d failed",
57787 - atomic_read(&sent[SMB2_CANCEL_HE]),
57788 - atomic_read(&failed[SMB2_CANCEL_HE]));
57789 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57790 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57791 seq_printf(m, "\nEchos: %d sent %d failed",
57792 - atomic_read(&sent[SMB2_ECHO_HE]),
57793 - atomic_read(&failed[SMB2_ECHO_HE]));
57794 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57795 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57796 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57797 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57798 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57799 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57800 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57801 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57802 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57803 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57804 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57805 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57806 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57807 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57808 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57809 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57810 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57811 seq_printf(m, "\nSetInfos: %d sent %d failed",
57812 - atomic_read(&sent[SMB2_SET_INFO_HE]),
57813 - atomic_read(&failed[SMB2_SET_INFO_HE]));
57814 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57815 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57816 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57817 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57818 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57819 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57820 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57821 #endif
57822 }
57823
57824 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57825 index 8603447..f9caeee 100644
57826 --- a/fs/cifs/smb2pdu.c
57827 +++ b/fs/cifs/smb2pdu.c
57828 @@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57829 default:
57830 cifs_dbg(VFS, "info level %u isn't supported\n",
57831 srch_inf->info_level);
57832 - rc = -EINVAL;
57833 - goto qdir_exit;
57834 + return -EINVAL;
57835 }
57836
57837 req->FileIndex = cpu_to_le32(index);
57838 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57839 index 1da168c..8bc7ff6 100644
57840 --- a/fs/coda/cache.c
57841 +++ b/fs/coda/cache.c
57842 @@ -24,7 +24,7 @@
57843 #include "coda_linux.h"
57844 #include "coda_cache.h"
57845
57846 -static atomic_t permission_epoch = ATOMIC_INIT(0);
57847 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57848
57849 /* replace or extend an acl cache hit */
57850 void coda_cache_enter(struct inode *inode, int mask)
57851 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57852 struct coda_inode_info *cii = ITOC(inode);
57853
57854 spin_lock(&cii->c_lock);
57855 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57856 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57857 if (!uid_eq(cii->c_uid, current_fsuid())) {
57858 cii->c_uid = current_fsuid();
57859 cii->c_cached_perm = mask;
57860 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57861 {
57862 struct coda_inode_info *cii = ITOC(inode);
57863 spin_lock(&cii->c_lock);
57864 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57865 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57866 spin_unlock(&cii->c_lock);
57867 }
57868
57869 /* remove all acl caches */
57870 void coda_cache_clear_all(struct super_block *sb)
57871 {
57872 - atomic_inc(&permission_epoch);
57873 + atomic_inc_unchecked(&permission_epoch);
57874 }
57875
57876
57877 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57878 spin_lock(&cii->c_lock);
57879 hit = (mask & cii->c_cached_perm) == mask &&
57880 uid_eq(cii->c_uid, current_fsuid()) &&
57881 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57882 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57883 spin_unlock(&cii->c_lock);
57884
57885 return hit;
57886 diff --git a/fs/compat.c b/fs/compat.c
57887 index 6af20de..fec3fbb 100644
57888 --- a/fs/compat.c
57889 +++ b/fs/compat.c
57890 @@ -54,7 +54,7 @@
57891 #include <asm/ioctls.h>
57892 #include "internal.h"
57893
57894 -int compat_log = 1;
57895 +int compat_log = 0;
57896
57897 int compat_printk(const char *fmt, ...)
57898 {
57899 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57900
57901 set_fs(KERNEL_DS);
57902 /* The __user pointer cast is valid because of the set_fs() */
57903 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57904 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57905 set_fs(oldfs);
57906 /* truncating is ok because it's a user address */
57907 if (!ret)
57908 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57909 goto out;
57910
57911 ret = -EINVAL;
57912 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57913 + if (nr_segs > UIO_MAXIOV)
57914 goto out;
57915 if (nr_segs > fast_segs) {
57916 ret = -ENOMEM;
57917 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57918 struct compat_readdir_callback {
57919 struct dir_context ctx;
57920 struct compat_old_linux_dirent __user *dirent;
57921 + struct file * file;
57922 int result;
57923 };
57924
57925 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57926 buf->result = -EOVERFLOW;
57927 return -EOVERFLOW;
57928 }
57929 +
57930 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57931 + return 0;
57932 +
57933 buf->result++;
57934 dirent = buf->dirent;
57935 if (!access_ok(VERIFY_WRITE, dirent,
57936 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57937 if (!f.file)
57938 return -EBADF;
57939
57940 + buf.file = f.file;
57941 error = iterate_dir(f.file, &buf.ctx);
57942 if (buf.result)
57943 error = buf.result;
57944 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
57945 struct dir_context ctx;
57946 struct compat_linux_dirent __user *current_dir;
57947 struct compat_linux_dirent __user *previous;
57948 + struct file * file;
57949 int count;
57950 int error;
57951 };
57952 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57953 buf->error = -EOVERFLOW;
57954 return -EOVERFLOW;
57955 }
57956 +
57957 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57958 + return 0;
57959 +
57960 dirent = buf->previous;
57961 if (dirent) {
57962 if (__put_user(offset, &dirent->d_off))
57963 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57964 if (!f.file)
57965 return -EBADF;
57966
57967 + buf.file = f.file;
57968 error = iterate_dir(f.file, &buf.ctx);
57969 if (error >= 0)
57970 error = buf.error;
57971 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57972 struct dir_context ctx;
57973 struct linux_dirent64 __user *current_dir;
57974 struct linux_dirent64 __user *previous;
57975 + struct file * file;
57976 int count;
57977 int error;
57978 };
57979 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57980 buf->error = -EINVAL; /* only used if we fail.. */
57981 if (reclen > buf->count)
57982 return -EINVAL;
57983 +
57984 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57985 + return 0;
57986 +
57987 dirent = buf->previous;
57988
57989 if (dirent) {
57990 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57991 if (!f.file)
57992 return -EBADF;
57993
57994 + buf.file = f.file;
57995 error = iterate_dir(f.file, &buf.ctx);
57996 if (error >= 0)
57997 error = buf.error;
57998 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57999 index a81147e..20bf2b5 100644
58000 --- a/fs/compat_binfmt_elf.c
58001 +++ b/fs/compat_binfmt_elf.c
58002 @@ -30,11 +30,13 @@
58003 #undef elf_phdr
58004 #undef elf_shdr
58005 #undef elf_note
58006 +#undef elf_dyn
58007 #undef elf_addr_t
58008 #define elfhdr elf32_hdr
58009 #define elf_phdr elf32_phdr
58010 #define elf_shdr elf32_shdr
58011 #define elf_note elf32_note
58012 +#define elf_dyn Elf32_Dyn
58013 #define elf_addr_t Elf32_Addr
58014
58015 /*
58016 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58017 index 3881610..ab3df0b 100644
58018 --- a/fs/compat_ioctl.c
58019 +++ b/fs/compat_ioctl.c
58020 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58021 return -EFAULT;
58022 if (__get_user(udata, &ss32->iomem_base))
58023 return -EFAULT;
58024 - ss.iomem_base = compat_ptr(udata);
58025 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58026 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58027 __get_user(ss.port_high, &ss32->port_high))
58028 return -EFAULT;
58029 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58030 for (i = 0; i < nmsgs; i++) {
58031 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58032 return -EFAULT;
58033 - if (get_user(datap, &umsgs[i].buf) ||
58034 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58035 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58036 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58037 return -EFAULT;
58038 }
58039 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58040 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58041 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58042 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58043 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58044 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58045 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58046 return -EFAULT;
58047
58048 return ioctl_preallocate(file, p);
58049 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58050 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58051 {
58052 unsigned int a, b;
58053 - a = *(unsigned int *)p;
58054 - b = *(unsigned int *)q;
58055 + a = *(const unsigned int *)p;
58056 + b = *(const unsigned int *)q;
58057 if (a > b)
58058 return 1;
58059 if (a < b)
58060 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58061 index e081acb..911df21 100644
58062 --- a/fs/configfs/dir.c
58063 +++ b/fs/configfs/dir.c
58064 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58065 }
58066 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58067 struct configfs_dirent *next;
58068 - const char *name;
58069 + const unsigned char * name;
58070 + char d_name[sizeof(next->s_dentry->d_iname)];
58071 int len;
58072 struct inode *inode = NULL;
58073
58074 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58075 continue;
58076
58077 name = configfs_get_name(next);
58078 - len = strlen(name);
58079 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58080 + len = next->s_dentry->d_name.len;
58081 + memcpy(d_name, name, len);
58082 + name = d_name;
58083 + } else
58084 + len = strlen(name);
58085
58086 /*
58087 * We'll have a dentry and an inode for
58088 diff --git a/fs/coredump.c b/fs/coredump.c
58089 index e3ad709..836c55f 100644
58090 --- a/fs/coredump.c
58091 +++ b/fs/coredump.c
58092 @@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58093 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58094 {
58095 int free, need;
58096 + va_list arg_copy;
58097
58098 again:
58099 free = cn->size - cn->used;
58100 - need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58101 +
58102 + va_copy(arg_copy, arg);
58103 + need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58104 + va_end(arg_copy);
58105 +
58106 if (need < free) {
58107 cn->used += need;
58108 return 0;
58109 @@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58110 struct pipe_inode_info *pipe = file->private_data;
58111
58112 pipe_lock(pipe);
58113 - pipe->readers++;
58114 - pipe->writers--;
58115 + atomic_inc(&pipe->readers);
58116 + atomic_dec(&pipe->writers);
58117 wake_up_interruptible_sync(&pipe->wait);
58118 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58119 pipe_unlock(pipe);
58120 @@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58121 * We actually want wait_event_freezable() but then we need
58122 * to clear TIF_SIGPENDING and improve dump_interrupted().
58123 */
58124 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58125 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58126
58127 pipe_lock(pipe);
58128 - pipe->readers--;
58129 - pipe->writers++;
58130 + atomic_dec(&pipe->readers);
58131 + atomic_inc(&pipe->writers);
58132 pipe_unlock(pipe);
58133 }
58134
58135 @@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58136 struct files_struct *displaced;
58137 bool need_nonrelative = false;
58138 bool core_dumped = false;
58139 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58140 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58141 + long signr = siginfo->si_signo;
58142 + int dumpable;
58143 struct coredump_params cprm = {
58144 .siginfo = siginfo,
58145 .regs = signal_pt_regs(),
58146 @@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58147 .mm_flags = mm->flags,
58148 };
58149
58150 - audit_core_dumps(siginfo->si_signo);
58151 + audit_core_dumps(signr);
58152 +
58153 + dumpable = __get_dumpable(cprm.mm_flags);
58154 +
58155 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58156 + gr_handle_brute_attach(dumpable);
58157
58158 binfmt = mm->binfmt;
58159 if (!binfmt || !binfmt->core_dump)
58160 goto fail;
58161 - if (!__get_dumpable(cprm.mm_flags))
58162 + if (!dumpable)
58163 goto fail;
58164
58165 cred = prepare_creds();
58166 @@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58167 need_nonrelative = true;
58168 }
58169
58170 - retval = coredump_wait(siginfo->si_signo, &core_state);
58171 + retval = coredump_wait(signr, &core_state);
58172 if (retval < 0)
58173 goto fail_creds;
58174
58175 @@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58176 }
58177 cprm.limit = RLIM_INFINITY;
58178
58179 - dump_count = atomic_inc_return(&core_dump_count);
58180 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58181 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58182 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58183 task_tgid_vnr(current), current->comm);
58184 @@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58185 } else {
58186 struct inode *inode;
58187
58188 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58189 +
58190 if (cprm.limit < binfmt->min_coredump)
58191 goto fail_unlock;
58192
58193 @@ -668,7 +682,7 @@ close_fail:
58194 filp_close(cprm.file, NULL);
58195 fail_dropcount:
58196 if (ispipe)
58197 - atomic_dec(&core_dump_count);
58198 + atomic_dec_unchecked(&core_dump_count);
58199 fail_unlock:
58200 kfree(cn.corename);
58201 coredump_finish(mm, core_dumped);
58202 @@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58203 struct file *file = cprm->file;
58204 loff_t pos = file->f_pos;
58205 ssize_t n;
58206 +
58207 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58208 if (cprm->written + nr > cprm->limit)
58209 return 0;
58210 while (nr) {
58211 diff --git a/fs/dcache.c b/fs/dcache.c
58212 index ca02c13..7e2b581 100644
58213 --- a/fs/dcache.c
58214 +++ b/fs/dcache.c
58215 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58216 */
58217 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58218 if (name->len > DNAME_INLINE_LEN-1) {
58219 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58220 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58221 if (!dname) {
58222 kmem_cache_free(dentry_cache, dentry);
58223 return NULL;
58224 @@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58225 mempages -= reserve;
58226
58227 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58228 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58229 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58230 + SLAB_NO_SANITIZE, NULL);
58231
58232 dcache_init();
58233 inode_init();
58234 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58235 index 9c0444c..628490c 100644
58236 --- a/fs/debugfs/inode.c
58237 +++ b/fs/debugfs/inode.c
58238 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58239 */
58240 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58241 {
58242 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58243 + return __create_file(name, S_IFDIR | S_IRWXU,
58244 +#else
58245 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58246 +#endif
58247 parent, NULL, NULL);
58248 }
58249 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58250 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58251 index b167ca4..a224e19 100644
58252 --- a/fs/ecryptfs/inode.c
58253 +++ b/fs/ecryptfs/inode.c
58254 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58255 old_fs = get_fs();
58256 set_fs(get_ds());
58257 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58258 - (char __user *)lower_buf,
58259 + (char __force_user *)lower_buf,
58260 PATH_MAX);
58261 set_fs(old_fs);
58262 if (rc < 0)
58263 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58264 index e4141f2..d8263e8 100644
58265 --- a/fs/ecryptfs/miscdev.c
58266 +++ b/fs/ecryptfs/miscdev.c
58267 @@ -304,7 +304,7 @@ check_list:
58268 goto out_unlock_msg_ctx;
58269 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58270 if (msg_ctx->msg) {
58271 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58272 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58273 goto out_unlock_msg_ctx;
58274 i += packet_length_size;
58275 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58276 diff --git a/fs/exec.c b/fs/exec.c
58277 index 3d78fcc..5a38b6b 100644
58278 --- a/fs/exec.c
58279 +++ b/fs/exec.c
58280 @@ -55,8 +55,20 @@
58281 #include <linux/pipe_fs_i.h>
58282 #include <linux/oom.h>
58283 #include <linux/compat.h>
58284 +#include <linux/random.h>
58285 +#include <linux/seq_file.h>
58286 +#include <linux/coredump.h>
58287 +#include <linux/mman.h>
58288 +
58289 +#ifdef CONFIG_PAX_REFCOUNT
58290 +#include <linux/kallsyms.h>
58291 +#include <linux/kdebug.h>
58292 +#endif
58293 +
58294 +#include <trace/events/fs.h>
58295
58296 #include <asm/uaccess.h>
58297 +#include <asm/sections.h>
58298 #include <asm/mmu_context.h>
58299 #include <asm/tlb.h>
58300
58301 @@ -65,19 +77,34 @@
58302
58303 #include <trace/events/sched.h>
58304
58305 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58306 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58307 +{
58308 + 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");
58309 +}
58310 +#endif
58311 +
58312 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58313 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58314 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58315 +#endif
58316 +
58317 int suid_dumpable = 0;
58318
58319 static LIST_HEAD(formats);
58320 static DEFINE_RWLOCK(binfmt_lock);
58321
58322 +extern int gr_process_kernel_exec_ban(void);
58323 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58324 +
58325 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58326 {
58327 BUG_ON(!fmt);
58328 if (WARN_ON(!fmt->load_binary))
58329 return;
58330 write_lock(&binfmt_lock);
58331 - insert ? list_add(&fmt->lh, &formats) :
58332 - list_add_tail(&fmt->lh, &formats);
58333 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58334 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58335 write_unlock(&binfmt_lock);
58336 }
58337
58338 @@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58339 void unregister_binfmt(struct linux_binfmt * fmt)
58340 {
58341 write_lock(&binfmt_lock);
58342 - list_del(&fmt->lh);
58343 + pax_list_del((struct list_head *)&fmt->lh);
58344 write_unlock(&binfmt_lock);
58345 }
58346
58347 @@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58348 int write)
58349 {
58350 struct page *page;
58351 - int ret;
58352
58353 -#ifdef CONFIG_STACK_GROWSUP
58354 - if (write) {
58355 - ret = expand_downwards(bprm->vma, pos);
58356 - if (ret < 0)
58357 - return NULL;
58358 - }
58359 -#endif
58360 - ret = get_user_pages(current, bprm->mm, pos,
58361 - 1, write, 1, &page, NULL);
58362 - if (ret <= 0)
58363 + if (0 > expand_downwards(bprm->vma, pos))
58364 + return NULL;
58365 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58366 return NULL;
58367
58368 if (write) {
58369 @@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58370 if (size <= ARG_MAX)
58371 return page;
58372
58373 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58374 + // only allow 512KB for argv+env on suid/sgid binaries
58375 + // to prevent easy ASLR exhaustion
58376 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58377 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58378 + (size > (512 * 1024))) {
58379 + put_page(page);
58380 + return NULL;
58381 + }
58382 +#endif
58383 +
58384 /*
58385 * Limit to 1/4-th the stack size for the argv+env strings.
58386 * This ensures that:
58387 @@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58388 vma->vm_end = STACK_TOP_MAX;
58389 vma->vm_start = vma->vm_end - PAGE_SIZE;
58390 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58391 +
58392 +#ifdef CONFIG_PAX_SEGMEXEC
58393 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58394 +#endif
58395 +
58396 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58397 INIT_LIST_HEAD(&vma->anon_vma_chain);
58398
58399 @@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58400 mm->stack_vm = mm->total_vm = 1;
58401 up_write(&mm->mmap_sem);
58402 bprm->p = vma->vm_end - sizeof(void *);
58403 +
58404 +#ifdef CONFIG_PAX_RANDUSTACK
58405 + if (randomize_va_space)
58406 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58407 +#endif
58408 +
58409 return 0;
58410 err:
58411 up_write(&mm->mmap_sem);
58412 @@ -396,7 +437,7 @@ struct user_arg_ptr {
58413 } ptr;
58414 };
58415
58416 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58417 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58418 {
58419 const char __user *native;
58420
58421 @@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58422 compat_uptr_t compat;
58423
58424 if (get_user(compat, argv.ptr.compat + nr))
58425 - return ERR_PTR(-EFAULT);
58426 + return (const char __force_user *)ERR_PTR(-EFAULT);
58427
58428 return compat_ptr(compat);
58429 }
58430 #endif
58431
58432 if (get_user(native, argv.ptr.native + nr))
58433 - return ERR_PTR(-EFAULT);
58434 + return (const char __force_user *)ERR_PTR(-EFAULT);
58435
58436 return native;
58437 }
58438 @@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58439 if (!p)
58440 break;
58441
58442 - if (IS_ERR(p))
58443 + if (IS_ERR((const char __force_kernel *)p))
58444 return -EFAULT;
58445
58446 if (i >= max)
58447 @@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58448
58449 ret = -EFAULT;
58450 str = get_user_arg_ptr(argv, argc);
58451 - if (IS_ERR(str))
58452 + if (IS_ERR((const char __force_kernel *)str))
58453 goto out;
58454
58455 len = strnlen_user(str, MAX_ARG_STRLEN);
58456 @@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58457 int r;
58458 mm_segment_t oldfs = get_fs();
58459 struct user_arg_ptr argv = {
58460 - .ptr.native = (const char __user *const __user *)__argv,
58461 + .ptr.native = (const char __user * const __force_user *)__argv,
58462 };
58463
58464 set_fs(KERNEL_DS);
58465 @@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58466 unsigned long new_end = old_end - shift;
58467 struct mmu_gather tlb;
58468
58469 - BUG_ON(new_start > new_end);
58470 + if (new_start >= new_end || new_start < mmap_min_addr)
58471 + return -ENOMEM;
58472
58473 /*
58474 * ensure there are no vmas between where we want to go
58475 @@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58476 if (vma != find_vma(mm, new_start))
58477 return -EFAULT;
58478
58479 +#ifdef CONFIG_PAX_SEGMEXEC
58480 + BUG_ON(pax_find_mirror_vma(vma));
58481 +#endif
58482 +
58483 /*
58484 * cover the whole range: [new_start, old_end)
58485 */
58486 @@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58487 stack_top = arch_align_stack(stack_top);
58488 stack_top = PAGE_ALIGN(stack_top);
58489
58490 - if (unlikely(stack_top < mmap_min_addr) ||
58491 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58492 - return -ENOMEM;
58493 -
58494 stack_shift = vma->vm_end - stack_top;
58495
58496 bprm->p -= stack_shift;
58497 @@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58498 bprm->exec -= stack_shift;
58499
58500 down_write(&mm->mmap_sem);
58501 +
58502 + /* Move stack pages down in memory. */
58503 + if (stack_shift) {
58504 + ret = shift_arg_pages(vma, stack_shift);
58505 + if (ret)
58506 + goto out_unlock;
58507 + }
58508 +
58509 vm_flags = VM_STACK_FLAGS;
58510
58511 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58512 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58513 + vm_flags &= ~VM_EXEC;
58514 +
58515 +#ifdef CONFIG_PAX_MPROTECT
58516 + if (mm->pax_flags & MF_PAX_MPROTECT)
58517 + vm_flags &= ~VM_MAYEXEC;
58518 +#endif
58519 +
58520 + }
58521 +#endif
58522 +
58523 /*
58524 * Adjust stack execute permissions; explicitly enable for
58525 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58526 @@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58527 goto out_unlock;
58528 BUG_ON(prev != vma);
58529
58530 - /* Move stack pages down in memory. */
58531 - if (stack_shift) {
58532 - ret = shift_arg_pages(vma, stack_shift);
58533 - if (ret)
58534 - goto out_unlock;
58535 - }
58536 -
58537 /* mprotect_fixup is overkill to remove the temporary stack flags */
58538 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58539
58540 @@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58541 #endif
58542 current->mm->start_stack = bprm->p;
58543 ret = expand_stack(vma, stack_base);
58544 +
58545 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58546 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58547 + unsigned long size;
58548 + vm_flags_t vm_flags;
58549 +
58550 + size = STACK_TOP - vma->vm_end;
58551 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58552 +
58553 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58554 +
58555 +#ifdef CONFIG_X86
58556 + if (!ret) {
58557 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58558 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58559 + }
58560 +#endif
58561 +
58562 + }
58563 +#endif
58564 +
58565 if (ret)
58566 ret = -EFAULT;
58567
58568 @@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
58569
58570 fsnotify_open(file);
58571
58572 + trace_open_exec(name->name);
58573 +
58574 err = deny_write_access(file);
58575 if (err)
58576 goto exit;
58577 @@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
58578 old_fs = get_fs();
58579 set_fs(get_ds());
58580 /* The cast to a user pointer is valid due to the set_fs() */
58581 - result = vfs_read(file, (void __user *)addr, count, &pos);
58582 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58583 set_fs(old_fs);
58584 return result;
58585 }
58586 @@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58587 }
58588 rcu_read_unlock();
58589
58590 - if (p->fs->users > n_fs)
58591 + if (atomic_read(&p->fs->users) > n_fs)
58592 bprm->unsafe |= LSM_UNSAFE_SHARE;
58593 else
58594 p->fs->in_exec = 1;
58595 @@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58596 return ret;
58597 }
58598
58599 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58600 +static DEFINE_PER_CPU(u64, exec_counter);
58601 +static int __init init_exec_counters(void)
58602 +{
58603 + unsigned int cpu;
58604 +
58605 + for_each_possible_cpu(cpu) {
58606 + per_cpu(exec_counter, cpu) = (u64)cpu;
58607 + }
58608 +
58609 + return 0;
58610 +}
58611 +early_initcall(init_exec_counters);
58612 +static inline void increment_exec_counter(void)
58613 +{
58614 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58615 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58616 +}
58617 +#else
58618 +static inline void increment_exec_counter(void) {}
58619 +#endif
58620 +
58621 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58622 + struct user_arg_ptr argv);
58623 +
58624 /*
58625 * sys_execve() executes a new program.
58626 */
58627 @@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
58628 struct user_arg_ptr argv,
58629 struct user_arg_ptr envp)
58630 {
58631 +#ifdef CONFIG_GRKERNSEC
58632 + struct file *old_exec_file;
58633 + struct acl_subject_label *old_acl;
58634 + struct rlimit old_rlim[RLIM_NLIMITS];
58635 +#endif
58636 struct linux_binprm *bprm;
58637 struct file *file;
58638 struct files_struct *displaced;
58639 @@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
58640 if (IS_ERR(filename))
58641 return PTR_ERR(filename);
58642
58643 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58644 +
58645 /*
58646 * We move the actual failure in case of RLIMIT_NPROC excess from
58647 * set*uid() to execve() because too many poorly written programs
58648 @@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
58649 if (IS_ERR(file))
58650 goto out_unmark;
58651
58652 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58653 + retval = -EPERM;
58654 + goto out_unmark;
58655 + }
58656 +
58657 sched_exec();
58658
58659 bprm->file = file;
58660 bprm->filename = bprm->interp = filename->name;
58661
58662 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58663 + retval = -EACCES;
58664 + goto out_unmark;
58665 + }
58666 +
58667 retval = bprm_mm_init(bprm);
58668 if (retval)
58669 goto out_unmark;
58670 @@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
58671 if (retval < 0)
58672 goto out;
58673
58674 +#ifdef CONFIG_GRKERNSEC
58675 + old_acl = current->acl;
58676 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58677 + old_exec_file = current->exec_file;
58678 + get_file(file);
58679 + current->exec_file = file;
58680 +#endif
58681 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58682 + /* limit suid stack to 8MB
58683 + * we saved the old limits above and will restore them if this exec fails
58684 + */
58685 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58686 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58687 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58688 +#endif
58689 +
58690 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58691 + retval = -EPERM;
58692 + goto out_fail;
58693 + }
58694 +
58695 + if (!gr_tpe_allow(file)) {
58696 + retval = -EACCES;
58697 + goto out_fail;
58698 + }
58699 +
58700 + if (gr_check_crash_exec(file)) {
58701 + retval = -EACCES;
58702 + goto out_fail;
58703 + }
58704 +
58705 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58706 + bprm->unsafe);
58707 + if (retval < 0)
58708 + goto out_fail;
58709 +
58710 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58711 if (retval < 0)
58712 - goto out;
58713 + goto out_fail;
58714
58715 bprm->exec = bprm->p;
58716 retval = copy_strings(bprm->envc, envp, bprm);
58717 if (retval < 0)
58718 - goto out;
58719 + goto out_fail;
58720
58721 retval = copy_strings(bprm->argc, argv, bprm);
58722 if (retval < 0)
58723 - goto out;
58724 + goto out_fail;
58725 +
58726 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58727 +
58728 + gr_handle_exec_args(bprm, argv);
58729
58730 retval = exec_binprm(bprm);
58731 if (retval < 0)
58732 - goto out;
58733 + goto out_fail;
58734 +#ifdef CONFIG_GRKERNSEC
58735 + if (old_exec_file)
58736 + fput(old_exec_file);
58737 +#endif
58738
58739 /* execve succeeded */
58740 +
58741 + increment_exec_counter();
58742 current->fs->in_exec = 0;
58743 current->in_execve = 0;
58744 acct_update_integrals(current);
58745 @@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
58746 put_files_struct(displaced);
58747 return retval;
58748
58749 +out_fail:
58750 +#ifdef CONFIG_GRKERNSEC
58751 + current->acl = old_acl;
58752 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58753 + fput(current->exec_file);
58754 + current->exec_file = old_exec_file;
58755 +#endif
58756 +
58757 out:
58758 if (bprm->mm) {
58759 acct_arg_size(bprm, 0);
58760 @@ -1626,3 +1800,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58761 return compat_do_execve(getname(filename), argv, envp);
58762 }
58763 #endif
58764 +
58765 +int pax_check_flags(unsigned long *flags)
58766 +{
58767 + int retval = 0;
58768 +
58769 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58770 + if (*flags & MF_PAX_SEGMEXEC)
58771 + {
58772 + *flags &= ~MF_PAX_SEGMEXEC;
58773 + retval = -EINVAL;
58774 + }
58775 +#endif
58776 +
58777 + if ((*flags & MF_PAX_PAGEEXEC)
58778 +
58779 +#ifdef CONFIG_PAX_PAGEEXEC
58780 + && (*flags & MF_PAX_SEGMEXEC)
58781 +#endif
58782 +
58783 + )
58784 + {
58785 + *flags &= ~MF_PAX_PAGEEXEC;
58786 + retval = -EINVAL;
58787 + }
58788 +
58789 + if ((*flags & MF_PAX_MPROTECT)
58790 +
58791 +#ifdef CONFIG_PAX_MPROTECT
58792 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58793 +#endif
58794 +
58795 + )
58796 + {
58797 + *flags &= ~MF_PAX_MPROTECT;
58798 + retval = -EINVAL;
58799 + }
58800 +
58801 + if ((*flags & MF_PAX_EMUTRAMP)
58802 +
58803 +#ifdef CONFIG_PAX_EMUTRAMP
58804 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58805 +#endif
58806 +
58807 + )
58808 + {
58809 + *flags &= ~MF_PAX_EMUTRAMP;
58810 + retval = -EINVAL;
58811 + }
58812 +
58813 + return retval;
58814 +}
58815 +
58816 +EXPORT_SYMBOL(pax_check_flags);
58817 +
58818 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58819 +char *pax_get_path(const struct path *path, char *buf, int buflen)
58820 +{
58821 + char *pathname = d_path(path, buf, buflen);
58822 +
58823 + if (IS_ERR(pathname))
58824 + goto toolong;
58825 +
58826 + pathname = mangle_path(buf, pathname, "\t\n\\");
58827 + if (!pathname)
58828 + goto toolong;
58829 +
58830 + *pathname = 0;
58831 + return buf;
58832 +
58833 +toolong:
58834 + return "<path too long>";
58835 +}
58836 +EXPORT_SYMBOL(pax_get_path);
58837 +
58838 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58839 +{
58840 + struct task_struct *tsk = current;
58841 + struct mm_struct *mm = current->mm;
58842 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58843 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58844 + char *path_exec = NULL;
58845 + char *path_fault = NULL;
58846 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
58847 + siginfo_t info = { };
58848 +
58849 + if (buffer_exec && buffer_fault) {
58850 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58851 +
58852 + down_read(&mm->mmap_sem);
58853 + vma = mm->mmap;
58854 + while (vma && (!vma_exec || !vma_fault)) {
58855 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58856 + vma_exec = vma;
58857 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58858 + vma_fault = vma;
58859 + vma = vma->vm_next;
58860 + }
58861 + if (vma_exec)
58862 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58863 + if (vma_fault) {
58864 + start = vma_fault->vm_start;
58865 + end = vma_fault->vm_end;
58866 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58867 + if (vma_fault->vm_file)
58868 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58869 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58870 + path_fault = "<heap>";
58871 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58872 + path_fault = "<stack>";
58873 + else
58874 + path_fault = "<anonymous mapping>";
58875 + }
58876 + up_read(&mm->mmap_sem);
58877 + }
58878 + if (tsk->signal->curr_ip)
58879 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58880 + else
58881 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58882 + 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),
58883 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58884 + free_page((unsigned long)buffer_exec);
58885 + free_page((unsigned long)buffer_fault);
58886 + pax_report_insns(regs, pc, sp);
58887 + info.si_signo = SIGKILL;
58888 + info.si_errno = 0;
58889 + info.si_code = SI_KERNEL;
58890 + info.si_pid = 0;
58891 + info.si_uid = 0;
58892 + do_coredump(&info);
58893 +}
58894 +#endif
58895 +
58896 +#ifdef CONFIG_PAX_REFCOUNT
58897 +void pax_report_refcount_overflow(struct pt_regs *regs)
58898 +{
58899 + if (current->signal->curr_ip)
58900 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58901 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58902 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58903 + else
58904 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58905 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58906 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58907 + preempt_disable();
58908 + show_regs(regs);
58909 + preempt_enable();
58910 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58911 +}
58912 +#endif
58913 +
58914 +#ifdef CONFIG_PAX_USERCOPY
58915 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58916 +static noinline int check_stack_object(const void *obj, unsigned long len)
58917 +{
58918 + const void * const stack = task_stack_page(current);
58919 + const void * const stackend = stack + THREAD_SIZE;
58920 +
58921 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58922 + const void *frame = NULL;
58923 + const void *oldframe;
58924 +#endif
58925 +
58926 + if (obj + len < obj)
58927 + return -1;
58928 +
58929 + if (obj + len <= stack || stackend <= obj)
58930 + return 0;
58931 +
58932 + if (obj < stack || stackend < obj + len)
58933 + return -1;
58934 +
58935 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58936 + oldframe = __builtin_frame_address(1);
58937 + if (oldframe)
58938 + frame = __builtin_frame_address(2);
58939 + /*
58940 + low ----------------------------------------------> high
58941 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
58942 + ^----------------^
58943 + allow copies only within here
58944 + */
58945 + while (stack <= frame && frame < stackend) {
58946 + /* if obj + len extends past the last frame, this
58947 + check won't pass and the next frame will be 0,
58948 + causing us to bail out and correctly report
58949 + the copy as invalid
58950 + */
58951 + if (obj + len <= frame)
58952 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58953 + oldframe = frame;
58954 + frame = *(const void * const *)frame;
58955 + }
58956 + return -1;
58957 +#else
58958 + return 1;
58959 +#endif
58960 +}
58961 +
58962 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58963 +{
58964 + if (current->signal->curr_ip)
58965 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58966 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58967 + else
58968 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58969 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58970 + dump_stack();
58971 + gr_handle_kernel_exploit();
58972 + do_group_exit(SIGKILL);
58973 +}
58974 +#endif
58975 +
58976 +#ifdef CONFIG_PAX_USERCOPY
58977 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58978 +{
58979 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58980 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
58981 +#ifdef CONFIG_MODULES
58982 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58983 +#else
58984 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58985 +#endif
58986 +
58987 +#else
58988 + unsigned long textlow = (unsigned long)_stext;
58989 + unsigned long texthigh = (unsigned long)_etext;
58990 +
58991 +#ifdef CONFIG_X86_64
58992 + /* check against linear mapping as well */
58993 + if (high > (unsigned long)__va(__pa(textlow)) &&
58994 + low < (unsigned long)__va(__pa(texthigh)))
58995 + return true;
58996 +#endif
58997 +
58998 +#endif
58999 +
59000 + if (high <= textlow || low >= texthigh)
59001 + return false;
59002 + else
59003 + return true;
59004 +}
59005 +#endif
59006 +
59007 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59008 +{
59009 +
59010 +#ifdef CONFIG_PAX_USERCOPY
59011 + const char *type;
59012 +
59013 + if (!n)
59014 + return;
59015 +
59016 + type = check_heap_object(ptr, n);
59017 + if (!type) {
59018 + int ret = check_stack_object(ptr, n);
59019 + if (ret == 1 || ret == 2)
59020 + return;
59021 + if (ret == 0) {
59022 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59023 + type = "<kernel text>";
59024 + else
59025 + return;
59026 + } else
59027 + type = "<process stack>";
59028 + }
59029 +
59030 + pax_report_usercopy(ptr, n, to_user, type);
59031 +#endif
59032 +
59033 +}
59034 +EXPORT_SYMBOL(__check_object_size);
59035 +
59036 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59037 +void pax_track_stack(void)
59038 +{
59039 + unsigned long sp = (unsigned long)&sp;
59040 + if (sp < current_thread_info()->lowest_stack &&
59041 + sp > (unsigned long)task_stack_page(current))
59042 + current_thread_info()->lowest_stack = sp;
59043 +}
59044 +EXPORT_SYMBOL(pax_track_stack);
59045 +#endif
59046 +
59047 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59048 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59049 +{
59050 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59051 + dump_stack();
59052 + do_group_exit(SIGKILL);
59053 +}
59054 +EXPORT_SYMBOL(report_size_overflow);
59055 +#endif
59056 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59057 index 9f9992b..8b59411 100644
59058 --- a/fs/ext2/balloc.c
59059 +++ b/fs/ext2/balloc.c
59060 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59061
59062 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59063 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59064 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59065 + if (free_blocks < root_blocks + 1 &&
59066 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59067 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59068 - !in_group_p (sbi->s_resgid))) {
59069 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59070 return 0;
59071 }
59072 return 1;
59073 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59074 index 9142614..97484fa 100644
59075 --- a/fs/ext2/xattr.c
59076 +++ b/fs/ext2/xattr.c
59077 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59078 struct buffer_head *bh = NULL;
59079 struct ext2_xattr_entry *entry;
59080 char *end;
59081 - size_t rest = buffer_size;
59082 + size_t rest = buffer_size, total_size = 0;
59083 int error;
59084
59085 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59086 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59087 buffer += size;
59088 }
59089 rest -= size;
59090 + total_size += size;
59091 }
59092 }
59093 - error = buffer_size - rest; /* total size */
59094 + error = total_size;
59095
59096 cleanup:
59097 brelse(bh);
59098 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59099 index 22548f5..41521d8 100644
59100 --- a/fs/ext3/balloc.c
59101 +++ b/fs/ext3/balloc.c
59102 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59103
59104 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59105 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59106 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59107 + if (free_blocks < root_blocks + 1 &&
59108 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59109 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59110 - !in_group_p (sbi->s_resgid))) {
59111 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59112 return 0;
59113 }
59114 return 1;
59115 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59116 index c6874be..f8a6ae8 100644
59117 --- a/fs/ext3/xattr.c
59118 +++ b/fs/ext3/xattr.c
59119 @@ -330,7 +330,7 @@ static int
59120 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59121 char *buffer, size_t buffer_size)
59122 {
59123 - size_t rest = buffer_size;
59124 + size_t rest = buffer_size, total_size = 0;
59125
59126 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59127 const struct xattr_handler *handler =
59128 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59129 buffer += size;
59130 }
59131 rest -= size;
59132 + total_size += size;
59133 }
59134 }
59135 - return buffer_size - rest;
59136 + return total_size;
59137 }
59138
59139 static int
59140 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59141 index 6ea7b14..8fa16d9 100644
59142 --- a/fs/ext4/balloc.c
59143 +++ b/fs/ext4/balloc.c
59144 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59145 /* Hm, nope. Are (enough) root reserved clusters available? */
59146 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59147 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59148 - capable(CAP_SYS_RESOURCE) ||
59149 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59150 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59151 + capable_nolog(CAP_SYS_RESOURCE)) {
59152
59153 if (free_clusters >= (nclusters + dirty_clusters +
59154 resv_clusters))
59155 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59156 index d3a534f..242c50a 100644
59157 --- a/fs/ext4/ext4.h
59158 +++ b/fs/ext4/ext4.h
59159 @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59160 unsigned long s_mb_last_start;
59161
59162 /* stats for buddy allocator */
59163 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59164 - atomic_t s_bal_success; /* we found long enough chunks */
59165 - atomic_t s_bal_allocated; /* in blocks */
59166 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59167 - atomic_t s_bal_goals; /* goal hits */
59168 - atomic_t s_bal_breaks; /* too long searches */
59169 - atomic_t s_bal_2orders; /* 2^order hits */
59170 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59171 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59172 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59173 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59174 + atomic_unchecked_t s_bal_goals; /* goal hits */
59175 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59176 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59177 spinlock_t s_bal_lock;
59178 unsigned long s_mb_buddies_generated;
59179 unsigned long long s_mb_generation_time;
59180 - atomic_t s_mb_lost_chunks;
59181 - atomic_t s_mb_preallocated;
59182 - atomic_t s_mb_discarded;
59183 + atomic_unchecked_t s_mb_lost_chunks;
59184 + atomic_unchecked_t s_mb_preallocated;
59185 + atomic_unchecked_t s_mb_discarded;
59186 atomic_t s_lock_busy;
59187
59188 /* locality groups */
59189 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59190 index 04a5c75..09894fa 100644
59191 --- a/fs/ext4/mballoc.c
59192 +++ b/fs/ext4/mballoc.c
59193 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59194 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59195
59196 if (EXT4_SB(sb)->s_mb_stats)
59197 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59198 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59199
59200 break;
59201 }
59202 @@ -2189,7 +2189,7 @@ repeat:
59203 ac->ac_status = AC_STATUS_CONTINUE;
59204 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59205 cr = 3;
59206 - atomic_inc(&sbi->s_mb_lost_chunks);
59207 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59208 goto repeat;
59209 }
59210 }
59211 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59212 if (sbi->s_mb_stats) {
59213 ext4_msg(sb, KERN_INFO,
59214 "mballoc: %u blocks %u reqs (%u success)",
59215 - atomic_read(&sbi->s_bal_allocated),
59216 - atomic_read(&sbi->s_bal_reqs),
59217 - atomic_read(&sbi->s_bal_success));
59218 + atomic_read_unchecked(&sbi->s_bal_allocated),
59219 + atomic_read_unchecked(&sbi->s_bal_reqs),
59220 + atomic_read_unchecked(&sbi->s_bal_success));
59221 ext4_msg(sb, KERN_INFO,
59222 "mballoc: %u extents scanned, %u goal hits, "
59223 "%u 2^N hits, %u breaks, %u lost",
59224 - atomic_read(&sbi->s_bal_ex_scanned),
59225 - atomic_read(&sbi->s_bal_goals),
59226 - atomic_read(&sbi->s_bal_2orders),
59227 - atomic_read(&sbi->s_bal_breaks),
59228 - atomic_read(&sbi->s_mb_lost_chunks));
59229 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59230 + atomic_read_unchecked(&sbi->s_bal_goals),
59231 + atomic_read_unchecked(&sbi->s_bal_2orders),
59232 + atomic_read_unchecked(&sbi->s_bal_breaks),
59233 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59234 ext4_msg(sb, KERN_INFO,
59235 "mballoc: %lu generated and it took %Lu",
59236 sbi->s_mb_buddies_generated,
59237 sbi->s_mb_generation_time);
59238 ext4_msg(sb, KERN_INFO,
59239 "mballoc: %u preallocated, %u discarded",
59240 - atomic_read(&sbi->s_mb_preallocated),
59241 - atomic_read(&sbi->s_mb_discarded));
59242 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59243 + atomic_read_unchecked(&sbi->s_mb_discarded));
59244 }
59245
59246 free_percpu(sbi->s_locality_groups);
59247 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59248 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59249
59250 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59251 - atomic_inc(&sbi->s_bal_reqs);
59252 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59253 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59254 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59255 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59256 - atomic_inc(&sbi->s_bal_success);
59257 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59258 + atomic_inc_unchecked(&sbi->s_bal_success);
59259 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59260 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59261 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59262 - atomic_inc(&sbi->s_bal_goals);
59263 + atomic_inc_unchecked(&sbi->s_bal_goals);
59264 if (ac->ac_found > sbi->s_mb_max_to_scan)
59265 - atomic_inc(&sbi->s_bal_breaks);
59266 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59267 }
59268
59269 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59270 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59271 trace_ext4_mb_new_inode_pa(ac, pa);
59272
59273 ext4_mb_use_inode_pa(ac, pa);
59274 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59275 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59276
59277 ei = EXT4_I(ac->ac_inode);
59278 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59279 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59280 trace_ext4_mb_new_group_pa(ac, pa);
59281
59282 ext4_mb_use_group_pa(ac, pa);
59283 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59284 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59285
59286 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59287 lg = ac->ac_lg;
59288 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59289 * from the bitmap and continue.
59290 */
59291 }
59292 - atomic_add(free, &sbi->s_mb_discarded);
59293 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59294
59295 return err;
59296 }
59297 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59298 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59299 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59300 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59301 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59302 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59303 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59304
59305 return 0;
59306 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59307 index 04434ad..6404663 100644
59308 --- a/fs/ext4/mmp.c
59309 +++ b/fs/ext4/mmp.c
59310 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59311 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59312 const char *function, unsigned int line, const char *msg)
59313 {
59314 - __ext4_warning(sb, function, line, msg);
59315 + __ext4_warning(sb, function, line, "%s", msg);
59316 __ext4_warning(sb, function, line,
59317 "MMP failure info: last update time: %llu, last update "
59318 "node: %s, last update device: %s\n",
59319 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59320 index 710fed2..a82e4e8 100644
59321 --- a/fs/ext4/super.c
59322 +++ b/fs/ext4/super.c
59323 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59324 }
59325
59326 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59327 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59328 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59329 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59330
59331 #ifdef CONFIG_QUOTA
59332 @@ -2450,7 +2450,7 @@ struct ext4_attr {
59333 int offset;
59334 int deprecated_val;
59335 } u;
59336 -};
59337 +} __do_const;
59338
59339 static int parse_strtoull(const char *buf,
59340 unsigned long long max, unsigned long long *value)
59341 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59342 index e175e94..3ea69bf 100644
59343 --- a/fs/ext4/xattr.c
59344 +++ b/fs/ext4/xattr.c
59345 @@ -381,7 +381,7 @@ static int
59346 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59347 char *buffer, size_t buffer_size)
59348 {
59349 - size_t rest = buffer_size;
59350 + size_t rest = buffer_size, total_size = 0;
59351
59352 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59353 const struct xattr_handler *handler =
59354 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59355 buffer += size;
59356 }
59357 rest -= size;
59358 + total_size += size;
59359 }
59360 }
59361 - return buffer_size - rest;
59362 + return total_size;
59363 }
59364
59365 static int
59366 diff --git a/fs/fcntl.c b/fs/fcntl.c
59367 index ef68665..5deacdc 100644
59368 --- a/fs/fcntl.c
59369 +++ b/fs/fcntl.c
59370 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59371 if (err)
59372 return err;
59373
59374 + if (gr_handle_chroot_fowner(pid, type))
59375 + return -ENOENT;
59376 + if (gr_check_protected_task_fowner(pid, type))
59377 + return -EACCES;
59378 +
59379 f_modown(filp, pid, type, force);
59380 return 0;
59381 }
59382 diff --git a/fs/fhandle.c b/fs/fhandle.c
59383 index 999ff5c..41f4109 100644
59384 --- a/fs/fhandle.c
59385 +++ b/fs/fhandle.c
59386 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59387 } else
59388 retval = 0;
59389 /* copy the mount id */
59390 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59391 - sizeof(*mnt_id)) ||
59392 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59393 copy_to_user(ufh, handle,
59394 sizeof(struct file_handle) + handle_bytes))
59395 retval = -EFAULT;
59396 diff --git a/fs/file.c b/fs/file.c
59397 index eb56a13..ccee850 100644
59398 --- a/fs/file.c
59399 +++ b/fs/file.c
59400 @@ -16,6 +16,7 @@
59401 #include <linux/slab.h>
59402 #include <linux/vmalloc.h>
59403 #include <linux/file.h>
59404 +#include <linux/security.h>
59405 #include <linux/fdtable.h>
59406 #include <linux/bitops.h>
59407 #include <linux/interrupt.h>
59408 @@ -141,7 +142,7 @@ out:
59409 * Return <0 error code on error; 1 on successful completion.
59410 * The files->file_lock should be held on entry, and will be held on exit.
59411 */
59412 -static int expand_fdtable(struct files_struct *files, int nr)
59413 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59414 __releases(files->file_lock)
59415 __acquires(files->file_lock)
59416 {
59417 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59418 * expanded and execution may have blocked.
59419 * The files->file_lock should be held on entry, and will be held on exit.
59420 */
59421 -static int expand_files(struct files_struct *files, int nr)
59422 +static int expand_files(struct files_struct *files, unsigned int nr)
59423 {
59424 struct fdtable *fdt;
59425
59426 @@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59427 if (!file)
59428 return __close_fd(files, fd);
59429
59430 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59431 if (fd >= rlimit(RLIMIT_NOFILE))
59432 return -EBADF;
59433
59434 @@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59435 if (unlikely(oldfd == newfd))
59436 return -EINVAL;
59437
59438 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59439 if (newfd >= rlimit(RLIMIT_NOFILE))
59440 return -EBADF;
59441
59442 @@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59443 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59444 {
59445 int err;
59446 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59447 if (from >= rlimit(RLIMIT_NOFILE))
59448 return -EINVAL;
59449 err = alloc_fd(from, flags);
59450 diff --git a/fs/filesystems.c b/fs/filesystems.c
59451 index 92567d9..fcd8cbf 100644
59452 --- a/fs/filesystems.c
59453 +++ b/fs/filesystems.c
59454 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59455 int len = dot ? dot - name : strlen(name);
59456
59457 fs = __get_fs_type(name, len);
59458 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59459 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59460 +#else
59461 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59462 +#endif
59463 fs = __get_fs_type(name, len);
59464
59465 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59466 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59467 index 7dca743..543d620 100644
59468 --- a/fs/fs_struct.c
59469 +++ b/fs/fs_struct.c
59470 @@ -4,6 +4,7 @@
59471 #include <linux/path.h>
59472 #include <linux/slab.h>
59473 #include <linux/fs_struct.h>
59474 +#include <linux/grsecurity.h>
59475 #include "internal.h"
59476
59477 /*
59478 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59479 write_seqcount_begin(&fs->seq);
59480 old_root = fs->root;
59481 fs->root = *path;
59482 + gr_set_chroot_entries(current, path);
59483 write_seqcount_end(&fs->seq);
59484 spin_unlock(&fs->lock);
59485 if (old_root.dentry)
59486 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59487 int hits = 0;
59488 spin_lock(&fs->lock);
59489 write_seqcount_begin(&fs->seq);
59490 + /* this root replacement is only done by pivot_root,
59491 + leave grsec's chroot tagging alone for this task
59492 + so that a pivoted root isn't treated as a chroot
59493 + */
59494 hits += replace_path(&fs->root, old_root, new_root);
59495 hits += replace_path(&fs->pwd, old_root, new_root);
59496 write_seqcount_end(&fs->seq);
59497 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59498 task_lock(tsk);
59499 spin_lock(&fs->lock);
59500 tsk->fs = NULL;
59501 - kill = !--fs->users;
59502 + gr_clear_chroot_entries(tsk);
59503 + kill = !atomic_dec_return(&fs->users);
59504 spin_unlock(&fs->lock);
59505 task_unlock(tsk);
59506 if (kill)
59507 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59508 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59509 /* We don't need to lock fs - think why ;-) */
59510 if (fs) {
59511 - fs->users = 1;
59512 + atomic_set(&fs->users, 1);
59513 fs->in_exec = 0;
59514 spin_lock_init(&fs->lock);
59515 seqcount_init(&fs->seq);
59516 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59517 spin_lock(&old->lock);
59518 fs->root = old->root;
59519 path_get(&fs->root);
59520 + /* instead of calling gr_set_chroot_entries here,
59521 + we call it from every caller of this function
59522 + */
59523 fs->pwd = old->pwd;
59524 path_get(&fs->pwd);
59525 spin_unlock(&old->lock);
59526 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59527
59528 task_lock(current);
59529 spin_lock(&fs->lock);
59530 - kill = !--fs->users;
59531 + kill = !atomic_dec_return(&fs->users);
59532 current->fs = new_fs;
59533 + gr_set_chroot_entries(current, &new_fs->root);
59534 spin_unlock(&fs->lock);
59535 task_unlock(current);
59536
59537 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59538
59539 int current_umask(void)
59540 {
59541 - return current->fs->umask;
59542 + return current->fs->umask | gr_acl_umask();
59543 }
59544 EXPORT_SYMBOL(current_umask);
59545
59546 /* to be mentioned only in INIT_TASK */
59547 struct fs_struct init_fs = {
59548 - .users = 1,
59549 + .users = ATOMIC_INIT(1),
59550 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59551 .seq = SEQCNT_ZERO(init_fs.seq),
59552 .umask = 0022,
59553 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59554 index 29d7feb..303644d 100644
59555 --- a/fs/fscache/cookie.c
59556 +++ b/fs/fscache/cookie.c
59557 @@ -19,7 +19,7 @@
59558
59559 struct kmem_cache *fscache_cookie_jar;
59560
59561 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59562 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59563
59564 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59565 static int fscache_alloc_object(struct fscache_cache *cache,
59566 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59567 parent ? (char *) parent->def->name : "<no-parent>",
59568 def->name, netfs_data, enable);
59569
59570 - fscache_stat(&fscache_n_acquires);
59571 + fscache_stat_unchecked(&fscache_n_acquires);
59572
59573 /* if there's no parent cookie, then we don't create one here either */
59574 if (!parent) {
59575 - fscache_stat(&fscache_n_acquires_null);
59576 + fscache_stat_unchecked(&fscache_n_acquires_null);
59577 _leave(" [no parent]");
59578 return NULL;
59579 }
59580 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59581 /* allocate and initialise a cookie */
59582 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59583 if (!cookie) {
59584 - fscache_stat(&fscache_n_acquires_oom);
59585 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59586 _leave(" [ENOMEM]");
59587 return NULL;
59588 }
59589 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59590
59591 switch (cookie->def->type) {
59592 case FSCACHE_COOKIE_TYPE_INDEX:
59593 - fscache_stat(&fscache_n_cookie_index);
59594 + fscache_stat_unchecked(&fscache_n_cookie_index);
59595 break;
59596 case FSCACHE_COOKIE_TYPE_DATAFILE:
59597 - fscache_stat(&fscache_n_cookie_data);
59598 + fscache_stat_unchecked(&fscache_n_cookie_data);
59599 break;
59600 default:
59601 - fscache_stat(&fscache_n_cookie_special);
59602 + fscache_stat_unchecked(&fscache_n_cookie_special);
59603 break;
59604 }
59605
59606 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59607 } else {
59608 atomic_dec(&parent->n_children);
59609 __fscache_cookie_put(cookie);
59610 - fscache_stat(&fscache_n_acquires_nobufs);
59611 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59612 _leave(" = NULL");
59613 return NULL;
59614 }
59615 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59616 }
59617 }
59618
59619 - fscache_stat(&fscache_n_acquires_ok);
59620 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59621 _leave(" = %p", cookie);
59622 return cookie;
59623 }
59624 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59625 cache = fscache_select_cache_for_object(cookie->parent);
59626 if (!cache) {
59627 up_read(&fscache_addremove_sem);
59628 - fscache_stat(&fscache_n_acquires_no_cache);
59629 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59630 _leave(" = -ENOMEDIUM [no cache]");
59631 return -ENOMEDIUM;
59632 }
59633 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59634 object = cache->ops->alloc_object(cache, cookie);
59635 fscache_stat_d(&fscache_n_cop_alloc_object);
59636 if (IS_ERR(object)) {
59637 - fscache_stat(&fscache_n_object_no_alloc);
59638 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59639 ret = PTR_ERR(object);
59640 goto error;
59641 }
59642
59643 - fscache_stat(&fscache_n_object_alloc);
59644 + fscache_stat_unchecked(&fscache_n_object_alloc);
59645
59646 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59647 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59648
59649 _debug("ALLOC OBJ%x: %s {%lx}",
59650 object->debug_id, cookie->def->name, object->events);
59651 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59652
59653 _enter("{%s}", cookie->def->name);
59654
59655 - fscache_stat(&fscache_n_invalidates);
59656 + fscache_stat_unchecked(&fscache_n_invalidates);
59657
59658 /* Only permit invalidation of data files. Invalidating an index will
59659 * require the caller to release all its attachments to the tree rooted
59660 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59661 {
59662 struct fscache_object *object;
59663
59664 - fscache_stat(&fscache_n_updates);
59665 + fscache_stat_unchecked(&fscache_n_updates);
59666
59667 if (!cookie) {
59668 - fscache_stat(&fscache_n_updates_null);
59669 + fscache_stat_unchecked(&fscache_n_updates_null);
59670 _leave(" [no cookie]");
59671 return;
59672 }
59673 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59674 */
59675 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59676 {
59677 - fscache_stat(&fscache_n_relinquishes);
59678 + fscache_stat_unchecked(&fscache_n_relinquishes);
59679 if (retire)
59680 - fscache_stat(&fscache_n_relinquishes_retire);
59681 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59682
59683 if (!cookie) {
59684 - fscache_stat(&fscache_n_relinquishes_null);
59685 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
59686 _leave(" [no cookie]");
59687 return;
59688 }
59689 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59690 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59691 goto inconsistent;
59692
59693 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59694 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59695
59696 __fscache_use_cookie(cookie);
59697 if (fscache_submit_op(object, op) < 0)
59698 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59699 index 4226f66..0fb3f45 100644
59700 --- a/fs/fscache/internal.h
59701 +++ b/fs/fscache/internal.h
59702 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59703 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59704 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59705 struct fscache_operation *,
59706 - atomic_t *,
59707 - atomic_t *,
59708 + atomic_unchecked_t *,
59709 + atomic_unchecked_t *,
59710 void (*)(struct fscache_operation *));
59711 extern void fscache_invalidate_writes(struct fscache_cookie *);
59712
59713 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59714 * stats.c
59715 */
59716 #ifdef CONFIG_FSCACHE_STATS
59717 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59718 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59719 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59720 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59721
59722 -extern atomic_t fscache_n_op_pend;
59723 -extern atomic_t fscache_n_op_run;
59724 -extern atomic_t fscache_n_op_enqueue;
59725 -extern atomic_t fscache_n_op_deferred_release;
59726 -extern atomic_t fscache_n_op_release;
59727 -extern atomic_t fscache_n_op_gc;
59728 -extern atomic_t fscache_n_op_cancelled;
59729 -extern atomic_t fscache_n_op_rejected;
59730 +extern atomic_unchecked_t fscache_n_op_pend;
59731 +extern atomic_unchecked_t fscache_n_op_run;
59732 +extern atomic_unchecked_t fscache_n_op_enqueue;
59733 +extern atomic_unchecked_t fscache_n_op_deferred_release;
59734 +extern atomic_unchecked_t fscache_n_op_release;
59735 +extern atomic_unchecked_t fscache_n_op_gc;
59736 +extern atomic_unchecked_t fscache_n_op_cancelled;
59737 +extern atomic_unchecked_t fscache_n_op_rejected;
59738
59739 -extern atomic_t fscache_n_attr_changed;
59740 -extern atomic_t fscache_n_attr_changed_ok;
59741 -extern atomic_t fscache_n_attr_changed_nobufs;
59742 -extern atomic_t fscache_n_attr_changed_nomem;
59743 -extern atomic_t fscache_n_attr_changed_calls;
59744 +extern atomic_unchecked_t fscache_n_attr_changed;
59745 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
59746 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59747 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59748 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
59749
59750 -extern atomic_t fscache_n_allocs;
59751 -extern atomic_t fscache_n_allocs_ok;
59752 -extern atomic_t fscache_n_allocs_wait;
59753 -extern atomic_t fscache_n_allocs_nobufs;
59754 -extern atomic_t fscache_n_allocs_intr;
59755 -extern atomic_t fscache_n_allocs_object_dead;
59756 -extern atomic_t fscache_n_alloc_ops;
59757 -extern atomic_t fscache_n_alloc_op_waits;
59758 +extern atomic_unchecked_t fscache_n_allocs;
59759 +extern atomic_unchecked_t fscache_n_allocs_ok;
59760 +extern atomic_unchecked_t fscache_n_allocs_wait;
59761 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
59762 +extern atomic_unchecked_t fscache_n_allocs_intr;
59763 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
59764 +extern atomic_unchecked_t fscache_n_alloc_ops;
59765 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
59766
59767 -extern atomic_t fscache_n_retrievals;
59768 -extern atomic_t fscache_n_retrievals_ok;
59769 -extern atomic_t fscache_n_retrievals_wait;
59770 -extern atomic_t fscache_n_retrievals_nodata;
59771 -extern atomic_t fscache_n_retrievals_nobufs;
59772 -extern atomic_t fscache_n_retrievals_intr;
59773 -extern atomic_t fscache_n_retrievals_nomem;
59774 -extern atomic_t fscache_n_retrievals_object_dead;
59775 -extern atomic_t fscache_n_retrieval_ops;
59776 -extern atomic_t fscache_n_retrieval_op_waits;
59777 +extern atomic_unchecked_t fscache_n_retrievals;
59778 +extern atomic_unchecked_t fscache_n_retrievals_ok;
59779 +extern atomic_unchecked_t fscache_n_retrievals_wait;
59780 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
59781 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59782 +extern atomic_unchecked_t fscache_n_retrievals_intr;
59783 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
59784 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59785 +extern atomic_unchecked_t fscache_n_retrieval_ops;
59786 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59787
59788 -extern atomic_t fscache_n_stores;
59789 -extern atomic_t fscache_n_stores_ok;
59790 -extern atomic_t fscache_n_stores_again;
59791 -extern atomic_t fscache_n_stores_nobufs;
59792 -extern atomic_t fscache_n_stores_oom;
59793 -extern atomic_t fscache_n_store_ops;
59794 -extern atomic_t fscache_n_store_calls;
59795 -extern atomic_t fscache_n_store_pages;
59796 -extern atomic_t fscache_n_store_radix_deletes;
59797 -extern atomic_t fscache_n_store_pages_over_limit;
59798 +extern atomic_unchecked_t fscache_n_stores;
59799 +extern atomic_unchecked_t fscache_n_stores_ok;
59800 +extern atomic_unchecked_t fscache_n_stores_again;
59801 +extern atomic_unchecked_t fscache_n_stores_nobufs;
59802 +extern atomic_unchecked_t fscache_n_stores_oom;
59803 +extern atomic_unchecked_t fscache_n_store_ops;
59804 +extern atomic_unchecked_t fscache_n_store_calls;
59805 +extern atomic_unchecked_t fscache_n_store_pages;
59806 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
59807 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59808
59809 -extern atomic_t fscache_n_store_vmscan_not_storing;
59810 -extern atomic_t fscache_n_store_vmscan_gone;
59811 -extern atomic_t fscache_n_store_vmscan_busy;
59812 -extern atomic_t fscache_n_store_vmscan_cancelled;
59813 -extern atomic_t fscache_n_store_vmscan_wait;
59814 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59815 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59816 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59817 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59818 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59819
59820 -extern atomic_t fscache_n_marks;
59821 -extern atomic_t fscache_n_uncaches;
59822 +extern atomic_unchecked_t fscache_n_marks;
59823 +extern atomic_unchecked_t fscache_n_uncaches;
59824
59825 -extern atomic_t fscache_n_acquires;
59826 -extern atomic_t fscache_n_acquires_null;
59827 -extern atomic_t fscache_n_acquires_no_cache;
59828 -extern atomic_t fscache_n_acquires_ok;
59829 -extern atomic_t fscache_n_acquires_nobufs;
59830 -extern atomic_t fscache_n_acquires_oom;
59831 +extern atomic_unchecked_t fscache_n_acquires;
59832 +extern atomic_unchecked_t fscache_n_acquires_null;
59833 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
59834 +extern atomic_unchecked_t fscache_n_acquires_ok;
59835 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
59836 +extern atomic_unchecked_t fscache_n_acquires_oom;
59837
59838 -extern atomic_t fscache_n_invalidates;
59839 -extern atomic_t fscache_n_invalidates_run;
59840 +extern atomic_unchecked_t fscache_n_invalidates;
59841 +extern atomic_unchecked_t fscache_n_invalidates_run;
59842
59843 -extern atomic_t fscache_n_updates;
59844 -extern atomic_t fscache_n_updates_null;
59845 -extern atomic_t fscache_n_updates_run;
59846 +extern atomic_unchecked_t fscache_n_updates;
59847 +extern atomic_unchecked_t fscache_n_updates_null;
59848 +extern atomic_unchecked_t fscache_n_updates_run;
59849
59850 -extern atomic_t fscache_n_relinquishes;
59851 -extern atomic_t fscache_n_relinquishes_null;
59852 -extern atomic_t fscache_n_relinquishes_waitcrt;
59853 -extern atomic_t fscache_n_relinquishes_retire;
59854 +extern atomic_unchecked_t fscache_n_relinquishes;
59855 +extern atomic_unchecked_t fscache_n_relinquishes_null;
59856 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59857 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
59858
59859 -extern atomic_t fscache_n_cookie_index;
59860 -extern atomic_t fscache_n_cookie_data;
59861 -extern atomic_t fscache_n_cookie_special;
59862 +extern atomic_unchecked_t fscache_n_cookie_index;
59863 +extern atomic_unchecked_t fscache_n_cookie_data;
59864 +extern atomic_unchecked_t fscache_n_cookie_special;
59865
59866 -extern atomic_t fscache_n_object_alloc;
59867 -extern atomic_t fscache_n_object_no_alloc;
59868 -extern atomic_t fscache_n_object_lookups;
59869 -extern atomic_t fscache_n_object_lookups_negative;
59870 -extern atomic_t fscache_n_object_lookups_positive;
59871 -extern atomic_t fscache_n_object_lookups_timed_out;
59872 -extern atomic_t fscache_n_object_created;
59873 -extern atomic_t fscache_n_object_avail;
59874 -extern atomic_t fscache_n_object_dead;
59875 +extern atomic_unchecked_t fscache_n_object_alloc;
59876 +extern atomic_unchecked_t fscache_n_object_no_alloc;
59877 +extern atomic_unchecked_t fscache_n_object_lookups;
59878 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
59879 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
59880 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59881 +extern atomic_unchecked_t fscache_n_object_created;
59882 +extern atomic_unchecked_t fscache_n_object_avail;
59883 +extern atomic_unchecked_t fscache_n_object_dead;
59884
59885 -extern atomic_t fscache_n_checkaux_none;
59886 -extern atomic_t fscache_n_checkaux_okay;
59887 -extern atomic_t fscache_n_checkaux_update;
59888 -extern atomic_t fscache_n_checkaux_obsolete;
59889 +extern atomic_unchecked_t fscache_n_checkaux_none;
59890 +extern atomic_unchecked_t fscache_n_checkaux_okay;
59891 +extern atomic_unchecked_t fscache_n_checkaux_update;
59892 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59893
59894 extern atomic_t fscache_n_cop_alloc_object;
59895 extern atomic_t fscache_n_cop_lookup_object;
59896 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59897 atomic_inc(stat);
59898 }
59899
59900 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59901 +{
59902 + atomic_inc_unchecked(stat);
59903 +}
59904 +
59905 static inline void fscache_stat_d(atomic_t *stat)
59906 {
59907 atomic_dec(stat);
59908 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59909
59910 #define __fscache_stat(stat) (NULL)
59911 #define fscache_stat(stat) do {} while (0)
59912 +#define fscache_stat_unchecked(stat) do {} while (0)
59913 #define fscache_stat_d(stat) do {} while (0)
59914 #endif
59915
59916 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59917 index d3b4539..ed0c659 100644
59918 --- a/fs/fscache/object.c
59919 +++ b/fs/fscache/object.c
59920 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59921 _debug("LOOKUP \"%s\" in \"%s\"",
59922 cookie->def->name, object->cache->tag->name);
59923
59924 - fscache_stat(&fscache_n_object_lookups);
59925 + fscache_stat_unchecked(&fscache_n_object_lookups);
59926 fscache_stat(&fscache_n_cop_lookup_object);
59927 ret = object->cache->ops->lookup_object(object);
59928 fscache_stat_d(&fscache_n_cop_lookup_object);
59929 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59930 if (ret == -ETIMEDOUT) {
59931 /* probably stuck behind another object, so move this one to
59932 * the back of the queue */
59933 - fscache_stat(&fscache_n_object_lookups_timed_out);
59934 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59935 _leave(" [timeout]");
59936 return NO_TRANSIT;
59937 }
59938 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59939 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59940
59941 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59942 - fscache_stat(&fscache_n_object_lookups_negative);
59943 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59944
59945 /* Allow write requests to begin stacking up and read requests to begin
59946 * returning ENODATA.
59947 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
59948 /* if we were still looking up, then we must have a positive lookup
59949 * result, in which case there may be data available */
59950 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59951 - fscache_stat(&fscache_n_object_lookups_positive);
59952 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59953
59954 /* We do (presumably) have data */
59955 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59956 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
59957 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59958 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59959 } else {
59960 - fscache_stat(&fscache_n_object_created);
59961 + fscache_stat_unchecked(&fscache_n_object_created);
59962 }
59963
59964 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59965 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59966 fscache_stat_d(&fscache_n_cop_lookup_complete);
59967
59968 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59969 - fscache_stat(&fscache_n_object_avail);
59970 + fscache_stat_unchecked(&fscache_n_object_avail);
59971
59972 _leave("");
59973 return transit_to(JUMPSTART_DEPS);
59974 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59975
59976 /* this just shifts the object release to the work processor */
59977 fscache_put_object(object);
59978 - fscache_stat(&fscache_n_object_dead);
59979 + fscache_stat_unchecked(&fscache_n_object_dead);
59980
59981 _leave("");
59982 return transit_to(OBJECT_DEAD);
59983 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59984 enum fscache_checkaux result;
59985
59986 if (!object->cookie->def->check_aux) {
59987 - fscache_stat(&fscache_n_checkaux_none);
59988 + fscache_stat_unchecked(&fscache_n_checkaux_none);
59989 return FSCACHE_CHECKAUX_OKAY;
59990 }
59991
59992 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59993 switch (result) {
59994 /* entry okay as is */
59995 case FSCACHE_CHECKAUX_OKAY:
59996 - fscache_stat(&fscache_n_checkaux_okay);
59997 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
59998 break;
59999
60000 /* entry requires update */
60001 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60002 - fscache_stat(&fscache_n_checkaux_update);
60003 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60004 break;
60005
60006 /* entry requires deletion */
60007 case FSCACHE_CHECKAUX_OBSOLETE:
60008 - fscache_stat(&fscache_n_checkaux_obsolete);
60009 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60010 break;
60011
60012 default:
60013 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60014 {
60015 const struct fscache_state *s;
60016
60017 - fscache_stat(&fscache_n_invalidates_run);
60018 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60019 fscache_stat(&fscache_n_cop_invalidate_object);
60020 s = _fscache_invalidate_object(object, event);
60021 fscache_stat_d(&fscache_n_cop_invalidate_object);
60022 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60023 {
60024 _enter("{OBJ%x},%d", object->debug_id, event);
60025
60026 - fscache_stat(&fscache_n_updates_run);
60027 + fscache_stat_unchecked(&fscache_n_updates_run);
60028 fscache_stat(&fscache_n_cop_update_object);
60029 object->cache->ops->update_object(object);
60030 fscache_stat_d(&fscache_n_cop_update_object);
60031 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60032 index 318071a..379938b 100644
60033 --- a/fs/fscache/operation.c
60034 +++ b/fs/fscache/operation.c
60035 @@ -17,7 +17,7 @@
60036 #include <linux/slab.h>
60037 #include "internal.h"
60038
60039 -atomic_t fscache_op_debug_id;
60040 +atomic_unchecked_t fscache_op_debug_id;
60041 EXPORT_SYMBOL(fscache_op_debug_id);
60042
60043 /**
60044 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60045 ASSERTCMP(atomic_read(&op->usage), >, 0);
60046 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60047
60048 - fscache_stat(&fscache_n_op_enqueue);
60049 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60050 switch (op->flags & FSCACHE_OP_TYPE) {
60051 case FSCACHE_OP_ASYNC:
60052 _debug("queue async");
60053 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60054 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60055 if (op->processor)
60056 fscache_enqueue_operation(op);
60057 - fscache_stat(&fscache_n_op_run);
60058 + fscache_stat_unchecked(&fscache_n_op_run);
60059 }
60060
60061 /*
60062 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60063 if (object->n_in_progress > 0) {
60064 atomic_inc(&op->usage);
60065 list_add_tail(&op->pend_link, &object->pending_ops);
60066 - fscache_stat(&fscache_n_op_pend);
60067 + fscache_stat_unchecked(&fscache_n_op_pend);
60068 } else if (!list_empty(&object->pending_ops)) {
60069 atomic_inc(&op->usage);
60070 list_add_tail(&op->pend_link, &object->pending_ops);
60071 - fscache_stat(&fscache_n_op_pend);
60072 + fscache_stat_unchecked(&fscache_n_op_pend);
60073 fscache_start_operations(object);
60074 } else {
60075 ASSERTCMP(object->n_in_progress, ==, 0);
60076 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60077 object->n_exclusive++; /* reads and writes must wait */
60078 atomic_inc(&op->usage);
60079 list_add_tail(&op->pend_link, &object->pending_ops);
60080 - fscache_stat(&fscache_n_op_pend);
60081 + fscache_stat_unchecked(&fscache_n_op_pend);
60082 ret = 0;
60083 } else {
60084 /* If we're in any other state, there must have been an I/O
60085 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60086 if (object->n_exclusive > 0) {
60087 atomic_inc(&op->usage);
60088 list_add_tail(&op->pend_link, &object->pending_ops);
60089 - fscache_stat(&fscache_n_op_pend);
60090 + fscache_stat_unchecked(&fscache_n_op_pend);
60091 } else if (!list_empty(&object->pending_ops)) {
60092 atomic_inc(&op->usage);
60093 list_add_tail(&op->pend_link, &object->pending_ops);
60094 - fscache_stat(&fscache_n_op_pend);
60095 + fscache_stat_unchecked(&fscache_n_op_pend);
60096 fscache_start_operations(object);
60097 } else {
60098 ASSERTCMP(object->n_exclusive, ==, 0);
60099 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60100 object->n_ops++;
60101 atomic_inc(&op->usage);
60102 list_add_tail(&op->pend_link, &object->pending_ops);
60103 - fscache_stat(&fscache_n_op_pend);
60104 + fscache_stat_unchecked(&fscache_n_op_pend);
60105 ret = 0;
60106 } else if (fscache_object_is_dying(object)) {
60107 - fscache_stat(&fscache_n_op_rejected);
60108 + fscache_stat_unchecked(&fscache_n_op_rejected);
60109 op->state = FSCACHE_OP_ST_CANCELLED;
60110 ret = -ENOBUFS;
60111 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60112 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60113 ret = -EBUSY;
60114 if (op->state == FSCACHE_OP_ST_PENDING) {
60115 ASSERT(!list_empty(&op->pend_link));
60116 - fscache_stat(&fscache_n_op_cancelled);
60117 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60118 list_del_init(&op->pend_link);
60119 if (do_cancel)
60120 do_cancel(op);
60121 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60122 while (!list_empty(&object->pending_ops)) {
60123 op = list_entry(object->pending_ops.next,
60124 struct fscache_operation, pend_link);
60125 - fscache_stat(&fscache_n_op_cancelled);
60126 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60127 list_del_init(&op->pend_link);
60128
60129 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60130 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60131 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60132 op->state = FSCACHE_OP_ST_DEAD;
60133
60134 - fscache_stat(&fscache_n_op_release);
60135 + fscache_stat_unchecked(&fscache_n_op_release);
60136
60137 if (op->release) {
60138 op->release(op);
60139 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60140 * lock, and defer it otherwise */
60141 if (!spin_trylock(&object->lock)) {
60142 _debug("defer put");
60143 - fscache_stat(&fscache_n_op_deferred_release);
60144 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60145
60146 cache = object->cache;
60147 spin_lock(&cache->op_gc_list_lock);
60148 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60149
60150 _debug("GC DEFERRED REL OBJ%x OP%x",
60151 object->debug_id, op->debug_id);
60152 - fscache_stat(&fscache_n_op_gc);
60153 + fscache_stat_unchecked(&fscache_n_op_gc);
60154
60155 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60156 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60157 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60158 index 7f5c658..6c1e164 100644
60159 --- a/fs/fscache/page.c
60160 +++ b/fs/fscache/page.c
60161 @@ -61,7 +61,7 @@ try_again:
60162 val = radix_tree_lookup(&cookie->stores, page->index);
60163 if (!val) {
60164 rcu_read_unlock();
60165 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60166 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60167 __fscache_uncache_page(cookie, page);
60168 return true;
60169 }
60170 @@ -91,11 +91,11 @@ try_again:
60171 spin_unlock(&cookie->stores_lock);
60172
60173 if (xpage) {
60174 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60175 - fscache_stat(&fscache_n_store_radix_deletes);
60176 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60177 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60178 ASSERTCMP(xpage, ==, page);
60179 } else {
60180 - fscache_stat(&fscache_n_store_vmscan_gone);
60181 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60182 }
60183
60184 wake_up_bit(&cookie->flags, 0);
60185 @@ -110,11 +110,11 @@ page_busy:
60186 * sleeping on memory allocation, so we may need to impose a timeout
60187 * too. */
60188 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60189 - fscache_stat(&fscache_n_store_vmscan_busy);
60190 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60191 return false;
60192 }
60193
60194 - fscache_stat(&fscache_n_store_vmscan_wait);
60195 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60196 __fscache_wait_on_page_write(cookie, page);
60197 gfp &= ~__GFP_WAIT;
60198 goto try_again;
60199 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60200 FSCACHE_COOKIE_STORING_TAG);
60201 if (!radix_tree_tag_get(&cookie->stores, page->index,
60202 FSCACHE_COOKIE_PENDING_TAG)) {
60203 - fscache_stat(&fscache_n_store_radix_deletes);
60204 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60205 xpage = radix_tree_delete(&cookie->stores, page->index);
60206 }
60207 spin_unlock(&cookie->stores_lock);
60208 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60209
60210 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60211
60212 - fscache_stat(&fscache_n_attr_changed_calls);
60213 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60214
60215 if (fscache_object_is_active(object)) {
60216 fscache_stat(&fscache_n_cop_attr_changed);
60217 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60218
60219 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60220
60221 - fscache_stat(&fscache_n_attr_changed);
60222 + fscache_stat_unchecked(&fscache_n_attr_changed);
60223
60224 op = kzalloc(sizeof(*op), GFP_KERNEL);
60225 if (!op) {
60226 - fscache_stat(&fscache_n_attr_changed_nomem);
60227 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60228 _leave(" = -ENOMEM");
60229 return -ENOMEM;
60230 }
60231 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60232 if (fscache_submit_exclusive_op(object, op) < 0)
60233 goto nobufs;
60234 spin_unlock(&cookie->lock);
60235 - fscache_stat(&fscache_n_attr_changed_ok);
60236 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60237 fscache_put_operation(op);
60238 _leave(" = 0");
60239 return 0;
60240 @@ -225,7 +225,7 @@ nobufs:
60241 kfree(op);
60242 if (wake_cookie)
60243 __fscache_wake_unused_cookie(cookie);
60244 - fscache_stat(&fscache_n_attr_changed_nobufs);
60245 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60246 _leave(" = %d", -ENOBUFS);
60247 return -ENOBUFS;
60248 }
60249 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60250 /* allocate a retrieval operation and attempt to submit it */
60251 op = kzalloc(sizeof(*op), GFP_NOIO);
60252 if (!op) {
60253 - fscache_stat(&fscache_n_retrievals_nomem);
60254 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60255 return NULL;
60256 }
60257
60258 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60259 return 0;
60260 }
60261
60262 - fscache_stat(&fscache_n_retrievals_wait);
60263 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60264
60265 jif = jiffies;
60266 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60267 fscache_wait_bit_interruptible,
60268 TASK_INTERRUPTIBLE) != 0) {
60269 - fscache_stat(&fscache_n_retrievals_intr);
60270 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60271 _leave(" = -ERESTARTSYS");
60272 return -ERESTARTSYS;
60273 }
60274 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60275 */
60276 int fscache_wait_for_operation_activation(struct fscache_object *object,
60277 struct fscache_operation *op,
60278 - atomic_t *stat_op_waits,
60279 - atomic_t *stat_object_dead,
60280 + atomic_unchecked_t *stat_op_waits,
60281 + atomic_unchecked_t *stat_object_dead,
60282 void (*do_cancel)(struct fscache_operation *))
60283 {
60284 int ret;
60285 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60286
60287 _debug(">>> WT");
60288 if (stat_op_waits)
60289 - fscache_stat(stat_op_waits);
60290 + fscache_stat_unchecked(stat_op_waits);
60291 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60292 fscache_wait_bit_interruptible,
60293 TASK_INTERRUPTIBLE) != 0) {
60294 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60295 check_if_dead:
60296 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60297 if (stat_object_dead)
60298 - fscache_stat(stat_object_dead);
60299 + fscache_stat_unchecked(stat_object_dead);
60300 _leave(" = -ENOBUFS [cancelled]");
60301 return -ENOBUFS;
60302 }
60303 @@ -366,7 +366,7 @@ check_if_dead:
60304 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60305 fscache_cancel_op(op, do_cancel);
60306 if (stat_object_dead)
60307 - fscache_stat(stat_object_dead);
60308 + fscache_stat_unchecked(stat_object_dead);
60309 return -ENOBUFS;
60310 }
60311 return 0;
60312 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60313
60314 _enter("%p,%p,,,", cookie, page);
60315
60316 - fscache_stat(&fscache_n_retrievals);
60317 + fscache_stat_unchecked(&fscache_n_retrievals);
60318
60319 if (hlist_empty(&cookie->backing_objects))
60320 goto nobufs;
60321 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60322 goto nobufs_unlock_dec;
60323 spin_unlock(&cookie->lock);
60324
60325 - fscache_stat(&fscache_n_retrieval_ops);
60326 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60327
60328 /* pin the netfs read context in case we need to do the actual netfs
60329 * read because we've encountered a cache read failure */
60330 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60331
60332 error:
60333 if (ret == -ENOMEM)
60334 - fscache_stat(&fscache_n_retrievals_nomem);
60335 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60336 else if (ret == -ERESTARTSYS)
60337 - fscache_stat(&fscache_n_retrievals_intr);
60338 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60339 else if (ret == -ENODATA)
60340 - fscache_stat(&fscache_n_retrievals_nodata);
60341 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60342 else if (ret < 0)
60343 - fscache_stat(&fscache_n_retrievals_nobufs);
60344 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60345 else
60346 - fscache_stat(&fscache_n_retrievals_ok);
60347 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60348
60349 fscache_put_retrieval(op);
60350 _leave(" = %d", ret);
60351 @@ -490,7 +490,7 @@ nobufs_unlock:
60352 __fscache_wake_unused_cookie(cookie);
60353 kfree(op);
60354 nobufs:
60355 - fscache_stat(&fscache_n_retrievals_nobufs);
60356 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60357 _leave(" = -ENOBUFS");
60358 return -ENOBUFS;
60359 }
60360 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60361
60362 _enter("%p,,%d,,,", cookie, *nr_pages);
60363
60364 - fscache_stat(&fscache_n_retrievals);
60365 + fscache_stat_unchecked(&fscache_n_retrievals);
60366
60367 if (hlist_empty(&cookie->backing_objects))
60368 goto nobufs;
60369 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60370 goto nobufs_unlock_dec;
60371 spin_unlock(&cookie->lock);
60372
60373 - fscache_stat(&fscache_n_retrieval_ops);
60374 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60375
60376 /* pin the netfs read context in case we need to do the actual netfs
60377 * read because we've encountered a cache read failure */
60378 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60379
60380 error:
60381 if (ret == -ENOMEM)
60382 - fscache_stat(&fscache_n_retrievals_nomem);
60383 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60384 else if (ret == -ERESTARTSYS)
60385 - fscache_stat(&fscache_n_retrievals_intr);
60386 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60387 else if (ret == -ENODATA)
60388 - fscache_stat(&fscache_n_retrievals_nodata);
60389 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60390 else if (ret < 0)
60391 - fscache_stat(&fscache_n_retrievals_nobufs);
60392 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60393 else
60394 - fscache_stat(&fscache_n_retrievals_ok);
60395 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60396
60397 fscache_put_retrieval(op);
60398 _leave(" = %d", ret);
60399 @@ -621,7 +621,7 @@ nobufs_unlock:
60400 if (wake_cookie)
60401 __fscache_wake_unused_cookie(cookie);
60402 nobufs:
60403 - fscache_stat(&fscache_n_retrievals_nobufs);
60404 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60405 _leave(" = -ENOBUFS");
60406 return -ENOBUFS;
60407 }
60408 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60409
60410 _enter("%p,%p,,,", cookie, page);
60411
60412 - fscache_stat(&fscache_n_allocs);
60413 + fscache_stat_unchecked(&fscache_n_allocs);
60414
60415 if (hlist_empty(&cookie->backing_objects))
60416 goto nobufs;
60417 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60418 goto nobufs_unlock_dec;
60419 spin_unlock(&cookie->lock);
60420
60421 - fscache_stat(&fscache_n_alloc_ops);
60422 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60423
60424 ret = fscache_wait_for_operation_activation(
60425 object, &op->op,
60426 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60427
60428 error:
60429 if (ret == -ERESTARTSYS)
60430 - fscache_stat(&fscache_n_allocs_intr);
60431 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60432 else if (ret < 0)
60433 - fscache_stat(&fscache_n_allocs_nobufs);
60434 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60435 else
60436 - fscache_stat(&fscache_n_allocs_ok);
60437 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60438
60439 fscache_put_retrieval(op);
60440 _leave(" = %d", ret);
60441 @@ -715,7 +715,7 @@ nobufs_unlock:
60442 if (wake_cookie)
60443 __fscache_wake_unused_cookie(cookie);
60444 nobufs:
60445 - fscache_stat(&fscache_n_allocs_nobufs);
60446 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60447 _leave(" = -ENOBUFS");
60448 return -ENOBUFS;
60449 }
60450 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60451
60452 spin_lock(&cookie->stores_lock);
60453
60454 - fscache_stat(&fscache_n_store_calls);
60455 + fscache_stat_unchecked(&fscache_n_store_calls);
60456
60457 /* find a page to store */
60458 page = NULL;
60459 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60460 page = results[0];
60461 _debug("gang %d [%lx]", n, page->index);
60462 if (page->index > op->store_limit) {
60463 - fscache_stat(&fscache_n_store_pages_over_limit);
60464 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60465 goto superseded;
60466 }
60467
60468 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60469 spin_unlock(&cookie->stores_lock);
60470 spin_unlock(&object->lock);
60471
60472 - fscache_stat(&fscache_n_store_pages);
60473 + fscache_stat_unchecked(&fscache_n_store_pages);
60474 fscache_stat(&fscache_n_cop_write_page);
60475 ret = object->cache->ops->write_page(op, page);
60476 fscache_stat_d(&fscache_n_cop_write_page);
60477 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60478 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60479 ASSERT(PageFsCache(page));
60480
60481 - fscache_stat(&fscache_n_stores);
60482 + fscache_stat_unchecked(&fscache_n_stores);
60483
60484 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60485 _leave(" = -ENOBUFS [invalidating]");
60486 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60487 spin_unlock(&cookie->stores_lock);
60488 spin_unlock(&object->lock);
60489
60490 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60491 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60492 op->store_limit = object->store_limit;
60493
60494 __fscache_use_cookie(cookie);
60495 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60496
60497 spin_unlock(&cookie->lock);
60498 radix_tree_preload_end();
60499 - fscache_stat(&fscache_n_store_ops);
60500 - fscache_stat(&fscache_n_stores_ok);
60501 + fscache_stat_unchecked(&fscache_n_store_ops);
60502 + fscache_stat_unchecked(&fscache_n_stores_ok);
60503
60504 /* the work queue now carries its own ref on the object */
60505 fscache_put_operation(&op->op);
60506 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60507 return 0;
60508
60509 already_queued:
60510 - fscache_stat(&fscache_n_stores_again);
60511 + fscache_stat_unchecked(&fscache_n_stores_again);
60512 already_pending:
60513 spin_unlock(&cookie->stores_lock);
60514 spin_unlock(&object->lock);
60515 spin_unlock(&cookie->lock);
60516 radix_tree_preload_end();
60517 kfree(op);
60518 - fscache_stat(&fscache_n_stores_ok);
60519 + fscache_stat_unchecked(&fscache_n_stores_ok);
60520 _leave(" = 0");
60521 return 0;
60522
60523 @@ -1024,14 +1024,14 @@ nobufs:
60524 kfree(op);
60525 if (wake_cookie)
60526 __fscache_wake_unused_cookie(cookie);
60527 - fscache_stat(&fscache_n_stores_nobufs);
60528 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60529 _leave(" = -ENOBUFS");
60530 return -ENOBUFS;
60531
60532 nomem_free:
60533 kfree(op);
60534 nomem:
60535 - fscache_stat(&fscache_n_stores_oom);
60536 + fscache_stat_unchecked(&fscache_n_stores_oom);
60537 _leave(" = -ENOMEM");
60538 return -ENOMEM;
60539 }
60540 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60541 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60542 ASSERTCMP(page, !=, NULL);
60543
60544 - fscache_stat(&fscache_n_uncaches);
60545 + fscache_stat_unchecked(&fscache_n_uncaches);
60546
60547 /* cache withdrawal may beat us to it */
60548 if (!PageFsCache(page))
60549 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60550 struct fscache_cookie *cookie = op->op.object->cookie;
60551
60552 #ifdef CONFIG_FSCACHE_STATS
60553 - atomic_inc(&fscache_n_marks);
60554 + atomic_inc_unchecked(&fscache_n_marks);
60555 #endif
60556
60557 _debug("- mark %p{%lx}", page, page->index);
60558 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60559 index 40d13c7..ddf52b9 100644
60560 --- a/fs/fscache/stats.c
60561 +++ b/fs/fscache/stats.c
60562 @@ -18,99 +18,99 @@
60563 /*
60564 * operation counters
60565 */
60566 -atomic_t fscache_n_op_pend;
60567 -atomic_t fscache_n_op_run;
60568 -atomic_t fscache_n_op_enqueue;
60569 -atomic_t fscache_n_op_requeue;
60570 -atomic_t fscache_n_op_deferred_release;
60571 -atomic_t fscache_n_op_release;
60572 -atomic_t fscache_n_op_gc;
60573 -atomic_t fscache_n_op_cancelled;
60574 -atomic_t fscache_n_op_rejected;
60575 +atomic_unchecked_t fscache_n_op_pend;
60576 +atomic_unchecked_t fscache_n_op_run;
60577 +atomic_unchecked_t fscache_n_op_enqueue;
60578 +atomic_unchecked_t fscache_n_op_requeue;
60579 +atomic_unchecked_t fscache_n_op_deferred_release;
60580 +atomic_unchecked_t fscache_n_op_release;
60581 +atomic_unchecked_t fscache_n_op_gc;
60582 +atomic_unchecked_t fscache_n_op_cancelled;
60583 +atomic_unchecked_t fscache_n_op_rejected;
60584
60585 -atomic_t fscache_n_attr_changed;
60586 -atomic_t fscache_n_attr_changed_ok;
60587 -atomic_t fscache_n_attr_changed_nobufs;
60588 -atomic_t fscache_n_attr_changed_nomem;
60589 -atomic_t fscache_n_attr_changed_calls;
60590 +atomic_unchecked_t fscache_n_attr_changed;
60591 +atomic_unchecked_t fscache_n_attr_changed_ok;
60592 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60593 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60594 +atomic_unchecked_t fscache_n_attr_changed_calls;
60595
60596 -atomic_t fscache_n_allocs;
60597 -atomic_t fscache_n_allocs_ok;
60598 -atomic_t fscache_n_allocs_wait;
60599 -atomic_t fscache_n_allocs_nobufs;
60600 -atomic_t fscache_n_allocs_intr;
60601 -atomic_t fscache_n_allocs_object_dead;
60602 -atomic_t fscache_n_alloc_ops;
60603 -atomic_t fscache_n_alloc_op_waits;
60604 +atomic_unchecked_t fscache_n_allocs;
60605 +atomic_unchecked_t fscache_n_allocs_ok;
60606 +atomic_unchecked_t fscache_n_allocs_wait;
60607 +atomic_unchecked_t fscache_n_allocs_nobufs;
60608 +atomic_unchecked_t fscache_n_allocs_intr;
60609 +atomic_unchecked_t fscache_n_allocs_object_dead;
60610 +atomic_unchecked_t fscache_n_alloc_ops;
60611 +atomic_unchecked_t fscache_n_alloc_op_waits;
60612
60613 -atomic_t fscache_n_retrievals;
60614 -atomic_t fscache_n_retrievals_ok;
60615 -atomic_t fscache_n_retrievals_wait;
60616 -atomic_t fscache_n_retrievals_nodata;
60617 -atomic_t fscache_n_retrievals_nobufs;
60618 -atomic_t fscache_n_retrievals_intr;
60619 -atomic_t fscache_n_retrievals_nomem;
60620 -atomic_t fscache_n_retrievals_object_dead;
60621 -atomic_t fscache_n_retrieval_ops;
60622 -atomic_t fscache_n_retrieval_op_waits;
60623 +atomic_unchecked_t fscache_n_retrievals;
60624 +atomic_unchecked_t fscache_n_retrievals_ok;
60625 +atomic_unchecked_t fscache_n_retrievals_wait;
60626 +atomic_unchecked_t fscache_n_retrievals_nodata;
60627 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60628 +atomic_unchecked_t fscache_n_retrievals_intr;
60629 +atomic_unchecked_t fscache_n_retrievals_nomem;
60630 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60631 +atomic_unchecked_t fscache_n_retrieval_ops;
60632 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60633
60634 -atomic_t fscache_n_stores;
60635 -atomic_t fscache_n_stores_ok;
60636 -atomic_t fscache_n_stores_again;
60637 -atomic_t fscache_n_stores_nobufs;
60638 -atomic_t fscache_n_stores_oom;
60639 -atomic_t fscache_n_store_ops;
60640 -atomic_t fscache_n_store_calls;
60641 -atomic_t fscache_n_store_pages;
60642 -atomic_t fscache_n_store_radix_deletes;
60643 -atomic_t fscache_n_store_pages_over_limit;
60644 +atomic_unchecked_t fscache_n_stores;
60645 +atomic_unchecked_t fscache_n_stores_ok;
60646 +atomic_unchecked_t fscache_n_stores_again;
60647 +atomic_unchecked_t fscache_n_stores_nobufs;
60648 +atomic_unchecked_t fscache_n_stores_oom;
60649 +atomic_unchecked_t fscache_n_store_ops;
60650 +atomic_unchecked_t fscache_n_store_calls;
60651 +atomic_unchecked_t fscache_n_store_pages;
60652 +atomic_unchecked_t fscache_n_store_radix_deletes;
60653 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60654
60655 -atomic_t fscache_n_store_vmscan_not_storing;
60656 -atomic_t fscache_n_store_vmscan_gone;
60657 -atomic_t fscache_n_store_vmscan_busy;
60658 -atomic_t fscache_n_store_vmscan_cancelled;
60659 -atomic_t fscache_n_store_vmscan_wait;
60660 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60661 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60662 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60663 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60664 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60665
60666 -atomic_t fscache_n_marks;
60667 -atomic_t fscache_n_uncaches;
60668 +atomic_unchecked_t fscache_n_marks;
60669 +atomic_unchecked_t fscache_n_uncaches;
60670
60671 -atomic_t fscache_n_acquires;
60672 -atomic_t fscache_n_acquires_null;
60673 -atomic_t fscache_n_acquires_no_cache;
60674 -atomic_t fscache_n_acquires_ok;
60675 -atomic_t fscache_n_acquires_nobufs;
60676 -atomic_t fscache_n_acquires_oom;
60677 +atomic_unchecked_t fscache_n_acquires;
60678 +atomic_unchecked_t fscache_n_acquires_null;
60679 +atomic_unchecked_t fscache_n_acquires_no_cache;
60680 +atomic_unchecked_t fscache_n_acquires_ok;
60681 +atomic_unchecked_t fscache_n_acquires_nobufs;
60682 +atomic_unchecked_t fscache_n_acquires_oom;
60683
60684 -atomic_t fscache_n_invalidates;
60685 -atomic_t fscache_n_invalidates_run;
60686 +atomic_unchecked_t fscache_n_invalidates;
60687 +atomic_unchecked_t fscache_n_invalidates_run;
60688
60689 -atomic_t fscache_n_updates;
60690 -atomic_t fscache_n_updates_null;
60691 -atomic_t fscache_n_updates_run;
60692 +atomic_unchecked_t fscache_n_updates;
60693 +atomic_unchecked_t fscache_n_updates_null;
60694 +atomic_unchecked_t fscache_n_updates_run;
60695
60696 -atomic_t fscache_n_relinquishes;
60697 -atomic_t fscache_n_relinquishes_null;
60698 -atomic_t fscache_n_relinquishes_waitcrt;
60699 -atomic_t fscache_n_relinquishes_retire;
60700 +atomic_unchecked_t fscache_n_relinquishes;
60701 +atomic_unchecked_t fscache_n_relinquishes_null;
60702 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60703 +atomic_unchecked_t fscache_n_relinquishes_retire;
60704
60705 -atomic_t fscache_n_cookie_index;
60706 -atomic_t fscache_n_cookie_data;
60707 -atomic_t fscache_n_cookie_special;
60708 +atomic_unchecked_t fscache_n_cookie_index;
60709 +atomic_unchecked_t fscache_n_cookie_data;
60710 +atomic_unchecked_t fscache_n_cookie_special;
60711
60712 -atomic_t fscache_n_object_alloc;
60713 -atomic_t fscache_n_object_no_alloc;
60714 -atomic_t fscache_n_object_lookups;
60715 -atomic_t fscache_n_object_lookups_negative;
60716 -atomic_t fscache_n_object_lookups_positive;
60717 -atomic_t fscache_n_object_lookups_timed_out;
60718 -atomic_t fscache_n_object_created;
60719 -atomic_t fscache_n_object_avail;
60720 -atomic_t fscache_n_object_dead;
60721 +atomic_unchecked_t fscache_n_object_alloc;
60722 +atomic_unchecked_t fscache_n_object_no_alloc;
60723 +atomic_unchecked_t fscache_n_object_lookups;
60724 +atomic_unchecked_t fscache_n_object_lookups_negative;
60725 +atomic_unchecked_t fscache_n_object_lookups_positive;
60726 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
60727 +atomic_unchecked_t fscache_n_object_created;
60728 +atomic_unchecked_t fscache_n_object_avail;
60729 +atomic_unchecked_t fscache_n_object_dead;
60730
60731 -atomic_t fscache_n_checkaux_none;
60732 -atomic_t fscache_n_checkaux_okay;
60733 -atomic_t fscache_n_checkaux_update;
60734 -atomic_t fscache_n_checkaux_obsolete;
60735 +atomic_unchecked_t fscache_n_checkaux_none;
60736 +atomic_unchecked_t fscache_n_checkaux_okay;
60737 +atomic_unchecked_t fscache_n_checkaux_update;
60738 +atomic_unchecked_t fscache_n_checkaux_obsolete;
60739
60740 atomic_t fscache_n_cop_alloc_object;
60741 atomic_t fscache_n_cop_lookup_object;
60742 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60743 seq_puts(m, "FS-Cache statistics\n");
60744
60745 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60746 - atomic_read(&fscache_n_cookie_index),
60747 - atomic_read(&fscache_n_cookie_data),
60748 - atomic_read(&fscache_n_cookie_special));
60749 + atomic_read_unchecked(&fscache_n_cookie_index),
60750 + atomic_read_unchecked(&fscache_n_cookie_data),
60751 + atomic_read_unchecked(&fscache_n_cookie_special));
60752
60753 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60754 - atomic_read(&fscache_n_object_alloc),
60755 - atomic_read(&fscache_n_object_no_alloc),
60756 - atomic_read(&fscache_n_object_avail),
60757 - atomic_read(&fscache_n_object_dead));
60758 + atomic_read_unchecked(&fscache_n_object_alloc),
60759 + atomic_read_unchecked(&fscache_n_object_no_alloc),
60760 + atomic_read_unchecked(&fscache_n_object_avail),
60761 + atomic_read_unchecked(&fscache_n_object_dead));
60762 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60763 - atomic_read(&fscache_n_checkaux_none),
60764 - atomic_read(&fscache_n_checkaux_okay),
60765 - atomic_read(&fscache_n_checkaux_update),
60766 - atomic_read(&fscache_n_checkaux_obsolete));
60767 + atomic_read_unchecked(&fscache_n_checkaux_none),
60768 + atomic_read_unchecked(&fscache_n_checkaux_okay),
60769 + atomic_read_unchecked(&fscache_n_checkaux_update),
60770 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60771
60772 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60773 - atomic_read(&fscache_n_marks),
60774 - atomic_read(&fscache_n_uncaches));
60775 + atomic_read_unchecked(&fscache_n_marks),
60776 + atomic_read_unchecked(&fscache_n_uncaches));
60777
60778 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60779 " oom=%u\n",
60780 - atomic_read(&fscache_n_acquires),
60781 - atomic_read(&fscache_n_acquires_null),
60782 - atomic_read(&fscache_n_acquires_no_cache),
60783 - atomic_read(&fscache_n_acquires_ok),
60784 - atomic_read(&fscache_n_acquires_nobufs),
60785 - atomic_read(&fscache_n_acquires_oom));
60786 + atomic_read_unchecked(&fscache_n_acquires),
60787 + atomic_read_unchecked(&fscache_n_acquires_null),
60788 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
60789 + atomic_read_unchecked(&fscache_n_acquires_ok),
60790 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
60791 + atomic_read_unchecked(&fscache_n_acquires_oom));
60792
60793 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60794 - atomic_read(&fscache_n_object_lookups),
60795 - atomic_read(&fscache_n_object_lookups_negative),
60796 - atomic_read(&fscache_n_object_lookups_positive),
60797 - atomic_read(&fscache_n_object_created),
60798 - atomic_read(&fscache_n_object_lookups_timed_out));
60799 + atomic_read_unchecked(&fscache_n_object_lookups),
60800 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
60801 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
60802 + atomic_read_unchecked(&fscache_n_object_created),
60803 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60804
60805 seq_printf(m, "Invals : n=%u run=%u\n",
60806 - atomic_read(&fscache_n_invalidates),
60807 - atomic_read(&fscache_n_invalidates_run));
60808 + atomic_read_unchecked(&fscache_n_invalidates),
60809 + atomic_read_unchecked(&fscache_n_invalidates_run));
60810
60811 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60812 - atomic_read(&fscache_n_updates),
60813 - atomic_read(&fscache_n_updates_null),
60814 - atomic_read(&fscache_n_updates_run));
60815 + atomic_read_unchecked(&fscache_n_updates),
60816 + atomic_read_unchecked(&fscache_n_updates_null),
60817 + atomic_read_unchecked(&fscache_n_updates_run));
60818
60819 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60820 - atomic_read(&fscache_n_relinquishes),
60821 - atomic_read(&fscache_n_relinquishes_null),
60822 - atomic_read(&fscache_n_relinquishes_waitcrt),
60823 - atomic_read(&fscache_n_relinquishes_retire));
60824 + atomic_read_unchecked(&fscache_n_relinquishes),
60825 + atomic_read_unchecked(&fscache_n_relinquishes_null),
60826 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60827 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
60828
60829 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60830 - atomic_read(&fscache_n_attr_changed),
60831 - atomic_read(&fscache_n_attr_changed_ok),
60832 - atomic_read(&fscache_n_attr_changed_nobufs),
60833 - atomic_read(&fscache_n_attr_changed_nomem),
60834 - atomic_read(&fscache_n_attr_changed_calls));
60835 + atomic_read_unchecked(&fscache_n_attr_changed),
60836 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
60837 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60838 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60839 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
60840
60841 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60842 - atomic_read(&fscache_n_allocs),
60843 - atomic_read(&fscache_n_allocs_ok),
60844 - atomic_read(&fscache_n_allocs_wait),
60845 - atomic_read(&fscache_n_allocs_nobufs),
60846 - atomic_read(&fscache_n_allocs_intr));
60847 + atomic_read_unchecked(&fscache_n_allocs),
60848 + atomic_read_unchecked(&fscache_n_allocs_ok),
60849 + atomic_read_unchecked(&fscache_n_allocs_wait),
60850 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
60851 + atomic_read_unchecked(&fscache_n_allocs_intr));
60852 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60853 - atomic_read(&fscache_n_alloc_ops),
60854 - atomic_read(&fscache_n_alloc_op_waits),
60855 - atomic_read(&fscache_n_allocs_object_dead));
60856 + atomic_read_unchecked(&fscache_n_alloc_ops),
60857 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
60858 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
60859
60860 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60861 " int=%u oom=%u\n",
60862 - atomic_read(&fscache_n_retrievals),
60863 - atomic_read(&fscache_n_retrievals_ok),
60864 - atomic_read(&fscache_n_retrievals_wait),
60865 - atomic_read(&fscache_n_retrievals_nodata),
60866 - atomic_read(&fscache_n_retrievals_nobufs),
60867 - atomic_read(&fscache_n_retrievals_intr),
60868 - atomic_read(&fscache_n_retrievals_nomem));
60869 + atomic_read_unchecked(&fscache_n_retrievals),
60870 + atomic_read_unchecked(&fscache_n_retrievals_ok),
60871 + atomic_read_unchecked(&fscache_n_retrievals_wait),
60872 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
60873 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60874 + atomic_read_unchecked(&fscache_n_retrievals_intr),
60875 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
60876 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60877 - atomic_read(&fscache_n_retrieval_ops),
60878 - atomic_read(&fscache_n_retrieval_op_waits),
60879 - atomic_read(&fscache_n_retrievals_object_dead));
60880 + atomic_read_unchecked(&fscache_n_retrieval_ops),
60881 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60882 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60883
60884 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60885 - atomic_read(&fscache_n_stores),
60886 - atomic_read(&fscache_n_stores_ok),
60887 - atomic_read(&fscache_n_stores_again),
60888 - atomic_read(&fscache_n_stores_nobufs),
60889 - atomic_read(&fscache_n_stores_oom));
60890 + atomic_read_unchecked(&fscache_n_stores),
60891 + atomic_read_unchecked(&fscache_n_stores_ok),
60892 + atomic_read_unchecked(&fscache_n_stores_again),
60893 + atomic_read_unchecked(&fscache_n_stores_nobufs),
60894 + atomic_read_unchecked(&fscache_n_stores_oom));
60895 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60896 - atomic_read(&fscache_n_store_ops),
60897 - atomic_read(&fscache_n_store_calls),
60898 - atomic_read(&fscache_n_store_pages),
60899 - atomic_read(&fscache_n_store_radix_deletes),
60900 - atomic_read(&fscache_n_store_pages_over_limit));
60901 + atomic_read_unchecked(&fscache_n_store_ops),
60902 + atomic_read_unchecked(&fscache_n_store_calls),
60903 + atomic_read_unchecked(&fscache_n_store_pages),
60904 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
60905 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60906
60907 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60908 - atomic_read(&fscache_n_store_vmscan_not_storing),
60909 - atomic_read(&fscache_n_store_vmscan_gone),
60910 - atomic_read(&fscache_n_store_vmscan_busy),
60911 - atomic_read(&fscache_n_store_vmscan_cancelled),
60912 - atomic_read(&fscache_n_store_vmscan_wait));
60913 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60914 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60915 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60916 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60917 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60918
60919 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60920 - atomic_read(&fscache_n_op_pend),
60921 - atomic_read(&fscache_n_op_run),
60922 - atomic_read(&fscache_n_op_enqueue),
60923 - atomic_read(&fscache_n_op_cancelled),
60924 - atomic_read(&fscache_n_op_rejected));
60925 + atomic_read_unchecked(&fscache_n_op_pend),
60926 + atomic_read_unchecked(&fscache_n_op_run),
60927 + atomic_read_unchecked(&fscache_n_op_enqueue),
60928 + atomic_read_unchecked(&fscache_n_op_cancelled),
60929 + atomic_read_unchecked(&fscache_n_op_rejected));
60930 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60931 - atomic_read(&fscache_n_op_deferred_release),
60932 - atomic_read(&fscache_n_op_release),
60933 - atomic_read(&fscache_n_op_gc));
60934 + atomic_read_unchecked(&fscache_n_op_deferred_release),
60935 + atomic_read_unchecked(&fscache_n_op_release),
60936 + atomic_read_unchecked(&fscache_n_op_gc));
60937
60938 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60939 atomic_read(&fscache_n_cop_alloc_object),
60940 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60941 index b96a49b..9bfdc47 100644
60942 --- a/fs/fuse/cuse.c
60943 +++ b/fs/fuse/cuse.c
60944 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
60945 INIT_LIST_HEAD(&cuse_conntbl[i]);
60946
60947 /* inherit and extend fuse_dev_operations */
60948 - cuse_channel_fops = fuse_dev_operations;
60949 - cuse_channel_fops.owner = THIS_MODULE;
60950 - cuse_channel_fops.open = cuse_channel_open;
60951 - cuse_channel_fops.release = cuse_channel_release;
60952 + pax_open_kernel();
60953 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60954 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60955 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
60956 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
60957 + pax_close_kernel();
60958
60959 cuse_class = class_create(THIS_MODULE, "cuse");
60960 if (IS_ERR(cuse_class))
60961 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60962 index 0a648bb..8d463f1 100644
60963 --- a/fs/fuse/dev.c
60964 +++ b/fs/fuse/dev.c
60965 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60966 ret = 0;
60967 pipe_lock(pipe);
60968
60969 - if (!pipe->readers) {
60970 + if (!atomic_read(&pipe->readers)) {
60971 send_sig(SIGPIPE, current, 0);
60972 if (!ret)
60973 ret = -EPIPE;
60974 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60975 page_nr++;
60976 ret += buf->len;
60977
60978 - if (pipe->files)
60979 + if (atomic_read(&pipe->files))
60980 do_wakeup = 1;
60981 }
60982
60983 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60984 index 1d1292c..bba17ea 100644
60985 --- a/fs/fuse/dir.c
60986 +++ b/fs/fuse/dir.c
60987 @@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
60988 return link;
60989 }
60990
60991 -static void free_link(char *link)
60992 +static void free_link(const char *link)
60993 {
60994 if (!IS_ERR(link))
60995 free_page((unsigned long) link);
60996 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60997 index fe649d3..c679164 100644
60998 --- a/fs/hostfs/hostfs_kern.c
60999 +++ b/fs/hostfs/hostfs_kern.c
61000 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61001
61002 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61003 {
61004 - char *s = nd_get_link(nd);
61005 + const char *s = nd_get_link(nd);
61006 if (!IS_ERR(s))
61007 __putname(s);
61008 }
61009 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61010 index d19b30a..ef89c36 100644
61011 --- a/fs/hugetlbfs/inode.c
61012 +++ b/fs/hugetlbfs/inode.c
61013 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61014 struct mm_struct *mm = current->mm;
61015 struct vm_area_struct *vma;
61016 struct hstate *h = hstate_file(file);
61017 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61018 struct vm_unmapped_area_info info;
61019
61020 if (len & ~huge_page_mask(h))
61021 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61022 return addr;
61023 }
61024
61025 +#ifdef CONFIG_PAX_RANDMMAP
61026 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61027 +#endif
61028 +
61029 if (addr) {
61030 addr = ALIGN(addr, huge_page_size(h));
61031 vma = find_vma(mm, addr);
61032 - if (TASK_SIZE - len >= addr &&
61033 - (!vma || addr + len <= vma->vm_start))
61034 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61035 return addr;
61036 }
61037
61038 info.flags = 0;
61039 info.length = len;
61040 info.low_limit = TASK_UNMAPPED_BASE;
61041 +
61042 +#ifdef CONFIG_PAX_RANDMMAP
61043 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61044 + info.low_limit += mm->delta_mmap;
61045 +#endif
61046 +
61047 info.high_limit = TASK_SIZE;
61048 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61049 info.align_offset = 0;
61050 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61051 };
61052 MODULE_ALIAS_FS("hugetlbfs");
61053
61054 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61055 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61056
61057 static int can_do_hugetlb_shm(void)
61058 {
61059 diff --git a/fs/inode.c b/fs/inode.c
61060 index 4bcdad3..1883822 100644
61061 --- a/fs/inode.c
61062 +++ b/fs/inode.c
61063 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61064
61065 #ifdef CONFIG_SMP
61066 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61067 - static atomic_t shared_last_ino;
61068 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61069 + static atomic_unchecked_t shared_last_ino;
61070 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61071
61072 res = next - LAST_INO_BATCH;
61073 }
61074 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61075 index 4a6cf28..d3a29d3 100644
61076 --- a/fs/jffs2/erase.c
61077 +++ b/fs/jffs2/erase.c
61078 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61079 struct jffs2_unknown_node marker = {
61080 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61081 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61082 - .totlen = cpu_to_je32(c->cleanmarker_size)
61083 + .totlen = cpu_to_je32(c->cleanmarker_size),
61084 + .hdr_crc = cpu_to_je32(0)
61085 };
61086
61087 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61088 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61089 index a6597d6..41b30ec 100644
61090 --- a/fs/jffs2/wbuf.c
61091 +++ b/fs/jffs2/wbuf.c
61092 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61093 {
61094 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61095 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61096 - .totlen = constant_cpu_to_je32(8)
61097 + .totlen = constant_cpu_to_je32(8),
61098 + .hdr_crc = constant_cpu_to_je32(0)
61099 };
61100
61101 /*
61102 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61103 index e2b7483..855bca3 100644
61104 --- a/fs/jfs/super.c
61105 +++ b/fs/jfs/super.c
61106 @@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61107
61108 jfs_inode_cachep =
61109 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61110 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61111 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61112 init_once);
61113 if (jfs_inode_cachep == NULL)
61114 return -ENOMEM;
61115 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61116 index 39c0143..d54fad4 100644
61117 --- a/fs/kernfs/dir.c
61118 +++ b/fs/kernfs/dir.c
61119 @@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61120 *
61121 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61122 */
61123 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
61124 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61125 {
61126 unsigned long hash = init_name_hash();
61127 unsigned int len = strlen(name);
61128 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61129 index dbf397b..d624b48 100644
61130 --- a/fs/kernfs/file.c
61131 +++ b/fs/kernfs/file.c
61132 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61133
61134 struct kernfs_open_node {
61135 atomic_t refcnt;
61136 - atomic_t event;
61137 + atomic_unchecked_t event;
61138 wait_queue_head_t poll;
61139 struct list_head files; /* goes through kernfs_open_file.list */
61140 };
61141 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61142 {
61143 struct kernfs_open_file *of = sf->private;
61144
61145 - of->event = atomic_read(&of->kn->attr.open->event);
61146 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61147
61148 return of->kn->attr.ops->seq_show(sf, v);
61149 }
61150 @@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61151 return ret;
61152 }
61153
61154 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61155 - void *buf, int len, int write)
61156 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61157 + void *buf, size_t len, int write)
61158 {
61159 struct file *file = vma->vm_file;
61160 struct kernfs_open_file *of = kernfs_of(file);
61161 - int ret;
61162 + ssize_t ret;
61163
61164 if (!of->vm_ops)
61165 return -EINVAL;
61166 @@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61167 return -ENOMEM;
61168
61169 atomic_set(&new_on->refcnt, 0);
61170 - atomic_set(&new_on->event, 1);
61171 + atomic_set_unchecked(&new_on->event, 1);
61172 init_waitqueue_head(&new_on->poll);
61173 INIT_LIST_HEAD(&new_on->files);
61174 goto retry;
61175 @@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61176
61177 kernfs_put_active(kn);
61178
61179 - if (of->event != atomic_read(&on->event))
61180 + if (of->event != atomic_read_unchecked(&on->event))
61181 goto trigger;
61182
61183 return DEFAULT_POLLMASK;
61184 @@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61185 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61186 on = kn->attr.open;
61187 if (on) {
61188 - atomic_inc(&on->event);
61189 + atomic_inc_unchecked(&on->event);
61190 wake_up_interruptible(&on->poll);
61191 }
61192 }
61193 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61194 index 4d45705..b35e0bd 100644
61195 --- a/fs/kernfs/symlink.c
61196 +++ b/fs/kernfs/symlink.c
61197 @@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61198 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61199 void *cookie)
61200 {
61201 - char *page = nd_get_link(nd);
61202 + const char *page = nd_get_link(nd);
61203 if (!IS_ERR(page))
61204 free_page((unsigned long)page);
61205 }
61206 diff --git a/fs/libfs.c b/fs/libfs.c
61207 index a184424..944ddce 100644
61208 --- a/fs/libfs.c
61209 +++ b/fs/libfs.c
61210 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61211
61212 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61213 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61214 + char d_name[sizeof(next->d_iname)];
61215 + const unsigned char *name;
61216 +
61217 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61218 if (!simple_positive(next)) {
61219 spin_unlock(&next->d_lock);
61220 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61221
61222 spin_unlock(&next->d_lock);
61223 spin_unlock(&dentry->d_lock);
61224 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61225 + name = next->d_name.name;
61226 + if (name == next->d_iname) {
61227 + memcpy(d_name, name, next->d_name.len);
61228 + name = d_name;
61229 + }
61230 + if (!dir_emit(ctx, name, next->d_name.len,
61231 next->d_inode->i_ino, dt_type(next->d_inode)))
61232 return 0;
61233 spin_lock(&dentry->d_lock);
61234 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61235 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61236 void *cookie)
61237 {
61238 - char *s = nd_get_link(nd);
61239 + const char *s = nd_get_link(nd);
61240 if (!IS_ERR(s))
61241 kfree(s);
61242 }
61243 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61244 index acd3947..1f896e2 100644
61245 --- a/fs/lockd/clntproc.c
61246 +++ b/fs/lockd/clntproc.c
61247 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61248 /*
61249 * Cookie counter for NLM requests
61250 */
61251 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61252 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61253
61254 void nlmclnt_next_cookie(struct nlm_cookie *c)
61255 {
61256 - u32 cookie = atomic_inc_return(&nlm_cookie);
61257 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61258
61259 memcpy(c->data, &cookie, 4);
61260 c->len=4;
61261 diff --git a/fs/locks.c b/fs/locks.c
61262 index 92a0f0a..45a48f0 100644
61263 --- a/fs/locks.c
61264 +++ b/fs/locks.c
61265 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61266 return;
61267
61268 if (filp->f_op->flock) {
61269 - struct file_lock fl = {
61270 + struct file_lock flock = {
61271 .fl_pid = current->tgid,
61272 .fl_file = filp,
61273 .fl_flags = FL_FLOCK,
61274 .fl_type = F_UNLCK,
61275 .fl_end = OFFSET_MAX,
61276 };
61277 - filp->f_op->flock(filp, F_SETLKW, &fl);
61278 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61279 - fl.fl_ops->fl_release_private(&fl);
61280 + filp->f_op->flock(filp, F_SETLKW, &flock);
61281 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61282 + flock.fl_ops->fl_release_private(&flock);
61283 }
61284
61285 spin_lock(&inode->i_lock);
61286 diff --git a/fs/mount.h b/fs/mount.h
61287 index b29e42f..5ea7fdf 100644
61288 --- a/fs/mount.h
61289 +++ b/fs/mount.h
61290 @@ -11,7 +11,7 @@ struct mnt_namespace {
61291 u64 seq; /* Sequence number to prevent loops */
61292 wait_queue_head_t poll;
61293 int event;
61294 -};
61295 +} __randomize_layout;
61296
61297 struct mnt_pcp {
61298 int mnt_count;
61299 @@ -57,7 +57,7 @@ struct mount {
61300 int mnt_expiry_mark; /* true if marked for expiry */
61301 int mnt_pinned;
61302 struct path mnt_ex_mountpoint;
61303 -};
61304 +} __randomize_layout;
61305
61306 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61307
61308 diff --git a/fs/namei.c b/fs/namei.c
61309 index 4b491b4..a0166f9 100644
61310 --- a/fs/namei.c
61311 +++ b/fs/namei.c
61312 @@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61313 if (ret != -EACCES)
61314 return ret;
61315
61316 +#ifdef CONFIG_GRKERNSEC
61317 + /* we'll block if we have to log due to a denied capability use */
61318 + if (mask & MAY_NOT_BLOCK)
61319 + return -ECHILD;
61320 +#endif
61321 +
61322 if (S_ISDIR(inode->i_mode)) {
61323 /* DACs are overridable for directories */
61324 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
61325 - return 0;
61326 if (!(mask & MAY_WRITE))
61327 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61328 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61329 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61330 return 0;
61331 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
61332 + return 0;
61333 return -EACCES;
61334 }
61335 /*
61336 + * Searching includes executable on directories, else just read.
61337 + */
61338 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61339 + if (mask == MAY_READ)
61340 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61341 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61342 + return 0;
61343 +
61344 + /*
61345 * Read/write DACs are always overridable.
61346 * Executable DACs are overridable when there is
61347 * at least one exec bit set.
61348 @@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61349 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61350 return 0;
61351
61352 - /*
61353 - * Searching includes executable on directories, else just read.
61354 - */
61355 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61356 - if (mask == MAY_READ)
61357 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61358 - return 0;
61359 -
61360 return -EACCES;
61361 }
61362
61363 @@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61364 {
61365 struct dentry *dentry = link->dentry;
61366 int error;
61367 - char *s;
61368 + const char *s;
61369
61370 BUG_ON(nd->flags & LOOKUP_RCU);
61371
61372 @@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61373 if (error)
61374 goto out_put_nd_path;
61375
61376 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61377 + dentry->d_inode, dentry, nd->path.mnt)) {
61378 + error = -EACCES;
61379 + goto out_put_nd_path;
61380 + }
61381 +
61382 nd->last_type = LAST_BIND;
61383 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61384 error = PTR_ERR(*p);
61385 @@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61386 if (res)
61387 break;
61388 res = walk_component(nd, path, LOOKUP_FOLLOW);
61389 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61390 + res = -EACCES;
61391 put_link(nd, &link, cookie);
61392 } while (res > 0);
61393
61394 @@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61395 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61396 {
61397 unsigned long a, b, adata, bdata, mask, hash, len;
61398 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61399 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61400
61401 hash = a = 0;
61402 len = -sizeof(unsigned long);
61403 @@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61404 if (err)
61405 break;
61406 err = lookup_last(nd, &path);
61407 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61408 + err = -EACCES;
61409 put_link(nd, &link, cookie);
61410 }
61411 }
61412 @@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61413 if (!err)
61414 err = complete_walk(nd);
61415
61416 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61417 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61418 + path_put(&nd->path);
61419 + err = -ENOENT;
61420 + }
61421 + }
61422 +
61423 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61424 if (!d_is_directory(nd->path.dentry)) {
61425 path_put(&nd->path);
61426 @@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61427 retval = path_lookupat(dfd, name->name,
61428 flags | LOOKUP_REVAL, nd);
61429
61430 - if (likely(!retval))
61431 + if (likely(!retval)) {
61432 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61433 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61434 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61435 + path_put(&nd->path);
61436 + return -ENOENT;
61437 + }
61438 + }
61439 + }
61440 return retval;
61441 }
61442
61443 @@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61444 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61445 return -EPERM;
61446
61447 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61448 + return -EPERM;
61449 + if (gr_handle_rawio(inode))
61450 + return -EPERM;
61451 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61452 + return -EACCES;
61453 +
61454 return 0;
61455 }
61456
61457 @@ -2787,7 +2826,7 @@ looked_up:
61458 * cleared otherwise prior to returning.
61459 */
61460 static int lookup_open(struct nameidata *nd, struct path *path,
61461 - struct file *file,
61462 + struct path *link, struct file *file,
61463 const struct open_flags *op,
61464 bool got_write, int *opened)
61465 {
61466 @@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61467 /* Negative dentry, just create the file */
61468 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61469 umode_t mode = op->mode;
61470 +
61471 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61472 + error = -EACCES;
61473 + goto out_dput;
61474 + }
61475 +
61476 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61477 + error = -EACCES;
61478 + goto out_dput;
61479 + }
61480 +
61481 if (!IS_POSIXACL(dir->d_inode))
61482 mode &= ~current_umask();
61483 /*
61484 @@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61485 nd->flags & LOOKUP_EXCL);
61486 if (error)
61487 goto out_dput;
61488 + else
61489 + gr_handle_create(dentry, nd->path.mnt);
61490 }
61491 out_no_open:
61492 path->dentry = dentry;
61493 @@ -2857,7 +2909,7 @@ out_dput:
61494 /*
61495 * Handle the last step of open()
61496 */
61497 -static int do_last(struct nameidata *nd, struct path *path,
61498 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61499 struct file *file, const struct open_flags *op,
61500 int *opened, struct filename *name)
61501 {
61502 @@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61503 if (error)
61504 return error;
61505
61506 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61507 + error = -ENOENT;
61508 + goto out;
61509 + }
61510 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61511 + error = -EACCES;
61512 + goto out;
61513 + }
61514 +
61515 audit_inode(name, dir, LOOKUP_PARENT);
61516 error = -EISDIR;
61517 /* trailing slashes? */
61518 @@ -2926,7 +2987,7 @@ retry_lookup:
61519 */
61520 }
61521 mutex_lock(&dir->d_inode->i_mutex);
61522 - error = lookup_open(nd, path, file, op, got_write, opened);
61523 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61524 mutex_unlock(&dir->d_inode->i_mutex);
61525
61526 if (error <= 0) {
61527 @@ -2950,11 +3011,28 @@ retry_lookup:
61528 goto finish_open_created;
61529 }
61530
61531 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61532 + error = -ENOENT;
61533 + goto exit_dput;
61534 + }
61535 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61536 + error = -EACCES;
61537 + goto exit_dput;
61538 + }
61539 +
61540 /*
61541 * create/update audit record if it already exists.
61542 */
61543 - if (d_is_positive(path->dentry))
61544 + if (d_is_positive(path->dentry)) {
61545 + /* only check if O_CREAT is specified, all other checks need to go
61546 + into may_open */
61547 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61548 + error = -EACCES;
61549 + goto exit_dput;
61550 + }
61551 +
61552 audit_inode(name, path->dentry, 0);
61553 + }
61554
61555 /*
61556 * If atomic_open() acquired write access it is dropped now due to
61557 @@ -2995,6 +3073,11 @@ finish_lookup:
61558 }
61559 }
61560 BUG_ON(inode != path->dentry->d_inode);
61561 + /* if we're resolving a symlink to another symlink */
61562 + if (link && gr_handle_symlink_owner(link, inode)) {
61563 + error = -EACCES;
61564 + goto out;
61565 + }
61566 return 1;
61567 }
61568
61569 @@ -3004,7 +3087,6 @@ finish_lookup:
61570 save_parent.dentry = nd->path.dentry;
61571 save_parent.mnt = mntget(path->mnt);
61572 nd->path.dentry = path->dentry;
61573 -
61574 }
61575 nd->inode = inode;
61576 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61577 @@ -3014,7 +3096,18 @@ finish_open:
61578 path_put(&save_parent);
61579 return error;
61580 }
61581 +
61582 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61583 + error = -ENOENT;
61584 + goto out;
61585 + }
61586 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61587 + error = -EACCES;
61588 + goto out;
61589 + }
61590 +
61591 audit_inode(name, nd->path.dentry, 0);
61592 +
61593 error = -EISDIR;
61594 if ((open_flag & O_CREAT) &&
61595 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61596 @@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61597 if (unlikely(error))
61598 goto out;
61599
61600 - error = do_last(nd, &path, file, op, &opened, pathname);
61601 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61602 while (unlikely(error > 0)) { /* trailing symlink */
61603 struct path link = path;
61604 void *cookie;
61605 @@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61606 error = follow_link(&link, nd, &cookie);
61607 if (unlikely(error))
61608 break;
61609 - error = do_last(nd, &path, file, op, &opened, pathname);
61610 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61611 put_link(nd, &link, cookie);
61612 }
61613 out:
61614 @@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61615 goto unlock;
61616
61617 error = -EEXIST;
61618 - if (d_is_positive(dentry))
61619 + if (d_is_positive(dentry)) {
61620 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61621 + error = -ENOENT;
61622 goto fail;
61623 -
61624 + }
61625 /*
61626 * Special case - lookup gave negative, but... we had foo/bar/
61627 * From the vfs_mknod() POV we just have a negative dentry -
61628 @@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61629 }
61630 EXPORT_SYMBOL(user_path_create);
61631
61632 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61633 +{
61634 + struct filename *tmp = getname(pathname);
61635 + struct dentry *res;
61636 + if (IS_ERR(tmp))
61637 + return ERR_CAST(tmp);
61638 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61639 + if (IS_ERR(res))
61640 + putname(tmp);
61641 + else
61642 + *to = tmp;
61643 + return res;
61644 +}
61645 +
61646 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61647 {
61648 int error = may_create(dir, dentry);
61649 @@ -3412,6 +3521,17 @@ retry:
61650
61651 if (!IS_POSIXACL(path.dentry->d_inode))
61652 mode &= ~current_umask();
61653 +
61654 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61655 + error = -EPERM;
61656 + goto out;
61657 + }
61658 +
61659 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61660 + error = -EACCES;
61661 + goto out;
61662 + }
61663 +
61664 error = security_path_mknod(&path, dentry, mode, dev);
61665 if (error)
61666 goto out;
61667 @@ -3428,6 +3548,8 @@ retry:
61668 break;
61669 }
61670 out:
61671 + if (!error)
61672 + gr_handle_create(dentry, path.mnt);
61673 done_path_create(&path, dentry);
61674 if (retry_estale(error, lookup_flags)) {
61675 lookup_flags |= LOOKUP_REVAL;
61676 @@ -3480,9 +3602,16 @@ retry:
61677
61678 if (!IS_POSIXACL(path.dentry->d_inode))
61679 mode &= ~current_umask();
61680 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61681 + error = -EACCES;
61682 + goto out;
61683 + }
61684 error = security_path_mkdir(&path, dentry, mode);
61685 if (!error)
61686 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61687 + if (!error)
61688 + gr_handle_create(dentry, path.mnt);
61689 +out:
61690 done_path_create(&path, dentry);
61691 if (retry_estale(error, lookup_flags)) {
61692 lookup_flags |= LOOKUP_REVAL;
61693 @@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61694 struct filename *name;
61695 struct dentry *dentry;
61696 struct nameidata nd;
61697 + ino_t saved_ino = 0;
61698 + dev_t saved_dev = 0;
61699 unsigned int lookup_flags = 0;
61700 retry:
61701 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61702 @@ -3595,10 +3726,21 @@ retry:
61703 error = -ENOENT;
61704 goto exit3;
61705 }
61706 +
61707 + saved_ino = dentry->d_inode->i_ino;
61708 + saved_dev = gr_get_dev_from_dentry(dentry);
61709 +
61710 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61711 + error = -EACCES;
61712 + goto exit3;
61713 + }
61714 +
61715 error = security_path_rmdir(&nd.path, dentry);
61716 if (error)
61717 goto exit3;
61718 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61719 + if (!error && (saved_dev || saved_ino))
61720 + gr_handle_delete(saved_ino, saved_dev);
61721 exit3:
61722 dput(dentry);
61723 exit2:
61724 @@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61725 struct nameidata nd;
61726 struct inode *inode = NULL;
61727 struct inode *delegated_inode = NULL;
61728 + ino_t saved_ino = 0;
61729 + dev_t saved_dev = 0;
61730 unsigned int lookup_flags = 0;
61731 retry:
61732 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61733 @@ -3714,10 +3858,22 @@ retry_deleg:
61734 if (d_is_negative(dentry))
61735 goto slashes;
61736 ihold(inode);
61737 +
61738 + if (inode->i_nlink <= 1) {
61739 + saved_ino = inode->i_ino;
61740 + saved_dev = gr_get_dev_from_dentry(dentry);
61741 + }
61742 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61743 + error = -EACCES;
61744 + goto exit2;
61745 + }
61746 +
61747 error = security_path_unlink(&nd.path, dentry);
61748 if (error)
61749 goto exit2;
61750 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61751 + if (!error && (saved_ino || saved_dev))
61752 + gr_handle_delete(saved_ino, saved_dev);
61753 exit2:
61754 dput(dentry);
61755 }
61756 @@ -3805,9 +3961,17 @@ retry:
61757 if (IS_ERR(dentry))
61758 goto out_putname;
61759
61760 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61761 + error = -EACCES;
61762 + goto out;
61763 + }
61764 +
61765 error = security_path_symlink(&path, dentry, from->name);
61766 if (!error)
61767 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61768 + if (!error)
61769 + gr_handle_create(dentry, path.mnt);
61770 +out:
61771 done_path_create(&path, dentry);
61772 if (retry_estale(error, lookup_flags)) {
61773 lookup_flags |= LOOKUP_REVAL;
61774 @@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61775 struct dentry *new_dentry;
61776 struct path old_path, new_path;
61777 struct inode *delegated_inode = NULL;
61778 + struct filename *to = NULL;
61779 int how = 0;
61780 int error;
61781
61782 @@ -3933,7 +4098,7 @@ retry:
61783 if (error)
61784 return error;
61785
61786 - new_dentry = user_path_create(newdfd, newname, &new_path,
61787 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61788 (how & LOOKUP_REVAL));
61789 error = PTR_ERR(new_dentry);
61790 if (IS_ERR(new_dentry))
61791 @@ -3945,11 +4110,28 @@ retry:
61792 error = may_linkat(&old_path);
61793 if (unlikely(error))
61794 goto out_dput;
61795 +
61796 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61797 + old_path.dentry->d_inode,
61798 + old_path.dentry->d_inode->i_mode, to)) {
61799 + error = -EACCES;
61800 + goto out_dput;
61801 + }
61802 +
61803 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61804 + old_path.dentry, old_path.mnt, to)) {
61805 + error = -EACCES;
61806 + goto out_dput;
61807 + }
61808 +
61809 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61810 if (error)
61811 goto out_dput;
61812 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61813 + if (!error)
61814 + gr_handle_create(new_dentry, new_path.mnt);
61815 out_dput:
61816 + putname(to);
61817 done_path_create(&new_path, new_dentry);
61818 if (delegated_inode) {
61819 error = break_deleg_wait(&delegated_inode);
61820 @@ -4236,6 +4418,12 @@ retry_deleg:
61821 if (new_dentry == trap)
61822 goto exit5;
61823
61824 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61825 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
61826 + to);
61827 + if (error)
61828 + goto exit5;
61829 +
61830 error = security_path_rename(&oldnd.path, old_dentry,
61831 &newnd.path, new_dentry);
61832 if (error)
61833 @@ -4243,6 +4431,9 @@ retry_deleg:
61834 error = vfs_rename(old_dir->d_inode, old_dentry,
61835 new_dir->d_inode, new_dentry,
61836 &delegated_inode);
61837 + if (!error)
61838 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61839 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61840 exit5:
61841 dput(new_dentry);
61842 exit4:
61843 @@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61844
61845 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61846 {
61847 + char tmpbuf[64];
61848 + const char *newlink;
61849 int len;
61850
61851 len = PTR_ERR(link);
61852 @@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61853 len = strlen(link);
61854 if (len > (unsigned) buflen)
61855 len = buflen;
61856 - if (copy_to_user(buffer, link, len))
61857 +
61858 + if (len < sizeof(tmpbuf)) {
61859 + memcpy(tmpbuf, link, len);
61860 + newlink = tmpbuf;
61861 + } else
61862 + newlink = link;
61863 +
61864 + if (copy_to_user(buffer, newlink, len))
61865 len = -EFAULT;
61866 out:
61867 return len;
61868 diff --git a/fs/namespace.c b/fs/namespace.c
61869 index 2ffc5a2..6737083 100644
61870 --- a/fs/namespace.c
61871 +++ b/fs/namespace.c
61872 @@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61873 if (!(sb->s_flags & MS_RDONLY))
61874 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61875 up_write(&sb->s_umount);
61876 +
61877 + gr_log_remount(mnt->mnt_devname, retval);
61878 +
61879 return retval;
61880 }
61881
61882 @@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61883 }
61884 unlock_mount_hash();
61885 namespace_unlock();
61886 +
61887 + gr_log_unmount(mnt->mnt_devname, retval);
61888 +
61889 return retval;
61890 }
61891
61892 @@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61893 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61894 */
61895
61896 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61897 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61898 {
61899 struct path path;
61900 struct mount *mnt;
61901 @@ -1422,7 +1428,7 @@ out:
61902 /*
61903 * The 2.0 compatible umount. No flags.
61904 */
61905 -SYSCALL_DEFINE1(oldumount, char __user *, name)
61906 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
61907 {
61908 return sys_umount(name, 0);
61909 }
61910 @@ -2426,6 +2432,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61911 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61912 MS_STRICTATIME);
61913
61914 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61915 + retval = -EPERM;
61916 + goto dput_out;
61917 + }
61918 +
61919 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61920 + retval = -EPERM;
61921 + goto dput_out;
61922 + }
61923 +
61924 if (flags & MS_REMOUNT)
61925 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61926 data_page);
61927 @@ -2440,6 +2456,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61928 dev_name, data_page);
61929 dput_out:
61930 path_put(&path);
61931 +
61932 + gr_log_mount(dev_name, dir_name, retval);
61933 +
61934 return retval;
61935 }
61936
61937 @@ -2457,7 +2476,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61938 * number incrementing at 10Ghz will take 12,427 years to wrap which
61939 * is effectively never, so we can ignore the possibility.
61940 */
61941 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61942 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61943
61944 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61945 {
61946 @@ -2472,7 +2491,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61947 kfree(new_ns);
61948 return ERR_PTR(ret);
61949 }
61950 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61951 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61952 atomic_set(&new_ns->count, 1);
61953 new_ns->root = NULL;
61954 INIT_LIST_HEAD(&new_ns->list);
61955 @@ -2482,7 +2501,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61956 return new_ns;
61957 }
61958
61959 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61960 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61961 struct user_namespace *user_ns, struct fs_struct *new_fs)
61962 {
61963 struct mnt_namespace *new_ns;
61964 @@ -2603,8 +2622,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61965 }
61966 EXPORT_SYMBOL(mount_subtree);
61967
61968 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61969 - char __user *, type, unsigned long, flags, void __user *, data)
61970 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61971 + const char __user *, type, unsigned long, flags, void __user *, data)
61972 {
61973 int ret;
61974 char *kernel_type;
61975 @@ -2717,6 +2736,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61976 if (error)
61977 goto out2;
61978
61979 + if (gr_handle_chroot_pivot()) {
61980 + error = -EPERM;
61981 + goto out2;
61982 + }
61983 +
61984 get_fs_root(current->fs, &root);
61985 old_mp = lock_mount(&old);
61986 error = PTR_ERR(old_mp);
61987 @@ -2985,7 +3009,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61988 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61989 return -EPERM;
61990
61991 - if (fs->users != 1)
61992 + if (atomic_read(&fs->users) != 1)
61993 return -EINVAL;
61994
61995 get_mnt_ns(mnt_ns);
61996 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61997 index f4ccfe6..a5cf064 100644
61998 --- a/fs/nfs/callback_xdr.c
61999 +++ b/fs/nfs/callback_xdr.c
62000 @@ -51,7 +51,7 @@ struct callback_op {
62001 callback_decode_arg_t decode_args;
62002 callback_encode_res_t encode_res;
62003 long res_maxsize;
62004 -};
62005 +} __do_const;
62006
62007 static struct callback_op callback_ops[];
62008
62009 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62010 index 360114a..ac6e265 100644
62011 --- a/fs/nfs/inode.c
62012 +++ b/fs/nfs/inode.c
62013 @@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62014 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62015 }
62016
62017 -static atomic_long_t nfs_attr_generation_counter;
62018 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62019
62020 static unsigned long nfs_read_attr_generation_counter(void)
62021 {
62022 - return atomic_long_read(&nfs_attr_generation_counter);
62023 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62024 }
62025
62026 unsigned long nfs_inc_attr_generation_counter(void)
62027 {
62028 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62029 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62030 }
62031
62032 void nfs_fattr_init(struct nfs_fattr *fattr)
62033 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
62034 index 450bfed..d5d06e8 100644
62035 --- a/fs/nfs/nfs4proc.c
62036 +++ b/fs/nfs/nfs4proc.c
62037 @@ -1068,6 +1068,7 @@ static void nfs4_opendata_free(struct kref *kref)
62038 dput(p->dentry);
62039 nfs_sb_deactive(sb);
62040 nfs_fattr_free_names(&p->f_attr);
62041 + kfree(p->f_attr.mdsthreshold);
62042 kfree(p);
62043 }
62044
62045 @@ -2244,10 +2245,12 @@ static int _nfs4_do_open(struct inode *dir,
62046 }
62047 }
62048
62049 - if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
62050 - opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
62051 - if (!opendata->f_attr.mdsthreshold)
62052 - goto err_free_label;
62053 + if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
62054 + if (!opendata->f_attr.mdsthreshold) {
62055 + opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
62056 + if (!opendata->f_attr.mdsthreshold)
62057 + goto err_free_label;
62058 + }
62059 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
62060 }
62061 if (dentry->d_inode != NULL)
62062 @@ -2275,11 +2278,10 @@ static int _nfs4_do_open(struct inode *dir,
62063 if (opendata->file_created)
62064 *opened |= FILE_CREATED;
62065
62066 - if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
62067 + if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) {
62068 *ctx_th = opendata->f_attr.mdsthreshold;
62069 - else
62070 - kfree(opendata->f_attr.mdsthreshold);
62071 - opendata->f_attr.mdsthreshold = NULL;
62072 + opendata->f_attr.mdsthreshold = NULL;
62073 + }
62074
62075 nfs4_label_free(olabel);
62076
62077 @@ -2289,7 +2291,6 @@ static int _nfs4_do_open(struct inode *dir,
62078 err_free_label:
62079 nfs4_label_free(olabel);
62080 err_opendata_put:
62081 - kfree(opendata->f_attr.mdsthreshold);
62082 nfs4_opendata_put(opendata);
62083 err_put_state_owner:
62084 nfs4_put_state_owner(sp);
62085 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62086 index 82189b2..e43a39f 100644
62087 --- a/fs/nfsd/nfs4proc.c
62088 +++ b/fs/nfsd/nfs4proc.c
62089 @@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62090 nfsd4op_rsize op_rsize_bop;
62091 stateid_getter op_get_currentstateid;
62092 stateid_setter op_set_currentstateid;
62093 -};
62094 +} __do_const;
62095
62096 static struct nfsd4_operation nfsd4_ops[];
62097
62098 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62099 index 63f2395..7c47f4d 100644
62100 --- a/fs/nfsd/nfs4xdr.c
62101 +++ b/fs/nfsd/nfs4xdr.c
62102 @@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62103
62104 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62105
62106 -static nfsd4_dec nfsd4_dec_ops[] = {
62107 +static const nfsd4_dec nfsd4_dec_ops[] = {
62108 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62109 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62110 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62111 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62112 index f8f060f..c4ba09a 100644
62113 --- a/fs/nfsd/nfscache.c
62114 +++ b/fs/nfsd/nfscache.c
62115 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62116 {
62117 struct svc_cacherep *rp = rqstp->rq_cacherep;
62118 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62119 - int len;
62120 + long len;
62121 size_t bufsize = 0;
62122
62123 if (!rp)
62124 return;
62125
62126 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62127 - len >>= 2;
62128 + if (statp) {
62129 + len = (char*)statp - (char*)resv->iov_base;
62130 + len = resv->iov_len - len;
62131 + len >>= 2;
62132 + }
62133
62134 /* Don't cache excessive amounts of data and XDR failures */
62135 if (!statp || len > (256 >> 2)) {
62136 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62137 index 6d7be3f..ef02c86 100644
62138 --- a/fs/nfsd/vfs.c
62139 +++ b/fs/nfsd/vfs.c
62140 @@ -834,7 +834,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62141 } else {
62142 oldfs = get_fs();
62143 set_fs(KERNEL_DS);
62144 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62145 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62146 set_fs(oldfs);
62147 }
62148
62149 @@ -925,7 +925,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62150
62151 /* Write the data. */
62152 oldfs = get_fs(); set_fs(KERNEL_DS);
62153 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62154 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62155 set_fs(oldfs);
62156 if (host_err < 0)
62157 goto out_nfserr;
62158 @@ -1470,7 +1470,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62159 */
62160
62161 oldfs = get_fs(); set_fs(KERNEL_DS);
62162 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62163 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62164 set_fs(oldfs);
62165
62166 if (host_err < 0)
62167 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62168 index 52ccd34..43a53b1 100644
62169 --- a/fs/nls/nls_base.c
62170 +++ b/fs/nls/nls_base.c
62171 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62172
62173 int __register_nls(struct nls_table *nls, struct module *owner)
62174 {
62175 - struct nls_table ** tmp = &tables;
62176 + struct nls_table *tmp = tables;
62177
62178 if (nls->next)
62179 return -EBUSY;
62180
62181 - nls->owner = owner;
62182 + pax_open_kernel();
62183 + *(void **)&nls->owner = owner;
62184 + pax_close_kernel();
62185 spin_lock(&nls_lock);
62186 - while (*tmp) {
62187 - if (nls == *tmp) {
62188 + while (tmp) {
62189 + if (nls == tmp) {
62190 spin_unlock(&nls_lock);
62191 return -EBUSY;
62192 }
62193 - tmp = &(*tmp)->next;
62194 + tmp = tmp->next;
62195 }
62196 - nls->next = tables;
62197 + pax_open_kernel();
62198 + *(struct nls_table **)&nls->next = tables;
62199 + pax_close_kernel();
62200 tables = nls;
62201 spin_unlock(&nls_lock);
62202 return 0;
62203 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62204
62205 int unregister_nls(struct nls_table * nls)
62206 {
62207 - struct nls_table ** tmp = &tables;
62208 + struct nls_table * const * tmp = &tables;
62209
62210 spin_lock(&nls_lock);
62211 while (*tmp) {
62212 if (nls == *tmp) {
62213 - *tmp = nls->next;
62214 + pax_open_kernel();
62215 + *(struct nls_table **)tmp = nls->next;
62216 + pax_close_kernel();
62217 spin_unlock(&nls_lock);
62218 return 0;
62219 }
62220 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62221 index 162b3f1..6076a7c 100644
62222 --- a/fs/nls/nls_euc-jp.c
62223 +++ b/fs/nls/nls_euc-jp.c
62224 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62225 p_nls = load_nls("cp932");
62226
62227 if (p_nls) {
62228 - table.charset2upper = p_nls->charset2upper;
62229 - table.charset2lower = p_nls->charset2lower;
62230 + pax_open_kernel();
62231 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62232 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62233 + pax_close_kernel();
62234 return register_nls(&table);
62235 }
62236
62237 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62238 index a80a741..7b96e1b 100644
62239 --- a/fs/nls/nls_koi8-ru.c
62240 +++ b/fs/nls/nls_koi8-ru.c
62241 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62242 p_nls = load_nls("koi8-u");
62243
62244 if (p_nls) {
62245 - table.charset2upper = p_nls->charset2upper;
62246 - table.charset2lower = p_nls->charset2lower;
62247 + pax_open_kernel();
62248 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62249 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62250 + pax_close_kernel();
62251 return register_nls(&table);
62252 }
62253
62254 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62255 index 287a22c..a2a043a 100644
62256 --- a/fs/notify/fanotify/fanotify_user.c
62257 +++ b/fs/notify/fanotify/fanotify_user.c
62258 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62259
62260 fd = fanotify_event_metadata.fd;
62261 ret = -EFAULT;
62262 - if (copy_to_user(buf, &fanotify_event_metadata,
62263 - fanotify_event_metadata.event_len))
62264 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62265 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62266 goto out_close_fd;
62267
62268 ret = prepare_for_access_response(group, event, fd);
62269 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62270 index 1e58402..bb2d6f4 100644
62271 --- a/fs/notify/notification.c
62272 +++ b/fs/notify/notification.c
62273 @@ -48,7 +48,7 @@
62274 #include <linux/fsnotify_backend.h>
62275 #include "fsnotify.h"
62276
62277 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62278 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62279
62280 /**
62281 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62282 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62283 */
62284 u32 fsnotify_get_cookie(void)
62285 {
62286 - return atomic_inc_return(&fsnotify_sync_cookie);
62287 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62288 }
62289 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62290
62291 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62292 index 9e38daf..5727cae 100644
62293 --- a/fs/ntfs/dir.c
62294 +++ b/fs/ntfs/dir.c
62295 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62296 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62297 ~(s64)(ndir->itype.index.block_size - 1)));
62298 /* Bounds checks. */
62299 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62300 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62301 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62302 "inode 0x%lx or driver bug.", vdir->i_ino);
62303 goto err_out;
62304 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62305 index db9bd8a..8338fb6 100644
62306 --- a/fs/ntfs/file.c
62307 +++ b/fs/ntfs/file.c
62308 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62309 char *addr;
62310 size_t total = 0;
62311 unsigned len;
62312 - int left;
62313 + unsigned left;
62314
62315 do {
62316 len = PAGE_CACHE_SIZE - ofs;
62317 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62318 index 82650d5..db37dcf 100644
62319 --- a/fs/ntfs/super.c
62320 +++ b/fs/ntfs/super.c
62321 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62322 if (!silent)
62323 ntfs_error(sb, "Primary boot sector is invalid.");
62324 } else if (!silent)
62325 - ntfs_error(sb, read_err_str, "primary");
62326 + ntfs_error(sb, read_err_str, "%s", "primary");
62327 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62328 if (bh_primary)
62329 brelse(bh_primary);
62330 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62331 goto hotfix_primary_boot_sector;
62332 brelse(bh_backup);
62333 } else if (!silent)
62334 - ntfs_error(sb, read_err_str, "backup");
62335 + ntfs_error(sb, read_err_str, "%s", "backup");
62336 /* Try to read NT3.51- backup boot sector. */
62337 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62338 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62339 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62340 "sector.");
62341 brelse(bh_backup);
62342 } else if (!silent)
62343 - ntfs_error(sb, read_err_str, "backup");
62344 + ntfs_error(sb, read_err_str, "%s", "backup");
62345 /* We failed. Cleanup and return. */
62346 if (bh_primary)
62347 brelse(bh_primary);
62348 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62349 index 0440134..d52c93a 100644
62350 --- a/fs/ocfs2/localalloc.c
62351 +++ b/fs/ocfs2/localalloc.c
62352 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62353 goto bail;
62354 }
62355
62356 - atomic_inc(&osb->alloc_stats.moves);
62357 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62358
62359 bail:
62360 if (handle)
62361 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62362 index 553f53c..aaf5133 100644
62363 --- a/fs/ocfs2/ocfs2.h
62364 +++ b/fs/ocfs2/ocfs2.h
62365 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
62366
62367 struct ocfs2_alloc_stats
62368 {
62369 - atomic_t moves;
62370 - atomic_t local_data;
62371 - atomic_t bitmap_data;
62372 - atomic_t bg_allocs;
62373 - atomic_t bg_extends;
62374 + atomic_unchecked_t moves;
62375 + atomic_unchecked_t local_data;
62376 + atomic_unchecked_t bitmap_data;
62377 + atomic_unchecked_t bg_allocs;
62378 + atomic_unchecked_t bg_extends;
62379 };
62380
62381 enum ocfs2_local_alloc_state
62382 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62383 index 47ae266..6e8b793 100644
62384 --- a/fs/ocfs2/suballoc.c
62385 +++ b/fs/ocfs2/suballoc.c
62386 @@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62387 mlog_errno(status);
62388 goto bail;
62389 }
62390 - atomic_inc(&osb->alloc_stats.bg_extends);
62391 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62392
62393 /* You should never ask for this much metadata */
62394 BUG_ON(bits_wanted >
62395 @@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62396 mlog_errno(status);
62397 goto bail;
62398 }
62399 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62400 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62401
62402 *suballoc_loc = res.sr_bg_blkno;
62403 *suballoc_bit_start = res.sr_bit_offset;
62404 @@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62405 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62406 res->sr_bits);
62407
62408 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62409 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62410
62411 BUG_ON(res->sr_bits != 1);
62412
62413 @@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62414 mlog_errno(status);
62415 goto bail;
62416 }
62417 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62418 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62419
62420 BUG_ON(res.sr_bits != 1);
62421
62422 @@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62423 cluster_start,
62424 num_clusters);
62425 if (!status)
62426 - atomic_inc(&osb->alloc_stats.local_data);
62427 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62428 } else {
62429 if (min_clusters > (osb->bitmap_cpg - 1)) {
62430 /* The only paths asking for contiguousness
62431 @@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62432 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62433 res.sr_bg_blkno,
62434 res.sr_bit_offset);
62435 - atomic_inc(&osb->alloc_stats.bitmap_data);
62436 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62437 *num_clusters = res.sr_bits;
62438 }
62439 }
62440 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62441 index 49d84f8..4807e0b 100644
62442 --- a/fs/ocfs2/super.c
62443 +++ b/fs/ocfs2/super.c
62444 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62445 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62446 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62447 "Stats",
62448 - atomic_read(&osb->alloc_stats.bitmap_data),
62449 - atomic_read(&osb->alloc_stats.local_data),
62450 - atomic_read(&osb->alloc_stats.bg_allocs),
62451 - atomic_read(&osb->alloc_stats.moves),
62452 - atomic_read(&osb->alloc_stats.bg_extends));
62453 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62454 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62455 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62456 + atomic_read_unchecked(&osb->alloc_stats.moves),
62457 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62458
62459 out += snprintf(buf + out, len - out,
62460 "%10s => State: %u Descriptor: %llu Size: %u bits "
62461 @@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62462 spin_lock_init(&osb->osb_xattr_lock);
62463 ocfs2_init_steal_slots(osb);
62464
62465 - atomic_set(&osb->alloc_stats.moves, 0);
62466 - atomic_set(&osb->alloc_stats.local_data, 0);
62467 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62468 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62469 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62470 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62471 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62472 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62473 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62474 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62475
62476 /* Copy the blockcheck stats from the superblock probe */
62477 osb->osb_ecc_stats = *stats;
62478 diff --git a/fs/open.c b/fs/open.c
62479 index b9ed8b2..0d5c7a0 100644
62480 --- a/fs/open.c
62481 +++ b/fs/open.c
62482 @@ -32,6 +32,8 @@
62483 #include <linux/dnotify.h>
62484 #include <linux/compat.h>
62485
62486 +#define CREATE_TRACE_POINTS
62487 +#include <trace/events/fs.h>
62488 #include "internal.h"
62489
62490 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62491 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62492 error = locks_verify_truncate(inode, NULL, length);
62493 if (!error)
62494 error = security_path_truncate(path);
62495 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62496 + error = -EACCES;
62497 if (!error)
62498 error = do_truncate(path->dentry, length, 0, NULL);
62499
62500 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62501 error = locks_verify_truncate(inode, f.file, length);
62502 if (!error)
62503 error = security_path_truncate(&f.file->f_path);
62504 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62505 + error = -EACCES;
62506 if (!error)
62507 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62508 sb_end_write(inode->i_sb);
62509 @@ -361,6 +367,9 @@ retry:
62510 if (__mnt_is_readonly(path.mnt))
62511 res = -EROFS;
62512
62513 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62514 + res = -EACCES;
62515 +
62516 out_path_release:
62517 path_put(&path);
62518 if (retry_estale(res, lookup_flags)) {
62519 @@ -392,6 +401,8 @@ retry:
62520 if (error)
62521 goto dput_and_out;
62522
62523 + gr_log_chdir(path.dentry, path.mnt);
62524 +
62525 set_fs_pwd(current->fs, &path);
62526
62527 dput_and_out:
62528 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62529 goto out_putf;
62530
62531 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62532 +
62533 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62534 + error = -EPERM;
62535 +
62536 + if (!error)
62537 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62538 +
62539 if (!error)
62540 set_fs_pwd(current->fs, &f.file->f_path);
62541 out_putf:
62542 @@ -450,7 +468,13 @@ retry:
62543 if (error)
62544 goto dput_and_out;
62545
62546 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62547 + goto dput_and_out;
62548 +
62549 set_fs_root(current->fs, &path);
62550 +
62551 + gr_handle_chroot_chdir(&path);
62552 +
62553 error = 0;
62554 dput_and_out:
62555 path_put(&path);
62556 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62557 return error;
62558 retry_deleg:
62559 mutex_lock(&inode->i_mutex);
62560 +
62561 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62562 + error = -EACCES;
62563 + goto out_unlock;
62564 + }
62565 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62566 + error = -EACCES;
62567 + goto out_unlock;
62568 + }
62569 +
62570 error = security_path_chmod(path, mode);
62571 if (error)
62572 goto out_unlock;
62573 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62574 uid = make_kuid(current_user_ns(), user);
62575 gid = make_kgid(current_user_ns(), group);
62576
62577 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62578 + return -EACCES;
62579 +
62580 newattrs.ia_valid = ATTR_CTIME;
62581 if (user != (uid_t) -1) {
62582 if (!uid_valid(uid))
62583 @@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62584 } else {
62585 fsnotify_open(f);
62586 fd_install(fd, f);
62587 + trace_do_sys_open(tmp->name, flags, mode);
62588 }
62589 }
62590 putname(tmp);
62591 diff --git a/fs/pipe.c b/fs/pipe.c
62592 index 78fd0d0..f71fc09 100644
62593 --- a/fs/pipe.c
62594 +++ b/fs/pipe.c
62595 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62596
62597 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62598 {
62599 - if (pipe->files)
62600 + if (atomic_read(&pipe->files))
62601 mutex_lock_nested(&pipe->mutex, subclass);
62602 }
62603
62604 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62605
62606 void pipe_unlock(struct pipe_inode_info *pipe)
62607 {
62608 - if (pipe->files)
62609 + if (atomic_read(&pipe->files))
62610 mutex_unlock(&pipe->mutex);
62611 }
62612 EXPORT_SYMBOL(pipe_unlock);
62613 @@ -449,9 +449,9 @@ redo:
62614 }
62615 if (bufs) /* More to do? */
62616 continue;
62617 - if (!pipe->writers)
62618 + if (!atomic_read(&pipe->writers))
62619 break;
62620 - if (!pipe->waiting_writers) {
62621 + if (!atomic_read(&pipe->waiting_writers)) {
62622 /* syscall merging: Usually we must not sleep
62623 * if O_NONBLOCK is set, or if we got some data.
62624 * But if a writer sleeps in kernel space, then
62625 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62626 ret = 0;
62627 __pipe_lock(pipe);
62628
62629 - if (!pipe->readers) {
62630 + if (!atomic_read(&pipe->readers)) {
62631 send_sig(SIGPIPE, current, 0);
62632 ret = -EPIPE;
62633 goto out;
62634 @@ -562,7 +562,7 @@ redo1:
62635 for (;;) {
62636 int bufs;
62637
62638 - if (!pipe->readers) {
62639 + if (!atomic_read(&pipe->readers)) {
62640 send_sig(SIGPIPE, current, 0);
62641 if (!ret)
62642 ret = -EPIPE;
62643 @@ -653,9 +653,9 @@ redo2:
62644 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62645 do_wakeup = 0;
62646 }
62647 - pipe->waiting_writers++;
62648 + atomic_inc(&pipe->waiting_writers);
62649 pipe_wait(pipe);
62650 - pipe->waiting_writers--;
62651 + atomic_dec(&pipe->waiting_writers);
62652 }
62653 out:
62654 __pipe_unlock(pipe);
62655 @@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62656 mask = 0;
62657 if (filp->f_mode & FMODE_READ) {
62658 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62659 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62660 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62661 mask |= POLLHUP;
62662 }
62663
62664 @@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62665 * Most Unices do not set POLLERR for FIFOs but on Linux they
62666 * behave exactly like pipes for poll().
62667 */
62668 - if (!pipe->readers)
62669 + if (!atomic_read(&pipe->readers))
62670 mask |= POLLERR;
62671 }
62672
62673 @@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62674 int kill = 0;
62675
62676 spin_lock(&inode->i_lock);
62677 - if (!--pipe->files) {
62678 + if (atomic_dec_and_test(&pipe->files)) {
62679 inode->i_pipe = NULL;
62680 kill = 1;
62681 }
62682 @@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
62683
62684 __pipe_lock(pipe);
62685 if (file->f_mode & FMODE_READ)
62686 - pipe->readers--;
62687 + atomic_dec(&pipe->readers);
62688 if (file->f_mode & FMODE_WRITE)
62689 - pipe->writers--;
62690 + atomic_dec(&pipe->writers);
62691
62692 - if (pipe->readers || pipe->writers) {
62693 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62694 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62695 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62696 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62697 @@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62698 kfree(pipe);
62699 }
62700
62701 -static struct vfsmount *pipe_mnt __read_mostly;
62702 +struct vfsmount *pipe_mnt __read_mostly;
62703
62704 /*
62705 * pipefs_dname() is called from d_path().
62706 @@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
62707 goto fail_iput;
62708
62709 inode->i_pipe = pipe;
62710 - pipe->files = 2;
62711 - pipe->readers = pipe->writers = 1;
62712 + atomic_set(&pipe->files, 2);
62713 + atomic_set(&pipe->readers, 1);
62714 + atomic_set(&pipe->writers, 1);
62715 inode->i_fop = &pipefifo_fops;
62716
62717 /*
62718 @@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62719 spin_lock(&inode->i_lock);
62720 if (inode->i_pipe) {
62721 pipe = inode->i_pipe;
62722 - pipe->files++;
62723 + atomic_inc(&pipe->files);
62724 spin_unlock(&inode->i_lock);
62725 } else {
62726 spin_unlock(&inode->i_lock);
62727 pipe = alloc_pipe_info();
62728 if (!pipe)
62729 return -ENOMEM;
62730 - pipe->files = 1;
62731 + atomic_set(&pipe->files, 1);
62732 spin_lock(&inode->i_lock);
62733 if (unlikely(inode->i_pipe)) {
62734 - inode->i_pipe->files++;
62735 + atomic_inc(&inode->i_pipe->files);
62736 spin_unlock(&inode->i_lock);
62737 free_pipe_info(pipe);
62738 pipe = inode->i_pipe;
62739 @@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62740 * opened, even when there is no process writing the FIFO.
62741 */
62742 pipe->r_counter++;
62743 - if (pipe->readers++ == 0)
62744 + if (atomic_inc_return(&pipe->readers) == 1)
62745 wake_up_partner(pipe);
62746
62747 - if (!is_pipe && !pipe->writers) {
62748 + if (!is_pipe && !atomic_read(&pipe->writers)) {
62749 if ((filp->f_flags & O_NONBLOCK)) {
62750 /* suppress POLLHUP until we have
62751 * seen a writer */
62752 @@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62753 * errno=ENXIO when there is no process reading the FIFO.
62754 */
62755 ret = -ENXIO;
62756 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62757 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62758 goto err;
62759
62760 pipe->w_counter++;
62761 - if (!pipe->writers++)
62762 + if (atomic_inc_return(&pipe->writers) == 1)
62763 wake_up_partner(pipe);
62764
62765 - if (!is_pipe && !pipe->readers) {
62766 + if (!is_pipe && !atomic_read(&pipe->readers)) {
62767 if (wait_for_partner(pipe, &pipe->r_counter))
62768 goto err_wr;
62769 }
62770 @@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62771 * the process can at least talk to itself.
62772 */
62773
62774 - pipe->readers++;
62775 - pipe->writers++;
62776 + atomic_inc(&pipe->readers);
62777 + atomic_inc(&pipe->writers);
62778 pipe->r_counter++;
62779 pipe->w_counter++;
62780 - if (pipe->readers == 1 || pipe->writers == 1)
62781 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62782 wake_up_partner(pipe);
62783 break;
62784
62785 @@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62786 return 0;
62787
62788 err_rd:
62789 - if (!--pipe->readers)
62790 + if (atomic_dec_and_test(&pipe->readers))
62791 wake_up_interruptible(&pipe->wait);
62792 ret = -ERESTARTSYS;
62793 goto err;
62794
62795 err_wr:
62796 - if (!--pipe->writers)
62797 + if (atomic_dec_and_test(&pipe->writers))
62798 wake_up_interruptible(&pipe->wait);
62799 ret = -ERESTARTSYS;
62800 goto err;
62801 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62802 index 9e363e4..d936d15 100644
62803 --- a/fs/posix_acl.c
62804 +++ b/fs/posix_acl.c
62805 @@ -20,6 +20,7 @@
62806 #include <linux/xattr.h>
62807 #include <linux/export.h>
62808 #include <linux/user_namespace.h>
62809 +#include <linux/grsecurity.h>
62810
62811 struct posix_acl **acl_by_type(struct inode *inode, int type)
62812 {
62813 @@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62814 }
62815 }
62816 if (mode_p)
62817 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62818 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62819 return not_equiv;
62820 }
62821 EXPORT_SYMBOL(posix_acl_equiv_mode);
62822 @@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62823 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62824 }
62825
62826 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62827 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62828 return not_equiv;
62829 }
62830
62831 @@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62832 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62833 int err = -ENOMEM;
62834 if (clone) {
62835 + *mode_p &= ~gr_acl_umask();
62836 +
62837 err = posix_acl_create_masq(clone, mode_p);
62838 if (err < 0) {
62839 posix_acl_release(clone);
62840 @@ -653,11 +656,12 @@ struct posix_acl *
62841 posix_acl_from_xattr(struct user_namespace *user_ns,
62842 const void *value, size_t size)
62843 {
62844 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62845 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62846 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62847 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62848 int count;
62849 struct posix_acl *acl;
62850 struct posix_acl_entry *acl_e;
62851 + umode_t umask = gr_acl_umask();
62852
62853 if (!value)
62854 return NULL;
62855 @@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62856
62857 switch(acl_e->e_tag) {
62858 case ACL_USER_OBJ:
62859 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62860 + break;
62861 case ACL_GROUP_OBJ:
62862 case ACL_MASK:
62863 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62864 + break;
62865 case ACL_OTHER:
62866 + acl_e->e_perm &= ~(umask & S_IRWXO);
62867 break;
62868
62869 case ACL_USER:
62870 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62871 acl_e->e_uid =
62872 make_kuid(user_ns,
62873 le32_to_cpu(entry->e_id));
62874 @@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62875 goto fail;
62876 break;
62877 case ACL_GROUP:
62878 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62879 acl_e->e_gid =
62880 make_kgid(user_ns,
62881 le32_to_cpu(entry->e_id));
62882 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62883 index 2183fcf..3c32a98 100644
62884 --- a/fs/proc/Kconfig
62885 +++ b/fs/proc/Kconfig
62886 @@ -30,7 +30,7 @@ config PROC_FS
62887
62888 config PROC_KCORE
62889 bool "/proc/kcore support" if !ARM
62890 - depends on PROC_FS && MMU
62891 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62892 help
62893 Provides a virtual ELF core file of the live kernel. This can
62894 be read with gdb and other ELF tools. No modifications can be
62895 @@ -38,8 +38,8 @@ config PROC_KCORE
62896
62897 config PROC_VMCORE
62898 bool "/proc/vmcore support"
62899 - depends on PROC_FS && CRASH_DUMP
62900 - default y
62901 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62902 + default n
62903 help
62904 Exports the dump image of crashed kernel in ELF format.
62905
62906 @@ -63,8 +63,8 @@ config PROC_SYSCTL
62907 limited in memory.
62908
62909 config PROC_PAGE_MONITOR
62910 - default y
62911 - depends on PROC_FS && MMU
62912 + default n
62913 + depends on PROC_FS && MMU && !GRKERNSEC
62914 bool "Enable /proc page monitoring" if EXPERT
62915 help
62916 Various /proc files exist to monitor process memory utilization:
62917 diff --git a/fs/proc/array.c b/fs/proc/array.c
62918 index 656e401..b5b86b9 100644
62919 --- a/fs/proc/array.c
62920 +++ b/fs/proc/array.c
62921 @@ -60,6 +60,7 @@
62922 #include <linux/tty.h>
62923 #include <linux/string.h>
62924 #include <linux/mman.h>
62925 +#include <linux/grsecurity.h>
62926 #include <linux/proc_fs.h>
62927 #include <linux/ioport.h>
62928 #include <linux/uaccess.h>
62929 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62930 seq_putc(m, '\n');
62931 }
62932
62933 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62934 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
62935 +{
62936 + if (p->mm)
62937 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62938 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62939 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62940 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62941 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62942 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62943 + else
62944 + seq_printf(m, "PaX:\t-----\n");
62945 +}
62946 +#endif
62947 +
62948 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62949 struct pid *pid, struct task_struct *task)
62950 {
62951 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62952 task_cpus_allowed(m, task);
62953 cpuset_task_status_allowed(m, task);
62954 task_context_switch_counts(m, task);
62955 +
62956 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62957 + task_pax(m, task);
62958 +#endif
62959 +
62960 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62961 + task_grsec_rbac(m, task);
62962 +#endif
62963 +
62964 return 0;
62965 }
62966
62967 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62968 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62969 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62970 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62971 +#endif
62972 +
62973 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62974 struct pid *pid, struct task_struct *task, int whole)
62975 {
62976 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62977 char tcomm[sizeof(task->comm)];
62978 unsigned long flags;
62979
62980 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62981 + if (current->exec_id != m->exec_id) {
62982 + gr_log_badprocpid("stat");
62983 + return 0;
62984 + }
62985 +#endif
62986 +
62987 state = *get_task_state(task);
62988 vsize = eip = esp = 0;
62989 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62990 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62991 gtime = task_gtime(task);
62992 }
62993
62994 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62995 + if (PAX_RAND_FLAGS(mm)) {
62996 + eip = 0;
62997 + esp = 0;
62998 + wchan = 0;
62999 + }
63000 +#endif
63001 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63002 + wchan = 0;
63003 + eip =0;
63004 + esp =0;
63005 +#endif
63006 +
63007 /* scale priority and nice values from timeslices to -20..20 */
63008 /* to make it look like a "normal" Unix priority/nice value */
63009 priority = task_prio(task);
63010 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63011 seq_put_decimal_ull(m, ' ', vsize);
63012 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63013 seq_put_decimal_ull(m, ' ', rsslim);
63014 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63015 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63016 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63017 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63018 +#else
63019 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63020 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63021 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63022 +#endif
63023 seq_put_decimal_ull(m, ' ', esp);
63024 seq_put_decimal_ull(m, ' ', eip);
63025 /* The signal information here is obsolete.
63026 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63027 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63028 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63029
63030 - if (mm && permitted) {
63031 + if (mm && permitted
63032 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63033 + && !PAX_RAND_FLAGS(mm)
63034 +#endif
63035 + ) {
63036 seq_put_decimal_ull(m, ' ', mm->start_data);
63037 seq_put_decimal_ull(m, ' ', mm->end_data);
63038 seq_put_decimal_ull(m, ' ', mm->start_brk);
63039 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63040 struct pid *pid, struct task_struct *task)
63041 {
63042 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63043 - struct mm_struct *mm = get_task_mm(task);
63044 + struct mm_struct *mm;
63045
63046 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63047 + if (current->exec_id != m->exec_id) {
63048 + gr_log_badprocpid("statm");
63049 + return 0;
63050 + }
63051 +#endif
63052 + mm = get_task_mm(task);
63053 if (mm) {
63054 size = task_statm(mm, &shared, &text, &data, &resident);
63055 mmput(mm);
63056 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63057 return 0;
63058 }
63059
63060 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63061 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63062 +{
63063 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63064 +}
63065 +#endif
63066 +
63067 #ifdef CONFIG_CHECKPOINT_RESTORE
63068 static struct pid *
63069 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63070 diff --git a/fs/proc/base.c b/fs/proc/base.c
63071 index b976062..584d0bc 100644
63072 --- a/fs/proc/base.c
63073 +++ b/fs/proc/base.c
63074 @@ -113,6 +113,14 @@ struct pid_entry {
63075 union proc_op op;
63076 };
63077
63078 +struct getdents_callback {
63079 + struct linux_dirent __user * current_dir;
63080 + struct linux_dirent __user * previous;
63081 + struct file * file;
63082 + int count;
63083 + int error;
63084 +};
63085 +
63086 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63087 .name = (NAME), \
63088 .len = sizeof(NAME) - 1, \
63089 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63090 if (!mm->arg_end)
63091 goto out_mm; /* Shh! No looking before we're done */
63092
63093 + if (gr_acl_handle_procpidmem(task))
63094 + goto out_mm;
63095 +
63096 len = mm->arg_end - mm->arg_start;
63097
63098 if (len > PAGE_SIZE)
63099 @@ -237,12 +248,28 @@ out:
63100 return res;
63101 }
63102
63103 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63104 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63105 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63106 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63107 +#endif
63108 +
63109 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63110 {
63111 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63112 int res = PTR_ERR(mm);
63113 if (mm && !IS_ERR(mm)) {
63114 unsigned int nwords = 0;
63115 +
63116 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63117 + /* allow if we're currently ptracing this task */
63118 + if (PAX_RAND_FLAGS(mm) &&
63119 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63120 + mmput(mm);
63121 + return 0;
63122 + }
63123 +#endif
63124 +
63125 do {
63126 nwords += 2;
63127 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63128 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63129 }
63130
63131
63132 -#ifdef CONFIG_KALLSYMS
63133 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63134 /*
63135 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63136 * Returns the resolved symbol. If that fails, simply return the address.
63137 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63138 mutex_unlock(&task->signal->cred_guard_mutex);
63139 }
63140
63141 -#ifdef CONFIG_STACKTRACE
63142 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63143
63144 #define MAX_STACK_TRACE_DEPTH 64
63145
63146 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63147 return count;
63148 }
63149
63150 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63151 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63152 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63153 {
63154 long nr;
63155 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63156 /************************************************************************/
63157
63158 /* permission checks */
63159 -static int proc_fd_access_allowed(struct inode *inode)
63160 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63161 {
63162 struct task_struct *task;
63163 int allowed = 0;
63164 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63165 */
63166 task = get_proc_task(inode);
63167 if (task) {
63168 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63169 + if (log)
63170 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63171 + else
63172 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63173 put_task_struct(task);
63174 }
63175 return allowed;
63176 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63177 struct task_struct *task,
63178 int hide_pid_min)
63179 {
63180 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63181 + return false;
63182 +
63183 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63184 + rcu_read_lock();
63185 + {
63186 + const struct cred *tmpcred = current_cred();
63187 + const struct cred *cred = __task_cred(task);
63188 +
63189 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63190 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63191 + || in_group_p(grsec_proc_gid)
63192 +#endif
63193 + ) {
63194 + rcu_read_unlock();
63195 + return true;
63196 + }
63197 + }
63198 + rcu_read_unlock();
63199 +
63200 + if (!pid->hide_pid)
63201 + return false;
63202 +#endif
63203 +
63204 if (pid->hide_pid < hide_pid_min)
63205 return true;
63206 if (in_group_p(pid->pid_gid))
63207 return true;
63208 +
63209 return ptrace_may_access(task, PTRACE_MODE_READ);
63210 }
63211
63212 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63213 put_task_struct(task);
63214
63215 if (!has_perms) {
63216 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63217 + {
63218 +#else
63219 if (pid->hide_pid == 2) {
63220 +#endif
63221 /*
63222 * Let's make getdents(), stat(), and open()
63223 * consistent with each other. If a process
63224 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63225 if (!task)
63226 return -ESRCH;
63227
63228 + if (gr_acl_handle_procpidmem(task)) {
63229 + put_task_struct(task);
63230 + return -EPERM;
63231 + }
63232 +
63233 mm = mm_access(task, mode);
63234 put_task_struct(task);
63235
63236 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63237
63238 file->private_data = mm;
63239
63240 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63241 + file->f_version = current->exec_id;
63242 +#endif
63243 +
63244 return 0;
63245 }
63246
63247 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63248 ssize_t copied;
63249 char *page;
63250
63251 +#ifdef CONFIG_GRKERNSEC
63252 + if (write)
63253 + return -EPERM;
63254 +#endif
63255 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63256 + if (file->f_version != current->exec_id) {
63257 + gr_log_badprocpid("mem");
63258 + return 0;
63259 + }
63260 +#endif
63261 +
63262 if (!mm)
63263 return 0;
63264
63265 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63266 goto free;
63267
63268 while (count > 0) {
63269 - int this_len = min_t(int, count, PAGE_SIZE);
63270 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63271
63272 if (write && copy_from_user(page, buf, this_len)) {
63273 copied = -EFAULT;
63274 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63275 if (!mm)
63276 return 0;
63277
63278 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63279 + if (file->f_version != current->exec_id) {
63280 + gr_log_badprocpid("environ");
63281 + return 0;
63282 + }
63283 +#endif
63284 +
63285 page = (char *)__get_free_page(GFP_TEMPORARY);
63286 if (!page)
63287 return -ENOMEM;
63288 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63289 goto free;
63290 while (count > 0) {
63291 size_t this_len, max_len;
63292 - int retval;
63293 + ssize_t retval;
63294
63295 if (src >= (mm->env_end - mm->env_start))
63296 break;
63297 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63298 int error = -EACCES;
63299
63300 /* Are we allowed to snoop on the tasks file descriptors? */
63301 - if (!proc_fd_access_allowed(inode))
63302 + if (!proc_fd_access_allowed(inode, 0))
63303 goto out;
63304
63305 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63306 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63307 struct path path;
63308
63309 /* Are we allowed to snoop on the tasks file descriptors? */
63310 - if (!proc_fd_access_allowed(inode))
63311 - goto out;
63312 + /* logging this is needed for learning on chromium to work properly,
63313 + but we don't want to flood the logs from 'ps' which does a readlink
63314 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63315 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63316 + */
63317 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63318 + if (!proc_fd_access_allowed(inode,0))
63319 + goto out;
63320 + } else {
63321 + if (!proc_fd_access_allowed(inode,1))
63322 + goto out;
63323 + }
63324
63325 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63326 if (error)
63327 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63328 rcu_read_lock();
63329 cred = __task_cred(task);
63330 inode->i_uid = cred->euid;
63331 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63332 + inode->i_gid = grsec_proc_gid;
63333 +#else
63334 inode->i_gid = cred->egid;
63335 +#endif
63336 rcu_read_unlock();
63337 }
63338 security_task_to_inode(task, inode);
63339 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63340 return -ENOENT;
63341 }
63342 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63343 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63344 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63345 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63346 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63347 +#endif
63348 task_dumpable(task)) {
63349 cred = __task_cred(task);
63350 stat->uid = cred->euid;
63351 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63352 + stat->gid = grsec_proc_gid;
63353 +#else
63354 stat->gid = cred->egid;
63355 +#endif
63356 }
63357 }
63358 rcu_read_unlock();
63359 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63360
63361 if (task) {
63362 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63363 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63364 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63365 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63366 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63367 +#endif
63368 task_dumpable(task)) {
63369 rcu_read_lock();
63370 cred = __task_cred(task);
63371 inode->i_uid = cred->euid;
63372 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63373 + inode->i_gid = grsec_proc_gid;
63374 +#else
63375 inode->i_gid = cred->egid;
63376 +#endif
63377 rcu_read_unlock();
63378 } else {
63379 inode->i_uid = GLOBAL_ROOT_UID;
63380 @@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63381 if (!task)
63382 goto out_no_task;
63383
63384 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63385 + goto out;
63386 +
63387 /*
63388 * Yes, it does not scale. And it should not. Don't add
63389 * new entries into /proc/<tgid>/ without very good reasons.
63390 @@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63391 if (!task)
63392 return -ENOENT;
63393
63394 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63395 + goto out;
63396 +
63397 if (!dir_emit_dots(file, ctx))
63398 goto out;
63399
63400 @@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63401 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63402 #endif
63403 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63404 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63405 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63406 INF("syscall", S_IRUGO, proc_pid_syscall),
63407 #endif
63408 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63409 @@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63410 #ifdef CONFIG_SECURITY
63411 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63412 #endif
63413 -#ifdef CONFIG_KALLSYMS
63414 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63415 INF("wchan", S_IRUGO, proc_pid_wchan),
63416 #endif
63417 -#ifdef CONFIG_STACKTRACE
63418 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63419 ONE("stack", S_IRUGO, proc_pid_stack),
63420 #endif
63421 #ifdef CONFIG_SCHEDSTATS
63422 @@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63423 #ifdef CONFIG_HARDWALL
63424 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63425 #endif
63426 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63427 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63428 +#endif
63429 #ifdef CONFIG_USER_NS
63430 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63431 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63432 @@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63433 if (!inode)
63434 goto out;
63435
63436 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63437 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63438 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63439 + inode->i_gid = grsec_proc_gid;
63440 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63441 +#else
63442 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63443 +#endif
63444 inode->i_op = &proc_tgid_base_inode_operations;
63445 inode->i_fop = &proc_tgid_base_operations;
63446 inode->i_flags|=S_IMMUTABLE;
63447 @@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63448 if (!task)
63449 goto out;
63450
63451 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63452 + goto out_put_task;
63453 +
63454 result = proc_pid_instantiate(dir, dentry, task, NULL);
63455 +out_put_task:
63456 put_task_struct(task);
63457 out:
63458 return ERR_PTR(result);
63459 @@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63460 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63461 #endif
63462 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63463 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63464 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63465 INF("syscall", S_IRUGO, proc_pid_syscall),
63466 #endif
63467 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63468 @@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63469 #ifdef CONFIG_SECURITY
63470 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63471 #endif
63472 -#ifdef CONFIG_KALLSYMS
63473 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63474 INF("wchan", S_IRUGO, proc_pid_wchan),
63475 #endif
63476 -#ifdef CONFIG_STACKTRACE
63477 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63478 ONE("stack", S_IRUGO, proc_pid_stack),
63479 #endif
63480 #ifdef CONFIG_SCHEDSTATS
63481 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63482 index cbd82df..c0407d2 100644
63483 --- a/fs/proc/cmdline.c
63484 +++ b/fs/proc/cmdline.c
63485 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63486
63487 static int __init proc_cmdline_init(void)
63488 {
63489 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63490 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63491 +#else
63492 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63493 +#endif
63494 return 0;
63495 }
63496 fs_initcall(proc_cmdline_init);
63497 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63498 index 50493ed..248166b 100644
63499 --- a/fs/proc/devices.c
63500 +++ b/fs/proc/devices.c
63501 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63502
63503 static int __init proc_devices_init(void)
63504 {
63505 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63506 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63507 +#else
63508 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63509 +#endif
63510 return 0;
63511 }
63512 fs_initcall(proc_devices_init);
63513 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63514 index 985ea88..d118a0a 100644
63515 --- a/fs/proc/fd.c
63516 +++ b/fs/proc/fd.c
63517 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63518 if (!task)
63519 return -ENOENT;
63520
63521 - files = get_files_struct(task);
63522 + if (!gr_acl_handle_procpidmem(task))
63523 + files = get_files_struct(task);
63524 put_task_struct(task);
63525
63526 if (files) {
63527 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63528 */
63529 int proc_fd_permission(struct inode *inode, int mask)
63530 {
63531 + struct task_struct *task;
63532 int rv = generic_permission(inode, mask);
63533 - if (rv == 0)
63534 - return 0;
63535 +
63536 if (task_tgid(current) == proc_pid(inode))
63537 rv = 0;
63538 +
63539 + task = get_proc_task(inode);
63540 + if (task == NULL)
63541 + return rv;
63542 +
63543 + if (gr_acl_handle_procpidmem(task))
63544 + rv = -EACCES;
63545 +
63546 + put_task_struct(task);
63547 +
63548 return rv;
63549 }
63550
63551 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63552 index 124fc43..8afbb02 100644
63553 --- a/fs/proc/inode.c
63554 +++ b/fs/proc/inode.c
63555 @@ -23,11 +23,17 @@
63556 #include <linux/slab.h>
63557 #include <linux/mount.h>
63558 #include <linux/magic.h>
63559 +#include <linux/grsecurity.h>
63560
63561 #include <asm/uaccess.h>
63562
63563 #include "internal.h"
63564
63565 +#ifdef CONFIG_PROC_SYSCTL
63566 +extern const struct inode_operations proc_sys_inode_operations;
63567 +extern const struct inode_operations proc_sys_dir_operations;
63568 +#endif
63569 +
63570 static void proc_evict_inode(struct inode *inode)
63571 {
63572 struct proc_dir_entry *de;
63573 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63574 ns = PROC_I(inode)->ns.ns;
63575 if (ns_ops && ns)
63576 ns_ops->put(ns);
63577 +
63578 +#ifdef CONFIG_PROC_SYSCTL
63579 + if (inode->i_op == &proc_sys_inode_operations ||
63580 + inode->i_op == &proc_sys_dir_operations)
63581 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63582 +#endif
63583 +
63584 }
63585
63586 static struct kmem_cache * proc_inode_cachep;
63587 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63588 if (de->mode) {
63589 inode->i_mode = de->mode;
63590 inode->i_uid = de->uid;
63591 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63592 + inode->i_gid = grsec_proc_gid;
63593 +#else
63594 inode->i_gid = de->gid;
63595 +#endif
63596 }
63597 if (de->size)
63598 inode->i_size = de->size;
63599 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63600 index 651d09a..3d7f0bf 100644
63601 --- a/fs/proc/internal.h
63602 +++ b/fs/proc/internal.h
63603 @@ -48,7 +48,7 @@ struct proc_dir_entry {
63604 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63605 u8 namelen;
63606 char name[];
63607 -};
63608 +} __randomize_layout;
63609
63610 union proc_op {
63611 int (*proc_get_link)(struct dentry *, struct path *);
63612 @@ -67,7 +67,7 @@ struct proc_inode {
63613 struct ctl_table *sysctl_entry;
63614 struct proc_ns ns;
63615 struct inode vfs_inode;
63616 -};
63617 +} __randomize_layout;
63618
63619 /*
63620 * General functions
63621 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63622 struct pid *, struct task_struct *);
63623 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63624 struct pid *, struct task_struct *);
63625 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63626 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63627 +#endif
63628
63629 /*
63630 * base.c
63631 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63632 index a352d57..cb94a5c 100644
63633 --- a/fs/proc/interrupts.c
63634 +++ b/fs/proc/interrupts.c
63635 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63636
63637 static int __init proc_interrupts_init(void)
63638 {
63639 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63640 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63641 +#else
63642 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63643 +#endif
63644 return 0;
63645 }
63646 fs_initcall(proc_interrupts_init);
63647 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63648 index 39e6ef3..2f9cb5e 100644
63649 --- a/fs/proc/kcore.c
63650 +++ b/fs/proc/kcore.c
63651 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63652 * the addresses in the elf_phdr on our list.
63653 */
63654 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63655 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63656 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63657 + if (tsz > buflen)
63658 tsz = buflen;
63659 -
63660 +
63661 while (buflen) {
63662 struct kcore_list *m;
63663
63664 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63665 kfree(elf_buf);
63666 } else {
63667 if (kern_addr_valid(start)) {
63668 - unsigned long n;
63669 + char *elf_buf;
63670 + mm_segment_t oldfs;
63671
63672 - n = copy_to_user(buffer, (char *)start, tsz);
63673 - /*
63674 - * We cannot distinguish between fault on source
63675 - * and fault on destination. When this happens
63676 - * we clear too and hope it will trigger the
63677 - * EFAULT again.
63678 - */
63679 - if (n) {
63680 - if (clear_user(buffer + tsz - n,
63681 - n))
63682 + elf_buf = kmalloc(tsz, GFP_KERNEL);
63683 + if (!elf_buf)
63684 + return -ENOMEM;
63685 + oldfs = get_fs();
63686 + set_fs(KERNEL_DS);
63687 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63688 + set_fs(oldfs);
63689 + if (copy_to_user(buffer, elf_buf, tsz)) {
63690 + kfree(elf_buf);
63691 return -EFAULT;
63692 + }
63693 }
63694 + set_fs(oldfs);
63695 + kfree(elf_buf);
63696 } else {
63697 if (clear_user(buffer, tsz))
63698 return -EFAULT;
63699 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63700
63701 static int open_kcore(struct inode *inode, struct file *filp)
63702 {
63703 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63704 + return -EPERM;
63705 +#endif
63706 if (!capable(CAP_SYS_RAWIO))
63707 return -EPERM;
63708 if (kcore_need_update)
63709 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63710 index 136e548..1f88922 100644
63711 --- a/fs/proc/meminfo.c
63712 +++ b/fs/proc/meminfo.c
63713 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63714 vmi.used >> 10,
63715 vmi.largest_chunk >> 10
63716 #ifdef CONFIG_MEMORY_FAILURE
63717 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63718 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63719 #endif
63720 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63721 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63722 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63723 index d4a3574..b421ce9 100644
63724 --- a/fs/proc/nommu.c
63725 +++ b/fs/proc/nommu.c
63726 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63727
63728 if (file) {
63729 seq_pad(m, ' ');
63730 - seq_path(m, &file->f_path, "");
63731 + seq_path(m, &file->f_path, "\n\\");
63732 }
63733
63734 seq_putc(m, '\n');
63735 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63736 index 4677bb7..408e936 100644
63737 --- a/fs/proc/proc_net.c
63738 +++ b/fs/proc/proc_net.c
63739 @@ -23,6 +23,7 @@
63740 #include <linux/nsproxy.h>
63741 #include <net/net_namespace.h>
63742 #include <linux/seq_file.h>
63743 +#include <linux/grsecurity.h>
63744
63745 #include "internal.h"
63746
63747 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63748 struct task_struct *task;
63749 struct nsproxy *ns;
63750 struct net *net = NULL;
63751 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63752 + const struct cred *cred = current_cred();
63753 +#endif
63754 +
63755 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63756 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63757 + return net;
63758 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63759 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63760 + return net;
63761 +#endif
63762
63763 rcu_read_lock();
63764 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63765 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63766 index 7129046..6914844 100644
63767 --- a/fs/proc/proc_sysctl.c
63768 +++ b/fs/proc/proc_sysctl.c
63769 @@ -11,13 +11,21 @@
63770 #include <linux/namei.h>
63771 #include <linux/mm.h>
63772 #include <linux/module.h>
63773 +#include <linux/nsproxy.h>
63774 +#ifdef CONFIG_GRKERNSEC
63775 +#include <net/net_namespace.h>
63776 +#endif
63777 #include "internal.h"
63778
63779 +extern int gr_handle_chroot_sysctl(const int op);
63780 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63781 + const int op);
63782 +
63783 static const struct dentry_operations proc_sys_dentry_operations;
63784 static const struct file_operations proc_sys_file_operations;
63785 -static const struct inode_operations proc_sys_inode_operations;
63786 +const struct inode_operations proc_sys_inode_operations;
63787 static const struct file_operations proc_sys_dir_file_operations;
63788 -static const struct inode_operations proc_sys_dir_operations;
63789 +const struct inode_operations proc_sys_dir_operations;
63790
63791 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63792 {
63793 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63794
63795 err = NULL;
63796 d_set_d_op(dentry, &proc_sys_dentry_operations);
63797 +
63798 + gr_handle_proc_create(dentry, inode);
63799 +
63800 d_add(dentry, inode);
63801
63802 out:
63803 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63804 struct inode *inode = file_inode(filp);
63805 struct ctl_table_header *head = grab_header(inode);
63806 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63807 + int op = write ? MAY_WRITE : MAY_READ;
63808 ssize_t error;
63809 size_t res;
63810
63811 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63812 * and won't be until we finish.
63813 */
63814 error = -EPERM;
63815 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63816 + if (sysctl_perm(head, table, op))
63817 goto out;
63818
63819 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63820 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63821 if (!table->proc_handler)
63822 goto out;
63823
63824 +#ifdef CONFIG_GRKERNSEC
63825 + error = -EPERM;
63826 + if (gr_handle_chroot_sysctl(op))
63827 + goto out;
63828 + dget(filp->f_path.dentry);
63829 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63830 + dput(filp->f_path.dentry);
63831 + goto out;
63832 + }
63833 + dput(filp->f_path.dentry);
63834 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63835 + goto out;
63836 + if (write) {
63837 + if (current->nsproxy->net_ns != table->extra2) {
63838 + if (!capable(CAP_SYS_ADMIN))
63839 + goto out;
63840 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63841 + goto out;
63842 + }
63843 +#endif
63844 +
63845 /* careful: calling conventions are nasty here */
63846 res = count;
63847 error = table->proc_handler(table, write, buf, &res, ppos);
63848 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63849 return false;
63850 } else {
63851 d_set_d_op(child, &proc_sys_dentry_operations);
63852 +
63853 + gr_handle_proc_create(child, inode);
63854 +
63855 d_add(child, inode);
63856 }
63857 } else {
63858 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63859 if ((*pos)++ < ctx->pos)
63860 return true;
63861
63862 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63863 + return 0;
63864 +
63865 if (unlikely(S_ISLNK(table->mode)))
63866 res = proc_sys_link_fill_cache(file, ctx, head, table);
63867 else
63868 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63869 if (IS_ERR(head))
63870 return PTR_ERR(head);
63871
63872 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63873 + return -ENOENT;
63874 +
63875 generic_fillattr(inode, stat);
63876 if (table)
63877 stat->mode = (stat->mode & S_IFMT) | table->mode;
63878 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63879 .llseek = generic_file_llseek,
63880 };
63881
63882 -static const struct inode_operations proc_sys_inode_operations = {
63883 +const struct inode_operations proc_sys_inode_operations = {
63884 .permission = proc_sys_permission,
63885 .setattr = proc_sys_setattr,
63886 .getattr = proc_sys_getattr,
63887 };
63888
63889 -static const struct inode_operations proc_sys_dir_operations = {
63890 +const struct inode_operations proc_sys_dir_operations = {
63891 .lookup = proc_sys_lookup,
63892 .permission = proc_sys_permission,
63893 .setattr = proc_sys_setattr,
63894 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63895 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63896 const char *name, int namelen)
63897 {
63898 - struct ctl_table *table;
63899 + ctl_table_no_const *table;
63900 struct ctl_dir *new;
63901 struct ctl_node *node;
63902 char *new_name;
63903 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63904 return NULL;
63905
63906 node = (struct ctl_node *)(new + 1);
63907 - table = (struct ctl_table *)(node + 1);
63908 + table = (ctl_table_no_const *)(node + 1);
63909 new_name = (char *)(table + 2);
63910 memcpy(new_name, name, namelen);
63911 new_name[namelen] = '\0';
63912 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63913 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63914 struct ctl_table_root *link_root)
63915 {
63916 - struct ctl_table *link_table, *entry, *link;
63917 + ctl_table_no_const *link_table, *link;
63918 + struct ctl_table *entry;
63919 struct ctl_table_header *links;
63920 struct ctl_node *node;
63921 char *link_name;
63922 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63923 return NULL;
63924
63925 node = (struct ctl_node *)(links + 1);
63926 - link_table = (struct ctl_table *)(node + nr_entries);
63927 + link_table = (ctl_table_no_const *)(node + nr_entries);
63928 link_name = (char *)&link_table[nr_entries + 1];
63929
63930 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63931 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63932 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63933 struct ctl_table *table)
63934 {
63935 - struct ctl_table *ctl_table_arg = NULL;
63936 - struct ctl_table *entry, *files;
63937 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63938 + struct ctl_table *entry;
63939 int nr_files = 0;
63940 int nr_dirs = 0;
63941 int err = -ENOMEM;
63942 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63943 nr_files++;
63944 }
63945
63946 - files = table;
63947 /* If there are mixed files and directories we need a new table */
63948 if (nr_dirs && nr_files) {
63949 - struct ctl_table *new;
63950 + ctl_table_no_const *new;
63951 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63952 GFP_KERNEL);
63953 if (!files)
63954 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63955 /* Register everything except a directory full of subdirectories */
63956 if (nr_files || !nr_dirs) {
63957 struct ctl_table_header *header;
63958 - header = __register_sysctl_table(set, path, files);
63959 + header = __register_sysctl_table(set, path, files ? files : table);
63960 if (!header) {
63961 kfree(ctl_table_arg);
63962 goto out;
63963 diff --git a/fs/proc/root.c b/fs/proc/root.c
63964 index 87dbcbe..55e1b4d 100644
63965 --- a/fs/proc/root.c
63966 +++ b/fs/proc/root.c
63967 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
63968 #ifdef CONFIG_PROC_DEVICETREE
63969 proc_device_tree_init();
63970 #endif
63971 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63972 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63973 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63974 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63975 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63976 +#endif
63977 +#else
63978 proc_mkdir("bus", NULL);
63979 +#endif
63980 proc_sys_init();
63981 }
63982
63983 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63984 index 6f599c6..8f4644f 100644
63985 --- a/fs/proc/stat.c
63986 +++ b/fs/proc/stat.c
63987 @@ -11,6 +11,7 @@
63988 #include <linux/irqnr.h>
63989 #include <asm/cputime.h>
63990 #include <linux/tick.h>
63991 +#include <linux/grsecurity.h>
63992
63993 #ifndef arch_irq_stat_cpu
63994 #define arch_irq_stat_cpu(cpu) 0
63995 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63996 u64 sum_softirq = 0;
63997 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63998 struct timespec boottime;
63999 + int unrestricted = 1;
64000 +
64001 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64002 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64003 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64004 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64005 + && !in_group_p(grsec_proc_gid)
64006 +#endif
64007 + )
64008 + unrestricted = 0;
64009 +#endif
64010 +#endif
64011
64012 user = nice = system = idle = iowait =
64013 irq = softirq = steal = 0;
64014 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
64015 getboottime(&boottime);
64016 jif = boottime.tv_sec;
64017
64018 + if (unrestricted) {
64019 for_each_possible_cpu(i) {
64020 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
64021 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64022 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
64023 }
64024 }
64025 sum += arch_irq_stat();
64026 + }
64027
64028 seq_puts(p, "cpu ");
64029 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64030 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
64031 seq_putc(p, '\n');
64032
64033 for_each_online_cpu(i) {
64034 + if (unrestricted) {
64035 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
64036 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
64037 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64038 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
64039 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64040 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64041 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64042 + }
64043 seq_printf(p, "cpu%d", i);
64044 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64045 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64046 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64047
64048 /* sum again ? it could be updated? */
64049 for_each_irq_nr(j)
64050 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64051 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64052
64053 seq_printf(p,
64054 "\nctxt %llu\n"
64055 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64056 "processes %lu\n"
64057 "procs_running %lu\n"
64058 "procs_blocked %lu\n",
64059 - nr_context_switches(),
64060 + unrestricted ? nr_context_switches() : 0ULL,
64061 (unsigned long)jif,
64062 - total_forks,
64063 - nr_running(),
64064 - nr_iowait());
64065 + unrestricted ? total_forks : 0UL,
64066 + unrestricted ? nr_running() : 0UL,
64067 + unrestricted ? nr_iowait() : 0UL);
64068
64069 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64070
64071 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64072 index fb52b54..5fc7c14 100644
64073 --- a/fs/proc/task_mmu.c
64074 +++ b/fs/proc/task_mmu.c
64075 @@ -12,12 +12,19 @@
64076 #include <linux/swap.h>
64077 #include <linux/swapops.h>
64078 #include <linux/mmu_notifier.h>
64079 +#include <linux/grsecurity.h>
64080
64081 #include <asm/elf.h>
64082 #include <asm/uaccess.h>
64083 #include <asm/tlbflush.h>
64084 #include "internal.h"
64085
64086 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64087 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64088 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
64089 + _mm->pax_flags & MF_PAX_SEGMEXEC))
64090 +#endif
64091 +
64092 void task_mem(struct seq_file *m, struct mm_struct *mm)
64093 {
64094 unsigned long data, text, lib, swap;
64095 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64096 "VmExe:\t%8lu kB\n"
64097 "VmLib:\t%8lu kB\n"
64098 "VmPTE:\t%8lu kB\n"
64099 - "VmSwap:\t%8lu kB\n",
64100 - hiwater_vm << (PAGE_SHIFT-10),
64101 + "VmSwap:\t%8lu kB\n"
64102 +
64103 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64104 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64105 +#endif
64106 +
64107 + ,hiwater_vm << (PAGE_SHIFT-10),
64108 total_vm << (PAGE_SHIFT-10),
64109 mm->locked_vm << (PAGE_SHIFT-10),
64110 mm->pinned_vm << (PAGE_SHIFT-10),
64111 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64112 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64113 (PTRS_PER_PTE * sizeof(pte_t) *
64114 atomic_long_read(&mm->nr_ptes)) >> 10,
64115 - swap << (PAGE_SHIFT-10));
64116 + swap << (PAGE_SHIFT-10)
64117 +
64118 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64119 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64120 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64121 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64122 +#else
64123 + , mm->context.user_cs_base
64124 + , mm->context.user_cs_limit
64125 +#endif
64126 +#endif
64127 +
64128 + );
64129 }
64130
64131 unsigned long task_vsize(struct mm_struct *mm)
64132 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64133 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64134 }
64135
64136 - /* We don't show the stack guard page in /proc/maps */
64137 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64138 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64139 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64140 +#else
64141 start = vma->vm_start;
64142 - if (stack_guard_page_start(vma, start))
64143 - start += PAGE_SIZE;
64144 end = vma->vm_end;
64145 - if (stack_guard_page_end(vma, end))
64146 - end -= PAGE_SIZE;
64147 +#endif
64148
64149 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64150 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64151 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64152 flags & VM_WRITE ? 'w' : '-',
64153 flags & VM_EXEC ? 'x' : '-',
64154 flags & VM_MAYSHARE ? 's' : 'p',
64155 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64156 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64157 +#else
64158 pgoff,
64159 +#endif
64160 MAJOR(dev), MINOR(dev), ino);
64161
64162 /*
64163 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64164 */
64165 if (file) {
64166 seq_pad(m, ' ');
64167 - seq_path(m, &file->f_path, "\n");
64168 + seq_path(m, &file->f_path, "\n\\");
64169 goto done;
64170 }
64171
64172 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64173 * Thread stack in /proc/PID/task/TID/maps or
64174 * the main process stack.
64175 */
64176 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
64177 - vma->vm_end >= mm->start_stack)) {
64178 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64179 + (vma->vm_start <= mm->start_stack &&
64180 + vma->vm_end >= mm->start_stack)) {
64181 name = "[stack]";
64182 } else {
64183 /* Thread stack in /proc/PID/maps */
64184 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64185 struct proc_maps_private *priv = m->private;
64186 struct task_struct *task = priv->task;
64187
64188 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64189 + if (current->exec_id != m->exec_id) {
64190 + gr_log_badprocpid("maps");
64191 + return 0;
64192 + }
64193 +#endif
64194 +
64195 show_map_vma(m, vma, is_pid);
64196
64197 if (m->count < m->size) /* vma is copied successfully */
64198 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64199 .private = &mss,
64200 };
64201
64202 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64203 + if (current->exec_id != m->exec_id) {
64204 + gr_log_badprocpid("smaps");
64205 + return 0;
64206 + }
64207 +#endif
64208 memset(&mss, 0, sizeof mss);
64209 - mss.vma = vma;
64210 - /* mmap_sem is held in m_start */
64211 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64212 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64213 -
64214 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64215 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64216 +#endif
64217 + mss.vma = vma;
64218 + /* mmap_sem is held in m_start */
64219 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64220 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64221 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64222 + }
64223 +#endif
64224 show_map_vma(m, vma, is_pid);
64225
64226 seq_printf(m,
64227 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64228 "KernelPageSize: %8lu kB\n"
64229 "MMUPageSize: %8lu kB\n"
64230 "Locked: %8lu kB\n",
64231 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64232 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64233 +#else
64234 (vma->vm_end - vma->vm_start) >> 10,
64235 +#endif
64236 mss.resident >> 10,
64237 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64238 mss.shared_clean >> 10,
64239 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64240 char buffer[64];
64241 int nid;
64242
64243 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64244 + if (current->exec_id != m->exec_id) {
64245 + gr_log_badprocpid("numa_maps");
64246 + return 0;
64247 + }
64248 +#endif
64249 +
64250 if (!mm)
64251 return 0;
64252
64253 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64254 mpol_to_str(buffer, sizeof(buffer), pol);
64255 mpol_cond_put(pol);
64256
64257 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64258 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64259 +#else
64260 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64261 +#endif
64262
64263 if (file) {
64264 seq_printf(m, " file=");
64265 - seq_path(m, &file->f_path, "\n\t= ");
64266 + seq_path(m, &file->f_path, "\n\t\\= ");
64267 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64268 seq_printf(m, " heap");
64269 } else {
64270 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64271 index 678455d..ebd3245 100644
64272 --- a/fs/proc/task_nommu.c
64273 +++ b/fs/proc/task_nommu.c
64274 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64275 else
64276 bytes += kobjsize(mm);
64277
64278 - if (current->fs && current->fs->users > 1)
64279 + if (current->fs && atomic_read(&current->fs->users) > 1)
64280 sbytes += kobjsize(current->fs);
64281 else
64282 bytes += kobjsize(current->fs);
64283 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64284
64285 if (file) {
64286 seq_pad(m, ' ');
64287 - seq_path(m, &file->f_path, "");
64288 + seq_path(m, &file->f_path, "\n\\");
64289 } else if (mm) {
64290 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64291
64292 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64293 index 88d4585..c10bfeb 100644
64294 --- a/fs/proc/vmcore.c
64295 +++ b/fs/proc/vmcore.c
64296 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64297 nr_bytes = count;
64298
64299 /* If pfn is not ram, return zeros for sparse dump files */
64300 - if (pfn_is_ram(pfn) == 0)
64301 - memset(buf, 0, nr_bytes);
64302 - else {
64303 + if (pfn_is_ram(pfn) == 0) {
64304 + if (userbuf) {
64305 + if (clear_user((char __force_user *)buf, nr_bytes))
64306 + return -EFAULT;
64307 + } else
64308 + memset(buf, 0, nr_bytes);
64309 + } else {
64310 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64311 offset, userbuf);
64312 if (tmp < 0)
64313 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64314 static int copy_to(void *target, void *src, size_t size, int userbuf)
64315 {
64316 if (userbuf) {
64317 - if (copy_to_user((char __user *) target, src, size))
64318 + if (copy_to_user((char __force_user *) target, src, size))
64319 return -EFAULT;
64320 } else {
64321 memcpy(target, src, size);
64322 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64323 if (*fpos < m->offset + m->size) {
64324 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64325 start = m->paddr + *fpos - m->offset;
64326 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64327 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64328 if (tmp < 0)
64329 return tmp;
64330 buflen -= tsz;
64331 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64332 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64333 size_t buflen, loff_t *fpos)
64334 {
64335 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64336 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64337 }
64338
64339 /*
64340 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64341 index b00fcc9..e0c6381 100644
64342 --- a/fs/qnx6/qnx6.h
64343 +++ b/fs/qnx6/qnx6.h
64344 @@ -74,7 +74,7 @@ enum {
64345 BYTESEX_BE,
64346 };
64347
64348 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64349 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64350 {
64351 if (sbi->s_bytesex == BYTESEX_LE)
64352 return le64_to_cpu((__force __le64)n);
64353 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64354 return (__force __fs64)cpu_to_be64(n);
64355 }
64356
64357 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64358 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64359 {
64360 if (sbi->s_bytesex == BYTESEX_LE)
64361 return le32_to_cpu((__force __le32)n);
64362 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64363 index 72d2917..c917c12 100644
64364 --- a/fs/quota/netlink.c
64365 +++ b/fs/quota/netlink.c
64366 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64367 void quota_send_warning(struct kqid qid, dev_t dev,
64368 const char warntype)
64369 {
64370 - static atomic_t seq;
64371 + static atomic_unchecked_t seq;
64372 struct sk_buff *skb;
64373 void *msg_head;
64374 int ret;
64375 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64376 "VFS: Not enough memory to send quota warning.\n");
64377 return;
64378 }
64379 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64380 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64381 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64382 if (!msg_head) {
64383 printk(KERN_ERR
64384 diff --git a/fs/read_write.c b/fs/read_write.c
64385 index 28cc9c8..208e4fb 100644
64386 --- a/fs/read_write.c
64387 +++ b/fs/read_write.c
64388 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64389
64390 old_fs = get_fs();
64391 set_fs(get_ds());
64392 - p = (__force const char __user *)buf;
64393 + p = (const char __force_user *)buf;
64394 if (count > MAX_RW_COUNT)
64395 count = MAX_RW_COUNT;
64396 if (file->f_op->write)
64397 diff --git a/fs/readdir.c b/fs/readdir.c
64398 index 5b53d99..a6c3049 100644
64399 --- a/fs/readdir.c
64400 +++ b/fs/readdir.c
64401 @@ -17,6 +17,7 @@
64402 #include <linux/security.h>
64403 #include <linux/syscalls.h>
64404 #include <linux/unistd.h>
64405 +#include <linux/namei.h>
64406
64407 #include <asm/uaccess.h>
64408
64409 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64410 struct readdir_callback {
64411 struct dir_context ctx;
64412 struct old_linux_dirent __user * dirent;
64413 + struct file * file;
64414 int result;
64415 };
64416
64417 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64418 buf->result = -EOVERFLOW;
64419 return -EOVERFLOW;
64420 }
64421 +
64422 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64423 + return 0;
64424 +
64425 buf->result++;
64426 dirent = buf->dirent;
64427 if (!access_ok(VERIFY_WRITE, dirent,
64428 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64429 if (!f.file)
64430 return -EBADF;
64431
64432 + buf.file = f.file;
64433 error = iterate_dir(f.file, &buf.ctx);
64434 if (buf.result)
64435 error = buf.result;
64436 @@ -142,6 +149,7 @@ struct getdents_callback {
64437 struct dir_context ctx;
64438 struct linux_dirent __user * current_dir;
64439 struct linux_dirent __user * previous;
64440 + struct file * file;
64441 int count;
64442 int error;
64443 };
64444 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64445 buf->error = -EOVERFLOW;
64446 return -EOVERFLOW;
64447 }
64448 +
64449 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64450 + return 0;
64451 +
64452 dirent = buf->previous;
64453 if (dirent) {
64454 if (__put_user(offset, &dirent->d_off))
64455 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64456 if (!f.file)
64457 return -EBADF;
64458
64459 + buf.file = f.file;
64460 error = iterate_dir(f.file, &buf.ctx);
64461 if (error >= 0)
64462 error = buf.error;
64463 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64464 struct dir_context ctx;
64465 struct linux_dirent64 __user * current_dir;
64466 struct linux_dirent64 __user * previous;
64467 + struct file *file;
64468 int count;
64469 int error;
64470 };
64471 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64472 buf->error = -EINVAL; /* only used if we fail.. */
64473 if (reclen > buf->count)
64474 return -EINVAL;
64475 +
64476 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64477 + return 0;
64478 +
64479 dirent = buf->previous;
64480 if (dirent) {
64481 if (__put_user(offset, &dirent->d_off))
64482 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64483 if (!f.file)
64484 return -EBADF;
64485
64486 + buf.file = f.file;
64487 error = iterate_dir(f.file, &buf.ctx);
64488 if (error >= 0)
64489 error = buf.error;
64490 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64491 index 9a3c68c..767933e 100644
64492 --- a/fs/reiserfs/do_balan.c
64493 +++ b/fs/reiserfs/do_balan.c
64494 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64495 return;
64496 }
64497
64498 - atomic_inc(&(fs_generation(tb->tb_sb)));
64499 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64500 do_balance_starts(tb);
64501
64502 /* balance leaf returns 0 except if combining L R and S into
64503 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64504 index ee382ef..f4eb6eb5 100644
64505 --- a/fs/reiserfs/item_ops.c
64506 +++ b/fs/reiserfs/item_ops.c
64507 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64508 }
64509
64510 static struct item_operations errcatch_ops = {
64511 - errcatch_bytes_number,
64512 - errcatch_decrement_key,
64513 - errcatch_is_left_mergeable,
64514 - errcatch_print_item,
64515 - errcatch_check_item,
64516 + .bytes_number = errcatch_bytes_number,
64517 + .decrement_key = errcatch_decrement_key,
64518 + .is_left_mergeable = errcatch_is_left_mergeable,
64519 + .print_item = errcatch_print_item,
64520 + .check_item = errcatch_check_item,
64521
64522 - errcatch_create_vi,
64523 - errcatch_check_left,
64524 - errcatch_check_right,
64525 - errcatch_part_size,
64526 - errcatch_unit_num,
64527 - errcatch_print_vi
64528 + .create_vi = errcatch_create_vi,
64529 + .check_left = errcatch_check_left,
64530 + .check_right = errcatch_check_right,
64531 + .part_size = errcatch_part_size,
64532 + .unit_num = errcatch_unit_num,
64533 + .print_vi = errcatch_print_vi
64534 };
64535
64536 //////////////////////////////////////////////////////////////////////////////
64537 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64538 index 02b0b7d..c85018b 100644
64539 --- a/fs/reiserfs/procfs.c
64540 +++ b/fs/reiserfs/procfs.c
64541 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64542 "SMALL_TAILS " : "NO_TAILS ",
64543 replay_only(sb) ? "REPLAY_ONLY " : "",
64544 convert_reiserfs(sb) ? "CONV " : "",
64545 - atomic_read(&r->s_generation_counter),
64546 + atomic_read_unchecked(&r->s_generation_counter),
64547 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64548 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64549 SF(s_good_search_by_key_reada), SF(s_bmaps),
64550 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64551 index 8d06adf..7e1c9f8 100644
64552 --- a/fs/reiserfs/reiserfs.h
64553 +++ b/fs/reiserfs/reiserfs.h
64554 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64555 /* Comment? -Hans */
64556 wait_queue_head_t s_wait;
64557 /* To be obsoleted soon by per buffer seals.. -Hans */
64558 - atomic_t s_generation_counter; // increased by one every time the
64559 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64560 // tree gets re-balanced
64561 unsigned long s_properties; /* File system properties. Currently holds
64562 on-disk FS format */
64563 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64564 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64565
64566 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64567 -#define get_generation(s) atomic_read (&fs_generation(s))
64568 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64569 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64570 #define __fs_changed(gen,s) (gen != get_generation (s))
64571 #define fs_changed(gen,s) \
64572 diff --git a/fs/select.c b/fs/select.c
64573 index 467bb1c..cf9d65a 100644
64574 --- a/fs/select.c
64575 +++ b/fs/select.c
64576 @@ -20,6 +20,7 @@
64577 #include <linux/export.h>
64578 #include <linux/slab.h>
64579 #include <linux/poll.h>
64580 +#include <linux/security.h>
64581 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64582 #include <linux/file.h>
64583 #include <linux/fdtable.h>
64584 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64585 struct poll_list *walk = head;
64586 unsigned long todo = nfds;
64587
64588 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64589 if (nfds > rlimit(RLIMIT_NOFILE))
64590 return -EINVAL;
64591
64592 diff --git a/fs/seq_file.c b/fs/seq_file.c
64593 index 1d641bb..e600623 100644
64594 --- a/fs/seq_file.c
64595 +++ b/fs/seq_file.c
64596 @@ -10,6 +10,7 @@
64597 #include <linux/seq_file.h>
64598 #include <linux/slab.h>
64599 #include <linux/cred.h>
64600 +#include <linux/sched.h>
64601
64602 #include <asm/uaccess.h>
64603 #include <asm/page.h>
64604 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64605 #ifdef CONFIG_USER_NS
64606 p->user_ns = file->f_cred->user_ns;
64607 #endif
64608 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64609 + p->exec_id = current->exec_id;
64610 +#endif
64611
64612 /*
64613 * Wrappers around seq_open(e.g. swaps_open) need to be
64614 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64615 return 0;
64616 }
64617 if (!m->buf) {
64618 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64619 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64620 if (!m->buf)
64621 return -ENOMEM;
64622 }
64623 @@ -137,7 +141,7 @@ Eoverflow:
64624 m->op->stop(m, p);
64625 kfree(m->buf);
64626 m->count = 0;
64627 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64628 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64629 return !m->buf ? -ENOMEM : -EAGAIN;
64630 }
64631
64632 @@ -153,7 +157,7 @@ Eoverflow:
64633 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64634 {
64635 struct seq_file *m = file->private_data;
64636 - size_t copied = 0;
64637 + ssize_t copied = 0;
64638 loff_t pos;
64639 size_t n;
64640 void *p;
64641 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64642
64643 /* grab buffer if we didn't have one */
64644 if (!m->buf) {
64645 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64646 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64647 if (!m->buf)
64648 goto Enomem;
64649 }
64650 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64651 m->op->stop(m, p);
64652 kfree(m->buf);
64653 m->count = 0;
64654 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64655 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64656 if (!m->buf)
64657 goto Enomem;
64658 m->version = 0;
64659 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64660 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64661 void *data)
64662 {
64663 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64664 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64665 int res = -ENOMEM;
64666
64667 if (op) {
64668 diff --git a/fs/splice.c b/fs/splice.c
64669 index 12028fa..a6f2619 100644
64670 --- a/fs/splice.c
64671 +++ b/fs/splice.c
64672 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64673 pipe_lock(pipe);
64674
64675 for (;;) {
64676 - if (!pipe->readers) {
64677 + if (!atomic_read(&pipe->readers)) {
64678 send_sig(SIGPIPE, current, 0);
64679 if (!ret)
64680 ret = -EPIPE;
64681 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64682 page_nr++;
64683 ret += buf->len;
64684
64685 - if (pipe->files)
64686 + if (atomic_read(&pipe->files))
64687 do_wakeup = 1;
64688
64689 if (!--spd->nr_pages)
64690 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64691 do_wakeup = 0;
64692 }
64693
64694 - pipe->waiting_writers++;
64695 + atomic_inc(&pipe->waiting_writers);
64696 pipe_wait(pipe);
64697 - pipe->waiting_writers--;
64698 + atomic_dec(&pipe->waiting_writers);
64699 }
64700
64701 pipe_unlock(pipe);
64702 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64703 old_fs = get_fs();
64704 set_fs(get_ds());
64705 /* The cast to a user pointer is valid due to the set_fs() */
64706 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64707 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64708 set_fs(old_fs);
64709
64710 return res;
64711 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64712 old_fs = get_fs();
64713 set_fs(get_ds());
64714 /* The cast to a user pointer is valid due to the set_fs() */
64715 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64716 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64717 set_fs(old_fs);
64718
64719 return res;
64720 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64721 goto err;
64722
64723 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64724 - vec[i].iov_base = (void __user *) page_address(page);
64725 + vec[i].iov_base = (void __force_user *) page_address(page);
64726 vec[i].iov_len = this_len;
64727 spd.pages[i] = page;
64728 spd.nr_pages++;
64729 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64730 ops->release(pipe, buf);
64731 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64732 pipe->nrbufs--;
64733 - if (pipe->files)
64734 + if (atomic_read(&pipe->files))
64735 sd->need_wakeup = true;
64736 }
64737
64738 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64739 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64740 {
64741 while (!pipe->nrbufs) {
64742 - if (!pipe->writers)
64743 + if (!atomic_read(&pipe->writers))
64744 return 0;
64745
64746 - if (!pipe->waiting_writers && sd->num_spliced)
64747 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64748 return 0;
64749
64750 if (sd->flags & SPLICE_F_NONBLOCK)
64751 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64752 * out of the pipe right after the splice_to_pipe(). So set
64753 * PIPE_READERS appropriately.
64754 */
64755 - pipe->readers = 1;
64756 + atomic_set(&pipe->readers, 1);
64757
64758 current->splice_pipe = pipe;
64759 }
64760 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64761
64762 partial[buffers].offset = off;
64763 partial[buffers].len = plen;
64764 + partial[buffers].private = 0;
64765
64766 off = 0;
64767 len -= plen;
64768 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64769 ret = -ERESTARTSYS;
64770 break;
64771 }
64772 - if (!pipe->writers)
64773 + if (!atomic_read(&pipe->writers))
64774 break;
64775 - if (!pipe->waiting_writers) {
64776 + if (!atomic_read(&pipe->waiting_writers)) {
64777 if (flags & SPLICE_F_NONBLOCK) {
64778 ret = -EAGAIN;
64779 break;
64780 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64781 pipe_lock(pipe);
64782
64783 while (pipe->nrbufs >= pipe->buffers) {
64784 - if (!pipe->readers) {
64785 + if (!atomic_read(&pipe->readers)) {
64786 send_sig(SIGPIPE, current, 0);
64787 ret = -EPIPE;
64788 break;
64789 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64790 ret = -ERESTARTSYS;
64791 break;
64792 }
64793 - pipe->waiting_writers++;
64794 + atomic_inc(&pipe->waiting_writers);
64795 pipe_wait(pipe);
64796 - pipe->waiting_writers--;
64797 + atomic_dec(&pipe->waiting_writers);
64798 }
64799
64800 pipe_unlock(pipe);
64801 @@ -1880,14 +1881,14 @@ retry:
64802 pipe_double_lock(ipipe, opipe);
64803
64804 do {
64805 - if (!opipe->readers) {
64806 + if (!atomic_read(&opipe->readers)) {
64807 send_sig(SIGPIPE, current, 0);
64808 if (!ret)
64809 ret = -EPIPE;
64810 break;
64811 }
64812
64813 - if (!ipipe->nrbufs && !ipipe->writers)
64814 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64815 break;
64816
64817 /*
64818 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64819 pipe_double_lock(ipipe, opipe);
64820
64821 do {
64822 - if (!opipe->readers) {
64823 + if (!atomic_read(&opipe->readers)) {
64824 send_sig(SIGPIPE, current, 0);
64825 if (!ret)
64826 ret = -EPIPE;
64827 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64828 * return EAGAIN if we have the potential of some data in the
64829 * future, otherwise just return 0
64830 */
64831 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64832 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64833 ret = -EAGAIN;
64834
64835 pipe_unlock(ipipe);
64836 diff --git a/fs/stat.c b/fs/stat.c
64837 index ae0c3ce..9ee641c 100644
64838 --- a/fs/stat.c
64839 +++ b/fs/stat.c
64840 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64841 stat->gid = inode->i_gid;
64842 stat->rdev = inode->i_rdev;
64843 stat->size = i_size_read(inode);
64844 - stat->atime = inode->i_atime;
64845 - stat->mtime = inode->i_mtime;
64846 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64847 + stat->atime = inode->i_ctime;
64848 + stat->mtime = inode->i_ctime;
64849 + } else {
64850 + stat->atime = inode->i_atime;
64851 + stat->mtime = inode->i_mtime;
64852 + }
64853 stat->ctime = inode->i_ctime;
64854 stat->blksize = (1 << inode->i_blkbits);
64855 stat->blocks = inode->i_blocks;
64856 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64857 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64858 {
64859 struct inode *inode = path->dentry->d_inode;
64860 + int retval;
64861
64862 - if (inode->i_op->getattr)
64863 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
64864 + if (inode->i_op->getattr) {
64865 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64866 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64867 + stat->atime = stat->ctime;
64868 + stat->mtime = stat->ctime;
64869 + }
64870 + return retval;
64871 + }
64872
64873 generic_fillattr(inode, stat);
64874 return 0;
64875 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64876 index ee0d761..b346c58 100644
64877 --- a/fs/sysfs/dir.c
64878 +++ b/fs/sysfs/dir.c
64879 @@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
64880 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
64881 {
64882 struct kernfs_node *parent, *kn;
64883 + const char *name;
64884 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
64885 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64886 + const char *parent_name;
64887 +#endif
64888
64889 BUG_ON(!kobj);
64890
64891 + name = kobject_name(kobj);
64892 +
64893 if (kobj->parent)
64894 parent = kobj->parent->sd;
64895 else
64896 @@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
64897 if (!parent)
64898 return -ENOENT;
64899
64900 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
64901 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
64902 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64903 + parent_name = parent->name;
64904 + mode = S_IRWXU;
64905 +
64906 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64907 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64908 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64909 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64910 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
64911 +#endif
64912 +
64913 + kn = kernfs_create_dir_ns(parent, name,
64914 + mode, kobj, ns);
64915 if (IS_ERR(kn)) {
64916 if (PTR_ERR(kn) == -EEXIST)
64917 - sysfs_warn_dup(parent, kobject_name(kobj));
64918 + sysfs_warn_dup(parent, name);
64919 return PTR_ERR(kn);
64920 }
64921
64922 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64923 index 69d4889..a810bd4 100644
64924 --- a/fs/sysv/sysv.h
64925 +++ b/fs/sysv/sysv.h
64926 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64927 #endif
64928 }
64929
64930 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64931 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64932 {
64933 if (sbi->s_bytesex == BYTESEX_PDP)
64934 return PDP_swab((__force __u32)n);
64935 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64936 index e18b988..f1d4ad0f 100644
64937 --- a/fs/ubifs/io.c
64938 +++ b/fs/ubifs/io.c
64939 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64940 return err;
64941 }
64942
64943 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64944 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64945 {
64946 int err;
64947
64948 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64949 index c175b4d..8f36a16 100644
64950 --- a/fs/udf/misc.c
64951 +++ b/fs/udf/misc.c
64952 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64953
64954 u8 udf_tag_checksum(const struct tag *t)
64955 {
64956 - u8 *data = (u8 *)t;
64957 + const u8 *data = (const u8 *)t;
64958 u8 checksum = 0;
64959 int i;
64960 for (i = 0; i < sizeof(struct tag); ++i)
64961 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64962 index 8d974c4..b82f6ec 100644
64963 --- a/fs/ufs/swab.h
64964 +++ b/fs/ufs/swab.h
64965 @@ -22,7 +22,7 @@ enum {
64966 BYTESEX_BE
64967 };
64968
64969 -static inline u64
64970 +static inline u64 __intentional_overflow(-1)
64971 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64972 {
64973 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64974 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64975 return (__force __fs64)cpu_to_be64(n);
64976 }
64977
64978 -static inline u32
64979 +static inline u32 __intentional_overflow(-1)
64980 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64981 {
64982 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64983 diff --git a/fs/utimes.c b/fs/utimes.c
64984 index aa138d6..5f3a811 100644
64985 --- a/fs/utimes.c
64986 +++ b/fs/utimes.c
64987 @@ -1,6 +1,7 @@
64988 #include <linux/compiler.h>
64989 #include <linux/file.h>
64990 #include <linux/fs.h>
64991 +#include <linux/security.h>
64992 #include <linux/linkage.h>
64993 #include <linux/mount.h>
64994 #include <linux/namei.h>
64995 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64996 }
64997 }
64998 retry_deleg:
64999 +
65000 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65001 + error = -EACCES;
65002 + goto mnt_drop_write_and_out;
65003 + }
65004 +
65005 mutex_lock(&inode->i_mutex);
65006 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65007 mutex_unlock(&inode->i_mutex);
65008 diff --git a/fs/xattr.c b/fs/xattr.c
65009 index 3377dff..f394815 100644
65010 --- a/fs/xattr.c
65011 +++ b/fs/xattr.c
65012 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65013 return rc;
65014 }
65015
65016 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65017 +ssize_t
65018 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
65019 +{
65020 + struct inode *inode = dentry->d_inode;
65021 + ssize_t error;
65022 +
65023 + error = inode_permission(inode, MAY_EXEC);
65024 + if (error)
65025 + return error;
65026 +
65027 + if (inode->i_op->getxattr)
65028 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65029 + else
65030 + error = -EOPNOTSUPP;
65031 +
65032 + return error;
65033 +}
65034 +EXPORT_SYMBOL(pax_getxattr);
65035 +#endif
65036 +
65037 ssize_t
65038 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65039 {
65040 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65041 * Extended attribute SET operations
65042 */
65043 static long
65044 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
65045 +setxattr(struct path *path, const char __user *name, const void __user *value,
65046 size_t size, int flags)
65047 {
65048 int error;
65049 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65050 posix_acl_fix_xattr_from_user(kvalue, size);
65051 }
65052
65053 - error = vfs_setxattr(d, kname, kvalue, size, flags);
65054 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65055 + error = -EACCES;
65056 + goto out;
65057 + }
65058 +
65059 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65060 out:
65061 if (vvalue)
65062 vfree(vvalue);
65063 @@ -377,7 +403,7 @@ retry:
65064 return error;
65065 error = mnt_want_write(path.mnt);
65066 if (!error) {
65067 - error = setxattr(path.dentry, name, value, size, flags);
65068 + error = setxattr(&path, name, value, size, flags);
65069 mnt_drop_write(path.mnt);
65070 }
65071 path_put(&path);
65072 @@ -401,7 +427,7 @@ retry:
65073 return error;
65074 error = mnt_want_write(path.mnt);
65075 if (!error) {
65076 - error = setxattr(path.dentry, name, value, size, flags);
65077 + error = setxattr(&path, name, value, size, flags);
65078 mnt_drop_write(path.mnt);
65079 }
65080 path_put(&path);
65081 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65082 const void __user *,value, size_t, size, int, flags)
65083 {
65084 struct fd f = fdget(fd);
65085 - struct dentry *dentry;
65086 int error = -EBADF;
65087
65088 if (!f.file)
65089 return error;
65090 - dentry = f.file->f_path.dentry;
65091 - audit_inode(NULL, dentry, 0);
65092 + audit_inode(NULL, f.file->f_path.dentry, 0);
65093 error = mnt_want_write_file(f.file);
65094 if (!error) {
65095 - error = setxattr(dentry, name, value, size, flags);
65096 + error = setxattr(&f.file->f_path, name, value, size, flags);
65097 mnt_drop_write_file(f.file);
65098 }
65099 fdput(f);
65100 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65101 * Extended attribute REMOVE operations
65102 */
65103 static long
65104 -removexattr(struct dentry *d, const char __user *name)
65105 +removexattr(struct path *path, const char __user *name)
65106 {
65107 int error;
65108 char kname[XATTR_NAME_MAX + 1];
65109 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65110 if (error < 0)
65111 return error;
65112
65113 - return vfs_removexattr(d, kname);
65114 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65115 + return -EACCES;
65116 +
65117 + return vfs_removexattr(path->dentry, kname);
65118 }
65119
65120 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65121 @@ -652,7 +679,7 @@ retry:
65122 return error;
65123 error = mnt_want_write(path.mnt);
65124 if (!error) {
65125 - error = removexattr(path.dentry, name);
65126 + error = removexattr(&path, name);
65127 mnt_drop_write(path.mnt);
65128 }
65129 path_put(&path);
65130 @@ -675,7 +702,7 @@ retry:
65131 return error;
65132 error = mnt_want_write(path.mnt);
65133 if (!error) {
65134 - error = removexattr(path.dentry, name);
65135 + error = removexattr(&path, name);
65136 mnt_drop_write(path.mnt);
65137 }
65138 path_put(&path);
65139 @@ -689,16 +716,16 @@ retry:
65140 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65141 {
65142 struct fd f = fdget(fd);
65143 - struct dentry *dentry;
65144 + struct path *path;
65145 int error = -EBADF;
65146
65147 if (!f.file)
65148 return error;
65149 - dentry = f.file->f_path.dentry;
65150 - audit_inode(NULL, dentry, 0);
65151 + path = &f.file->f_path;
65152 + audit_inode(NULL, path->dentry, 0);
65153 error = mnt_want_write_file(f.file);
65154 if (!error) {
65155 - error = removexattr(dentry, name);
65156 + error = removexattr(path, name);
65157 mnt_drop_write_file(f.file);
65158 }
65159 fdput(f);
65160 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65161 index 152543c..d80c361 100644
65162 --- a/fs/xfs/xfs_bmap.c
65163 +++ b/fs/xfs/xfs_bmap.c
65164 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65165
65166 #else
65167 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65168 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65169 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65170 #endif /* DEBUG */
65171
65172 /*
65173 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65174 index aead369..0dfecfd 100644
65175 --- a/fs/xfs/xfs_dir2_readdir.c
65176 +++ b/fs/xfs/xfs_dir2_readdir.c
65177 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65178 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65179 filetype = dp->d_ops->sf_get_ftype(sfep);
65180 ctx->pos = off & 0x7fffffff;
65181 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65182 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65183 + char name[sfep->namelen];
65184 + memcpy(name, sfep->name, sfep->namelen);
65185 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65186 + return 0;
65187 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65188 xfs_dir3_get_dtype(mp, filetype)))
65189 return 0;
65190 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65191 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65192 index bcfe612..aa399c0 100644
65193 --- a/fs/xfs/xfs_ioctl.c
65194 +++ b/fs/xfs/xfs_ioctl.c
65195 @@ -122,7 +122,7 @@ xfs_find_handle(
65196 }
65197
65198 error = -EFAULT;
65199 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65200 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65201 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65202 goto out_put;
65203
65204 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65205 new file mode 100644
65206 index 0000000..3abaf02
65207 --- /dev/null
65208 +++ b/grsecurity/Kconfig
65209 @@ -0,0 +1,1161 @@
65210 +#
65211 +# grecurity configuration
65212 +#
65213 +menu "Memory Protections"
65214 +depends on GRKERNSEC
65215 +
65216 +config GRKERNSEC_KMEM
65217 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65218 + default y if GRKERNSEC_CONFIG_AUTO
65219 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65220 + help
65221 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65222 + be written to or read from to modify or leak the contents of the running
65223 + kernel. /dev/port will also not be allowed to be opened, writing to
65224 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65225 + If you have module support disabled, enabling this will close up several
65226 + ways that are currently used to insert malicious code into the running
65227 + kernel.
65228 +
65229 + Even with this feature enabled, we still highly recommend that
65230 + you use the RBAC system, as it is still possible for an attacker to
65231 + modify the running kernel through other more obscure methods.
65232 +
65233 + It is highly recommended that you say Y here if you meet all the
65234 + conditions above.
65235 +
65236 +config GRKERNSEC_VM86
65237 + bool "Restrict VM86 mode"
65238 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65239 + depends on X86_32
65240 +
65241 + help
65242 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65243 + make use of a special execution mode on 32bit x86 processors called
65244 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65245 + video cards and will still work with this option enabled. The purpose
65246 + of the option is to prevent exploitation of emulation errors in
65247 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65248 + Nearly all users should be able to enable this option.
65249 +
65250 +config GRKERNSEC_IO
65251 + bool "Disable privileged I/O"
65252 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65253 + depends on X86
65254 + select RTC_CLASS
65255 + select RTC_INTF_DEV
65256 + select RTC_DRV_CMOS
65257 +
65258 + help
65259 + If you say Y here, all ioperm and iopl calls will return an error.
65260 + Ioperm and iopl can be used to modify the running kernel.
65261 + Unfortunately, some programs need this access to operate properly,
65262 + the most notable of which are XFree86 and hwclock. hwclock can be
65263 + remedied by having RTC support in the kernel, so real-time
65264 + clock support is enabled if this option is enabled, to ensure
65265 + that hwclock operates correctly. If hwclock still does not work,
65266 + either update udev or symlink /dev/rtc to /dev/rtc0.
65267 +
65268 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65269 + you may not be able to boot into a graphical environment with this
65270 + option enabled. In this case, you should use the RBAC system instead.
65271 +
65272 +config GRKERNSEC_JIT_HARDEN
65273 + bool "Harden BPF JIT against spray attacks"
65274 + default y if GRKERNSEC_CONFIG_AUTO
65275 + depends on BPF_JIT && X86
65276 + help
65277 + If you say Y here, the native code generated by the kernel's Berkeley
65278 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65279 + attacks that attempt to fit attacker-beneficial instructions in
65280 + 32bit immediate fields of JIT-generated native instructions. The
65281 + attacker will generally aim to cause an unintended instruction sequence
65282 + of JIT-generated native code to execute by jumping into the middle of
65283 + a generated instruction. This feature effectively randomizes the 32bit
65284 + immediate constants present in the generated code to thwart such attacks.
65285 +
65286 + If you're using KERNEXEC, it's recommended that you enable this option
65287 + to supplement the hardening of the kernel.
65288 +
65289 +config GRKERNSEC_PERF_HARDEN
65290 + bool "Disable unprivileged PERF_EVENTS usage by default"
65291 + default y if GRKERNSEC_CONFIG_AUTO
65292 + depends on PERF_EVENTS
65293 + help
65294 + If you say Y here, the range of acceptable values for the
65295 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65296 + default to a new value: 3. When the sysctl is set to this value, no
65297 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65298 +
65299 + Though PERF_EVENTS can be used legitimately for performance monitoring
65300 + and low-level application profiling, it is forced on regardless of
65301 + configuration, has been at fault for several vulnerabilities, and
65302 + creates new opportunities for side channels and other information leaks.
65303 +
65304 + This feature puts PERF_EVENTS into a secure default state and permits
65305 + the administrator to change out of it temporarily if unprivileged
65306 + application profiling is needed.
65307 +
65308 +config GRKERNSEC_RAND_THREADSTACK
65309 + bool "Insert random gaps between thread stacks"
65310 + default y if GRKERNSEC_CONFIG_AUTO
65311 + depends on PAX_RANDMMAP && !PPC
65312 + help
65313 + If you say Y here, a random-sized gap will be enforced between allocated
65314 + thread stacks. Glibc's NPTL and other threading libraries that
65315 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65316 + The implementation currently provides 8 bits of entropy for the gap.
65317 +
65318 + Many distributions do not compile threaded remote services with the
65319 + -fstack-check argument to GCC, causing the variable-sized stack-based
65320 + allocator, alloca(), to not probe the stack on allocation. This
65321 + permits an unbounded alloca() to skip over any guard page and potentially
65322 + modify another thread's stack reliably. An enforced random gap
65323 + reduces the reliability of such an attack and increases the chance
65324 + that such a read/write to another thread's stack instead lands in
65325 + an unmapped area, causing a crash and triggering grsecurity's
65326 + anti-bruteforcing logic.
65327 +
65328 +config GRKERNSEC_PROC_MEMMAP
65329 + bool "Harden ASLR against information leaks and entropy reduction"
65330 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65331 + depends on PAX_NOEXEC || PAX_ASLR
65332 + help
65333 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65334 + give no information about the addresses of its mappings if
65335 + PaX features that rely on random addresses are enabled on the task.
65336 + In addition to sanitizing this information and disabling other
65337 + dangerous sources of information, this option causes reads of sensitive
65338 + /proc/<pid> entries where the file descriptor was opened in a different
65339 + task than the one performing the read. Such attempts are logged.
65340 + This option also limits argv/env strings for suid/sgid binaries
65341 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65342 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65343 + binaries to prevent alternative mmap layouts from being abused.
65344 +
65345 + If you use PaX it is essential that you say Y here as it closes up
65346 + several holes that make full ASLR useless locally.
65347 +
65348 +config GRKERNSEC_BRUTE
65349 + bool "Deter exploit bruteforcing"
65350 + default y if GRKERNSEC_CONFIG_AUTO
65351 + help
65352 + If you say Y here, attempts to bruteforce exploits against forking
65353 + daemons such as apache or sshd, as well as against suid/sgid binaries
65354 + will be deterred. When a child of a forking daemon is killed by PaX
65355 + or crashes due to an illegal instruction or other suspicious signal,
65356 + the parent process will be delayed 30 seconds upon every subsequent
65357 + fork until the administrator is able to assess the situation and
65358 + restart the daemon.
65359 + In the suid/sgid case, the attempt is logged, the user has all their
65360 + existing instances of the suid/sgid binary terminated and will
65361 + be unable to execute any suid/sgid binaries for 15 minutes.
65362 +
65363 + It is recommended that you also enable signal logging in the auditing
65364 + section so that logs are generated when a process triggers a suspicious
65365 + signal.
65366 + If the sysctl option is enabled, a sysctl option with name
65367 + "deter_bruteforce" is created.
65368 +
65369 +config GRKERNSEC_MODHARDEN
65370 + bool "Harden module auto-loading"
65371 + default y if GRKERNSEC_CONFIG_AUTO
65372 + depends on MODULES
65373 + help
65374 + If you say Y here, module auto-loading in response to use of some
65375 + feature implemented by an unloaded module will be restricted to
65376 + root users. Enabling this option helps defend against attacks
65377 + by unprivileged users who abuse the auto-loading behavior to
65378 + cause a vulnerable module to load that is then exploited.
65379 +
65380 + If this option prevents a legitimate use of auto-loading for a
65381 + non-root user, the administrator can execute modprobe manually
65382 + with the exact name of the module mentioned in the alert log.
65383 + Alternatively, the administrator can add the module to the list
65384 + of modules loaded at boot by modifying init scripts.
65385 +
65386 + Modification of init scripts will most likely be needed on
65387 + Ubuntu servers with encrypted home directory support enabled,
65388 + as the first non-root user logging in will cause the ecb(aes),
65389 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65390 +
65391 +config GRKERNSEC_HIDESYM
65392 + bool "Hide kernel symbols"
65393 + default y if GRKERNSEC_CONFIG_AUTO
65394 + select PAX_USERCOPY_SLABS
65395 + help
65396 + If you say Y here, getting information on loaded modules, and
65397 + displaying all kernel symbols through a syscall will be restricted
65398 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65399 + /proc/kallsyms will be restricted to the root user. The RBAC
65400 + system can hide that entry even from root.
65401 +
65402 + This option also prevents leaking of kernel addresses through
65403 + several /proc entries.
65404 +
65405 + Note that this option is only effective provided the following
65406 + conditions are met:
65407 + 1) The kernel using grsecurity is not precompiled by some distribution
65408 + 2) You have also enabled GRKERNSEC_DMESG
65409 + 3) You are using the RBAC system and hiding other files such as your
65410 + kernel image and System.map. Alternatively, enabling this option
65411 + causes the permissions on /boot, /lib/modules, and the kernel
65412 + source directory to change at compile time to prevent
65413 + reading by non-root users.
65414 + If the above conditions are met, this option will aid in providing a
65415 + useful protection against local kernel exploitation of overflows
65416 + and arbitrary read/write vulnerabilities.
65417 +
65418 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65419 + in addition to this feature.
65420 +
65421 +config GRKERNSEC_RANDSTRUCT
65422 + bool "Randomize layout of sensitive kernel structures"
65423 + default y if GRKERNSEC_CONFIG_AUTO
65424 + select GRKERNSEC_HIDESYM
65425 + select MODVERSIONS if MODULES
65426 + help
65427 + If you say Y here, the layouts of a number of sensitive kernel
65428 + structures (task, fs, cred, etc) and all structures composed entirely
65429 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65430 + This can introduce the requirement of an additional infoleak
65431 + vulnerability for exploits targeting these structure types.
65432 +
65433 + Enabling this feature will introduce some performance impact, slightly
65434 + increase memory usage, and prevent the use of forensic tools like
65435 + Volatility against the system (unless the kernel source tree isn't
65436 + cleaned after kernel installation).
65437 +
65438 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65439 + It remains after a make clean to allow for external modules to be compiled
65440 + with the existing seed and will be removed by a make mrproper or
65441 + make distclean.
65442 +
65443 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65444 + to install the supporting headers explicitly in addition to the normal
65445 + gcc package.
65446 +
65447 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65448 + bool "Use cacheline-aware structure randomization"
65449 + depends on GRKERNSEC_RANDSTRUCT
65450 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65451 + help
65452 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65453 + at restricting randomization to cacheline-sized groups of elements. It
65454 + will further not randomize bitfields in structures. This reduces the
65455 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65456 +
65457 +config GRKERNSEC_KERN_LOCKOUT
65458 + bool "Active kernel exploit response"
65459 + default y if GRKERNSEC_CONFIG_AUTO
65460 + depends on X86 || ARM || PPC || SPARC
65461 + help
65462 + If you say Y here, when a PaX alert is triggered due to suspicious
65463 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65464 + or an OOPS occurs due to bad memory accesses, instead of just
65465 + terminating the offending process (and potentially allowing
65466 + a subsequent exploit from the same user), we will take one of two
65467 + actions:
65468 + If the user was root, we will panic the system
65469 + If the user was non-root, we will log the attempt, terminate
65470 + all processes owned by the user, then prevent them from creating
65471 + any new processes until the system is restarted
65472 + This deters repeated kernel exploitation/bruteforcing attempts
65473 + and is useful for later forensics.
65474 +
65475 +config GRKERNSEC_OLD_ARM_USERLAND
65476 + bool "Old ARM userland compatibility"
65477 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65478 + help
65479 + If you say Y here, stubs of executable code to perform such operations
65480 + as "compare-exchange" will be placed at fixed locations in the ARM vector
65481 + table. This is unfortunately needed for old ARM userland meant to run
65482 + across a wide range of processors. Without this option enabled,
65483 + the get_tls and data memory barrier stubs will be emulated by the kernel,
65484 + which is enough for Linaro userlands or other userlands designed for v6
65485 + and newer ARM CPUs. It's recommended that you try without this option enabled
65486 + first, and only enable it if your userland does not boot (it will likely fail
65487 + at init time).
65488 +
65489 +endmenu
65490 +menu "Role Based Access Control Options"
65491 +depends on GRKERNSEC
65492 +
65493 +config GRKERNSEC_RBAC_DEBUG
65494 + bool
65495 +
65496 +config GRKERNSEC_NO_RBAC
65497 + bool "Disable RBAC system"
65498 + help
65499 + If you say Y here, the /dev/grsec device will be removed from the kernel,
65500 + preventing the RBAC system from being enabled. You should only say Y
65501 + here if you have no intention of using the RBAC system, so as to prevent
65502 + an attacker with root access from misusing the RBAC system to hide files
65503 + and processes when loadable module support and /dev/[k]mem have been
65504 + locked down.
65505 +
65506 +config GRKERNSEC_ACL_HIDEKERN
65507 + bool "Hide kernel processes"
65508 + help
65509 + If you say Y here, all kernel threads will be hidden to all
65510 + processes but those whose subject has the "view hidden processes"
65511 + flag.
65512 +
65513 +config GRKERNSEC_ACL_MAXTRIES
65514 + int "Maximum tries before password lockout"
65515 + default 3
65516 + help
65517 + This option enforces the maximum number of times a user can attempt
65518 + to authorize themselves with the grsecurity RBAC system before being
65519 + denied the ability to attempt authorization again for a specified time.
65520 + The lower the number, the harder it will be to brute-force a password.
65521 +
65522 +config GRKERNSEC_ACL_TIMEOUT
65523 + int "Time to wait after max password tries, in seconds"
65524 + default 30
65525 + help
65526 + This option specifies the time the user must wait after attempting to
65527 + authorize to the RBAC system with the maximum number of invalid
65528 + passwords. The higher the number, the harder it will be to brute-force
65529 + a password.
65530 +
65531 +endmenu
65532 +menu "Filesystem Protections"
65533 +depends on GRKERNSEC
65534 +
65535 +config GRKERNSEC_PROC
65536 + bool "Proc restrictions"
65537 + default y if GRKERNSEC_CONFIG_AUTO
65538 + help
65539 + If you say Y here, the permissions of the /proc filesystem
65540 + will be altered to enhance system security and privacy. You MUST
65541 + choose either a user only restriction or a user and group restriction.
65542 + Depending upon the option you choose, you can either restrict users to
65543 + see only the processes they themselves run, or choose a group that can
65544 + view all processes and files normally restricted to root if you choose
65545 + the "restrict to user only" option. NOTE: If you're running identd or
65546 + ntpd as a non-root user, you will have to run it as the group you
65547 + specify here.
65548 +
65549 +config GRKERNSEC_PROC_USER
65550 + bool "Restrict /proc to user only"
65551 + depends on GRKERNSEC_PROC
65552 + help
65553 + If you say Y here, non-root users will only be able to view their own
65554 + processes, and restricts them from viewing network-related information,
65555 + and viewing kernel symbol and module information.
65556 +
65557 +config GRKERNSEC_PROC_USERGROUP
65558 + bool "Allow special group"
65559 + default y if GRKERNSEC_CONFIG_AUTO
65560 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65561 + help
65562 + If you say Y here, you will be able to select a group that will be
65563 + able to view all processes and network-related information. If you've
65564 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65565 + remain hidden. This option is useful if you want to run identd as
65566 + a non-root user. The group you select may also be chosen at boot time
65567 + via "grsec_proc_gid=" on the kernel commandline.
65568 +
65569 +config GRKERNSEC_PROC_GID
65570 + int "GID for special group"
65571 + depends on GRKERNSEC_PROC_USERGROUP
65572 + default 1001
65573 +
65574 +config GRKERNSEC_PROC_ADD
65575 + bool "Additional restrictions"
65576 + default y if GRKERNSEC_CONFIG_AUTO
65577 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65578 + help
65579 + If you say Y here, additional restrictions will be placed on
65580 + /proc that keep normal users from viewing device information and
65581 + slabinfo information that could be useful for exploits.
65582 +
65583 +config GRKERNSEC_LINK
65584 + bool "Linking restrictions"
65585 + default y if GRKERNSEC_CONFIG_AUTO
65586 + help
65587 + If you say Y here, /tmp race exploits will be prevented, since users
65588 + will no longer be able to follow symlinks owned by other users in
65589 + world-writable +t directories (e.g. /tmp), unless the owner of the
65590 + symlink is the owner of the directory. users will also not be
65591 + able to hardlink to files they do not own. If the sysctl option is
65592 + enabled, a sysctl option with name "linking_restrictions" is created.
65593 +
65594 +config GRKERNSEC_SYMLINKOWN
65595 + bool "Kernel-enforced SymlinksIfOwnerMatch"
65596 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65597 + help
65598 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
65599 + that prevents it from being used as a security feature. As Apache
65600 + verifies the symlink by performing a stat() against the target of
65601 + the symlink before it is followed, an attacker can setup a symlink
65602 + to point to a same-owned file, then replace the symlink with one
65603 + that targets another user's file just after Apache "validates" the
65604 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
65605 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65606 + will be in place for the group you specify. If the sysctl option
65607 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
65608 + created.
65609 +
65610 +config GRKERNSEC_SYMLINKOWN_GID
65611 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65612 + depends on GRKERNSEC_SYMLINKOWN
65613 + default 1006
65614 + help
65615 + Setting this GID determines what group kernel-enforced
65616 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65617 + is enabled, a sysctl option with name "symlinkown_gid" is created.
65618 +
65619 +config GRKERNSEC_FIFO
65620 + bool "FIFO restrictions"
65621 + default y if GRKERNSEC_CONFIG_AUTO
65622 + help
65623 + If you say Y here, users will not be able to write to FIFOs they don't
65624 + own in world-writable +t directories (e.g. /tmp), unless the owner of
65625 + the FIFO is the same owner of the directory it's held in. If the sysctl
65626 + option is enabled, a sysctl option with name "fifo_restrictions" is
65627 + created.
65628 +
65629 +config GRKERNSEC_SYSFS_RESTRICT
65630 + bool "Sysfs/debugfs restriction"
65631 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65632 + depends on SYSFS
65633 + help
65634 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65635 + any filesystem normally mounted under it (e.g. debugfs) will be
65636 + mostly accessible only by root. These filesystems generally provide access
65637 + to hardware and debug information that isn't appropriate for unprivileged
65638 + users of the system. Sysfs and debugfs have also become a large source
65639 + of new vulnerabilities, ranging from infoleaks to local compromise.
65640 + There has been very little oversight with an eye toward security involved
65641 + in adding new exporters of information to these filesystems, so their
65642 + use is discouraged.
65643 + For reasons of compatibility, a few directories have been whitelisted
65644 + for access by non-root users:
65645 + /sys/fs/selinux
65646 + /sys/fs/fuse
65647 + /sys/devices/system/cpu
65648 +
65649 +config GRKERNSEC_ROFS
65650 + bool "Runtime read-only mount protection"
65651 + depends on SYSCTL
65652 + help
65653 + If you say Y here, a sysctl option with name "romount_protect" will
65654 + be created. By setting this option to 1 at runtime, filesystems
65655 + will be protected in the following ways:
65656 + * No new writable mounts will be allowed
65657 + * Existing read-only mounts won't be able to be remounted read/write
65658 + * Write operations will be denied on all block devices
65659 + This option acts independently of grsec_lock: once it is set to 1,
65660 + it cannot be turned off. Therefore, please be mindful of the resulting
65661 + behavior if this option is enabled in an init script on a read-only
65662 + filesystem.
65663 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65664 + and GRKERNSEC_IO should be enabled and module loading disabled via
65665 + config or at runtime.
65666 + This feature is mainly intended for secure embedded systems.
65667 +
65668 +
65669 +config GRKERNSEC_DEVICE_SIDECHANNEL
65670 + bool "Eliminate stat/notify-based device sidechannels"
65671 + default y if GRKERNSEC_CONFIG_AUTO
65672 + help
65673 + If you say Y here, timing analyses on block or character
65674 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65675 + will be thwarted for unprivileged users. If a process without
65676 + CAP_MKNOD stats such a device, the last access and last modify times
65677 + will match the device's create time. No access or modify events
65678 + will be triggered through inotify/dnotify/fanotify for such devices.
65679 + This feature will prevent attacks that may at a minimum
65680 + allow an attacker to determine the administrator's password length.
65681 +
65682 +config GRKERNSEC_CHROOT
65683 + bool "Chroot jail restrictions"
65684 + default y if GRKERNSEC_CONFIG_AUTO
65685 + help
65686 + If you say Y here, you will be able to choose several options that will
65687 + make breaking out of a chrooted jail much more difficult. If you
65688 + encounter no software incompatibilities with the following options, it
65689 + is recommended that you enable each one.
65690 +
65691 + Note that the chroot restrictions are not intended to apply to "chroots"
65692 + to directories that are simple bind mounts of the global root filesystem.
65693 + For several other reasons, a user shouldn't expect any significant
65694 + security by performing such a chroot.
65695 +
65696 +config GRKERNSEC_CHROOT_MOUNT
65697 + bool "Deny mounts"
65698 + default y if GRKERNSEC_CONFIG_AUTO
65699 + depends on GRKERNSEC_CHROOT
65700 + help
65701 + If you say Y here, processes inside a chroot will not be able to
65702 + mount or remount filesystems. If the sysctl option is enabled, a
65703 + sysctl option with name "chroot_deny_mount" is created.
65704 +
65705 +config GRKERNSEC_CHROOT_DOUBLE
65706 + bool "Deny double-chroots"
65707 + default y if GRKERNSEC_CONFIG_AUTO
65708 + depends on GRKERNSEC_CHROOT
65709 + help
65710 + If you say Y here, processes inside a chroot will not be able to chroot
65711 + again outside the chroot. This is a widely used method of breaking
65712 + out of a chroot jail and should not be allowed. If the sysctl
65713 + option is enabled, a sysctl option with name
65714 + "chroot_deny_chroot" is created.
65715 +
65716 +config GRKERNSEC_CHROOT_PIVOT
65717 + bool "Deny pivot_root in chroot"
65718 + default y if GRKERNSEC_CONFIG_AUTO
65719 + depends on GRKERNSEC_CHROOT
65720 + help
65721 + If you say Y here, processes inside a chroot will not be able to use
65722 + a function called pivot_root() that was introduced in Linux 2.3.41. It
65723 + works similar to chroot in that it changes the root filesystem. This
65724 + function could be misused in a chrooted process to attempt to break out
65725 + of the chroot, and therefore should not be allowed. If the sysctl
65726 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
65727 + created.
65728 +
65729 +config GRKERNSEC_CHROOT_CHDIR
65730 + bool "Enforce chdir(\"/\") on all chroots"
65731 + default y if GRKERNSEC_CONFIG_AUTO
65732 + depends on GRKERNSEC_CHROOT
65733 + help
65734 + If you say Y here, the current working directory of all newly-chrooted
65735 + applications will be set to the the root directory of the chroot.
65736 + The man page on chroot(2) states:
65737 + Note that this call does not change the current working
65738 + directory, so that `.' can be outside the tree rooted at
65739 + `/'. In particular, the super-user can escape from a
65740 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65741 +
65742 + It is recommended that you say Y here, since it's not known to break
65743 + any software. If the sysctl option is enabled, a sysctl option with
65744 + name "chroot_enforce_chdir" is created.
65745 +
65746 +config GRKERNSEC_CHROOT_CHMOD
65747 + bool "Deny (f)chmod +s"
65748 + default y if GRKERNSEC_CONFIG_AUTO
65749 + depends on GRKERNSEC_CHROOT
65750 + help
65751 + If you say Y here, processes inside a chroot will not be able to chmod
65752 + or fchmod files to make them have suid or sgid bits. This protects
65753 + against another published method of breaking a chroot. If the sysctl
65754 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
65755 + created.
65756 +
65757 +config GRKERNSEC_CHROOT_FCHDIR
65758 + bool "Deny fchdir out of chroot"
65759 + default y if GRKERNSEC_CONFIG_AUTO
65760 + depends on GRKERNSEC_CHROOT
65761 + help
65762 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
65763 + to a file descriptor of the chrooting process that points to a directory
65764 + outside the filesystem will be stopped. If the sysctl option
65765 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65766 +
65767 +config GRKERNSEC_CHROOT_MKNOD
65768 + bool "Deny mknod"
65769 + default y if GRKERNSEC_CONFIG_AUTO
65770 + depends on GRKERNSEC_CHROOT
65771 + help
65772 + If you say Y here, processes inside a chroot will not be allowed to
65773 + mknod. The problem with using mknod inside a chroot is that it
65774 + would allow an attacker to create a device entry that is the same
65775 + as one on the physical root of your system, which could range from
65776 + anything from the console device to a device for your harddrive (which
65777 + they could then use to wipe the drive or steal data). It is recommended
65778 + that you say Y here, unless you run into software incompatibilities.
65779 + If the sysctl option is enabled, a sysctl option with name
65780 + "chroot_deny_mknod" is created.
65781 +
65782 +config GRKERNSEC_CHROOT_SHMAT
65783 + bool "Deny shmat() out of chroot"
65784 + default y if GRKERNSEC_CONFIG_AUTO
65785 + depends on GRKERNSEC_CHROOT
65786 + help
65787 + If you say Y here, processes inside a chroot will not be able to attach
65788 + to shared memory segments that were created outside of the chroot jail.
65789 + It is recommended that you say Y here. If the sysctl option is enabled,
65790 + a sysctl option with name "chroot_deny_shmat" is created.
65791 +
65792 +config GRKERNSEC_CHROOT_UNIX
65793 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
65794 + default y if GRKERNSEC_CONFIG_AUTO
65795 + depends on GRKERNSEC_CHROOT
65796 + help
65797 + If you say Y here, processes inside a chroot will not be able to
65798 + connect to abstract (meaning not belonging to a filesystem) Unix
65799 + domain sockets that were bound outside of a chroot. It is recommended
65800 + that you say Y here. If the sysctl option is enabled, a sysctl option
65801 + with name "chroot_deny_unix" is created.
65802 +
65803 +config GRKERNSEC_CHROOT_FINDTASK
65804 + bool "Protect outside processes"
65805 + default y if GRKERNSEC_CONFIG_AUTO
65806 + depends on GRKERNSEC_CHROOT
65807 + help
65808 + If you say Y here, processes inside a chroot will not be able to
65809 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65810 + getsid, or view any process outside of the chroot. If the sysctl
65811 + option is enabled, a sysctl option with name "chroot_findtask" is
65812 + created.
65813 +
65814 +config GRKERNSEC_CHROOT_NICE
65815 + bool "Restrict priority changes"
65816 + default y if GRKERNSEC_CONFIG_AUTO
65817 + depends on GRKERNSEC_CHROOT
65818 + help
65819 + If you say Y here, processes inside a chroot will not be able to raise
65820 + the priority of processes in the chroot, or alter the priority of
65821 + processes outside the chroot. This provides more security than simply
65822 + removing CAP_SYS_NICE from the process' capability set. If the
65823 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65824 + is created.
65825 +
65826 +config GRKERNSEC_CHROOT_SYSCTL
65827 + bool "Deny sysctl writes"
65828 + default y if GRKERNSEC_CONFIG_AUTO
65829 + depends on GRKERNSEC_CHROOT
65830 + help
65831 + If you say Y here, an attacker in a chroot will not be able to
65832 + write to sysctl entries, either by sysctl(2) or through a /proc
65833 + interface. It is strongly recommended that you say Y here. If the
65834 + sysctl option is enabled, a sysctl option with name
65835 + "chroot_deny_sysctl" is created.
65836 +
65837 +config GRKERNSEC_CHROOT_CAPS
65838 + bool "Capability restrictions"
65839 + default y if GRKERNSEC_CONFIG_AUTO
65840 + depends on GRKERNSEC_CHROOT
65841 + help
65842 + If you say Y here, the capabilities on all processes within a
65843 + chroot jail will be lowered to stop module insertion, raw i/o,
65844 + system and net admin tasks, rebooting the system, modifying immutable
65845 + files, modifying IPC owned by another, and changing the system time.
65846 + This is left an option because it can break some apps. Disable this
65847 + if your chrooted apps are having problems performing those kinds of
65848 + tasks. If the sysctl option is enabled, a sysctl option with
65849 + name "chroot_caps" is created.
65850 +
65851 +config GRKERNSEC_CHROOT_INITRD
65852 + bool "Exempt initrd tasks from restrictions"
65853 + default y if GRKERNSEC_CONFIG_AUTO
65854 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65855 + help
65856 + If you say Y here, tasks started prior to init will be exempted from
65857 + grsecurity's chroot restrictions. This option is mainly meant to
65858 + resolve Plymouth's performing privileged operations unnecessarily
65859 + in a chroot.
65860 +
65861 +endmenu
65862 +menu "Kernel Auditing"
65863 +depends on GRKERNSEC
65864 +
65865 +config GRKERNSEC_AUDIT_GROUP
65866 + bool "Single group for auditing"
65867 + help
65868 + If you say Y here, the exec and chdir logging features will only operate
65869 + on a group you specify. This option is recommended if you only want to
65870 + watch certain users instead of having a large amount of logs from the
65871 + entire system. If the sysctl option is enabled, a sysctl option with
65872 + name "audit_group" is created.
65873 +
65874 +config GRKERNSEC_AUDIT_GID
65875 + int "GID for auditing"
65876 + depends on GRKERNSEC_AUDIT_GROUP
65877 + default 1007
65878 +
65879 +config GRKERNSEC_EXECLOG
65880 + bool "Exec logging"
65881 + help
65882 + If you say Y here, all execve() calls will be logged (since the
65883 + other exec*() calls are frontends to execve(), all execution
65884 + will be logged). Useful for shell-servers that like to keep track
65885 + of their users. If the sysctl option is enabled, a sysctl option with
65886 + name "exec_logging" is created.
65887 + WARNING: This option when enabled will produce a LOT of logs, especially
65888 + on an active system.
65889 +
65890 +config GRKERNSEC_RESLOG
65891 + bool "Resource logging"
65892 + default y if GRKERNSEC_CONFIG_AUTO
65893 + help
65894 + If you say Y here, all attempts to overstep resource limits will
65895 + be logged with the resource name, the requested size, and the current
65896 + limit. It is highly recommended that you say Y here. If the sysctl
65897 + option is enabled, a sysctl option with name "resource_logging" is
65898 + created. If the RBAC system is enabled, the sysctl value is ignored.
65899 +
65900 +config GRKERNSEC_CHROOT_EXECLOG
65901 + bool "Log execs within chroot"
65902 + help
65903 + If you say Y here, all executions inside a chroot jail will be logged
65904 + to syslog. This can cause a large amount of logs if certain
65905 + applications (eg. djb's daemontools) are installed on the system, and
65906 + is therefore left as an option. If the sysctl option is enabled, a
65907 + sysctl option with name "chroot_execlog" is created.
65908 +
65909 +config GRKERNSEC_AUDIT_PTRACE
65910 + bool "Ptrace logging"
65911 + help
65912 + If you say Y here, all attempts to attach to a process via ptrace
65913 + will be logged. If the sysctl option is enabled, a sysctl option
65914 + with name "audit_ptrace" is created.
65915 +
65916 +config GRKERNSEC_AUDIT_CHDIR
65917 + bool "Chdir logging"
65918 + help
65919 + If you say Y here, all chdir() calls will be logged. If the sysctl
65920 + option is enabled, a sysctl option with name "audit_chdir" is created.
65921 +
65922 +config GRKERNSEC_AUDIT_MOUNT
65923 + bool "(Un)Mount logging"
65924 + help
65925 + If you say Y here, all mounts and unmounts will be logged. If the
65926 + sysctl option is enabled, a sysctl option with name "audit_mount" is
65927 + created.
65928 +
65929 +config GRKERNSEC_SIGNAL
65930 + bool "Signal logging"
65931 + default y if GRKERNSEC_CONFIG_AUTO
65932 + help
65933 + If you say Y here, certain important signals will be logged, such as
65934 + SIGSEGV, which will as a result inform you of when a error in a program
65935 + occurred, which in some cases could mean a possible exploit attempt.
65936 + If the sysctl option is enabled, a sysctl option with name
65937 + "signal_logging" is created.
65938 +
65939 +config GRKERNSEC_FORKFAIL
65940 + bool "Fork failure logging"
65941 + help
65942 + If you say Y here, all failed fork() attempts will be logged.
65943 + This could suggest a fork bomb, or someone attempting to overstep
65944 + their process limit. If the sysctl option is enabled, a sysctl option
65945 + with name "forkfail_logging" is created.
65946 +
65947 +config GRKERNSEC_TIME
65948 + bool "Time change logging"
65949 + default y if GRKERNSEC_CONFIG_AUTO
65950 + help
65951 + If you say Y here, any changes of the system clock will be logged.
65952 + If the sysctl option is enabled, a sysctl option with name
65953 + "timechange_logging" is created.
65954 +
65955 +config GRKERNSEC_PROC_IPADDR
65956 + bool "/proc/<pid>/ipaddr support"
65957 + default y if GRKERNSEC_CONFIG_AUTO
65958 + help
65959 + If you say Y here, a new entry will be added to each /proc/<pid>
65960 + directory that contains the IP address of the person using the task.
65961 + The IP is carried across local TCP and AF_UNIX stream sockets.
65962 + This information can be useful for IDS/IPSes to perform remote response
65963 + to a local attack. The entry is readable by only the owner of the
65964 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65965 + the RBAC system), and thus does not create privacy concerns.
65966 +
65967 +config GRKERNSEC_RWXMAP_LOG
65968 + bool 'Denied RWX mmap/mprotect logging'
65969 + default y if GRKERNSEC_CONFIG_AUTO
65970 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65971 + help
65972 + If you say Y here, calls to mmap() and mprotect() with explicit
65973 + usage of PROT_WRITE and PROT_EXEC together will be logged when
65974 + denied by the PAX_MPROTECT feature. This feature will also
65975 + log other problematic scenarios that can occur when PAX_MPROTECT
65976 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
65977 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65978 + is created.
65979 +
65980 +endmenu
65981 +
65982 +menu "Executable Protections"
65983 +depends on GRKERNSEC
65984 +
65985 +config GRKERNSEC_DMESG
65986 + bool "Dmesg(8) restriction"
65987 + default y if GRKERNSEC_CONFIG_AUTO
65988 + help
65989 + If you say Y here, non-root users will not be able to use dmesg(8)
65990 + to view the contents of the kernel's circular log buffer.
65991 + The kernel's log buffer often contains kernel addresses and other
65992 + identifying information useful to an attacker in fingerprinting a
65993 + system for a targeted exploit.
65994 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
65995 + created.
65996 +
65997 +config GRKERNSEC_HARDEN_PTRACE
65998 + bool "Deter ptrace-based process snooping"
65999 + default y if GRKERNSEC_CONFIG_AUTO
66000 + help
66001 + If you say Y here, TTY sniffers and other malicious monitoring
66002 + programs implemented through ptrace will be defeated. If you
66003 + have been using the RBAC system, this option has already been
66004 + enabled for several years for all users, with the ability to make
66005 + fine-grained exceptions.
66006 +
66007 + This option only affects the ability of non-root users to ptrace
66008 + processes that are not a descendent of the ptracing process.
66009 + This means that strace ./binary and gdb ./binary will still work,
66010 + but attaching to arbitrary processes will not. If the sysctl
66011 + option is enabled, a sysctl option with name "harden_ptrace" is
66012 + created.
66013 +
66014 +config GRKERNSEC_PTRACE_READEXEC
66015 + bool "Require read access to ptrace sensitive binaries"
66016 + default y if GRKERNSEC_CONFIG_AUTO
66017 + help
66018 + If you say Y here, unprivileged users will not be able to ptrace unreadable
66019 + binaries. This option is useful in environments that
66020 + remove the read bits (e.g. file mode 4711) from suid binaries to
66021 + prevent infoleaking of their contents. This option adds
66022 + consistency to the use of that file mode, as the binary could normally
66023 + be read out when run without privileges while ptracing.
66024 +
66025 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66026 + is created.
66027 +
66028 +config GRKERNSEC_SETXID
66029 + bool "Enforce consistent multithreaded privileges"
66030 + default y if GRKERNSEC_CONFIG_AUTO
66031 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66032 + help
66033 + If you say Y here, a change from a root uid to a non-root uid
66034 + in a multithreaded application will cause the resulting uids,
66035 + gids, supplementary groups, and capabilities in that thread
66036 + to be propagated to the other threads of the process. In most
66037 + cases this is unnecessary, as glibc will emulate this behavior
66038 + on behalf of the application. Other libcs do not act in the
66039 + same way, allowing the other threads of the process to continue
66040 + running with root privileges. If the sysctl option is enabled,
66041 + a sysctl option with name "consistent_setxid" is created.
66042 +
66043 +config GRKERNSEC_HARDEN_IPC
66044 + bool "Disallow access to overly-permissive IPC objects"
66045 + default y if GRKERNSEC_CONFIG_AUTO
66046 + depends on SYSVIPC
66047 + help
66048 + If you say Y here, access to overly-permissive IPC objects (shared
66049 + memory, message queues, and semaphores) will be denied for processes
66050 + given the following criteria beyond normal permission checks:
66051 + 1) If the IPC object is world-accessible and the euid doesn't match
66052 + that of the creator or current uid for the IPC object
66053 + 2) If the IPC object is group-accessible and the egid doesn't
66054 + match that of the creator or current gid for the IPC object
66055 + It's a common error to grant too much permission to these objects,
66056 + with impact ranging from denial of service and information leaking to
66057 + privilege escalation. This feature was developed in response to
66058 + research by Tim Brown:
66059 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66060 + who found hundreds of such insecure usages. Processes with
66061 + CAP_IPC_OWNER are still permitted to access these IPC objects.
66062 + If the sysctl option is enabled, a sysctl option with name
66063 + "harden_ipc" is created.
66064 +
66065 +config GRKERNSEC_TPE
66066 + bool "Trusted Path Execution (TPE)"
66067 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66068 + help
66069 + If you say Y here, you will be able to choose a gid to add to the
66070 + supplementary groups of users you want to mark as "untrusted."
66071 + These users will not be able to execute any files that are not in
66072 + root-owned directories writable only by root. If the sysctl option
66073 + is enabled, a sysctl option with name "tpe" is created.
66074 +
66075 +config GRKERNSEC_TPE_ALL
66076 + bool "Partially restrict all non-root users"
66077 + depends on GRKERNSEC_TPE
66078 + help
66079 + If you say Y here, all non-root users will be covered under
66080 + a weaker TPE restriction. This is separate from, and in addition to,
66081 + the main TPE options that you have selected elsewhere. Thus, if a
66082 + "trusted" GID is chosen, this restriction applies to even that GID.
66083 + Under this restriction, all non-root users will only be allowed to
66084 + execute files in directories they own that are not group or
66085 + world-writable, or in directories owned by root and writable only by
66086 + root. If the sysctl option is enabled, a sysctl option with name
66087 + "tpe_restrict_all" is created.
66088 +
66089 +config GRKERNSEC_TPE_INVERT
66090 + bool "Invert GID option"
66091 + depends on GRKERNSEC_TPE
66092 + help
66093 + If you say Y here, the group you specify in the TPE configuration will
66094 + decide what group TPE restrictions will be *disabled* for. This
66095 + option is useful if you want TPE restrictions to be applied to most
66096 + users on the system. If the sysctl option is enabled, a sysctl option
66097 + with name "tpe_invert" is created. Unlike other sysctl options, this
66098 + entry will default to on for backward-compatibility.
66099 +
66100 +config GRKERNSEC_TPE_GID
66101 + int
66102 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66103 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66104 +
66105 +config GRKERNSEC_TPE_UNTRUSTED_GID
66106 + int "GID for TPE-untrusted users"
66107 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66108 + default 1005
66109 + help
66110 + Setting this GID determines what group TPE restrictions will be
66111 + *enabled* for. If the sysctl option is enabled, a sysctl option
66112 + with name "tpe_gid" is created.
66113 +
66114 +config GRKERNSEC_TPE_TRUSTED_GID
66115 + int "GID for TPE-trusted users"
66116 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66117 + default 1005
66118 + help
66119 + Setting this GID determines what group TPE restrictions will be
66120 + *disabled* for. If the sysctl option is enabled, a sysctl option
66121 + with name "tpe_gid" is created.
66122 +
66123 +endmenu
66124 +menu "Network Protections"
66125 +depends on GRKERNSEC
66126 +
66127 +config GRKERNSEC_RANDNET
66128 + bool "Larger entropy pools"
66129 + default y if GRKERNSEC_CONFIG_AUTO
66130 + help
66131 + If you say Y here, the entropy pools used for many features of Linux
66132 + and grsecurity will be doubled in size. Since several grsecurity
66133 + features use additional randomness, it is recommended that you say Y
66134 + here. Saying Y here has a similar effect as modifying
66135 + /proc/sys/kernel/random/poolsize.
66136 +
66137 +config GRKERNSEC_BLACKHOLE
66138 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66139 + default y if GRKERNSEC_CONFIG_AUTO
66140 + depends on NET
66141 + help
66142 + If you say Y here, neither TCP resets nor ICMP
66143 + destination-unreachable packets will be sent in response to packets
66144 + sent to ports for which no associated listening process exists.
66145 + This feature supports both IPV4 and IPV6 and exempts the
66146 + loopback interface from blackholing. Enabling this feature
66147 + makes a host more resilient to DoS attacks and reduces network
66148 + visibility against scanners.
66149 +
66150 + The blackhole feature as-implemented is equivalent to the FreeBSD
66151 + blackhole feature, as it prevents RST responses to all packets, not
66152 + just SYNs. Under most application behavior this causes no
66153 + problems, but applications (like haproxy) may not close certain
66154 + connections in a way that cleanly terminates them on the remote
66155 + end, leaving the remote host in LAST_ACK state. Because of this
66156 + side-effect and to prevent intentional LAST_ACK DoSes, this
66157 + feature also adds automatic mitigation against such attacks.
66158 + The mitigation drastically reduces the amount of time a socket
66159 + can spend in LAST_ACK state. If you're using haproxy and not
66160 + all servers it connects to have this option enabled, consider
66161 + disabling this feature on the haproxy host.
66162 +
66163 + If the sysctl option is enabled, two sysctl options with names
66164 + "ip_blackhole" and "lastack_retries" will be created.
66165 + While "ip_blackhole" takes the standard zero/non-zero on/off
66166 + toggle, "lastack_retries" uses the same kinds of values as
66167 + "tcp_retries1" and "tcp_retries2". The default value of 4
66168 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66169 + state.
66170 +
66171 +config GRKERNSEC_NO_SIMULT_CONNECT
66172 + bool "Disable TCP Simultaneous Connect"
66173 + default y if GRKERNSEC_CONFIG_AUTO
66174 + depends on NET
66175 + help
66176 + If you say Y here, a feature by Willy Tarreau will be enabled that
66177 + removes a weakness in Linux's strict implementation of TCP that
66178 + allows two clients to connect to each other without either entering
66179 + a listening state. The weakness allows an attacker to easily prevent
66180 + a client from connecting to a known server provided the source port
66181 + for the connection is guessed correctly.
66182 +
66183 + As the weakness could be used to prevent an antivirus or IPS from
66184 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66185 + it should be eliminated by enabling this option. Though Linux is
66186 + one of few operating systems supporting simultaneous connect, it
66187 + has no legitimate use in practice and is rarely supported by firewalls.
66188 +
66189 +config GRKERNSEC_SOCKET
66190 + bool "Socket restrictions"
66191 + depends on NET
66192 + help
66193 + If you say Y here, you will be able to choose from several options.
66194 + If you assign a GID on your system and add it to the supplementary
66195 + groups of users you want to restrict socket access to, this patch
66196 + will perform up to three things, based on the option(s) you choose.
66197 +
66198 +config GRKERNSEC_SOCKET_ALL
66199 + bool "Deny any sockets to group"
66200 + depends on GRKERNSEC_SOCKET
66201 + help
66202 + If you say Y here, you will be able to choose a GID of whose users will
66203 + be unable to connect to other hosts from your machine or run server
66204 + applications from your machine. If the sysctl option is enabled, a
66205 + sysctl option with name "socket_all" is created.
66206 +
66207 +config GRKERNSEC_SOCKET_ALL_GID
66208 + int "GID to deny all sockets for"
66209 + depends on GRKERNSEC_SOCKET_ALL
66210 + default 1004
66211 + help
66212 + Here you can choose the GID to disable socket access for. Remember to
66213 + add the users you want socket access disabled for to the GID
66214 + specified here. If the sysctl option is enabled, a sysctl option
66215 + with name "socket_all_gid" is created.
66216 +
66217 +config GRKERNSEC_SOCKET_CLIENT
66218 + bool "Deny client sockets to group"
66219 + depends on GRKERNSEC_SOCKET
66220 + help
66221 + If you say Y here, you will be able to choose a GID of whose users will
66222 + be unable to connect to other hosts from your machine, but will be
66223 + able to run servers. If this option is enabled, all users in the group
66224 + you specify will have to use passive mode when initiating ftp transfers
66225 + from the shell on your machine. If the sysctl option is enabled, a
66226 + sysctl option with name "socket_client" is created.
66227 +
66228 +config GRKERNSEC_SOCKET_CLIENT_GID
66229 + int "GID to deny client sockets for"
66230 + depends on GRKERNSEC_SOCKET_CLIENT
66231 + default 1003
66232 + help
66233 + Here you can choose the GID to disable client socket access for.
66234 + Remember to add the users you want client socket access disabled for to
66235 + the GID specified here. If the sysctl option is enabled, a sysctl
66236 + option with name "socket_client_gid" is created.
66237 +
66238 +config GRKERNSEC_SOCKET_SERVER
66239 + bool "Deny server sockets to group"
66240 + depends on GRKERNSEC_SOCKET
66241 + help
66242 + If you say Y here, you will be able to choose a GID of whose users will
66243 + be unable to run server applications from your machine. If the sysctl
66244 + option is enabled, a sysctl option with name "socket_server" is created.
66245 +
66246 +config GRKERNSEC_SOCKET_SERVER_GID
66247 + int "GID to deny server sockets for"
66248 + depends on GRKERNSEC_SOCKET_SERVER
66249 + default 1002
66250 + help
66251 + Here you can choose the GID to disable server socket access for.
66252 + Remember to add the users you want server socket access disabled for to
66253 + the GID specified here. If the sysctl option is enabled, a sysctl
66254 + option with name "socket_server_gid" is created.
66255 +
66256 +endmenu
66257 +
66258 +menu "Physical Protections"
66259 +depends on GRKERNSEC
66260 +
66261 +config GRKERNSEC_DENYUSB
66262 + bool "Deny new USB connections after toggle"
66263 + default y if GRKERNSEC_CONFIG_AUTO
66264 + depends on SYSCTL && USB_SUPPORT
66265 + help
66266 + If you say Y here, a new sysctl option with name "deny_new_usb"
66267 + will be created. Setting its value to 1 will prevent any new
66268 + USB devices from being recognized by the OS. Any attempted USB
66269 + device insertion will be logged. This option is intended to be
66270 + used against custom USB devices designed to exploit vulnerabilities
66271 + in various USB device drivers.
66272 +
66273 + For greatest effectiveness, this sysctl should be set after any
66274 + relevant init scripts. This option is safe to enable in distros
66275 + as each user can choose whether or not to toggle the sysctl.
66276 +
66277 +config GRKERNSEC_DENYUSB_FORCE
66278 + bool "Reject all USB devices not connected at boot"
66279 + select USB
66280 + depends on GRKERNSEC_DENYUSB
66281 + help
66282 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66283 + that doesn't involve a sysctl entry. This option should only be
66284 + enabled if you're sure you want to deny all new USB connections
66285 + at runtime and don't want to modify init scripts. This should not
66286 + be enabled by distros. It forces the core USB code to be built
66287 + into the kernel image so that all devices connected at boot time
66288 + can be recognized and new USB device connections can be prevented
66289 + prior to init running.
66290 +
66291 +endmenu
66292 +
66293 +menu "Sysctl Support"
66294 +depends on GRKERNSEC && SYSCTL
66295 +
66296 +config GRKERNSEC_SYSCTL
66297 + bool "Sysctl support"
66298 + default y if GRKERNSEC_CONFIG_AUTO
66299 + help
66300 + If you say Y here, you will be able to change the options that
66301 + grsecurity runs with at bootup, without having to recompile your
66302 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66303 + to enable (1) or disable (0) various features. All the sysctl entries
66304 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66305 + All features enabled in the kernel configuration are disabled at boot
66306 + if you do not say Y to the "Turn on features by default" option.
66307 + All options should be set at startup, and the grsec_lock entry should
66308 + be set to a non-zero value after all the options are set.
66309 + *THIS IS EXTREMELY IMPORTANT*
66310 +
66311 +config GRKERNSEC_SYSCTL_DISTRO
66312 + bool "Extra sysctl support for distro makers (READ HELP)"
66313 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66314 + help
66315 + If you say Y here, additional sysctl options will be created
66316 + for features that affect processes running as root. Therefore,
66317 + it is critical when using this option that the grsec_lock entry be
66318 + enabled after boot. Only distros with prebuilt kernel packages
66319 + with this option enabled that can ensure grsec_lock is enabled
66320 + after boot should use this option.
66321 + *Failure to set grsec_lock after boot makes all grsec features
66322 + this option covers useless*
66323 +
66324 + Currently this option creates the following sysctl entries:
66325 + "Disable Privileged I/O": "disable_priv_io"
66326 +
66327 +config GRKERNSEC_SYSCTL_ON
66328 + bool "Turn on features by default"
66329 + default y if GRKERNSEC_CONFIG_AUTO
66330 + depends on GRKERNSEC_SYSCTL
66331 + help
66332 + If you say Y here, instead of having all features enabled in the
66333 + kernel configuration disabled at boot time, the features will be
66334 + enabled at boot time. It is recommended you say Y here unless
66335 + there is some reason you would want all sysctl-tunable features to
66336 + be disabled by default. As mentioned elsewhere, it is important
66337 + to enable the grsec_lock entry once you have finished modifying
66338 + the sysctl entries.
66339 +
66340 +endmenu
66341 +menu "Logging Options"
66342 +depends on GRKERNSEC
66343 +
66344 +config GRKERNSEC_FLOODTIME
66345 + int "Seconds in between log messages (minimum)"
66346 + default 10
66347 + help
66348 + This option allows you to enforce the number of seconds between
66349 + grsecurity log messages. The default should be suitable for most
66350 + people, however, if you choose to change it, choose a value small enough
66351 + to allow informative logs to be produced, but large enough to
66352 + prevent flooding.
66353 +
66354 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66355 + any rate limiting on grsecurity log messages.
66356 +
66357 +config GRKERNSEC_FLOODBURST
66358 + int "Number of messages in a burst (maximum)"
66359 + default 6
66360 + help
66361 + This option allows you to choose the maximum number of messages allowed
66362 + within the flood time interval you chose in a separate option. The
66363 + default should be suitable for most people, however if you find that
66364 + many of your logs are being interpreted as flooding, you may want to
66365 + raise this value.
66366 +
66367 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66368 + any rate limiting on grsecurity log messages.
66369 +
66370 +endmenu
66371 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66372 new file mode 100644
66373 index 0000000..5307c8a
66374 --- /dev/null
66375 +++ b/grsecurity/Makefile
66376 @@ -0,0 +1,54 @@
66377 +# grsecurity – access control and security hardening for Linux
66378 +# All code in this directory and various hooks located throughout the Linux kernel are
66379 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66380 +# http://www.grsecurity.net spender@grsecurity.net
66381 +#
66382 +# This program is free software; you can redistribute it and/or
66383 +# modify it under the terms of the GNU General Public License version 2
66384 +# as published by the Free Software Foundation.
66385 +#
66386 +# This program is distributed in the hope that it will be useful,
66387 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66388 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66389 +# GNU General Public License for more details.
66390 +#
66391 +# You should have received a copy of the GNU General Public License
66392 +# along with this program; if not, write to the Free Software
66393 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66394 +
66395 +KBUILD_CFLAGS += -Werror
66396 +
66397 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66398 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66399 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66400 + grsec_usb.o grsec_ipc.o
66401 +
66402 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66403 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66404 + gracl_learn.o grsec_log.o gracl_policy.o
66405 +ifdef CONFIG_COMPAT
66406 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66407 +endif
66408 +
66409 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66410 +
66411 +ifdef CONFIG_NET
66412 +obj-y += grsec_sock.o
66413 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66414 +endif
66415 +
66416 +ifndef CONFIG_GRKERNSEC
66417 +obj-y += grsec_disabled.o
66418 +endif
66419 +
66420 +ifdef CONFIG_GRKERNSEC_HIDESYM
66421 +extra-y := grsec_hidesym.o
66422 +$(obj)/grsec_hidesym.o:
66423 + @-chmod -f 500 /boot
66424 + @-chmod -f 500 /lib/modules
66425 + @-chmod -f 500 /lib64/modules
66426 + @-chmod -f 500 /lib32/modules
66427 + @-chmod -f 700 .
66428 + @-chmod -f 700 $(objtree)
66429 + @echo ' grsec: protected kernel image paths'
66430 +endif
66431 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66432 new file mode 100644
66433 index 0000000..e56396f
66434 --- /dev/null
66435 +++ b/grsecurity/gracl.c
66436 @@ -0,0 +1,2679 @@
66437 +#include <linux/kernel.h>
66438 +#include <linux/module.h>
66439 +#include <linux/sched.h>
66440 +#include <linux/mm.h>
66441 +#include <linux/file.h>
66442 +#include <linux/fs.h>
66443 +#include <linux/namei.h>
66444 +#include <linux/mount.h>
66445 +#include <linux/tty.h>
66446 +#include <linux/proc_fs.h>
66447 +#include <linux/lglock.h>
66448 +#include <linux/slab.h>
66449 +#include <linux/vmalloc.h>
66450 +#include <linux/types.h>
66451 +#include <linux/sysctl.h>
66452 +#include <linux/netdevice.h>
66453 +#include <linux/ptrace.h>
66454 +#include <linux/gracl.h>
66455 +#include <linux/gralloc.h>
66456 +#include <linux/security.h>
66457 +#include <linux/grinternal.h>
66458 +#include <linux/pid_namespace.h>
66459 +#include <linux/stop_machine.h>
66460 +#include <linux/fdtable.h>
66461 +#include <linux/percpu.h>
66462 +#include <linux/lglock.h>
66463 +#include <linux/hugetlb.h>
66464 +#include <linux/posix-timers.h>
66465 +#include <linux/prefetch.h>
66466 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66467 +#include <linux/magic.h>
66468 +#include <linux/pagemap.h>
66469 +#include "../fs/btrfs/async-thread.h"
66470 +#include "../fs/btrfs/ctree.h"
66471 +#include "../fs/btrfs/btrfs_inode.h"
66472 +#endif
66473 +#include "../fs/mount.h"
66474 +
66475 +#include <asm/uaccess.h>
66476 +#include <asm/errno.h>
66477 +#include <asm/mman.h>
66478 +
66479 +#define FOR_EACH_ROLE_START(role) \
66480 + role = running_polstate.role_list; \
66481 + while (role) {
66482 +
66483 +#define FOR_EACH_ROLE_END(role) \
66484 + role = role->prev; \
66485 + }
66486 +
66487 +extern struct path gr_real_root;
66488 +
66489 +static struct gr_policy_state running_polstate;
66490 +struct gr_policy_state *polstate = &running_polstate;
66491 +extern struct gr_alloc_state *current_alloc_state;
66492 +
66493 +extern char *gr_shared_page[4];
66494 +DEFINE_RWLOCK(gr_inode_lock);
66495 +
66496 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
66497 +
66498 +#ifdef CONFIG_NET
66499 +extern struct vfsmount *sock_mnt;
66500 +#endif
66501 +
66502 +extern struct vfsmount *pipe_mnt;
66503 +extern struct vfsmount *shm_mnt;
66504 +
66505 +#ifdef CONFIG_HUGETLBFS
66506 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66507 +#endif
66508 +
66509 +extern u16 acl_sp_role_value;
66510 +extern struct acl_object_label *fakefs_obj_rw;
66511 +extern struct acl_object_label *fakefs_obj_rwx;
66512 +
66513 +int gr_acl_is_enabled(void)
66514 +{
66515 + return (gr_status & GR_READY);
66516 +}
66517 +
66518 +void gr_enable_rbac_system(void)
66519 +{
66520 + pax_open_kernel();
66521 + gr_status |= GR_READY;
66522 + pax_close_kernel();
66523 +}
66524 +
66525 +int gr_rbac_disable(void *unused)
66526 +{
66527 + pax_open_kernel();
66528 + gr_status &= ~GR_READY;
66529 + pax_close_kernel();
66530 +
66531 + return 0;
66532 +}
66533 +
66534 +static inline dev_t __get_dev(const struct dentry *dentry)
66535 +{
66536 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66537 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66538 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
66539 + else
66540 +#endif
66541 + return dentry->d_sb->s_dev;
66542 +}
66543 +
66544 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66545 +{
66546 + return __get_dev(dentry);
66547 +}
66548 +
66549 +static char gr_task_roletype_to_char(struct task_struct *task)
66550 +{
66551 + switch (task->role->roletype &
66552 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66553 + GR_ROLE_SPECIAL)) {
66554 + case GR_ROLE_DEFAULT:
66555 + return 'D';
66556 + case GR_ROLE_USER:
66557 + return 'U';
66558 + case GR_ROLE_GROUP:
66559 + return 'G';
66560 + case GR_ROLE_SPECIAL:
66561 + return 'S';
66562 + }
66563 +
66564 + return 'X';
66565 +}
66566 +
66567 +char gr_roletype_to_char(void)
66568 +{
66569 + return gr_task_roletype_to_char(current);
66570 +}
66571 +
66572 +__inline__ int
66573 +gr_acl_tpe_check(void)
66574 +{
66575 + if (unlikely(!(gr_status & GR_READY)))
66576 + return 0;
66577 + if (current->role->roletype & GR_ROLE_TPE)
66578 + return 1;
66579 + else
66580 + return 0;
66581 +}
66582 +
66583 +int
66584 +gr_handle_rawio(const struct inode *inode)
66585 +{
66586 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66587 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66588 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66589 + !capable(CAP_SYS_RAWIO))
66590 + return 1;
66591 +#endif
66592 + return 0;
66593 +}
66594 +
66595 +int
66596 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66597 +{
66598 + if (likely(lena != lenb))
66599 + return 0;
66600 +
66601 + return !memcmp(a, b, lena);
66602 +}
66603 +
66604 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66605 +{
66606 + *buflen -= namelen;
66607 + if (*buflen < 0)
66608 + return -ENAMETOOLONG;
66609 + *buffer -= namelen;
66610 + memcpy(*buffer, str, namelen);
66611 + return 0;
66612 +}
66613 +
66614 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66615 +{
66616 + return prepend(buffer, buflen, name->name, name->len);
66617 +}
66618 +
66619 +static int prepend_path(const struct path *path, struct path *root,
66620 + char **buffer, int *buflen)
66621 +{
66622 + struct dentry *dentry = path->dentry;
66623 + struct vfsmount *vfsmnt = path->mnt;
66624 + struct mount *mnt = real_mount(vfsmnt);
66625 + bool slash = false;
66626 + int error = 0;
66627 +
66628 + while (dentry != root->dentry || vfsmnt != root->mnt) {
66629 + struct dentry * parent;
66630 +
66631 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66632 + /* Global root? */
66633 + if (!mnt_has_parent(mnt)) {
66634 + goto out;
66635 + }
66636 + dentry = mnt->mnt_mountpoint;
66637 + mnt = mnt->mnt_parent;
66638 + vfsmnt = &mnt->mnt;
66639 + continue;
66640 + }
66641 + parent = dentry->d_parent;
66642 + prefetch(parent);
66643 + spin_lock(&dentry->d_lock);
66644 + error = prepend_name(buffer, buflen, &dentry->d_name);
66645 + spin_unlock(&dentry->d_lock);
66646 + if (!error)
66647 + error = prepend(buffer, buflen, "/", 1);
66648 + if (error)
66649 + break;
66650 +
66651 + slash = true;
66652 + dentry = parent;
66653 + }
66654 +
66655 +out:
66656 + if (!error && !slash)
66657 + error = prepend(buffer, buflen, "/", 1);
66658 +
66659 + return error;
66660 +}
66661 +
66662 +/* this must be called with mount_lock and rename_lock held */
66663 +
66664 +static char *__our_d_path(const struct path *path, struct path *root,
66665 + char *buf, int buflen)
66666 +{
66667 + char *res = buf + buflen;
66668 + int error;
66669 +
66670 + prepend(&res, &buflen, "\0", 1);
66671 + error = prepend_path(path, root, &res, &buflen);
66672 + if (error)
66673 + return ERR_PTR(error);
66674 +
66675 + return res;
66676 +}
66677 +
66678 +static char *
66679 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66680 +{
66681 + char *retval;
66682 +
66683 + retval = __our_d_path(path, root, buf, buflen);
66684 + if (unlikely(IS_ERR(retval)))
66685 + retval = strcpy(buf, "<path too long>");
66686 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66687 + retval[1] = '\0';
66688 +
66689 + return retval;
66690 +}
66691 +
66692 +static char *
66693 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66694 + char *buf, int buflen)
66695 +{
66696 + struct path path;
66697 + char *res;
66698 +
66699 + path.dentry = (struct dentry *)dentry;
66700 + path.mnt = (struct vfsmount *)vfsmnt;
66701 +
66702 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66703 + by the RBAC system */
66704 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
66705 +
66706 + return res;
66707 +}
66708 +
66709 +static char *
66710 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66711 + char *buf, int buflen)
66712 +{
66713 + char *res;
66714 + struct path path;
66715 + struct path root;
66716 + struct task_struct *reaper = init_pid_ns.child_reaper;
66717 +
66718 + path.dentry = (struct dentry *)dentry;
66719 + path.mnt = (struct vfsmount *)vfsmnt;
66720 +
66721 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66722 + get_fs_root(reaper->fs, &root);
66723 +
66724 + read_seqlock_excl(&mount_lock);
66725 + write_seqlock(&rename_lock);
66726 + res = gen_full_path(&path, &root, buf, buflen);
66727 + write_sequnlock(&rename_lock);
66728 + read_sequnlock_excl(&mount_lock);
66729 +
66730 + path_put(&root);
66731 + return res;
66732 +}
66733 +
66734 +char *
66735 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66736 +{
66737 + char *ret;
66738 + read_seqlock_excl(&mount_lock);
66739 + write_seqlock(&rename_lock);
66740 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66741 + PAGE_SIZE);
66742 + write_sequnlock(&rename_lock);
66743 + read_sequnlock_excl(&mount_lock);
66744 + return ret;
66745 +}
66746 +
66747 +static char *
66748 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66749 +{
66750 + char *ret;
66751 + char *buf;
66752 + int buflen;
66753 +
66754 + read_seqlock_excl(&mount_lock);
66755 + write_seqlock(&rename_lock);
66756 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66757 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66758 + buflen = (int)(ret - buf);
66759 + if (buflen >= 5)
66760 + prepend(&ret, &buflen, "/proc", 5);
66761 + else
66762 + ret = strcpy(buf, "<path too long>");
66763 + write_sequnlock(&rename_lock);
66764 + read_sequnlock_excl(&mount_lock);
66765 + return ret;
66766 +}
66767 +
66768 +char *
66769 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66770 +{
66771 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66772 + PAGE_SIZE);
66773 +}
66774 +
66775 +char *
66776 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66777 +{
66778 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66779 + PAGE_SIZE);
66780 +}
66781 +
66782 +char *
66783 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66784 +{
66785 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66786 + PAGE_SIZE);
66787 +}
66788 +
66789 +char *
66790 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66791 +{
66792 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66793 + PAGE_SIZE);
66794 +}
66795 +
66796 +char *
66797 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66798 +{
66799 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66800 + PAGE_SIZE);
66801 +}
66802 +
66803 +__inline__ __u32
66804 +to_gr_audit(const __u32 reqmode)
66805 +{
66806 + /* masks off auditable permission flags, then shifts them to create
66807 + auditing flags, and adds the special case of append auditing if
66808 + we're requesting write */
66809 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66810 +}
66811 +
66812 +struct acl_role_label *
66813 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66814 + const gid_t gid)
66815 +{
66816 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66817 + struct acl_role_label *match;
66818 + struct role_allowed_ip *ipp;
66819 + unsigned int x;
66820 + u32 curr_ip = task->signal->saved_ip;
66821 +
66822 + match = state->acl_role_set.r_hash[index];
66823 +
66824 + while (match) {
66825 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66826 + for (x = 0; x < match->domain_child_num; x++) {
66827 + if (match->domain_children[x] == uid)
66828 + goto found;
66829 + }
66830 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66831 + break;
66832 + match = match->next;
66833 + }
66834 +found:
66835 + if (match == NULL) {
66836 + try_group:
66837 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66838 + match = state->acl_role_set.r_hash[index];
66839 +
66840 + while (match) {
66841 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66842 + for (x = 0; x < match->domain_child_num; x++) {
66843 + if (match->domain_children[x] == gid)
66844 + goto found2;
66845 + }
66846 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66847 + break;
66848 + match = match->next;
66849 + }
66850 +found2:
66851 + if (match == NULL)
66852 + match = state->default_role;
66853 + if (match->allowed_ips == NULL)
66854 + return match;
66855 + else {
66856 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66857 + if (likely
66858 + ((ntohl(curr_ip) & ipp->netmask) ==
66859 + (ntohl(ipp->addr) & ipp->netmask)))
66860 + return match;
66861 + }
66862 + match = state->default_role;
66863 + }
66864 + } else if (match->allowed_ips == NULL) {
66865 + return match;
66866 + } else {
66867 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66868 + if (likely
66869 + ((ntohl(curr_ip) & ipp->netmask) ==
66870 + (ntohl(ipp->addr) & ipp->netmask)))
66871 + return match;
66872 + }
66873 + goto try_group;
66874 + }
66875 +
66876 + return match;
66877 +}
66878 +
66879 +static struct acl_role_label *
66880 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66881 + const gid_t gid)
66882 +{
66883 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66884 +}
66885 +
66886 +struct acl_subject_label *
66887 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66888 + const struct acl_role_label *role)
66889 +{
66890 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66891 + struct acl_subject_label *match;
66892 +
66893 + match = role->subj_hash[index];
66894 +
66895 + while (match && (match->inode != ino || match->device != dev ||
66896 + (match->mode & GR_DELETED))) {
66897 + match = match->next;
66898 + }
66899 +
66900 + if (match && !(match->mode & GR_DELETED))
66901 + return match;
66902 + else
66903 + return NULL;
66904 +}
66905 +
66906 +struct acl_subject_label *
66907 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66908 + const struct acl_role_label *role)
66909 +{
66910 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66911 + struct acl_subject_label *match;
66912 +
66913 + match = role->subj_hash[index];
66914 +
66915 + while (match && (match->inode != ino || match->device != dev ||
66916 + !(match->mode & GR_DELETED))) {
66917 + match = match->next;
66918 + }
66919 +
66920 + if (match && (match->mode & GR_DELETED))
66921 + return match;
66922 + else
66923 + return NULL;
66924 +}
66925 +
66926 +static struct acl_object_label *
66927 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66928 + const struct acl_subject_label *subj)
66929 +{
66930 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66931 + struct acl_object_label *match;
66932 +
66933 + match = subj->obj_hash[index];
66934 +
66935 + while (match && (match->inode != ino || match->device != dev ||
66936 + (match->mode & GR_DELETED))) {
66937 + match = match->next;
66938 + }
66939 +
66940 + if (match && !(match->mode & GR_DELETED))
66941 + return match;
66942 + else
66943 + return NULL;
66944 +}
66945 +
66946 +static struct acl_object_label *
66947 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66948 + const struct acl_subject_label *subj)
66949 +{
66950 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66951 + struct acl_object_label *match;
66952 +
66953 + match = subj->obj_hash[index];
66954 +
66955 + while (match && (match->inode != ino || match->device != dev ||
66956 + !(match->mode & GR_DELETED))) {
66957 + match = match->next;
66958 + }
66959 +
66960 + if (match && (match->mode & GR_DELETED))
66961 + return match;
66962 +
66963 + match = subj->obj_hash[index];
66964 +
66965 + while (match && (match->inode != ino || match->device != dev ||
66966 + (match->mode & GR_DELETED))) {
66967 + match = match->next;
66968 + }
66969 +
66970 + if (match && !(match->mode & GR_DELETED))
66971 + return match;
66972 + else
66973 + return NULL;
66974 +}
66975 +
66976 +struct name_entry *
66977 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66978 +{
66979 + unsigned int len = strlen(name);
66980 + unsigned int key = full_name_hash(name, len);
66981 + unsigned int index = key % state->name_set.n_size;
66982 + struct name_entry *match;
66983 +
66984 + match = state->name_set.n_hash[index];
66985 +
66986 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66987 + match = match->next;
66988 +
66989 + return match;
66990 +}
66991 +
66992 +static struct name_entry *
66993 +lookup_name_entry(const char *name)
66994 +{
66995 + return __lookup_name_entry(&running_polstate, name);
66996 +}
66997 +
66998 +static struct name_entry *
66999 +lookup_name_entry_create(const char *name)
67000 +{
67001 + unsigned int len = strlen(name);
67002 + unsigned int key = full_name_hash(name, len);
67003 + unsigned int index = key % running_polstate.name_set.n_size;
67004 + struct name_entry *match;
67005 +
67006 + match = running_polstate.name_set.n_hash[index];
67007 +
67008 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67009 + !match->deleted))
67010 + match = match->next;
67011 +
67012 + if (match && match->deleted)
67013 + return match;
67014 +
67015 + match = running_polstate.name_set.n_hash[index];
67016 +
67017 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67018 + match->deleted))
67019 + match = match->next;
67020 +
67021 + if (match && !match->deleted)
67022 + return match;
67023 + else
67024 + return NULL;
67025 +}
67026 +
67027 +static struct inodev_entry *
67028 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
67029 +{
67030 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67031 + struct inodev_entry *match;
67032 +
67033 + match = running_polstate.inodev_set.i_hash[index];
67034 +
67035 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67036 + match = match->next;
67037 +
67038 + return match;
67039 +}
67040 +
67041 +void
67042 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67043 +{
67044 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67045 + state->inodev_set.i_size);
67046 + struct inodev_entry **curr;
67047 +
67048 + entry->prev = NULL;
67049 +
67050 + curr = &state->inodev_set.i_hash[index];
67051 + if (*curr != NULL)
67052 + (*curr)->prev = entry;
67053 +
67054 + entry->next = *curr;
67055 + *curr = entry;
67056 +
67057 + return;
67058 +}
67059 +
67060 +static void
67061 +insert_inodev_entry(struct inodev_entry *entry)
67062 +{
67063 + __insert_inodev_entry(&running_polstate, entry);
67064 +}
67065 +
67066 +void
67067 +insert_acl_obj_label(struct acl_object_label *obj,
67068 + struct acl_subject_label *subj)
67069 +{
67070 + unsigned int index =
67071 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67072 + struct acl_object_label **curr;
67073 +
67074 + obj->prev = NULL;
67075 +
67076 + curr = &subj->obj_hash[index];
67077 + if (*curr != NULL)
67078 + (*curr)->prev = obj;
67079 +
67080 + obj->next = *curr;
67081 + *curr = obj;
67082 +
67083 + return;
67084 +}
67085 +
67086 +void
67087 +insert_acl_subj_label(struct acl_subject_label *obj,
67088 + struct acl_role_label *role)
67089 +{
67090 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67091 + struct acl_subject_label **curr;
67092 +
67093 + obj->prev = NULL;
67094 +
67095 + curr = &role->subj_hash[index];
67096 + if (*curr != NULL)
67097 + (*curr)->prev = obj;
67098 +
67099 + obj->next = *curr;
67100 + *curr = obj;
67101 +
67102 + return;
67103 +}
67104 +
67105 +/* derived from glibc fnmatch() 0: match, 1: no match*/
67106 +
67107 +static int
67108 +glob_match(const char *p, const char *n)
67109 +{
67110 + char c;
67111 +
67112 + while ((c = *p++) != '\0') {
67113 + switch (c) {
67114 + case '?':
67115 + if (*n == '\0')
67116 + return 1;
67117 + else if (*n == '/')
67118 + return 1;
67119 + break;
67120 + case '\\':
67121 + if (*n != c)
67122 + return 1;
67123 + break;
67124 + case '*':
67125 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67126 + if (*n == '/')
67127 + return 1;
67128 + else if (c == '?') {
67129 + if (*n == '\0')
67130 + return 1;
67131 + else
67132 + ++n;
67133 + }
67134 + }
67135 + if (c == '\0') {
67136 + return 0;
67137 + } else {
67138 + const char *endp;
67139 +
67140 + if ((endp = strchr(n, '/')) == NULL)
67141 + endp = n + strlen(n);
67142 +
67143 + if (c == '[') {
67144 + for (--p; n < endp; ++n)
67145 + if (!glob_match(p, n))
67146 + return 0;
67147 + } else if (c == '/') {
67148 + while (*n != '\0' && *n != '/')
67149 + ++n;
67150 + if (*n == '/' && !glob_match(p, n + 1))
67151 + return 0;
67152 + } else {
67153 + for (--p; n < endp; ++n)
67154 + if (*n == c && !glob_match(p, n))
67155 + return 0;
67156 + }
67157 +
67158 + return 1;
67159 + }
67160 + case '[':
67161 + {
67162 + int not;
67163 + char cold;
67164 +
67165 + if (*n == '\0' || *n == '/')
67166 + return 1;
67167 +
67168 + not = (*p == '!' || *p == '^');
67169 + if (not)
67170 + ++p;
67171 +
67172 + c = *p++;
67173 + for (;;) {
67174 + unsigned char fn = (unsigned char)*n;
67175 +
67176 + if (c == '\0')
67177 + return 1;
67178 + else {
67179 + if (c == fn)
67180 + goto matched;
67181 + cold = c;
67182 + c = *p++;
67183 +
67184 + if (c == '-' && *p != ']') {
67185 + unsigned char cend = *p++;
67186 +
67187 + if (cend == '\0')
67188 + return 1;
67189 +
67190 + if (cold <= fn && fn <= cend)
67191 + goto matched;
67192 +
67193 + c = *p++;
67194 + }
67195 + }
67196 +
67197 + if (c == ']')
67198 + break;
67199 + }
67200 + if (!not)
67201 + return 1;
67202 + break;
67203 + matched:
67204 + while (c != ']') {
67205 + if (c == '\0')
67206 + return 1;
67207 +
67208 + c = *p++;
67209 + }
67210 + if (not)
67211 + return 1;
67212 + }
67213 + break;
67214 + default:
67215 + if (c != *n)
67216 + return 1;
67217 + }
67218 +
67219 + ++n;
67220 + }
67221 +
67222 + if (*n == '\0')
67223 + return 0;
67224 +
67225 + if (*n == '/')
67226 + return 0;
67227 +
67228 + return 1;
67229 +}
67230 +
67231 +static struct acl_object_label *
67232 +chk_glob_label(struct acl_object_label *globbed,
67233 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67234 +{
67235 + struct acl_object_label *tmp;
67236 +
67237 + if (*path == NULL)
67238 + *path = gr_to_filename_nolock(dentry, mnt);
67239 +
67240 + tmp = globbed;
67241 +
67242 + while (tmp) {
67243 + if (!glob_match(tmp->filename, *path))
67244 + return tmp;
67245 + tmp = tmp->next;
67246 + }
67247 +
67248 + return NULL;
67249 +}
67250 +
67251 +static struct acl_object_label *
67252 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67253 + const ino_t curr_ino, const dev_t curr_dev,
67254 + const struct acl_subject_label *subj, char **path, const int checkglob)
67255 +{
67256 + struct acl_subject_label *tmpsubj;
67257 + struct acl_object_label *retval;
67258 + struct acl_object_label *retval2;
67259 +
67260 + tmpsubj = (struct acl_subject_label *) subj;
67261 + read_lock(&gr_inode_lock);
67262 + do {
67263 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67264 + if (retval) {
67265 + if (checkglob && retval->globbed) {
67266 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67267 + if (retval2)
67268 + retval = retval2;
67269 + }
67270 + break;
67271 + }
67272 + } while ((tmpsubj = tmpsubj->parent_subject));
67273 + read_unlock(&gr_inode_lock);
67274 +
67275 + return retval;
67276 +}
67277 +
67278 +static __inline__ struct acl_object_label *
67279 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67280 + struct dentry *curr_dentry,
67281 + const struct acl_subject_label *subj, char **path, const int checkglob)
67282 +{
67283 + int newglob = checkglob;
67284 + ino_t inode;
67285 + dev_t device;
67286 +
67287 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67288 + as we don't want a / * rule to match instead of the / object
67289 + don't do this for create lookups that call this function though, since they're looking up
67290 + on the parent and thus need globbing checks on all paths
67291 + */
67292 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67293 + newglob = GR_NO_GLOB;
67294 +
67295 + spin_lock(&curr_dentry->d_lock);
67296 + inode = curr_dentry->d_inode->i_ino;
67297 + device = __get_dev(curr_dentry);
67298 + spin_unlock(&curr_dentry->d_lock);
67299 +
67300 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67301 +}
67302 +
67303 +#ifdef CONFIG_HUGETLBFS
67304 +static inline bool
67305 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67306 +{
67307 + int i;
67308 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67309 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67310 + return true;
67311 + }
67312 +
67313 + return false;
67314 +}
67315 +#endif
67316 +
67317 +static struct acl_object_label *
67318 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67319 + const struct acl_subject_label *subj, char *path, const int checkglob)
67320 +{
67321 + struct dentry *dentry = (struct dentry *) l_dentry;
67322 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67323 + struct mount *real_mnt = real_mount(mnt);
67324 + struct acl_object_label *retval;
67325 + struct dentry *parent;
67326 +
67327 + read_seqlock_excl(&mount_lock);
67328 + write_seqlock(&rename_lock);
67329 +
67330 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67331 +#ifdef CONFIG_NET
67332 + mnt == sock_mnt ||
67333 +#endif
67334 +#ifdef CONFIG_HUGETLBFS
67335 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67336 +#endif
67337 + /* ignore Eric Biederman */
67338 + IS_PRIVATE(l_dentry->d_inode))) {
67339 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67340 + goto out;
67341 + }
67342 +
67343 + for (;;) {
67344 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67345 + break;
67346 +
67347 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67348 + if (!mnt_has_parent(real_mnt))
67349 + break;
67350 +
67351 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67352 + if (retval != NULL)
67353 + goto out;
67354 +
67355 + dentry = real_mnt->mnt_mountpoint;
67356 + real_mnt = real_mnt->mnt_parent;
67357 + mnt = &real_mnt->mnt;
67358 + continue;
67359 + }
67360 +
67361 + parent = dentry->d_parent;
67362 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67363 + if (retval != NULL)
67364 + goto out;
67365 +
67366 + dentry = parent;
67367 + }
67368 +
67369 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67370 +
67371 + /* gr_real_root is pinned so we don't have to hold a reference */
67372 + if (retval == NULL)
67373 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67374 +out:
67375 + write_sequnlock(&rename_lock);
67376 + read_sequnlock_excl(&mount_lock);
67377 +
67378 + BUG_ON(retval == NULL);
67379 +
67380 + return retval;
67381 +}
67382 +
67383 +static __inline__ struct acl_object_label *
67384 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67385 + const struct acl_subject_label *subj)
67386 +{
67387 + char *path = NULL;
67388 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67389 +}
67390 +
67391 +static __inline__ struct acl_object_label *
67392 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67393 + const struct acl_subject_label *subj)
67394 +{
67395 + char *path = NULL;
67396 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67397 +}
67398 +
67399 +static __inline__ struct acl_object_label *
67400 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67401 + const struct acl_subject_label *subj, char *path)
67402 +{
67403 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67404 +}
67405 +
67406 +struct acl_subject_label *
67407 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67408 + const struct acl_role_label *role)
67409 +{
67410 + struct dentry *dentry = (struct dentry *) l_dentry;
67411 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67412 + struct mount *real_mnt = real_mount(mnt);
67413 + struct acl_subject_label *retval;
67414 + struct dentry *parent;
67415 +
67416 + read_seqlock_excl(&mount_lock);
67417 + write_seqlock(&rename_lock);
67418 +
67419 + for (;;) {
67420 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67421 + break;
67422 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67423 + if (!mnt_has_parent(real_mnt))
67424 + break;
67425 +
67426 + spin_lock(&dentry->d_lock);
67427 + read_lock(&gr_inode_lock);
67428 + retval =
67429 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67430 + __get_dev(dentry), role);
67431 + read_unlock(&gr_inode_lock);
67432 + spin_unlock(&dentry->d_lock);
67433 + if (retval != NULL)
67434 + goto out;
67435 +
67436 + dentry = real_mnt->mnt_mountpoint;
67437 + real_mnt = real_mnt->mnt_parent;
67438 + mnt = &real_mnt->mnt;
67439 + continue;
67440 + }
67441 +
67442 + spin_lock(&dentry->d_lock);
67443 + read_lock(&gr_inode_lock);
67444 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67445 + __get_dev(dentry), role);
67446 + read_unlock(&gr_inode_lock);
67447 + parent = dentry->d_parent;
67448 + spin_unlock(&dentry->d_lock);
67449 +
67450 + if (retval != NULL)
67451 + goto out;
67452 +
67453 + dentry = parent;
67454 + }
67455 +
67456 + spin_lock(&dentry->d_lock);
67457 + read_lock(&gr_inode_lock);
67458 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67459 + __get_dev(dentry), role);
67460 + read_unlock(&gr_inode_lock);
67461 + spin_unlock(&dentry->d_lock);
67462 +
67463 + if (unlikely(retval == NULL)) {
67464 + /* gr_real_root is pinned, we don't need to hold a reference */
67465 + read_lock(&gr_inode_lock);
67466 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67467 + __get_dev(gr_real_root.dentry), role);
67468 + read_unlock(&gr_inode_lock);
67469 + }
67470 +out:
67471 + write_sequnlock(&rename_lock);
67472 + read_sequnlock_excl(&mount_lock);
67473 +
67474 + BUG_ON(retval == NULL);
67475 +
67476 + return retval;
67477 +}
67478 +
67479 +void
67480 +assign_special_role(const char *rolename)
67481 +{
67482 + struct acl_object_label *obj;
67483 + struct acl_role_label *r;
67484 + struct acl_role_label *assigned = NULL;
67485 + struct task_struct *tsk;
67486 + struct file *filp;
67487 +
67488 + FOR_EACH_ROLE_START(r)
67489 + if (!strcmp(rolename, r->rolename) &&
67490 + (r->roletype & GR_ROLE_SPECIAL)) {
67491 + assigned = r;
67492 + break;
67493 + }
67494 + FOR_EACH_ROLE_END(r)
67495 +
67496 + if (!assigned)
67497 + return;
67498 +
67499 + read_lock(&tasklist_lock);
67500 + read_lock(&grsec_exec_file_lock);
67501 +
67502 + tsk = current->real_parent;
67503 + if (tsk == NULL)
67504 + goto out_unlock;
67505 +
67506 + filp = tsk->exec_file;
67507 + if (filp == NULL)
67508 + goto out_unlock;
67509 +
67510 + tsk->is_writable = 0;
67511 + tsk->inherited = 0;
67512 +
67513 + tsk->acl_sp_role = 1;
67514 + tsk->acl_role_id = ++acl_sp_role_value;
67515 + tsk->role = assigned;
67516 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67517 +
67518 + /* ignore additional mmap checks for processes that are writable
67519 + by the default ACL */
67520 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67521 + if (unlikely(obj->mode & GR_WRITE))
67522 + tsk->is_writable = 1;
67523 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67524 + if (unlikely(obj->mode & GR_WRITE))
67525 + tsk->is_writable = 1;
67526 +
67527 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67528 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67529 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67530 +#endif
67531 +
67532 +out_unlock:
67533 + read_unlock(&grsec_exec_file_lock);
67534 + read_unlock(&tasklist_lock);
67535 + return;
67536 +}
67537 +
67538 +
67539 +static void
67540 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67541 +{
67542 + struct task_struct *task = current;
67543 + const struct cred *cred = current_cred();
67544 +
67545 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67546 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67547 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67548 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67549 +
67550 + return;
67551 +}
67552 +
67553 +static void
67554 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67555 +{
67556 + struct task_struct *task = current;
67557 + const struct cred *cred = current_cred();
67558 +
67559 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67560 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67561 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67562 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67563 +
67564 + return;
67565 +}
67566 +
67567 +static void
67568 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67569 +{
67570 + struct task_struct *task = current;
67571 + const struct cred *cred = current_cred();
67572 +
67573 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67574 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67575 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67576 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67577 +
67578 + return;
67579 +}
67580 +
67581 +static void
67582 +gr_set_proc_res(struct task_struct *task)
67583 +{
67584 + struct acl_subject_label *proc;
67585 + unsigned short i;
67586 +
67587 + proc = task->acl;
67588 +
67589 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67590 + return;
67591 +
67592 + for (i = 0; i < RLIM_NLIMITS; i++) {
67593 + if (!(proc->resmask & (1U << i)))
67594 + continue;
67595 +
67596 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67597 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67598 +
67599 + if (i == RLIMIT_CPU)
67600 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
67601 + }
67602 +
67603 + return;
67604 +}
67605 +
67606 +/* both of the below must be called with
67607 + rcu_read_lock();
67608 + read_lock(&tasklist_lock);
67609 + read_lock(&grsec_exec_file_lock);
67610 +*/
67611 +
67612 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67613 +{
67614 + char *tmpname;
67615 + struct acl_subject_label *tmpsubj;
67616 + struct file *filp;
67617 + struct name_entry *nmatch;
67618 +
67619 + filp = task->exec_file;
67620 + if (filp == NULL)
67621 + return NULL;
67622 +
67623 + /* the following is to apply the correct subject
67624 + on binaries running when the RBAC system
67625 + is enabled, when the binaries have been
67626 + replaced or deleted since their execution
67627 + -----
67628 + when the RBAC system starts, the inode/dev
67629 + from exec_file will be one the RBAC system
67630 + is unaware of. It only knows the inode/dev
67631 + of the present file on disk, or the absence
67632 + of it.
67633 + */
67634 +
67635 + if (filename)
67636 + nmatch = __lookup_name_entry(state, filename);
67637 + else {
67638 + preempt_disable();
67639 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67640 +
67641 + nmatch = __lookup_name_entry(state, tmpname);
67642 + preempt_enable();
67643 + }
67644 + tmpsubj = NULL;
67645 + if (nmatch) {
67646 + if (nmatch->deleted)
67647 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67648 + else
67649 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67650 + }
67651 + /* this also works for the reload case -- if we don't match a potentially inherited subject
67652 + then we fall back to a normal lookup based on the binary's ino/dev
67653 + */
67654 + if (tmpsubj == NULL)
67655 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67656 +
67657 + return tmpsubj;
67658 +}
67659 +
67660 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67661 +{
67662 + return __gr_get_subject_for_task(&running_polstate, task, filename);
67663 +}
67664 +
67665 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67666 +{
67667 + struct acl_object_label *obj;
67668 + struct file *filp;
67669 +
67670 + filp = task->exec_file;
67671 +
67672 + task->acl = subj;
67673 + task->is_writable = 0;
67674 + /* ignore additional mmap checks for processes that are writable
67675 + by the default ACL */
67676 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67677 + if (unlikely(obj->mode & GR_WRITE))
67678 + task->is_writable = 1;
67679 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67680 + if (unlikely(obj->mode & GR_WRITE))
67681 + task->is_writable = 1;
67682 +
67683 + gr_set_proc_res(task);
67684 +
67685 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67686 + 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);
67687 +#endif
67688 +}
67689 +
67690 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67691 +{
67692 + __gr_apply_subject_to_task(&running_polstate, task, subj);
67693 +}
67694 +
67695 +__u32
67696 +gr_search_file(const struct dentry * dentry, const __u32 mode,
67697 + const struct vfsmount * mnt)
67698 +{
67699 + __u32 retval = mode;
67700 + struct acl_subject_label *curracl;
67701 + struct acl_object_label *currobj;
67702 +
67703 + if (unlikely(!(gr_status & GR_READY)))
67704 + return (mode & ~GR_AUDITS);
67705 +
67706 + curracl = current->acl;
67707 +
67708 + currobj = chk_obj_label(dentry, mnt, curracl);
67709 + retval = currobj->mode & mode;
67710 +
67711 + /* if we're opening a specified transfer file for writing
67712 + (e.g. /dev/initctl), then transfer our role to init
67713 + */
67714 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67715 + current->role->roletype & GR_ROLE_PERSIST)) {
67716 + struct task_struct *task = init_pid_ns.child_reaper;
67717 +
67718 + if (task->role != current->role) {
67719 + struct acl_subject_label *subj;
67720 +
67721 + task->acl_sp_role = 0;
67722 + task->acl_role_id = current->acl_role_id;
67723 + task->role = current->role;
67724 + rcu_read_lock();
67725 + read_lock(&grsec_exec_file_lock);
67726 + subj = gr_get_subject_for_task(task, NULL);
67727 + gr_apply_subject_to_task(task, subj);
67728 + read_unlock(&grsec_exec_file_lock);
67729 + rcu_read_unlock();
67730 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67731 + }
67732 + }
67733 +
67734 + if (unlikely
67735 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67736 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67737 + __u32 new_mode = mode;
67738 +
67739 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67740 +
67741 + retval = new_mode;
67742 +
67743 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67744 + new_mode |= GR_INHERIT;
67745 +
67746 + if (!(mode & GR_NOLEARN))
67747 + gr_log_learn(dentry, mnt, new_mode);
67748 + }
67749 +
67750 + return retval;
67751 +}
67752 +
67753 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67754 + const struct dentry *parent,
67755 + const struct vfsmount *mnt)
67756 +{
67757 + struct name_entry *match;
67758 + struct acl_object_label *matchpo;
67759 + struct acl_subject_label *curracl;
67760 + char *path;
67761 +
67762 + if (unlikely(!(gr_status & GR_READY)))
67763 + return NULL;
67764 +
67765 + preempt_disable();
67766 + path = gr_to_filename_rbac(new_dentry, mnt);
67767 + match = lookup_name_entry_create(path);
67768 +
67769 + curracl = current->acl;
67770 +
67771 + if (match) {
67772 + read_lock(&gr_inode_lock);
67773 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67774 + read_unlock(&gr_inode_lock);
67775 +
67776 + if (matchpo) {
67777 + preempt_enable();
67778 + return matchpo;
67779 + }
67780 + }
67781 +
67782 + // lookup parent
67783 +
67784 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67785 +
67786 + preempt_enable();
67787 + return matchpo;
67788 +}
67789 +
67790 +__u32
67791 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67792 + const struct vfsmount * mnt, const __u32 mode)
67793 +{
67794 + struct acl_object_label *matchpo;
67795 + __u32 retval;
67796 +
67797 + if (unlikely(!(gr_status & GR_READY)))
67798 + return (mode & ~GR_AUDITS);
67799 +
67800 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
67801 +
67802 + retval = matchpo->mode & mode;
67803 +
67804 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67805 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67806 + __u32 new_mode = mode;
67807 +
67808 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67809 +
67810 + gr_log_learn(new_dentry, mnt, new_mode);
67811 + return new_mode;
67812 + }
67813 +
67814 + return retval;
67815 +}
67816 +
67817 +__u32
67818 +gr_check_link(const struct dentry * new_dentry,
67819 + const struct dentry * parent_dentry,
67820 + const struct vfsmount * parent_mnt,
67821 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67822 +{
67823 + struct acl_object_label *obj;
67824 + __u32 oldmode, newmode;
67825 + __u32 needmode;
67826 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67827 + GR_DELETE | GR_INHERIT;
67828 +
67829 + if (unlikely(!(gr_status & GR_READY)))
67830 + return (GR_CREATE | GR_LINK);
67831 +
67832 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67833 + oldmode = obj->mode;
67834 +
67835 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67836 + newmode = obj->mode;
67837 +
67838 + needmode = newmode & checkmodes;
67839 +
67840 + // old name for hardlink must have at least the permissions of the new name
67841 + if ((oldmode & needmode) != needmode)
67842 + goto bad;
67843 +
67844 + // if old name had restrictions/auditing, make sure the new name does as well
67845 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67846 +
67847 + // don't allow hardlinking of suid/sgid/fcapped files without permission
67848 + if (is_privileged_binary(old_dentry))
67849 + needmode |= GR_SETID;
67850 +
67851 + if ((newmode & needmode) != needmode)
67852 + goto bad;
67853 +
67854 + // enforce minimum permissions
67855 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67856 + return newmode;
67857 +bad:
67858 + needmode = oldmode;
67859 + if (is_privileged_binary(old_dentry))
67860 + needmode |= GR_SETID;
67861 +
67862 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67863 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67864 + return (GR_CREATE | GR_LINK);
67865 + } else if (newmode & GR_SUPPRESS)
67866 + return GR_SUPPRESS;
67867 + else
67868 + return 0;
67869 +}
67870 +
67871 +int
67872 +gr_check_hidden_task(const struct task_struct *task)
67873 +{
67874 + if (unlikely(!(gr_status & GR_READY)))
67875 + return 0;
67876 +
67877 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67878 + return 1;
67879 +
67880 + return 0;
67881 +}
67882 +
67883 +int
67884 +gr_check_protected_task(const struct task_struct *task)
67885 +{
67886 + if (unlikely(!(gr_status & GR_READY) || !task))
67887 + return 0;
67888 +
67889 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67890 + task->acl != current->acl)
67891 + return 1;
67892 +
67893 + return 0;
67894 +}
67895 +
67896 +int
67897 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67898 +{
67899 + struct task_struct *p;
67900 + int ret = 0;
67901 +
67902 + if (unlikely(!(gr_status & GR_READY) || !pid))
67903 + return ret;
67904 +
67905 + read_lock(&tasklist_lock);
67906 + do_each_pid_task(pid, type, p) {
67907 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67908 + p->acl != current->acl) {
67909 + ret = 1;
67910 + goto out;
67911 + }
67912 + } while_each_pid_task(pid, type, p);
67913 +out:
67914 + read_unlock(&tasklist_lock);
67915 +
67916 + return ret;
67917 +}
67918 +
67919 +void
67920 +gr_copy_label(struct task_struct *tsk)
67921 +{
67922 + struct task_struct *p = current;
67923 +
67924 + tsk->inherited = p->inherited;
67925 + tsk->acl_sp_role = 0;
67926 + tsk->acl_role_id = p->acl_role_id;
67927 + tsk->acl = p->acl;
67928 + tsk->role = p->role;
67929 + tsk->signal->used_accept = 0;
67930 + tsk->signal->curr_ip = p->signal->curr_ip;
67931 + tsk->signal->saved_ip = p->signal->saved_ip;
67932 + if (p->exec_file)
67933 + get_file(p->exec_file);
67934 + tsk->exec_file = p->exec_file;
67935 + tsk->is_writable = p->is_writable;
67936 + if (unlikely(p->signal->used_accept)) {
67937 + p->signal->curr_ip = 0;
67938 + p->signal->saved_ip = 0;
67939 + }
67940 +
67941 + return;
67942 +}
67943 +
67944 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67945 +
67946 +int
67947 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67948 +{
67949 + unsigned int i;
67950 + __u16 num;
67951 + uid_t *uidlist;
67952 + uid_t curuid;
67953 + int realok = 0;
67954 + int effectiveok = 0;
67955 + int fsok = 0;
67956 + uid_t globalreal, globaleffective, globalfs;
67957 +
67958 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67959 + struct user_struct *user;
67960 +
67961 + if (!uid_valid(real))
67962 + goto skipit;
67963 +
67964 + /* find user based on global namespace */
67965 +
67966 + globalreal = GR_GLOBAL_UID(real);
67967 +
67968 + user = find_user(make_kuid(&init_user_ns, globalreal));
67969 + if (user == NULL)
67970 + goto skipit;
67971 +
67972 + if (gr_process_kernel_setuid_ban(user)) {
67973 + /* for find_user */
67974 + free_uid(user);
67975 + return 1;
67976 + }
67977 +
67978 + /* for find_user */
67979 + free_uid(user);
67980 +
67981 +skipit:
67982 +#endif
67983 +
67984 + if (unlikely(!(gr_status & GR_READY)))
67985 + return 0;
67986 +
67987 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67988 + gr_log_learn_uid_change(real, effective, fs);
67989 +
67990 + num = current->acl->user_trans_num;
67991 + uidlist = current->acl->user_transitions;
67992 +
67993 + if (uidlist == NULL)
67994 + return 0;
67995 +
67996 + if (!uid_valid(real)) {
67997 + realok = 1;
67998 + globalreal = (uid_t)-1;
67999 + } else {
68000 + globalreal = GR_GLOBAL_UID(real);
68001 + }
68002 + if (!uid_valid(effective)) {
68003 + effectiveok = 1;
68004 + globaleffective = (uid_t)-1;
68005 + } else {
68006 + globaleffective = GR_GLOBAL_UID(effective);
68007 + }
68008 + if (!uid_valid(fs)) {
68009 + fsok = 1;
68010 + globalfs = (uid_t)-1;
68011 + } else {
68012 + globalfs = GR_GLOBAL_UID(fs);
68013 + }
68014 +
68015 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
68016 + for (i = 0; i < num; i++) {
68017 + curuid = uidlist[i];
68018 + if (globalreal == curuid)
68019 + realok = 1;
68020 + if (globaleffective == curuid)
68021 + effectiveok = 1;
68022 + if (globalfs == curuid)
68023 + fsok = 1;
68024 + }
68025 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
68026 + for (i = 0; i < num; i++) {
68027 + curuid = uidlist[i];
68028 + if (globalreal == curuid)
68029 + break;
68030 + if (globaleffective == curuid)
68031 + break;
68032 + if (globalfs == curuid)
68033 + break;
68034 + }
68035 + /* not in deny list */
68036 + if (i == num) {
68037 + realok = 1;
68038 + effectiveok = 1;
68039 + fsok = 1;
68040 + }
68041 + }
68042 +
68043 + if (realok && effectiveok && fsok)
68044 + return 0;
68045 + else {
68046 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68047 + return 1;
68048 + }
68049 +}
68050 +
68051 +int
68052 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68053 +{
68054 + unsigned int i;
68055 + __u16 num;
68056 + gid_t *gidlist;
68057 + gid_t curgid;
68058 + int realok = 0;
68059 + int effectiveok = 0;
68060 + int fsok = 0;
68061 + gid_t globalreal, globaleffective, globalfs;
68062 +
68063 + if (unlikely(!(gr_status & GR_READY)))
68064 + return 0;
68065 +
68066 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68067 + gr_log_learn_gid_change(real, effective, fs);
68068 +
68069 + num = current->acl->group_trans_num;
68070 + gidlist = current->acl->group_transitions;
68071 +
68072 + if (gidlist == NULL)
68073 + return 0;
68074 +
68075 + if (!gid_valid(real)) {
68076 + realok = 1;
68077 + globalreal = (gid_t)-1;
68078 + } else {
68079 + globalreal = GR_GLOBAL_GID(real);
68080 + }
68081 + if (!gid_valid(effective)) {
68082 + effectiveok = 1;
68083 + globaleffective = (gid_t)-1;
68084 + } else {
68085 + globaleffective = GR_GLOBAL_GID(effective);
68086 + }
68087 + if (!gid_valid(fs)) {
68088 + fsok = 1;
68089 + globalfs = (gid_t)-1;
68090 + } else {
68091 + globalfs = GR_GLOBAL_GID(fs);
68092 + }
68093 +
68094 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
68095 + for (i = 0; i < num; i++) {
68096 + curgid = gidlist[i];
68097 + if (globalreal == curgid)
68098 + realok = 1;
68099 + if (globaleffective == curgid)
68100 + effectiveok = 1;
68101 + if (globalfs == curgid)
68102 + fsok = 1;
68103 + }
68104 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
68105 + for (i = 0; i < num; i++) {
68106 + curgid = gidlist[i];
68107 + if (globalreal == curgid)
68108 + break;
68109 + if (globaleffective == curgid)
68110 + break;
68111 + if (globalfs == curgid)
68112 + break;
68113 + }
68114 + /* not in deny list */
68115 + if (i == num) {
68116 + realok = 1;
68117 + effectiveok = 1;
68118 + fsok = 1;
68119 + }
68120 + }
68121 +
68122 + if (realok && effectiveok && fsok)
68123 + return 0;
68124 + else {
68125 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68126 + return 1;
68127 + }
68128 +}
68129 +
68130 +extern int gr_acl_is_capable(const int cap);
68131 +
68132 +void
68133 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68134 +{
68135 + struct acl_role_label *role = task->role;
68136 + struct acl_subject_label *subj = NULL;
68137 + struct acl_object_label *obj;
68138 + struct file *filp;
68139 + uid_t uid;
68140 + gid_t gid;
68141 +
68142 + if (unlikely(!(gr_status & GR_READY)))
68143 + return;
68144 +
68145 + uid = GR_GLOBAL_UID(kuid);
68146 + gid = GR_GLOBAL_GID(kgid);
68147 +
68148 + filp = task->exec_file;
68149 +
68150 + /* kernel process, we'll give them the kernel role */
68151 + if (unlikely(!filp)) {
68152 + task->role = running_polstate.kernel_role;
68153 + task->acl = running_polstate.kernel_role->root_label;
68154 + return;
68155 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68156 + /* save the current ip at time of role lookup so that the proper
68157 + IP will be learned for role_allowed_ip */
68158 + task->signal->saved_ip = task->signal->curr_ip;
68159 + role = lookup_acl_role_label(task, uid, gid);
68160 + }
68161 +
68162 + /* don't change the role if we're not a privileged process */
68163 + if (role && task->role != role &&
68164 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68165 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68166 + return;
68167 +
68168 + /* perform subject lookup in possibly new role
68169 + we can use this result below in the case where role == task->role
68170 + */
68171 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68172 +
68173 + /* if we changed uid/gid, but result in the same role
68174 + and are using inheritance, don't lose the inherited subject
68175 + if current subject is other than what normal lookup
68176 + would result in, we arrived via inheritance, don't
68177 + lose subject
68178 + */
68179 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68180 + (subj == task->acl)))
68181 + task->acl = subj;
68182 +
68183 + /* leave task->inherited unaffected */
68184 +
68185 + task->role = role;
68186 +
68187 + task->is_writable = 0;
68188 +
68189 + /* ignore additional mmap checks for processes that are writable
68190 + by the default ACL */
68191 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68192 + if (unlikely(obj->mode & GR_WRITE))
68193 + task->is_writable = 1;
68194 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68195 + if (unlikely(obj->mode & GR_WRITE))
68196 + task->is_writable = 1;
68197 +
68198 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68199 + 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);
68200 +#endif
68201 +
68202 + gr_set_proc_res(task);
68203 +
68204 + return;
68205 +}
68206 +
68207 +int
68208 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68209 + const int unsafe_flags)
68210 +{
68211 + struct task_struct *task = current;
68212 + struct acl_subject_label *newacl;
68213 + struct acl_object_label *obj;
68214 + __u32 retmode;
68215 +
68216 + if (unlikely(!(gr_status & GR_READY)))
68217 + return 0;
68218 +
68219 + newacl = chk_subj_label(dentry, mnt, task->role);
68220 +
68221 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68222 + did an exec
68223 + */
68224 + rcu_read_lock();
68225 + read_lock(&tasklist_lock);
68226 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68227 + (task->parent->acl->mode & GR_POVERRIDE))) {
68228 + read_unlock(&tasklist_lock);
68229 + rcu_read_unlock();
68230 + goto skip_check;
68231 + }
68232 + read_unlock(&tasklist_lock);
68233 + rcu_read_unlock();
68234 +
68235 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68236 + !(task->role->roletype & GR_ROLE_GOD) &&
68237 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68238 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68239 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68240 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68241 + else
68242 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68243 + return -EACCES;
68244 + }
68245 +
68246 +skip_check:
68247 +
68248 + obj = chk_obj_label(dentry, mnt, task->acl);
68249 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68250 +
68251 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68252 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68253 + if (obj->nested)
68254 + task->acl = obj->nested;
68255 + else
68256 + task->acl = newacl;
68257 + task->inherited = 0;
68258 + } else {
68259 + task->inherited = 1;
68260 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68261 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68262 + }
68263 +
68264 + task->is_writable = 0;
68265 +
68266 + /* ignore additional mmap checks for processes that are writable
68267 + by the default ACL */
68268 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68269 + if (unlikely(obj->mode & GR_WRITE))
68270 + task->is_writable = 1;
68271 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68272 + if (unlikely(obj->mode & GR_WRITE))
68273 + task->is_writable = 1;
68274 +
68275 + gr_set_proc_res(task);
68276 +
68277 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68278 + 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);
68279 +#endif
68280 + return 0;
68281 +}
68282 +
68283 +/* always called with valid inodev ptr */
68284 +static void
68285 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68286 +{
68287 + struct acl_object_label *matchpo;
68288 + struct acl_subject_label *matchps;
68289 + struct acl_subject_label *subj;
68290 + struct acl_role_label *role;
68291 + unsigned int x;
68292 +
68293 + FOR_EACH_ROLE_START(role)
68294 + FOR_EACH_SUBJECT_START(role, subj, x)
68295 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68296 + matchpo->mode |= GR_DELETED;
68297 + FOR_EACH_SUBJECT_END(subj,x)
68298 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68299 + /* nested subjects aren't in the role's subj_hash table */
68300 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68301 + matchpo->mode |= GR_DELETED;
68302 + FOR_EACH_NESTED_SUBJECT_END(subj)
68303 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68304 + matchps->mode |= GR_DELETED;
68305 + FOR_EACH_ROLE_END(role)
68306 +
68307 + inodev->nentry->deleted = 1;
68308 +
68309 + return;
68310 +}
68311 +
68312 +void
68313 +gr_handle_delete(const ino_t ino, const dev_t dev)
68314 +{
68315 + struct inodev_entry *inodev;
68316 +
68317 + if (unlikely(!(gr_status & GR_READY)))
68318 + return;
68319 +
68320 + write_lock(&gr_inode_lock);
68321 + inodev = lookup_inodev_entry(ino, dev);
68322 + if (inodev != NULL)
68323 + do_handle_delete(inodev, ino, dev);
68324 + write_unlock(&gr_inode_lock);
68325 +
68326 + return;
68327 +}
68328 +
68329 +static void
68330 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68331 + const ino_t newinode, const dev_t newdevice,
68332 + struct acl_subject_label *subj)
68333 +{
68334 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68335 + struct acl_object_label *match;
68336 +
68337 + match = subj->obj_hash[index];
68338 +
68339 + while (match && (match->inode != oldinode ||
68340 + match->device != olddevice ||
68341 + !(match->mode & GR_DELETED)))
68342 + match = match->next;
68343 +
68344 + if (match && (match->inode == oldinode)
68345 + && (match->device == olddevice)
68346 + && (match->mode & GR_DELETED)) {
68347 + if (match->prev == NULL) {
68348 + subj->obj_hash[index] = match->next;
68349 + if (match->next != NULL)
68350 + match->next->prev = NULL;
68351 + } else {
68352 + match->prev->next = match->next;
68353 + if (match->next != NULL)
68354 + match->next->prev = match->prev;
68355 + }
68356 + match->prev = NULL;
68357 + match->next = NULL;
68358 + match->inode = newinode;
68359 + match->device = newdevice;
68360 + match->mode &= ~GR_DELETED;
68361 +
68362 + insert_acl_obj_label(match, subj);
68363 + }
68364 +
68365 + return;
68366 +}
68367 +
68368 +static void
68369 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68370 + const ino_t newinode, const dev_t newdevice,
68371 + struct acl_role_label *role)
68372 +{
68373 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68374 + struct acl_subject_label *match;
68375 +
68376 + match = role->subj_hash[index];
68377 +
68378 + while (match && (match->inode != oldinode ||
68379 + match->device != olddevice ||
68380 + !(match->mode & GR_DELETED)))
68381 + match = match->next;
68382 +
68383 + if (match && (match->inode == oldinode)
68384 + && (match->device == olddevice)
68385 + && (match->mode & GR_DELETED)) {
68386 + if (match->prev == NULL) {
68387 + role->subj_hash[index] = match->next;
68388 + if (match->next != NULL)
68389 + match->next->prev = NULL;
68390 + } else {
68391 + match->prev->next = match->next;
68392 + if (match->next != NULL)
68393 + match->next->prev = match->prev;
68394 + }
68395 + match->prev = NULL;
68396 + match->next = NULL;
68397 + match->inode = newinode;
68398 + match->device = newdevice;
68399 + match->mode &= ~GR_DELETED;
68400 +
68401 + insert_acl_subj_label(match, role);
68402 + }
68403 +
68404 + return;
68405 +}
68406 +
68407 +static void
68408 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68409 + const ino_t newinode, const dev_t newdevice)
68410 +{
68411 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68412 + struct inodev_entry *match;
68413 +
68414 + match = running_polstate.inodev_set.i_hash[index];
68415 +
68416 + while (match && (match->nentry->inode != oldinode ||
68417 + match->nentry->device != olddevice || !match->nentry->deleted))
68418 + match = match->next;
68419 +
68420 + if (match && (match->nentry->inode == oldinode)
68421 + && (match->nentry->device == olddevice) &&
68422 + match->nentry->deleted) {
68423 + if (match->prev == NULL) {
68424 + running_polstate.inodev_set.i_hash[index] = match->next;
68425 + if (match->next != NULL)
68426 + match->next->prev = NULL;
68427 + } else {
68428 + match->prev->next = match->next;
68429 + if (match->next != NULL)
68430 + match->next->prev = match->prev;
68431 + }
68432 + match->prev = NULL;
68433 + match->next = NULL;
68434 + match->nentry->inode = newinode;
68435 + match->nentry->device = newdevice;
68436 + match->nentry->deleted = 0;
68437 +
68438 + insert_inodev_entry(match);
68439 + }
68440 +
68441 + return;
68442 +}
68443 +
68444 +static void
68445 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68446 +{
68447 + struct acl_subject_label *subj;
68448 + struct acl_role_label *role;
68449 + unsigned int x;
68450 +
68451 + FOR_EACH_ROLE_START(role)
68452 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68453 +
68454 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68455 + if ((subj->inode == ino) && (subj->device == dev)) {
68456 + subj->inode = ino;
68457 + subj->device = dev;
68458 + }
68459 + /* nested subjects aren't in the role's subj_hash table */
68460 + update_acl_obj_label(matchn->inode, matchn->device,
68461 + ino, dev, subj);
68462 + FOR_EACH_NESTED_SUBJECT_END(subj)
68463 + FOR_EACH_SUBJECT_START(role, subj, x)
68464 + update_acl_obj_label(matchn->inode, matchn->device,
68465 + ino, dev, subj);
68466 + FOR_EACH_SUBJECT_END(subj,x)
68467 + FOR_EACH_ROLE_END(role)
68468 +
68469 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68470 +
68471 + return;
68472 +}
68473 +
68474 +static void
68475 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68476 + const struct vfsmount *mnt)
68477 +{
68478 + ino_t ino = dentry->d_inode->i_ino;
68479 + dev_t dev = __get_dev(dentry);
68480 +
68481 + __do_handle_create(matchn, ino, dev);
68482 +
68483 + return;
68484 +}
68485 +
68486 +void
68487 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68488 +{
68489 + struct name_entry *matchn;
68490 +
68491 + if (unlikely(!(gr_status & GR_READY)))
68492 + return;
68493 +
68494 + preempt_disable();
68495 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68496 +
68497 + if (unlikely((unsigned long)matchn)) {
68498 + write_lock(&gr_inode_lock);
68499 + do_handle_create(matchn, dentry, mnt);
68500 + write_unlock(&gr_inode_lock);
68501 + }
68502 + preempt_enable();
68503 +
68504 + return;
68505 +}
68506 +
68507 +void
68508 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68509 +{
68510 + struct name_entry *matchn;
68511 +
68512 + if (unlikely(!(gr_status & GR_READY)))
68513 + return;
68514 +
68515 + preempt_disable();
68516 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68517 +
68518 + if (unlikely((unsigned long)matchn)) {
68519 + write_lock(&gr_inode_lock);
68520 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68521 + write_unlock(&gr_inode_lock);
68522 + }
68523 + preempt_enable();
68524 +
68525 + return;
68526 +}
68527 +
68528 +void
68529 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68530 + struct dentry *old_dentry,
68531 + struct dentry *new_dentry,
68532 + struct vfsmount *mnt, const __u8 replace)
68533 +{
68534 + struct name_entry *matchn;
68535 + struct inodev_entry *inodev;
68536 + struct inode *inode = new_dentry->d_inode;
68537 + ino_t old_ino = old_dentry->d_inode->i_ino;
68538 + dev_t old_dev = __get_dev(old_dentry);
68539 +
68540 + /* vfs_rename swaps the name and parent link for old_dentry and
68541 + new_dentry
68542 + at this point, old_dentry has the new name, parent link, and inode
68543 + for the renamed file
68544 + if a file is being replaced by a rename, new_dentry has the inode
68545 + and name for the replaced file
68546 + */
68547 +
68548 + if (unlikely(!(gr_status & GR_READY)))
68549 + return;
68550 +
68551 + preempt_disable();
68552 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68553 +
68554 + /* we wouldn't have to check d_inode if it weren't for
68555 + NFS silly-renaming
68556 + */
68557 +
68558 + write_lock(&gr_inode_lock);
68559 + if (unlikely(replace && inode)) {
68560 + ino_t new_ino = inode->i_ino;
68561 + dev_t new_dev = __get_dev(new_dentry);
68562 +
68563 + inodev = lookup_inodev_entry(new_ino, new_dev);
68564 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68565 + do_handle_delete(inodev, new_ino, new_dev);
68566 + }
68567 +
68568 + inodev = lookup_inodev_entry(old_ino, old_dev);
68569 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68570 + do_handle_delete(inodev, old_ino, old_dev);
68571 +
68572 + if (unlikely((unsigned long)matchn))
68573 + do_handle_create(matchn, old_dentry, mnt);
68574 +
68575 + write_unlock(&gr_inode_lock);
68576 + preempt_enable();
68577 +
68578 + return;
68579 +}
68580 +
68581 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68582 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68583 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68584 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68585 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68586 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68587 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68588 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68589 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68590 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68591 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68592 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68593 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68594 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68595 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68596 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68597 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68598 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68599 +};
68600 +
68601 +void
68602 +gr_learn_resource(const struct task_struct *task,
68603 + const int res, const unsigned long wanted, const int gt)
68604 +{
68605 + struct acl_subject_label *acl;
68606 + const struct cred *cred;
68607 +
68608 + if (unlikely((gr_status & GR_READY) &&
68609 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68610 + goto skip_reslog;
68611 +
68612 + gr_log_resource(task, res, wanted, gt);
68613 +skip_reslog:
68614 +
68615 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68616 + return;
68617 +
68618 + acl = task->acl;
68619 +
68620 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68621 + !(acl->resmask & (1U << (unsigned short) res))))
68622 + return;
68623 +
68624 + if (wanted >= acl->res[res].rlim_cur) {
68625 + unsigned long res_add;
68626 +
68627 + res_add = wanted + res_learn_bumps[res];
68628 +
68629 + acl->res[res].rlim_cur = res_add;
68630 +
68631 + if (wanted > acl->res[res].rlim_max)
68632 + acl->res[res].rlim_max = res_add;
68633 +
68634 + /* only log the subject filename, since resource logging is supported for
68635 + single-subject learning only */
68636 + rcu_read_lock();
68637 + cred = __task_cred(task);
68638 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68639 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68640 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68641 + "", (unsigned long) res, &task->signal->saved_ip);
68642 + rcu_read_unlock();
68643 + }
68644 +
68645 + return;
68646 +}
68647 +EXPORT_SYMBOL_GPL(gr_learn_resource);
68648 +#endif
68649 +
68650 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68651 +void
68652 +pax_set_initial_flags(struct linux_binprm *bprm)
68653 +{
68654 + struct task_struct *task = current;
68655 + struct acl_subject_label *proc;
68656 + unsigned long flags;
68657 +
68658 + if (unlikely(!(gr_status & GR_READY)))
68659 + return;
68660 +
68661 + flags = pax_get_flags(task);
68662 +
68663 + proc = task->acl;
68664 +
68665 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68666 + flags &= ~MF_PAX_PAGEEXEC;
68667 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68668 + flags &= ~MF_PAX_SEGMEXEC;
68669 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68670 + flags &= ~MF_PAX_RANDMMAP;
68671 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68672 + flags &= ~MF_PAX_EMUTRAMP;
68673 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68674 + flags &= ~MF_PAX_MPROTECT;
68675 +
68676 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68677 + flags |= MF_PAX_PAGEEXEC;
68678 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68679 + flags |= MF_PAX_SEGMEXEC;
68680 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68681 + flags |= MF_PAX_RANDMMAP;
68682 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68683 + flags |= MF_PAX_EMUTRAMP;
68684 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68685 + flags |= MF_PAX_MPROTECT;
68686 +
68687 + pax_set_flags(task, flags);
68688 +
68689 + return;
68690 +}
68691 +#endif
68692 +
68693 +int
68694 +gr_handle_proc_ptrace(struct task_struct *task)
68695 +{
68696 + struct file *filp;
68697 + struct task_struct *tmp = task;
68698 + struct task_struct *curtemp = current;
68699 + __u32 retmode;
68700 +
68701 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68702 + if (unlikely(!(gr_status & GR_READY)))
68703 + return 0;
68704 +#endif
68705 +
68706 + read_lock(&tasklist_lock);
68707 + read_lock(&grsec_exec_file_lock);
68708 + filp = task->exec_file;
68709 +
68710 + while (task_pid_nr(tmp) > 0) {
68711 + if (tmp == curtemp)
68712 + break;
68713 + tmp = tmp->real_parent;
68714 + }
68715 +
68716 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68717 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68718 + read_unlock(&grsec_exec_file_lock);
68719 + read_unlock(&tasklist_lock);
68720 + return 1;
68721 + }
68722 +
68723 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68724 + if (!(gr_status & GR_READY)) {
68725 + read_unlock(&grsec_exec_file_lock);
68726 + read_unlock(&tasklist_lock);
68727 + return 0;
68728 + }
68729 +#endif
68730 +
68731 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68732 + read_unlock(&grsec_exec_file_lock);
68733 + read_unlock(&tasklist_lock);
68734 +
68735 + if (retmode & GR_NOPTRACE)
68736 + return 1;
68737 +
68738 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68739 + && (current->acl != task->acl || (current->acl != current->role->root_label
68740 + && task_pid_nr(current) != task_pid_nr(task))))
68741 + return 1;
68742 +
68743 + return 0;
68744 +}
68745 +
68746 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68747 +{
68748 + if (unlikely(!(gr_status & GR_READY)))
68749 + return;
68750 +
68751 + if (!(current->role->roletype & GR_ROLE_GOD))
68752 + return;
68753 +
68754 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68755 + p->role->rolename, gr_task_roletype_to_char(p),
68756 + p->acl->filename);
68757 +}
68758 +
68759 +int
68760 +gr_handle_ptrace(struct task_struct *task, const long request)
68761 +{
68762 + struct task_struct *tmp = task;
68763 + struct task_struct *curtemp = current;
68764 + __u32 retmode;
68765 +
68766 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68767 + if (unlikely(!(gr_status & GR_READY)))
68768 + return 0;
68769 +#endif
68770 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68771 + read_lock(&tasklist_lock);
68772 + while (task_pid_nr(tmp) > 0) {
68773 + if (tmp == curtemp)
68774 + break;
68775 + tmp = tmp->real_parent;
68776 + }
68777 +
68778 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68779 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68780 + read_unlock(&tasklist_lock);
68781 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68782 + return 1;
68783 + }
68784 + read_unlock(&tasklist_lock);
68785 + }
68786 +
68787 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68788 + if (!(gr_status & GR_READY))
68789 + return 0;
68790 +#endif
68791 +
68792 + read_lock(&grsec_exec_file_lock);
68793 + if (unlikely(!task->exec_file)) {
68794 + read_unlock(&grsec_exec_file_lock);
68795 + return 0;
68796 + }
68797 +
68798 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68799 + read_unlock(&grsec_exec_file_lock);
68800 +
68801 + if (retmode & GR_NOPTRACE) {
68802 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68803 + return 1;
68804 + }
68805 +
68806 + if (retmode & GR_PTRACERD) {
68807 + switch (request) {
68808 + case PTRACE_SEIZE:
68809 + case PTRACE_POKETEXT:
68810 + case PTRACE_POKEDATA:
68811 + case PTRACE_POKEUSR:
68812 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68813 + case PTRACE_SETREGS:
68814 + case PTRACE_SETFPREGS:
68815 +#endif
68816 +#ifdef CONFIG_X86
68817 + case PTRACE_SETFPXREGS:
68818 +#endif
68819 +#ifdef CONFIG_ALTIVEC
68820 + case PTRACE_SETVRREGS:
68821 +#endif
68822 + return 1;
68823 + default:
68824 + return 0;
68825 + }
68826 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
68827 + !(current->role->roletype & GR_ROLE_GOD) &&
68828 + (current->acl != task->acl)) {
68829 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68830 + return 1;
68831 + }
68832 +
68833 + return 0;
68834 +}
68835 +
68836 +static int is_writable_mmap(const struct file *filp)
68837 +{
68838 + struct task_struct *task = current;
68839 + struct acl_object_label *obj, *obj2;
68840 +
68841 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68842 + !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))) {
68843 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68844 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68845 + task->role->root_label);
68846 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68847 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68848 + return 1;
68849 + }
68850 + }
68851 + return 0;
68852 +}
68853 +
68854 +int
68855 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68856 +{
68857 + __u32 mode;
68858 +
68859 + if (unlikely(!file || !(prot & PROT_EXEC)))
68860 + return 1;
68861 +
68862 + if (is_writable_mmap(file))
68863 + return 0;
68864 +
68865 + mode =
68866 + gr_search_file(file->f_path.dentry,
68867 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68868 + file->f_path.mnt);
68869 +
68870 + if (!gr_tpe_allow(file))
68871 + return 0;
68872 +
68873 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68874 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68875 + return 0;
68876 + } else if (unlikely(!(mode & GR_EXEC))) {
68877 + return 0;
68878 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68879 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68880 + return 1;
68881 + }
68882 +
68883 + return 1;
68884 +}
68885 +
68886 +int
68887 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68888 +{
68889 + __u32 mode;
68890 +
68891 + if (unlikely(!file || !(prot & PROT_EXEC)))
68892 + return 1;
68893 +
68894 + if (is_writable_mmap(file))
68895 + return 0;
68896 +
68897 + mode =
68898 + gr_search_file(file->f_path.dentry,
68899 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68900 + file->f_path.mnt);
68901 +
68902 + if (!gr_tpe_allow(file))
68903 + return 0;
68904 +
68905 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68906 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68907 + return 0;
68908 + } else if (unlikely(!(mode & GR_EXEC))) {
68909 + return 0;
68910 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68911 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68912 + return 1;
68913 + }
68914 +
68915 + return 1;
68916 +}
68917 +
68918 +void
68919 +gr_acl_handle_psacct(struct task_struct *task, const long code)
68920 +{
68921 + unsigned long runtime, cputime;
68922 + cputime_t utime, stime;
68923 + unsigned int wday, cday;
68924 + __u8 whr, chr;
68925 + __u8 wmin, cmin;
68926 + __u8 wsec, csec;
68927 + struct timespec timeval;
68928 +
68929 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68930 + !(task->acl->mode & GR_PROCACCT)))
68931 + return;
68932 +
68933 + do_posix_clock_monotonic_gettime(&timeval);
68934 + runtime = timeval.tv_sec - task->start_time.tv_sec;
68935 + wday = runtime / (60 * 60 * 24);
68936 + runtime -= wday * (60 * 60 * 24);
68937 + whr = runtime / (60 * 60);
68938 + runtime -= whr * (60 * 60);
68939 + wmin = runtime / 60;
68940 + runtime -= wmin * 60;
68941 + wsec = runtime;
68942 +
68943 + task_cputime(task, &utime, &stime);
68944 + cputime = cputime_to_secs(utime + stime);
68945 + cday = cputime / (60 * 60 * 24);
68946 + cputime -= cday * (60 * 60 * 24);
68947 + chr = cputime / (60 * 60);
68948 + cputime -= chr * (60 * 60);
68949 + cmin = cputime / 60;
68950 + cputime -= cmin * 60;
68951 + csec = cputime;
68952 +
68953 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68954 +
68955 + return;
68956 +}
68957 +
68958 +#ifdef CONFIG_TASKSTATS
68959 +int gr_is_taskstats_denied(int pid)
68960 +{
68961 + struct task_struct *task;
68962 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68963 + const struct cred *cred;
68964 +#endif
68965 + int ret = 0;
68966 +
68967 + /* restrict taskstats viewing to un-chrooted root users
68968 + who have the 'view' subject flag if the RBAC system is enabled
68969 + */
68970 +
68971 + rcu_read_lock();
68972 + read_lock(&tasklist_lock);
68973 + task = find_task_by_vpid(pid);
68974 + if (task) {
68975 +#ifdef CONFIG_GRKERNSEC_CHROOT
68976 + if (proc_is_chrooted(task))
68977 + ret = -EACCES;
68978 +#endif
68979 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68980 + cred = __task_cred(task);
68981 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68982 + if (gr_is_global_nonroot(cred->uid))
68983 + ret = -EACCES;
68984 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68985 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68986 + ret = -EACCES;
68987 +#endif
68988 +#endif
68989 + if (gr_status & GR_READY) {
68990 + if (!(task->acl->mode & GR_VIEW))
68991 + ret = -EACCES;
68992 + }
68993 + } else
68994 + ret = -ENOENT;
68995 +
68996 + read_unlock(&tasklist_lock);
68997 + rcu_read_unlock();
68998 +
68999 + return ret;
69000 +}
69001 +#endif
69002 +
69003 +/* AUXV entries are filled via a descendant of search_binary_handler
69004 + after we've already applied the subject for the target
69005 +*/
69006 +int gr_acl_enable_at_secure(void)
69007 +{
69008 + if (unlikely(!(gr_status & GR_READY)))
69009 + return 0;
69010 +
69011 + if (current->acl->mode & GR_ATSECURE)
69012 + return 1;
69013 +
69014 + return 0;
69015 +}
69016 +
69017 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69018 +{
69019 + struct task_struct *task = current;
69020 + struct dentry *dentry = file->f_path.dentry;
69021 + struct vfsmount *mnt = file->f_path.mnt;
69022 + struct acl_object_label *obj, *tmp;
69023 + struct acl_subject_label *subj;
69024 + unsigned int bufsize;
69025 + int is_not_root;
69026 + char *path;
69027 + dev_t dev = __get_dev(dentry);
69028 +
69029 + if (unlikely(!(gr_status & GR_READY)))
69030 + return 1;
69031 +
69032 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69033 + return 1;
69034 +
69035 + /* ignore Eric Biederman */
69036 + if (IS_PRIVATE(dentry->d_inode))
69037 + return 1;
69038 +
69039 + subj = task->acl;
69040 + read_lock(&gr_inode_lock);
69041 + do {
69042 + obj = lookup_acl_obj_label(ino, dev, subj);
69043 + if (obj != NULL) {
69044 + read_unlock(&gr_inode_lock);
69045 + return (obj->mode & GR_FIND) ? 1 : 0;
69046 + }
69047 + } while ((subj = subj->parent_subject));
69048 + read_unlock(&gr_inode_lock);
69049 +
69050 + /* this is purely an optimization since we're looking for an object
69051 + for the directory we're doing a readdir on
69052 + if it's possible for any globbed object to match the entry we're
69053 + filling into the directory, then the object we find here will be
69054 + an anchor point with attached globbed objects
69055 + */
69056 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69057 + if (obj->globbed == NULL)
69058 + return (obj->mode & GR_FIND) ? 1 : 0;
69059 +
69060 + is_not_root = ((obj->filename[0] == '/') &&
69061 + (obj->filename[1] == '\0')) ? 0 : 1;
69062 + bufsize = PAGE_SIZE - namelen - is_not_root;
69063 +
69064 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
69065 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69066 + return 1;
69067 +
69068 + preempt_disable();
69069 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69070 + bufsize);
69071 +
69072 + bufsize = strlen(path);
69073 +
69074 + /* if base is "/", don't append an additional slash */
69075 + if (is_not_root)
69076 + *(path + bufsize) = '/';
69077 + memcpy(path + bufsize + is_not_root, name, namelen);
69078 + *(path + bufsize + namelen + is_not_root) = '\0';
69079 +
69080 + tmp = obj->globbed;
69081 + while (tmp) {
69082 + if (!glob_match(tmp->filename, path)) {
69083 + preempt_enable();
69084 + return (tmp->mode & GR_FIND) ? 1 : 0;
69085 + }
69086 + tmp = tmp->next;
69087 + }
69088 + preempt_enable();
69089 + return (obj->mode & GR_FIND) ? 1 : 0;
69090 +}
69091 +
69092 +void gr_put_exec_file(struct task_struct *task)
69093 +{
69094 + struct file *filp;
69095 +
69096 + write_lock(&grsec_exec_file_lock);
69097 + filp = task->exec_file;
69098 + task->exec_file = NULL;
69099 + write_unlock(&grsec_exec_file_lock);
69100 +
69101 + if (filp)
69102 + fput(filp);
69103 +
69104 + return;
69105 +}
69106 +
69107 +
69108 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69109 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69110 +#endif
69111 +#ifdef CONFIG_SECURITY
69112 +EXPORT_SYMBOL_GPL(gr_check_user_change);
69113 +EXPORT_SYMBOL_GPL(gr_check_group_change);
69114 +#endif
69115 +
69116 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69117 new file mode 100644
69118 index 0000000..18ffbbd
69119 --- /dev/null
69120 +++ b/grsecurity/gracl_alloc.c
69121 @@ -0,0 +1,105 @@
69122 +#include <linux/kernel.h>
69123 +#include <linux/mm.h>
69124 +#include <linux/slab.h>
69125 +#include <linux/vmalloc.h>
69126 +#include <linux/gracl.h>
69127 +#include <linux/grsecurity.h>
69128 +
69129 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69130 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69131 +
69132 +static __inline__ int
69133 +alloc_pop(void)
69134 +{
69135 + if (current_alloc_state->alloc_stack_next == 1)
69136 + return 0;
69137 +
69138 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69139 +
69140 + current_alloc_state->alloc_stack_next--;
69141 +
69142 + return 1;
69143 +}
69144 +
69145 +static __inline__ int
69146 +alloc_push(void *buf)
69147 +{
69148 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69149 + return 1;
69150 +
69151 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69152 +
69153 + current_alloc_state->alloc_stack_next++;
69154 +
69155 + return 0;
69156 +}
69157 +
69158 +void *
69159 +acl_alloc(unsigned long len)
69160 +{
69161 + void *ret = NULL;
69162 +
69163 + if (!len || len > PAGE_SIZE)
69164 + goto out;
69165 +
69166 + ret = kmalloc(len, GFP_KERNEL);
69167 +
69168 + if (ret) {
69169 + if (alloc_push(ret)) {
69170 + kfree(ret);
69171 + ret = NULL;
69172 + }
69173 + }
69174 +
69175 +out:
69176 + return ret;
69177 +}
69178 +
69179 +void *
69180 +acl_alloc_num(unsigned long num, unsigned long len)
69181 +{
69182 + if (!len || (num > (PAGE_SIZE / len)))
69183 + return NULL;
69184 +
69185 + return acl_alloc(num * len);
69186 +}
69187 +
69188 +void
69189 +acl_free_all(void)
69190 +{
69191 + if (!current_alloc_state->alloc_stack)
69192 + return;
69193 +
69194 + while (alloc_pop()) ;
69195 +
69196 + if (current_alloc_state->alloc_stack) {
69197 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69198 + kfree(current_alloc_state->alloc_stack);
69199 + else
69200 + vfree(current_alloc_state->alloc_stack);
69201 + }
69202 +
69203 + current_alloc_state->alloc_stack = NULL;
69204 + current_alloc_state->alloc_stack_size = 1;
69205 + current_alloc_state->alloc_stack_next = 1;
69206 +
69207 + return;
69208 +}
69209 +
69210 +int
69211 +acl_alloc_stack_init(unsigned long size)
69212 +{
69213 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69214 + current_alloc_state->alloc_stack =
69215 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69216 + else
69217 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69218 +
69219 + current_alloc_state->alloc_stack_size = size;
69220 + current_alloc_state->alloc_stack_next = 1;
69221 +
69222 + if (!current_alloc_state->alloc_stack)
69223 + return 0;
69224 + else
69225 + return 1;
69226 +}
69227 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69228 new file mode 100644
69229 index 0000000..bdd51ea
69230 --- /dev/null
69231 +++ b/grsecurity/gracl_cap.c
69232 @@ -0,0 +1,110 @@
69233 +#include <linux/kernel.h>
69234 +#include <linux/module.h>
69235 +#include <linux/sched.h>
69236 +#include <linux/gracl.h>
69237 +#include <linux/grsecurity.h>
69238 +#include <linux/grinternal.h>
69239 +
69240 +extern const char *captab_log[];
69241 +extern int captab_log_entries;
69242 +
69243 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69244 +{
69245 + struct acl_subject_label *curracl;
69246 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69247 + kernel_cap_t cap_audit = __cap_empty_set;
69248 +
69249 + if (!gr_acl_is_enabled())
69250 + return 1;
69251 +
69252 + curracl = task->acl;
69253 +
69254 + cap_drop = curracl->cap_lower;
69255 + cap_mask = curracl->cap_mask;
69256 + cap_audit = curracl->cap_invert_audit;
69257 +
69258 + while ((curracl = curracl->parent_subject)) {
69259 + /* if the cap isn't specified in the current computed mask but is specified in the
69260 + current level subject, and is lowered in the current level subject, then add
69261 + it to the set of dropped capabilities
69262 + otherwise, add the current level subject's mask to the current computed mask
69263 + */
69264 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69265 + cap_raise(cap_mask, cap);
69266 + if (cap_raised(curracl->cap_lower, cap))
69267 + cap_raise(cap_drop, cap);
69268 + if (cap_raised(curracl->cap_invert_audit, cap))
69269 + cap_raise(cap_audit, cap);
69270 + }
69271 + }
69272 +
69273 + if (!cap_raised(cap_drop, cap)) {
69274 + if (cap_raised(cap_audit, cap))
69275 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69276 + return 1;
69277 + }
69278 +
69279 + curracl = task->acl;
69280 +
69281 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69282 + && cap_raised(cred->cap_effective, cap)) {
69283 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69284 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69285 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69286 + gr_to_filename(task->exec_file->f_path.dentry,
69287 + task->exec_file->f_path.mnt) : curracl->filename,
69288 + curracl->filename, 0UL,
69289 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69290 + return 1;
69291 + }
69292 +
69293 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69294 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69295 +
69296 + return 0;
69297 +}
69298 +
69299 +int
69300 +gr_acl_is_capable(const int cap)
69301 +{
69302 + return gr_task_acl_is_capable(current, current_cred(), cap);
69303 +}
69304 +
69305 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69306 +{
69307 + struct acl_subject_label *curracl;
69308 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69309 +
69310 + if (!gr_acl_is_enabled())
69311 + return 1;
69312 +
69313 + curracl = task->acl;
69314 +
69315 + cap_drop = curracl->cap_lower;
69316 + cap_mask = curracl->cap_mask;
69317 +
69318 + while ((curracl = curracl->parent_subject)) {
69319 + /* if the cap isn't specified in the current computed mask but is specified in the
69320 + current level subject, and is lowered in the current level subject, then add
69321 + it to the set of dropped capabilities
69322 + otherwise, add the current level subject's mask to the current computed mask
69323 + */
69324 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69325 + cap_raise(cap_mask, cap);
69326 + if (cap_raised(curracl->cap_lower, cap))
69327 + cap_raise(cap_drop, cap);
69328 + }
69329 + }
69330 +
69331 + if (!cap_raised(cap_drop, cap))
69332 + return 1;
69333 +
69334 + return 0;
69335 +}
69336 +
69337 +int
69338 +gr_acl_is_capable_nolog(const int cap)
69339 +{
69340 + return gr_task_acl_is_capable_nolog(current, cap);
69341 +}
69342 +
69343 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69344 new file mode 100644
69345 index 0000000..ca25605
69346 --- /dev/null
69347 +++ b/grsecurity/gracl_compat.c
69348 @@ -0,0 +1,270 @@
69349 +#include <linux/kernel.h>
69350 +#include <linux/gracl.h>
69351 +#include <linux/compat.h>
69352 +#include <linux/gracl_compat.h>
69353 +
69354 +#include <asm/uaccess.h>
69355 +
69356 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69357 +{
69358 + struct gr_arg_wrapper_compat uwrapcompat;
69359 +
69360 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69361 + return -EFAULT;
69362 +
69363 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69364 + (uwrapcompat.version != 0x2901)) ||
69365 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69366 + return -EINVAL;
69367 +
69368 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69369 + uwrap->version = uwrapcompat.version;
69370 + uwrap->size = sizeof(struct gr_arg);
69371 +
69372 + return 0;
69373 +}
69374 +
69375 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69376 +{
69377 + struct gr_arg_compat argcompat;
69378 +
69379 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69380 + return -EFAULT;
69381 +
69382 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69383 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69384 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69385 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69386 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69387 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69388 +
69389 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69390 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69391 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69392 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69393 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69394 + arg->segv_device = argcompat.segv_device;
69395 + arg->segv_inode = argcompat.segv_inode;
69396 + arg->segv_uid = argcompat.segv_uid;
69397 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69398 + arg->mode = argcompat.mode;
69399 +
69400 + return 0;
69401 +}
69402 +
69403 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69404 +{
69405 + struct acl_object_label_compat objcompat;
69406 +
69407 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69408 + return -EFAULT;
69409 +
69410 + obj->filename = compat_ptr(objcompat.filename);
69411 + obj->inode = objcompat.inode;
69412 + obj->device = objcompat.device;
69413 + obj->mode = objcompat.mode;
69414 +
69415 + obj->nested = compat_ptr(objcompat.nested);
69416 + obj->globbed = compat_ptr(objcompat.globbed);
69417 +
69418 + obj->prev = compat_ptr(objcompat.prev);
69419 + obj->next = compat_ptr(objcompat.next);
69420 +
69421 + return 0;
69422 +}
69423 +
69424 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69425 +{
69426 + unsigned int i;
69427 + struct acl_subject_label_compat subjcompat;
69428 +
69429 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69430 + return -EFAULT;
69431 +
69432 + subj->filename = compat_ptr(subjcompat.filename);
69433 + subj->inode = subjcompat.inode;
69434 + subj->device = subjcompat.device;
69435 + subj->mode = subjcompat.mode;
69436 + subj->cap_mask = subjcompat.cap_mask;
69437 + subj->cap_lower = subjcompat.cap_lower;
69438 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69439 +
69440 + for (i = 0; i < GR_NLIMITS; i++) {
69441 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69442 + subj->res[i].rlim_cur = RLIM_INFINITY;
69443 + else
69444 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69445 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69446 + subj->res[i].rlim_max = RLIM_INFINITY;
69447 + else
69448 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69449 + }
69450 + subj->resmask = subjcompat.resmask;
69451 +
69452 + subj->user_trans_type = subjcompat.user_trans_type;
69453 + subj->group_trans_type = subjcompat.group_trans_type;
69454 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69455 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69456 + subj->user_trans_num = subjcompat.user_trans_num;
69457 + subj->group_trans_num = subjcompat.group_trans_num;
69458 +
69459 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69460 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69461 + subj->ip_type = subjcompat.ip_type;
69462 + subj->ips = compat_ptr(subjcompat.ips);
69463 + subj->ip_num = subjcompat.ip_num;
69464 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
69465 +
69466 + subj->crashes = subjcompat.crashes;
69467 + subj->expires = subjcompat.expires;
69468 +
69469 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69470 + subj->hash = compat_ptr(subjcompat.hash);
69471 + subj->prev = compat_ptr(subjcompat.prev);
69472 + subj->next = compat_ptr(subjcompat.next);
69473 +
69474 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69475 + subj->obj_hash_size = subjcompat.obj_hash_size;
69476 + subj->pax_flags = subjcompat.pax_flags;
69477 +
69478 + return 0;
69479 +}
69480 +
69481 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69482 +{
69483 + struct acl_role_label_compat rolecompat;
69484 +
69485 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69486 + return -EFAULT;
69487 +
69488 + role->rolename = compat_ptr(rolecompat.rolename);
69489 + role->uidgid = rolecompat.uidgid;
69490 + role->roletype = rolecompat.roletype;
69491 +
69492 + role->auth_attempts = rolecompat.auth_attempts;
69493 + role->expires = rolecompat.expires;
69494 +
69495 + role->root_label = compat_ptr(rolecompat.root_label);
69496 + role->hash = compat_ptr(rolecompat.hash);
69497 +
69498 + role->prev = compat_ptr(rolecompat.prev);
69499 + role->next = compat_ptr(rolecompat.next);
69500 +
69501 + role->transitions = compat_ptr(rolecompat.transitions);
69502 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69503 + role->domain_children = compat_ptr(rolecompat.domain_children);
69504 + role->domain_child_num = rolecompat.domain_child_num;
69505 +
69506 + role->umask = rolecompat.umask;
69507 +
69508 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
69509 + role->subj_hash_size = rolecompat.subj_hash_size;
69510 +
69511 + return 0;
69512 +}
69513 +
69514 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69515 +{
69516 + struct role_allowed_ip_compat roleip_compat;
69517 +
69518 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69519 + return -EFAULT;
69520 +
69521 + roleip->addr = roleip_compat.addr;
69522 + roleip->netmask = roleip_compat.netmask;
69523 +
69524 + roleip->prev = compat_ptr(roleip_compat.prev);
69525 + roleip->next = compat_ptr(roleip_compat.next);
69526 +
69527 + return 0;
69528 +}
69529 +
69530 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69531 +{
69532 + struct role_transition_compat trans_compat;
69533 +
69534 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69535 + return -EFAULT;
69536 +
69537 + trans->rolename = compat_ptr(trans_compat.rolename);
69538 +
69539 + trans->prev = compat_ptr(trans_compat.prev);
69540 + trans->next = compat_ptr(trans_compat.next);
69541 +
69542 + return 0;
69543 +
69544 +}
69545 +
69546 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69547 +{
69548 + struct gr_hash_struct_compat hash_compat;
69549 +
69550 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69551 + return -EFAULT;
69552 +
69553 + hash->table = compat_ptr(hash_compat.table);
69554 + hash->nametable = compat_ptr(hash_compat.nametable);
69555 + hash->first = compat_ptr(hash_compat.first);
69556 +
69557 + hash->table_size = hash_compat.table_size;
69558 + hash->used_size = hash_compat.used_size;
69559 +
69560 + hash->type = hash_compat.type;
69561 +
69562 + return 0;
69563 +}
69564 +
69565 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69566 +{
69567 + compat_uptr_t ptrcompat;
69568 +
69569 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69570 + return -EFAULT;
69571 +
69572 + *(void **)ptr = compat_ptr(ptrcompat);
69573 +
69574 + return 0;
69575 +}
69576 +
69577 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69578 +{
69579 + struct acl_ip_label_compat ip_compat;
69580 +
69581 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69582 + return -EFAULT;
69583 +
69584 + ip->iface = compat_ptr(ip_compat.iface);
69585 + ip->addr = ip_compat.addr;
69586 + ip->netmask = ip_compat.netmask;
69587 + ip->low = ip_compat.low;
69588 + ip->high = ip_compat.high;
69589 + ip->mode = ip_compat.mode;
69590 + ip->type = ip_compat.type;
69591 +
69592 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69593 +
69594 + ip->prev = compat_ptr(ip_compat.prev);
69595 + ip->next = compat_ptr(ip_compat.next);
69596 +
69597 + return 0;
69598 +}
69599 +
69600 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69601 +{
69602 + struct sprole_pw_compat pw_compat;
69603 +
69604 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69605 + return -EFAULT;
69606 +
69607 + pw->rolename = compat_ptr(pw_compat.rolename);
69608 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69609 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69610 +
69611 + return 0;
69612 +}
69613 +
69614 +size_t get_gr_arg_wrapper_size_compat(void)
69615 +{
69616 + return sizeof(struct gr_arg_wrapper_compat);
69617 +}
69618 +
69619 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69620 new file mode 100644
69621 index 0000000..a89b1f4
69622 --- /dev/null
69623 +++ b/grsecurity/gracl_fs.c
69624 @@ -0,0 +1,437 @@
69625 +#include <linux/kernel.h>
69626 +#include <linux/sched.h>
69627 +#include <linux/types.h>
69628 +#include <linux/fs.h>
69629 +#include <linux/file.h>
69630 +#include <linux/stat.h>
69631 +#include <linux/grsecurity.h>
69632 +#include <linux/grinternal.h>
69633 +#include <linux/gracl.h>
69634 +
69635 +umode_t
69636 +gr_acl_umask(void)
69637 +{
69638 + if (unlikely(!gr_acl_is_enabled()))
69639 + return 0;
69640 +
69641 + return current->role->umask;
69642 +}
69643 +
69644 +__u32
69645 +gr_acl_handle_hidden_file(const struct dentry * dentry,
69646 + const struct vfsmount * mnt)
69647 +{
69648 + __u32 mode;
69649 +
69650 + if (unlikely(d_is_negative(dentry)))
69651 + return GR_FIND;
69652 +
69653 + mode =
69654 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69655 +
69656 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69657 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69658 + return mode;
69659 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69660 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69661 + return 0;
69662 + } else if (unlikely(!(mode & GR_FIND)))
69663 + return 0;
69664 +
69665 + return GR_FIND;
69666 +}
69667 +
69668 +__u32
69669 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69670 + int acc_mode)
69671 +{
69672 + __u32 reqmode = GR_FIND;
69673 + __u32 mode;
69674 +
69675 + if (unlikely(d_is_negative(dentry)))
69676 + return reqmode;
69677 +
69678 + if (acc_mode & MAY_APPEND)
69679 + reqmode |= GR_APPEND;
69680 + else if (acc_mode & MAY_WRITE)
69681 + reqmode |= GR_WRITE;
69682 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69683 + reqmode |= GR_READ;
69684 +
69685 + mode =
69686 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69687 + mnt);
69688 +
69689 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69690 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69691 + reqmode & GR_READ ? " reading" : "",
69692 + reqmode & GR_WRITE ? " writing" : reqmode &
69693 + GR_APPEND ? " appending" : "");
69694 + return reqmode;
69695 + } else
69696 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69697 + {
69698 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69699 + reqmode & GR_READ ? " reading" : "",
69700 + reqmode & GR_WRITE ? " writing" : reqmode &
69701 + GR_APPEND ? " appending" : "");
69702 + return 0;
69703 + } else if (unlikely((mode & reqmode) != reqmode))
69704 + return 0;
69705 +
69706 + return reqmode;
69707 +}
69708 +
69709 +__u32
69710 +gr_acl_handle_creat(const struct dentry * dentry,
69711 + const struct dentry * p_dentry,
69712 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69713 + const int imode)
69714 +{
69715 + __u32 reqmode = GR_WRITE | GR_CREATE;
69716 + __u32 mode;
69717 +
69718 + if (acc_mode & MAY_APPEND)
69719 + reqmode |= GR_APPEND;
69720 + // if a directory was required or the directory already exists, then
69721 + // don't count this open as a read
69722 + if ((acc_mode & MAY_READ) &&
69723 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69724 + reqmode |= GR_READ;
69725 + if ((open_flags & O_CREAT) &&
69726 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69727 + reqmode |= GR_SETID;
69728 +
69729 + mode =
69730 + gr_check_create(dentry, p_dentry, p_mnt,
69731 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69732 +
69733 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69734 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69735 + reqmode & GR_READ ? " reading" : "",
69736 + reqmode & GR_WRITE ? " writing" : reqmode &
69737 + GR_APPEND ? " appending" : "");
69738 + return reqmode;
69739 + } else
69740 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69741 + {
69742 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69743 + reqmode & GR_READ ? " reading" : "",
69744 + reqmode & GR_WRITE ? " writing" : reqmode &
69745 + GR_APPEND ? " appending" : "");
69746 + return 0;
69747 + } else if (unlikely((mode & reqmode) != reqmode))
69748 + return 0;
69749 +
69750 + return reqmode;
69751 +}
69752 +
69753 +__u32
69754 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69755 + const int fmode)
69756 +{
69757 + __u32 mode, reqmode = GR_FIND;
69758 +
69759 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69760 + reqmode |= GR_EXEC;
69761 + if (fmode & S_IWOTH)
69762 + reqmode |= GR_WRITE;
69763 + if (fmode & S_IROTH)
69764 + reqmode |= GR_READ;
69765 +
69766 + mode =
69767 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69768 + mnt);
69769 +
69770 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69771 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69772 + reqmode & GR_READ ? " reading" : "",
69773 + reqmode & GR_WRITE ? " writing" : "",
69774 + reqmode & GR_EXEC ? " executing" : "");
69775 + return reqmode;
69776 + } else
69777 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69778 + {
69779 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69780 + reqmode & GR_READ ? " reading" : "",
69781 + reqmode & GR_WRITE ? " writing" : "",
69782 + reqmode & GR_EXEC ? " executing" : "");
69783 + return 0;
69784 + } else if (unlikely((mode & reqmode) != reqmode))
69785 + return 0;
69786 +
69787 + return reqmode;
69788 +}
69789 +
69790 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69791 +{
69792 + __u32 mode;
69793 +
69794 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69795 +
69796 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69797 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69798 + return mode;
69799 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69800 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69801 + return 0;
69802 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69803 + return 0;
69804 +
69805 + return (reqmode);
69806 +}
69807 +
69808 +__u32
69809 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69810 +{
69811 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69812 +}
69813 +
69814 +__u32
69815 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69816 +{
69817 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69818 +}
69819 +
69820 +__u32
69821 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69822 +{
69823 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69824 +}
69825 +
69826 +__u32
69827 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69828 +{
69829 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69830 +}
69831 +
69832 +__u32
69833 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69834 + umode_t *modeptr)
69835 +{
69836 + umode_t mode;
69837 +
69838 + *modeptr &= ~gr_acl_umask();
69839 + mode = *modeptr;
69840 +
69841 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69842 + return 1;
69843 +
69844 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69845 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69846 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69847 + GR_CHMOD_ACL_MSG);
69848 + } else {
69849 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69850 + }
69851 +}
69852 +
69853 +__u32
69854 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69855 +{
69856 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69857 +}
69858 +
69859 +__u32
69860 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69861 +{
69862 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69863 +}
69864 +
69865 +__u32
69866 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69867 +{
69868 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69869 +}
69870 +
69871 +__u32
69872 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69873 +{
69874 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69875 +}
69876 +
69877 +__u32
69878 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69879 +{
69880 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69881 + GR_UNIXCONNECT_ACL_MSG);
69882 +}
69883 +
69884 +/* hardlinks require at minimum create and link permission,
69885 + any additional privilege required is based on the
69886 + privilege of the file being linked to
69887 +*/
69888 +__u32
69889 +gr_acl_handle_link(const struct dentry * new_dentry,
69890 + const struct dentry * parent_dentry,
69891 + const struct vfsmount * parent_mnt,
69892 + const struct dentry * old_dentry,
69893 + const struct vfsmount * old_mnt, const struct filename *to)
69894 +{
69895 + __u32 mode;
69896 + __u32 needmode = GR_CREATE | GR_LINK;
69897 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69898 +
69899 + mode =
69900 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69901 + old_mnt);
69902 +
69903 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69904 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69905 + return mode;
69906 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69907 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69908 + return 0;
69909 + } else if (unlikely((mode & needmode) != needmode))
69910 + return 0;
69911 +
69912 + return 1;
69913 +}
69914 +
69915 +__u32
69916 +gr_acl_handle_symlink(const struct dentry * new_dentry,
69917 + const struct dentry * parent_dentry,
69918 + const struct vfsmount * parent_mnt, const struct filename *from)
69919 +{
69920 + __u32 needmode = GR_WRITE | GR_CREATE;
69921 + __u32 mode;
69922 +
69923 + mode =
69924 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
69925 + GR_CREATE | GR_AUDIT_CREATE |
69926 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69927 +
69928 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69929 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69930 + return mode;
69931 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69932 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69933 + return 0;
69934 + } else if (unlikely((mode & needmode) != needmode))
69935 + return 0;
69936 +
69937 + return (GR_WRITE | GR_CREATE);
69938 +}
69939 +
69940 +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)
69941 +{
69942 + __u32 mode;
69943 +
69944 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69945 +
69946 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69947 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69948 + return mode;
69949 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69950 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69951 + return 0;
69952 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69953 + return 0;
69954 +
69955 + return (reqmode);
69956 +}
69957 +
69958 +__u32
69959 +gr_acl_handle_mknod(const struct dentry * new_dentry,
69960 + const struct dentry * parent_dentry,
69961 + const struct vfsmount * parent_mnt,
69962 + const int mode)
69963 +{
69964 + __u32 reqmode = GR_WRITE | GR_CREATE;
69965 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69966 + reqmode |= GR_SETID;
69967 +
69968 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69969 + reqmode, GR_MKNOD_ACL_MSG);
69970 +}
69971 +
69972 +__u32
69973 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
69974 + const struct dentry *parent_dentry,
69975 + const struct vfsmount *parent_mnt)
69976 +{
69977 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69978 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69979 +}
69980 +
69981 +#define RENAME_CHECK_SUCCESS(old, new) \
69982 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69983 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69984 +
69985 +int
69986 +gr_acl_handle_rename(struct dentry *new_dentry,
69987 + struct dentry *parent_dentry,
69988 + const struct vfsmount *parent_mnt,
69989 + struct dentry *old_dentry,
69990 + struct inode *old_parent_inode,
69991 + struct vfsmount *old_mnt, const struct filename *newname)
69992 +{
69993 + __u32 comp1, comp2;
69994 + int error = 0;
69995 +
69996 + if (unlikely(!gr_acl_is_enabled()))
69997 + return 0;
69998 +
69999 + if (d_is_negative(new_dentry)) {
70000 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70001 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70002 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70003 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70004 + GR_DELETE | GR_AUDIT_DELETE |
70005 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70006 + GR_SUPPRESS, old_mnt);
70007 + } else {
70008 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70009 + GR_CREATE | GR_DELETE |
70010 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70011 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70012 + GR_SUPPRESS, parent_mnt);
70013 + comp2 =
70014 + gr_search_file(old_dentry,
70015 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70016 + GR_DELETE | GR_AUDIT_DELETE |
70017 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70018 + }
70019 +
70020 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70021 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70022 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70023 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70024 + && !(comp2 & GR_SUPPRESS)) {
70025 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70026 + error = -EACCES;
70027 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70028 + error = -EACCES;
70029 +
70030 + return error;
70031 +}
70032 +
70033 +void
70034 +gr_acl_handle_exit(void)
70035 +{
70036 + u16 id;
70037 + char *rolename;
70038 +
70039 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70040 + !(current->role->roletype & GR_ROLE_PERSIST))) {
70041 + id = current->acl_role_id;
70042 + rolename = current->role->rolename;
70043 + gr_set_acls(1);
70044 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70045 + }
70046 +
70047 + gr_put_exec_file(current);
70048 + return;
70049 +}
70050 +
70051 +int
70052 +gr_acl_handle_procpidmem(const struct task_struct *task)
70053 +{
70054 + if (unlikely(!gr_acl_is_enabled()))
70055 + return 0;
70056 +
70057 + if (task != current && task->acl->mode & GR_PROTPROCFD)
70058 + return -EACCES;
70059 +
70060 + return 0;
70061 +}
70062 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70063 new file mode 100644
70064 index 0000000..f056b81
70065 --- /dev/null
70066 +++ b/grsecurity/gracl_ip.c
70067 @@ -0,0 +1,386 @@
70068 +#include <linux/kernel.h>
70069 +#include <asm/uaccess.h>
70070 +#include <asm/errno.h>
70071 +#include <net/sock.h>
70072 +#include <linux/file.h>
70073 +#include <linux/fs.h>
70074 +#include <linux/net.h>
70075 +#include <linux/in.h>
70076 +#include <linux/skbuff.h>
70077 +#include <linux/ip.h>
70078 +#include <linux/udp.h>
70079 +#include <linux/types.h>
70080 +#include <linux/sched.h>
70081 +#include <linux/netdevice.h>
70082 +#include <linux/inetdevice.h>
70083 +#include <linux/gracl.h>
70084 +#include <linux/grsecurity.h>
70085 +#include <linux/grinternal.h>
70086 +
70087 +#define GR_BIND 0x01
70088 +#define GR_CONNECT 0x02
70089 +#define GR_INVERT 0x04
70090 +#define GR_BINDOVERRIDE 0x08
70091 +#define GR_CONNECTOVERRIDE 0x10
70092 +#define GR_SOCK_FAMILY 0x20
70093 +
70094 +static const char * gr_protocols[IPPROTO_MAX] = {
70095 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70096 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70097 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70098 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70099 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70100 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70101 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70102 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70103 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70104 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70105 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70106 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70107 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70108 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70109 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70110 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70111 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70112 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70113 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70114 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70115 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70116 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70117 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70118 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70119 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70120 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70121 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70122 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70123 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70124 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70125 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70126 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70127 + };
70128 +
70129 +static const char * gr_socktypes[SOCK_MAX] = {
70130 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70131 + "unknown:7", "unknown:8", "unknown:9", "packet"
70132 + };
70133 +
70134 +static const char * gr_sockfamilies[AF_MAX+1] = {
70135 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70136 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70137 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70138 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70139 + };
70140 +
70141 +const char *
70142 +gr_proto_to_name(unsigned char proto)
70143 +{
70144 + return gr_protocols[proto];
70145 +}
70146 +
70147 +const char *
70148 +gr_socktype_to_name(unsigned char type)
70149 +{
70150 + return gr_socktypes[type];
70151 +}
70152 +
70153 +const char *
70154 +gr_sockfamily_to_name(unsigned char family)
70155 +{
70156 + return gr_sockfamilies[family];
70157 +}
70158 +
70159 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70160 +
70161 +int
70162 +gr_search_socket(const int domain, const int type, const int protocol)
70163 +{
70164 + struct acl_subject_label *curr;
70165 + const struct cred *cred = current_cred();
70166 +
70167 + if (unlikely(!gr_acl_is_enabled()))
70168 + goto exit;
70169 +
70170 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70171 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70172 + goto exit; // let the kernel handle it
70173 +
70174 + curr = current->acl;
70175 +
70176 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70177 + /* the family is allowed, if this is PF_INET allow it only if
70178 + the extra sock type/protocol checks pass */
70179 + if (domain == PF_INET)
70180 + goto inet_check;
70181 + goto exit;
70182 + } else {
70183 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70184 + __u32 fakeip = 0;
70185 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70186 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70187 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70188 + gr_to_filename(current->exec_file->f_path.dentry,
70189 + current->exec_file->f_path.mnt) :
70190 + curr->filename, curr->filename,
70191 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70192 + &current->signal->saved_ip);
70193 + goto exit;
70194 + }
70195 + goto exit_fail;
70196 + }
70197 +
70198 +inet_check:
70199 + /* the rest of this checking is for IPv4 only */
70200 + if (!curr->ips)
70201 + goto exit;
70202 +
70203 + if ((curr->ip_type & (1U << type)) &&
70204 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70205 + goto exit;
70206 +
70207 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70208 + /* we don't place acls on raw sockets , and sometimes
70209 + dgram/ip sockets are opened for ioctl and not
70210 + bind/connect, so we'll fake a bind learn log */
70211 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70212 + __u32 fakeip = 0;
70213 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70214 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70215 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70216 + gr_to_filename(current->exec_file->f_path.dentry,
70217 + current->exec_file->f_path.mnt) :
70218 + curr->filename, curr->filename,
70219 + &fakeip, 0, type,
70220 + protocol, GR_CONNECT, &current->signal->saved_ip);
70221 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70222 + __u32 fakeip = 0;
70223 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70224 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70225 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70226 + gr_to_filename(current->exec_file->f_path.dentry,
70227 + current->exec_file->f_path.mnt) :
70228 + curr->filename, curr->filename,
70229 + &fakeip, 0, type,
70230 + protocol, GR_BIND, &current->signal->saved_ip);
70231 + }
70232 + /* we'll log when they use connect or bind */
70233 + goto exit;
70234 + }
70235 +
70236 +exit_fail:
70237 + if (domain == PF_INET)
70238 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70239 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70240 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70241 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70242 + gr_socktype_to_name(type), protocol);
70243 +
70244 + return 0;
70245 +exit:
70246 + return 1;
70247 +}
70248 +
70249 +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)
70250 +{
70251 + if ((ip->mode & mode) &&
70252 + (ip_port >= ip->low) &&
70253 + (ip_port <= ip->high) &&
70254 + ((ntohl(ip_addr) & our_netmask) ==
70255 + (ntohl(our_addr) & our_netmask))
70256 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70257 + && (ip->type & (1U << type))) {
70258 + if (ip->mode & GR_INVERT)
70259 + return 2; // specifically denied
70260 + else
70261 + return 1; // allowed
70262 + }
70263 +
70264 + return 0; // not specifically allowed, may continue parsing
70265 +}
70266 +
70267 +static int
70268 +gr_search_connectbind(const int full_mode, struct sock *sk,
70269 + struct sockaddr_in *addr, const int type)
70270 +{
70271 + char iface[IFNAMSIZ] = {0};
70272 + struct acl_subject_label *curr;
70273 + struct acl_ip_label *ip;
70274 + struct inet_sock *isk;
70275 + struct net_device *dev;
70276 + struct in_device *idev;
70277 + unsigned long i;
70278 + int ret;
70279 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70280 + __u32 ip_addr = 0;
70281 + __u32 our_addr;
70282 + __u32 our_netmask;
70283 + char *p;
70284 + __u16 ip_port = 0;
70285 + const struct cred *cred = current_cred();
70286 +
70287 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70288 + return 0;
70289 +
70290 + curr = current->acl;
70291 + isk = inet_sk(sk);
70292 +
70293 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70294 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70295 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70296 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70297 + struct sockaddr_in saddr;
70298 + int err;
70299 +
70300 + saddr.sin_family = AF_INET;
70301 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70302 + saddr.sin_port = isk->inet_sport;
70303 +
70304 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70305 + if (err)
70306 + return err;
70307 +
70308 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70309 + if (err)
70310 + return err;
70311 + }
70312 +
70313 + if (!curr->ips)
70314 + return 0;
70315 +
70316 + ip_addr = addr->sin_addr.s_addr;
70317 + ip_port = ntohs(addr->sin_port);
70318 +
70319 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70320 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70321 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70322 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70323 + gr_to_filename(current->exec_file->f_path.dentry,
70324 + current->exec_file->f_path.mnt) :
70325 + curr->filename, curr->filename,
70326 + &ip_addr, ip_port, type,
70327 + sk->sk_protocol, mode, &current->signal->saved_ip);
70328 + return 0;
70329 + }
70330 +
70331 + for (i = 0; i < curr->ip_num; i++) {
70332 + ip = *(curr->ips + i);
70333 + if (ip->iface != NULL) {
70334 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70335 + p = strchr(iface, ':');
70336 + if (p != NULL)
70337 + *p = '\0';
70338 + dev = dev_get_by_name(sock_net(sk), iface);
70339 + if (dev == NULL)
70340 + continue;
70341 + idev = in_dev_get(dev);
70342 + if (idev == NULL) {
70343 + dev_put(dev);
70344 + continue;
70345 + }
70346 + rcu_read_lock();
70347 + for_ifa(idev) {
70348 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70349 + our_addr = ifa->ifa_address;
70350 + our_netmask = 0xffffffff;
70351 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70352 + if (ret == 1) {
70353 + rcu_read_unlock();
70354 + in_dev_put(idev);
70355 + dev_put(dev);
70356 + return 0;
70357 + } else if (ret == 2) {
70358 + rcu_read_unlock();
70359 + in_dev_put(idev);
70360 + dev_put(dev);
70361 + goto denied;
70362 + }
70363 + }
70364 + } endfor_ifa(idev);
70365 + rcu_read_unlock();
70366 + in_dev_put(idev);
70367 + dev_put(dev);
70368 + } else {
70369 + our_addr = ip->addr;
70370 + our_netmask = ip->netmask;
70371 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70372 + if (ret == 1)
70373 + return 0;
70374 + else if (ret == 2)
70375 + goto denied;
70376 + }
70377 + }
70378 +
70379 +denied:
70380 + if (mode == GR_BIND)
70381 + 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));
70382 + else if (mode == GR_CONNECT)
70383 + 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));
70384 +
70385 + return -EACCES;
70386 +}
70387 +
70388 +int
70389 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70390 +{
70391 + /* always allow disconnection of dgram sockets with connect */
70392 + if (addr->sin_family == AF_UNSPEC)
70393 + return 0;
70394 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70395 +}
70396 +
70397 +int
70398 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70399 +{
70400 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70401 +}
70402 +
70403 +int gr_search_listen(struct socket *sock)
70404 +{
70405 + struct sock *sk = sock->sk;
70406 + struct sockaddr_in addr;
70407 +
70408 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70409 + addr.sin_port = inet_sk(sk)->inet_sport;
70410 +
70411 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70412 +}
70413 +
70414 +int gr_search_accept(struct socket *sock)
70415 +{
70416 + struct sock *sk = sock->sk;
70417 + struct sockaddr_in addr;
70418 +
70419 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70420 + addr.sin_port = inet_sk(sk)->inet_sport;
70421 +
70422 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70423 +}
70424 +
70425 +int
70426 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70427 +{
70428 + if (addr)
70429 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70430 + else {
70431 + struct sockaddr_in sin;
70432 + const struct inet_sock *inet = inet_sk(sk);
70433 +
70434 + sin.sin_addr.s_addr = inet->inet_daddr;
70435 + sin.sin_port = inet->inet_dport;
70436 +
70437 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70438 + }
70439 +}
70440 +
70441 +int
70442 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70443 +{
70444 + struct sockaddr_in sin;
70445 +
70446 + if (unlikely(skb->len < sizeof (struct udphdr)))
70447 + return 0; // skip this packet
70448 +
70449 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70450 + sin.sin_port = udp_hdr(skb)->source;
70451 +
70452 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70453 +}
70454 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70455 new file mode 100644
70456 index 0000000..25f54ef
70457 --- /dev/null
70458 +++ b/grsecurity/gracl_learn.c
70459 @@ -0,0 +1,207 @@
70460 +#include <linux/kernel.h>
70461 +#include <linux/mm.h>
70462 +#include <linux/sched.h>
70463 +#include <linux/poll.h>
70464 +#include <linux/string.h>
70465 +#include <linux/file.h>
70466 +#include <linux/types.h>
70467 +#include <linux/vmalloc.h>
70468 +#include <linux/grinternal.h>
70469 +
70470 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70471 + size_t count, loff_t *ppos);
70472 +extern int gr_acl_is_enabled(void);
70473 +
70474 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70475 +static int gr_learn_attached;
70476 +
70477 +/* use a 512k buffer */
70478 +#define LEARN_BUFFER_SIZE (512 * 1024)
70479 +
70480 +static DEFINE_SPINLOCK(gr_learn_lock);
70481 +static DEFINE_MUTEX(gr_learn_user_mutex);
70482 +
70483 +/* we need to maintain two buffers, so that the kernel context of grlearn
70484 + uses a semaphore around the userspace copying, and the other kernel contexts
70485 + use a spinlock when copying into the buffer, since they cannot sleep
70486 +*/
70487 +static char *learn_buffer;
70488 +static char *learn_buffer_user;
70489 +static int learn_buffer_len;
70490 +static int learn_buffer_user_len;
70491 +
70492 +static ssize_t
70493 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70494 +{
70495 + DECLARE_WAITQUEUE(wait, current);
70496 + ssize_t retval = 0;
70497 +
70498 + add_wait_queue(&learn_wait, &wait);
70499 + set_current_state(TASK_INTERRUPTIBLE);
70500 + do {
70501 + mutex_lock(&gr_learn_user_mutex);
70502 + spin_lock(&gr_learn_lock);
70503 + if (learn_buffer_len)
70504 + break;
70505 + spin_unlock(&gr_learn_lock);
70506 + mutex_unlock(&gr_learn_user_mutex);
70507 + if (file->f_flags & O_NONBLOCK) {
70508 + retval = -EAGAIN;
70509 + goto out;
70510 + }
70511 + if (signal_pending(current)) {
70512 + retval = -ERESTARTSYS;
70513 + goto out;
70514 + }
70515 +
70516 + schedule();
70517 + } while (1);
70518 +
70519 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70520 + learn_buffer_user_len = learn_buffer_len;
70521 + retval = learn_buffer_len;
70522 + learn_buffer_len = 0;
70523 +
70524 + spin_unlock(&gr_learn_lock);
70525 +
70526 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70527 + retval = -EFAULT;
70528 +
70529 + mutex_unlock(&gr_learn_user_mutex);
70530 +out:
70531 + set_current_state(TASK_RUNNING);
70532 + remove_wait_queue(&learn_wait, &wait);
70533 + return retval;
70534 +}
70535 +
70536 +static unsigned int
70537 +poll_learn(struct file * file, poll_table * wait)
70538 +{
70539 + poll_wait(file, &learn_wait, wait);
70540 +
70541 + if (learn_buffer_len)
70542 + return (POLLIN | POLLRDNORM);
70543 +
70544 + return 0;
70545 +}
70546 +
70547 +void
70548 +gr_clear_learn_entries(void)
70549 +{
70550 + char *tmp;
70551 +
70552 + mutex_lock(&gr_learn_user_mutex);
70553 + spin_lock(&gr_learn_lock);
70554 + tmp = learn_buffer;
70555 + learn_buffer = NULL;
70556 + spin_unlock(&gr_learn_lock);
70557 + if (tmp)
70558 + vfree(tmp);
70559 + if (learn_buffer_user != NULL) {
70560 + vfree(learn_buffer_user);
70561 + learn_buffer_user = NULL;
70562 + }
70563 + learn_buffer_len = 0;
70564 + mutex_unlock(&gr_learn_user_mutex);
70565 +
70566 + return;
70567 +}
70568 +
70569 +void
70570 +gr_add_learn_entry(const char *fmt, ...)
70571 +{
70572 + va_list args;
70573 + unsigned int len;
70574 +
70575 + if (!gr_learn_attached)
70576 + return;
70577 +
70578 + spin_lock(&gr_learn_lock);
70579 +
70580 + /* leave a gap at the end so we know when it's "full" but don't have to
70581 + compute the exact length of the string we're trying to append
70582 + */
70583 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70584 + spin_unlock(&gr_learn_lock);
70585 + wake_up_interruptible(&learn_wait);
70586 + return;
70587 + }
70588 + if (learn_buffer == NULL) {
70589 + spin_unlock(&gr_learn_lock);
70590 + return;
70591 + }
70592 +
70593 + va_start(args, fmt);
70594 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70595 + va_end(args);
70596 +
70597 + learn_buffer_len += len + 1;
70598 +
70599 + spin_unlock(&gr_learn_lock);
70600 + wake_up_interruptible(&learn_wait);
70601 +
70602 + return;
70603 +}
70604 +
70605 +static int
70606 +open_learn(struct inode *inode, struct file *file)
70607 +{
70608 + if (file->f_mode & FMODE_READ && gr_learn_attached)
70609 + return -EBUSY;
70610 + if (file->f_mode & FMODE_READ) {
70611 + int retval = 0;
70612 + mutex_lock(&gr_learn_user_mutex);
70613 + if (learn_buffer == NULL)
70614 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70615 + if (learn_buffer_user == NULL)
70616 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70617 + if (learn_buffer == NULL) {
70618 + retval = -ENOMEM;
70619 + goto out_error;
70620 + }
70621 + if (learn_buffer_user == NULL) {
70622 + retval = -ENOMEM;
70623 + goto out_error;
70624 + }
70625 + learn_buffer_len = 0;
70626 + learn_buffer_user_len = 0;
70627 + gr_learn_attached = 1;
70628 +out_error:
70629 + mutex_unlock(&gr_learn_user_mutex);
70630 + return retval;
70631 + }
70632 + return 0;
70633 +}
70634 +
70635 +static int
70636 +close_learn(struct inode *inode, struct file *file)
70637 +{
70638 + if (file->f_mode & FMODE_READ) {
70639 + char *tmp = NULL;
70640 + mutex_lock(&gr_learn_user_mutex);
70641 + spin_lock(&gr_learn_lock);
70642 + tmp = learn_buffer;
70643 + learn_buffer = NULL;
70644 + spin_unlock(&gr_learn_lock);
70645 + if (tmp)
70646 + vfree(tmp);
70647 + if (learn_buffer_user != NULL) {
70648 + vfree(learn_buffer_user);
70649 + learn_buffer_user = NULL;
70650 + }
70651 + learn_buffer_len = 0;
70652 + learn_buffer_user_len = 0;
70653 + gr_learn_attached = 0;
70654 + mutex_unlock(&gr_learn_user_mutex);
70655 + }
70656 +
70657 + return 0;
70658 +}
70659 +
70660 +const struct file_operations grsec_fops = {
70661 + .read = read_learn,
70662 + .write = write_grsec_handler,
70663 + .open = open_learn,
70664 + .release = close_learn,
70665 + .poll = poll_learn,
70666 +};
70667 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70668 new file mode 100644
70669 index 0000000..361a099
70670 --- /dev/null
70671 +++ b/grsecurity/gracl_policy.c
70672 @@ -0,0 +1,1782 @@
70673 +#include <linux/kernel.h>
70674 +#include <linux/module.h>
70675 +#include <linux/sched.h>
70676 +#include <linux/mm.h>
70677 +#include <linux/file.h>
70678 +#include <linux/fs.h>
70679 +#include <linux/namei.h>
70680 +#include <linux/mount.h>
70681 +#include <linux/tty.h>
70682 +#include <linux/proc_fs.h>
70683 +#include <linux/lglock.h>
70684 +#include <linux/slab.h>
70685 +#include <linux/vmalloc.h>
70686 +#include <linux/types.h>
70687 +#include <linux/sysctl.h>
70688 +#include <linux/netdevice.h>
70689 +#include <linux/ptrace.h>
70690 +#include <linux/gracl.h>
70691 +#include <linux/gralloc.h>
70692 +#include <linux/security.h>
70693 +#include <linux/grinternal.h>
70694 +#include <linux/pid_namespace.h>
70695 +#include <linux/stop_machine.h>
70696 +#include <linux/fdtable.h>
70697 +#include <linux/percpu.h>
70698 +#include <linux/lglock.h>
70699 +#include <linux/hugetlb.h>
70700 +#include <linux/posix-timers.h>
70701 +#include "../fs/mount.h"
70702 +
70703 +#include <asm/uaccess.h>
70704 +#include <asm/errno.h>
70705 +#include <asm/mman.h>
70706 +
70707 +extern struct gr_policy_state *polstate;
70708 +
70709 +#define FOR_EACH_ROLE_START(role) \
70710 + role = polstate->role_list; \
70711 + while (role) {
70712 +
70713 +#define FOR_EACH_ROLE_END(role) \
70714 + role = role->prev; \
70715 + }
70716 +
70717 +struct path gr_real_root;
70718 +
70719 +extern struct gr_alloc_state *current_alloc_state;
70720 +
70721 +u16 acl_sp_role_value;
70722 +
70723 +static DEFINE_MUTEX(gr_dev_mutex);
70724 +
70725 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70726 +extern void gr_clear_learn_entries(void);
70727 +
70728 +static struct gr_arg gr_usermode;
70729 +static unsigned char gr_system_salt[GR_SALT_LEN];
70730 +static unsigned char gr_system_sum[GR_SHA_LEN];
70731 +
70732 +static unsigned int gr_auth_attempts = 0;
70733 +static unsigned long gr_auth_expires = 0UL;
70734 +
70735 +struct acl_object_label *fakefs_obj_rw;
70736 +struct acl_object_label *fakefs_obj_rwx;
70737 +
70738 +extern int gr_init_uidset(void);
70739 +extern void gr_free_uidset(void);
70740 +extern void gr_remove_uid(uid_t uid);
70741 +extern int gr_find_uid(uid_t uid);
70742 +
70743 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70744 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70745 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70746 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70747 +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);
70748 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70749 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70750 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70751 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70752 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70753 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70754 +extern void assign_special_role(const char *rolename);
70755 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70756 +extern int gr_rbac_disable(void *unused);
70757 +extern void gr_enable_rbac_system(void);
70758 +
70759 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70760 +{
70761 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70762 + return -EFAULT;
70763 +
70764 + return 0;
70765 +}
70766 +
70767 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70768 +{
70769 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70770 + return -EFAULT;
70771 +
70772 + return 0;
70773 +}
70774 +
70775 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70776 +{
70777 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70778 + return -EFAULT;
70779 +
70780 + return 0;
70781 +}
70782 +
70783 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70784 +{
70785 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70786 + return -EFAULT;
70787 +
70788 + return 0;
70789 +}
70790 +
70791 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70792 +{
70793 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70794 + return -EFAULT;
70795 +
70796 + return 0;
70797 +}
70798 +
70799 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70800 +{
70801 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70802 + return -EFAULT;
70803 +
70804 + return 0;
70805 +}
70806 +
70807 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70808 +{
70809 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70810 + return -EFAULT;
70811 +
70812 + return 0;
70813 +}
70814 +
70815 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70816 +{
70817 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70818 + return -EFAULT;
70819 +
70820 + return 0;
70821 +}
70822 +
70823 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70824 +{
70825 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70826 + return -EFAULT;
70827 +
70828 + return 0;
70829 +}
70830 +
70831 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70832 +{
70833 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70834 + return -EFAULT;
70835 +
70836 + if (((uwrap->version != GRSECURITY_VERSION) &&
70837 + (uwrap->version != 0x2901)) ||
70838 + (uwrap->size != sizeof(struct gr_arg)))
70839 + return -EINVAL;
70840 +
70841 + return 0;
70842 +}
70843 +
70844 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70845 +{
70846 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70847 + return -EFAULT;
70848 +
70849 + return 0;
70850 +}
70851 +
70852 +static size_t get_gr_arg_wrapper_size_normal(void)
70853 +{
70854 + return sizeof(struct gr_arg_wrapper);
70855 +}
70856 +
70857 +#ifdef CONFIG_COMPAT
70858 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70859 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70860 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70861 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70862 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70863 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70864 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70865 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70866 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70867 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70868 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70869 +extern size_t get_gr_arg_wrapper_size_compat(void);
70870 +
70871 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70872 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70873 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70874 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70875 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70876 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70877 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70878 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70879 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70880 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70881 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70882 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70883 +
70884 +#else
70885 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70886 +#define copy_gr_arg copy_gr_arg_normal
70887 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
70888 +#define copy_acl_object_label copy_acl_object_label_normal
70889 +#define copy_acl_subject_label copy_acl_subject_label_normal
70890 +#define copy_acl_role_label copy_acl_role_label_normal
70891 +#define copy_acl_ip_label copy_acl_ip_label_normal
70892 +#define copy_pointer_from_array copy_pointer_from_array_normal
70893 +#define copy_sprole_pw copy_sprole_pw_normal
70894 +#define copy_role_transition copy_role_transition_normal
70895 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
70896 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70897 +#endif
70898 +
70899 +static struct acl_subject_label *
70900 +lookup_subject_map(const struct acl_subject_label *userp)
70901 +{
70902 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70903 + struct subject_map *match;
70904 +
70905 + match = polstate->subj_map_set.s_hash[index];
70906 +
70907 + while (match && match->user != userp)
70908 + match = match->next;
70909 +
70910 + if (match != NULL)
70911 + return match->kernel;
70912 + else
70913 + return NULL;
70914 +}
70915 +
70916 +static void
70917 +insert_subj_map_entry(struct subject_map *subjmap)
70918 +{
70919 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70920 + struct subject_map **curr;
70921 +
70922 + subjmap->prev = NULL;
70923 +
70924 + curr = &polstate->subj_map_set.s_hash[index];
70925 + if (*curr != NULL)
70926 + (*curr)->prev = subjmap;
70927 +
70928 + subjmap->next = *curr;
70929 + *curr = subjmap;
70930 +
70931 + return;
70932 +}
70933 +
70934 +static void
70935 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70936 +{
70937 + unsigned int index =
70938 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70939 + struct acl_role_label **curr;
70940 + struct acl_role_label *tmp, *tmp2;
70941 +
70942 + curr = &polstate->acl_role_set.r_hash[index];
70943 +
70944 + /* simple case, slot is empty, just set it to our role */
70945 + if (*curr == NULL) {
70946 + *curr = role;
70947 + } else {
70948 + /* example:
70949 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
70950 + 2 -> 3
70951 + */
70952 + /* first check to see if we can already be reached via this slot */
70953 + tmp = *curr;
70954 + while (tmp && tmp != role)
70955 + tmp = tmp->next;
70956 + if (tmp == role) {
70957 + /* we don't need to add ourselves to this slot's chain */
70958 + return;
70959 + }
70960 + /* we need to add ourselves to this chain, two cases */
70961 + if (role->next == NULL) {
70962 + /* simple case, append the current chain to our role */
70963 + role->next = *curr;
70964 + *curr = role;
70965 + } else {
70966 + /* 1 -> 2 -> 3 -> 4
70967 + 2 -> 3 -> 4
70968 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70969 + */
70970 + /* trickier case: walk our role's chain until we find
70971 + the role for the start of the current slot's chain */
70972 + tmp = role;
70973 + tmp2 = *curr;
70974 + while (tmp->next && tmp->next != tmp2)
70975 + tmp = tmp->next;
70976 + if (tmp->next == tmp2) {
70977 + /* from example above, we found 3, so just
70978 + replace this slot's chain with ours */
70979 + *curr = role;
70980 + } else {
70981 + /* we didn't find a subset of our role's chain
70982 + in the current slot's chain, so append their
70983 + chain to ours, and set us as the first role in
70984 + the slot's chain
70985 +
70986 + we could fold this case with the case above,
70987 + but making it explicit for clarity
70988 + */
70989 + tmp->next = tmp2;
70990 + *curr = role;
70991 + }
70992 + }
70993 + }
70994 +
70995 + return;
70996 +}
70997 +
70998 +static void
70999 +insert_acl_role_label(struct acl_role_label *role)
71000 +{
71001 + int i;
71002 +
71003 + if (polstate->role_list == NULL) {
71004 + polstate->role_list = role;
71005 + role->prev = NULL;
71006 + } else {
71007 + role->prev = polstate->role_list;
71008 + polstate->role_list = role;
71009 + }
71010 +
71011 + /* used for hash chains */
71012 + role->next = NULL;
71013 +
71014 + if (role->roletype & GR_ROLE_DOMAIN) {
71015 + for (i = 0; i < role->domain_child_num; i++)
71016 + __insert_acl_role_label(role, role->domain_children[i]);
71017 + } else
71018 + __insert_acl_role_label(role, role->uidgid);
71019 +}
71020 +
71021 +static int
71022 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71023 +{
71024 + struct name_entry **curr, *nentry;
71025 + struct inodev_entry *ientry;
71026 + unsigned int len = strlen(name);
71027 + unsigned int key = full_name_hash(name, len);
71028 + unsigned int index = key % polstate->name_set.n_size;
71029 +
71030 + curr = &polstate->name_set.n_hash[index];
71031 +
71032 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71033 + curr = &((*curr)->next);
71034 +
71035 + if (*curr != NULL)
71036 + return 1;
71037 +
71038 + nentry = acl_alloc(sizeof (struct name_entry));
71039 + if (nentry == NULL)
71040 + return 0;
71041 + ientry = acl_alloc(sizeof (struct inodev_entry));
71042 + if (ientry == NULL)
71043 + return 0;
71044 + ientry->nentry = nentry;
71045 +
71046 + nentry->key = key;
71047 + nentry->name = name;
71048 + nentry->inode = inode;
71049 + nentry->device = device;
71050 + nentry->len = len;
71051 + nentry->deleted = deleted;
71052 +
71053 + nentry->prev = NULL;
71054 + curr = &polstate->name_set.n_hash[index];
71055 + if (*curr != NULL)
71056 + (*curr)->prev = nentry;
71057 + nentry->next = *curr;
71058 + *curr = nentry;
71059 +
71060 + /* insert us into the table searchable by inode/dev */
71061 + __insert_inodev_entry(polstate, ientry);
71062 +
71063 + return 1;
71064 +}
71065 +
71066 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71067 +
71068 +static void *
71069 +create_table(__u32 * len, int elementsize)
71070 +{
71071 + unsigned int table_sizes[] = {
71072 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71073 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71074 + 4194301, 8388593, 16777213, 33554393, 67108859
71075 + };
71076 + void *newtable = NULL;
71077 + unsigned int pwr = 0;
71078 +
71079 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71080 + table_sizes[pwr] <= *len)
71081 + pwr++;
71082 +
71083 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71084 + return newtable;
71085 +
71086 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71087 + newtable =
71088 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71089 + else
71090 + newtable = vmalloc(table_sizes[pwr] * elementsize);
71091 +
71092 + *len = table_sizes[pwr];
71093 +
71094 + return newtable;
71095 +}
71096 +
71097 +static int
71098 +init_variables(const struct gr_arg *arg, bool reload)
71099 +{
71100 + struct task_struct *reaper = init_pid_ns.child_reaper;
71101 + unsigned int stacksize;
71102 +
71103 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71104 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71105 + polstate->name_set.n_size = arg->role_db.num_objects;
71106 + polstate->inodev_set.i_size = arg->role_db.num_objects;
71107 +
71108 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71109 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71110 + return 1;
71111 +
71112 + if (!reload) {
71113 + if (!gr_init_uidset())
71114 + return 1;
71115 + }
71116 +
71117 + /* set up the stack that holds allocation info */
71118 +
71119 + stacksize = arg->role_db.num_pointers + 5;
71120 +
71121 + if (!acl_alloc_stack_init(stacksize))
71122 + return 1;
71123 +
71124 + if (!reload) {
71125 + /* grab reference for the real root dentry and vfsmount */
71126 + get_fs_root(reaper->fs, &gr_real_root);
71127 +
71128 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71129 + 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);
71130 +#endif
71131 +
71132 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71133 + if (fakefs_obj_rw == NULL)
71134 + return 1;
71135 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71136 +
71137 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71138 + if (fakefs_obj_rwx == NULL)
71139 + return 1;
71140 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71141 + }
71142 +
71143 + polstate->subj_map_set.s_hash =
71144 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71145 + polstate->acl_role_set.r_hash =
71146 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71147 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71148 + polstate->inodev_set.i_hash =
71149 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71150 +
71151 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71152 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71153 + return 1;
71154 +
71155 + memset(polstate->subj_map_set.s_hash, 0,
71156 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71157 + memset(polstate->acl_role_set.r_hash, 0,
71158 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71159 + memset(polstate->name_set.n_hash, 0,
71160 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71161 + memset(polstate->inodev_set.i_hash, 0,
71162 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71163 +
71164 + return 0;
71165 +}
71166 +
71167 +/* free information not needed after startup
71168 + currently contains user->kernel pointer mappings for subjects
71169 +*/
71170 +
71171 +static void
71172 +free_init_variables(void)
71173 +{
71174 + __u32 i;
71175 +
71176 + if (polstate->subj_map_set.s_hash) {
71177 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71178 + if (polstate->subj_map_set.s_hash[i]) {
71179 + kfree(polstate->subj_map_set.s_hash[i]);
71180 + polstate->subj_map_set.s_hash[i] = NULL;
71181 + }
71182 + }
71183 +
71184 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71185 + PAGE_SIZE)
71186 + kfree(polstate->subj_map_set.s_hash);
71187 + else
71188 + vfree(polstate->subj_map_set.s_hash);
71189 + }
71190 +
71191 + return;
71192 +}
71193 +
71194 +static void
71195 +free_variables(bool reload)
71196 +{
71197 + struct acl_subject_label *s;
71198 + struct acl_role_label *r;
71199 + struct task_struct *task, *task2;
71200 + unsigned int x;
71201 +
71202 + if (!reload) {
71203 + gr_clear_learn_entries();
71204 +
71205 + read_lock(&tasklist_lock);
71206 + do_each_thread(task2, task) {
71207 + task->acl_sp_role = 0;
71208 + task->acl_role_id = 0;
71209 + task->inherited = 0;
71210 + task->acl = NULL;
71211 + task->role = NULL;
71212 + } while_each_thread(task2, task);
71213 + read_unlock(&tasklist_lock);
71214 +
71215 + kfree(fakefs_obj_rw);
71216 + fakefs_obj_rw = NULL;
71217 + kfree(fakefs_obj_rwx);
71218 + fakefs_obj_rwx = NULL;
71219 +
71220 + /* release the reference to the real root dentry and vfsmount */
71221 + path_put(&gr_real_root);
71222 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71223 + }
71224 +
71225 + /* free all object hash tables */
71226 +
71227 + FOR_EACH_ROLE_START(r)
71228 + if (r->subj_hash == NULL)
71229 + goto next_role;
71230 + FOR_EACH_SUBJECT_START(r, s, x)
71231 + if (s->obj_hash == NULL)
71232 + break;
71233 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71234 + kfree(s->obj_hash);
71235 + else
71236 + vfree(s->obj_hash);
71237 + FOR_EACH_SUBJECT_END(s, x)
71238 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71239 + if (s->obj_hash == NULL)
71240 + break;
71241 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71242 + kfree(s->obj_hash);
71243 + else
71244 + vfree(s->obj_hash);
71245 + FOR_EACH_NESTED_SUBJECT_END(s)
71246 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71247 + kfree(r->subj_hash);
71248 + else
71249 + vfree(r->subj_hash);
71250 + r->subj_hash = NULL;
71251 +next_role:
71252 + FOR_EACH_ROLE_END(r)
71253 +
71254 + acl_free_all();
71255 +
71256 + if (polstate->acl_role_set.r_hash) {
71257 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71258 + PAGE_SIZE)
71259 + kfree(polstate->acl_role_set.r_hash);
71260 + else
71261 + vfree(polstate->acl_role_set.r_hash);
71262 + }
71263 + if (polstate->name_set.n_hash) {
71264 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71265 + PAGE_SIZE)
71266 + kfree(polstate->name_set.n_hash);
71267 + else
71268 + vfree(polstate->name_set.n_hash);
71269 + }
71270 +
71271 + if (polstate->inodev_set.i_hash) {
71272 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71273 + PAGE_SIZE)
71274 + kfree(polstate->inodev_set.i_hash);
71275 + else
71276 + vfree(polstate->inodev_set.i_hash);
71277 + }
71278 +
71279 + if (!reload)
71280 + gr_free_uidset();
71281 +
71282 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71283 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71284 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71285 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71286 +
71287 + polstate->default_role = NULL;
71288 + polstate->kernel_role = NULL;
71289 + polstate->role_list = NULL;
71290 +
71291 + return;
71292 +}
71293 +
71294 +static struct acl_subject_label *
71295 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71296 +
71297 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71298 +{
71299 + unsigned int len = strnlen_user(*name, maxlen);
71300 + char *tmp;
71301 +
71302 + if (!len || len >= maxlen)
71303 + return -EINVAL;
71304 +
71305 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71306 + return -ENOMEM;
71307 +
71308 + if (copy_from_user(tmp, *name, len))
71309 + return -EFAULT;
71310 +
71311 + tmp[len-1] = '\0';
71312 + *name = tmp;
71313 +
71314 + return 0;
71315 +}
71316 +
71317 +static int
71318 +copy_user_glob(struct acl_object_label *obj)
71319 +{
71320 + struct acl_object_label *g_tmp, **guser;
71321 + int error;
71322 +
71323 + if (obj->globbed == NULL)
71324 + return 0;
71325 +
71326 + guser = &obj->globbed;
71327 + while (*guser) {
71328 + g_tmp = (struct acl_object_label *)
71329 + acl_alloc(sizeof (struct acl_object_label));
71330 + if (g_tmp == NULL)
71331 + return -ENOMEM;
71332 +
71333 + if (copy_acl_object_label(g_tmp, *guser))
71334 + return -EFAULT;
71335 +
71336 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71337 + if (error)
71338 + return error;
71339 +
71340 + *guser = g_tmp;
71341 + guser = &(g_tmp->next);
71342 + }
71343 +
71344 + return 0;
71345 +}
71346 +
71347 +static int
71348 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71349 + struct acl_role_label *role)
71350 +{
71351 + struct acl_object_label *o_tmp;
71352 + int ret;
71353 +
71354 + while (userp) {
71355 + if ((o_tmp = (struct acl_object_label *)
71356 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71357 + return -ENOMEM;
71358 +
71359 + if (copy_acl_object_label(o_tmp, userp))
71360 + return -EFAULT;
71361 +
71362 + userp = o_tmp->prev;
71363 +
71364 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71365 + if (ret)
71366 + return ret;
71367 +
71368 + insert_acl_obj_label(o_tmp, subj);
71369 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71370 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71371 + return -ENOMEM;
71372 +
71373 + ret = copy_user_glob(o_tmp);
71374 + if (ret)
71375 + return ret;
71376 +
71377 + if (o_tmp->nested) {
71378 + int already_copied;
71379 +
71380 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71381 + if (IS_ERR(o_tmp->nested))
71382 + return PTR_ERR(o_tmp->nested);
71383 +
71384 + /* insert into nested subject list if we haven't copied this one yet
71385 + to prevent duplicate entries */
71386 + if (!already_copied) {
71387 + o_tmp->nested->next = role->hash->first;
71388 + role->hash->first = o_tmp->nested;
71389 + }
71390 + }
71391 + }
71392 +
71393 + return 0;
71394 +}
71395 +
71396 +static __u32
71397 +count_user_subjs(struct acl_subject_label *userp)
71398 +{
71399 + struct acl_subject_label s_tmp;
71400 + __u32 num = 0;
71401 +
71402 + while (userp) {
71403 + if (copy_acl_subject_label(&s_tmp, userp))
71404 + break;
71405 +
71406 + userp = s_tmp.prev;
71407 + }
71408 +
71409 + return num;
71410 +}
71411 +
71412 +static int
71413 +copy_user_allowedips(struct acl_role_label *rolep)
71414 +{
71415 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71416 +
71417 + ruserip = rolep->allowed_ips;
71418 +
71419 + while (ruserip) {
71420 + rlast = rtmp;
71421 +
71422 + if ((rtmp = (struct role_allowed_ip *)
71423 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71424 + return -ENOMEM;
71425 +
71426 + if (copy_role_allowed_ip(rtmp, ruserip))
71427 + return -EFAULT;
71428 +
71429 + ruserip = rtmp->prev;
71430 +
71431 + if (!rlast) {
71432 + rtmp->prev = NULL;
71433 + rolep->allowed_ips = rtmp;
71434 + } else {
71435 + rlast->next = rtmp;
71436 + rtmp->prev = rlast;
71437 + }
71438 +
71439 + if (!ruserip)
71440 + rtmp->next = NULL;
71441 + }
71442 +
71443 + return 0;
71444 +}
71445 +
71446 +static int
71447 +copy_user_transitions(struct acl_role_label *rolep)
71448 +{
71449 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
71450 + int error;
71451 +
71452 + rusertp = rolep->transitions;
71453 +
71454 + while (rusertp) {
71455 + rlast = rtmp;
71456 +
71457 + if ((rtmp = (struct role_transition *)
71458 + acl_alloc(sizeof (struct role_transition))) == NULL)
71459 + return -ENOMEM;
71460 +
71461 + if (copy_role_transition(rtmp, rusertp))
71462 + return -EFAULT;
71463 +
71464 + rusertp = rtmp->prev;
71465 +
71466 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71467 + if (error)
71468 + return error;
71469 +
71470 + if (!rlast) {
71471 + rtmp->prev = NULL;
71472 + rolep->transitions = rtmp;
71473 + } else {
71474 + rlast->next = rtmp;
71475 + rtmp->prev = rlast;
71476 + }
71477 +
71478 + if (!rusertp)
71479 + rtmp->next = NULL;
71480 + }
71481 +
71482 + return 0;
71483 +}
71484 +
71485 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
71486 +{
71487 + struct acl_object_label o_tmp;
71488 + __u32 num = 0;
71489 +
71490 + while (userp) {
71491 + if (copy_acl_object_label(&o_tmp, userp))
71492 + break;
71493 +
71494 + userp = o_tmp.prev;
71495 + num++;
71496 + }
71497 +
71498 + return num;
71499 +}
71500 +
71501 +static struct acl_subject_label *
71502 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71503 +{
71504 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71505 + __u32 num_objs;
71506 + struct acl_ip_label **i_tmp, *i_utmp2;
71507 + struct gr_hash_struct ghash;
71508 + struct subject_map *subjmap;
71509 + unsigned int i_num;
71510 + int err;
71511 +
71512 + if (already_copied != NULL)
71513 + *already_copied = 0;
71514 +
71515 + s_tmp = lookup_subject_map(userp);
71516 +
71517 + /* we've already copied this subject into the kernel, just return
71518 + the reference to it, and don't copy it over again
71519 + */
71520 + if (s_tmp) {
71521 + if (already_copied != NULL)
71522 + *already_copied = 1;
71523 + return(s_tmp);
71524 + }
71525 +
71526 + if ((s_tmp = (struct acl_subject_label *)
71527 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71528 + return ERR_PTR(-ENOMEM);
71529 +
71530 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71531 + if (subjmap == NULL)
71532 + return ERR_PTR(-ENOMEM);
71533 +
71534 + subjmap->user = userp;
71535 + subjmap->kernel = s_tmp;
71536 + insert_subj_map_entry(subjmap);
71537 +
71538 + if (copy_acl_subject_label(s_tmp, userp))
71539 + return ERR_PTR(-EFAULT);
71540 +
71541 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71542 + if (err)
71543 + return ERR_PTR(err);
71544 +
71545 + if (!strcmp(s_tmp->filename, "/"))
71546 + role->root_label = s_tmp;
71547 +
71548 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71549 + return ERR_PTR(-EFAULT);
71550 +
71551 + /* copy user and group transition tables */
71552 +
71553 + if (s_tmp->user_trans_num) {
71554 + uid_t *uidlist;
71555 +
71556 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71557 + if (uidlist == NULL)
71558 + return ERR_PTR(-ENOMEM);
71559 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71560 + return ERR_PTR(-EFAULT);
71561 +
71562 + s_tmp->user_transitions = uidlist;
71563 + }
71564 +
71565 + if (s_tmp->group_trans_num) {
71566 + gid_t *gidlist;
71567 +
71568 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71569 + if (gidlist == NULL)
71570 + return ERR_PTR(-ENOMEM);
71571 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71572 + return ERR_PTR(-EFAULT);
71573 +
71574 + s_tmp->group_transitions = gidlist;
71575 + }
71576 +
71577 + /* set up object hash table */
71578 + num_objs = count_user_objs(ghash.first);
71579 +
71580 + s_tmp->obj_hash_size = num_objs;
71581 + s_tmp->obj_hash =
71582 + (struct acl_object_label **)
71583 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71584 +
71585 + if (!s_tmp->obj_hash)
71586 + return ERR_PTR(-ENOMEM);
71587 +
71588 + memset(s_tmp->obj_hash, 0,
71589 + s_tmp->obj_hash_size *
71590 + sizeof (struct acl_object_label *));
71591 +
71592 + /* add in objects */
71593 + err = copy_user_objs(ghash.first, s_tmp, role);
71594 +
71595 + if (err)
71596 + return ERR_PTR(err);
71597 +
71598 + /* set pointer for parent subject */
71599 + if (s_tmp->parent_subject) {
71600 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71601 +
71602 + if (IS_ERR(s_tmp2))
71603 + return s_tmp2;
71604 +
71605 + s_tmp->parent_subject = s_tmp2;
71606 + }
71607 +
71608 + /* add in ip acls */
71609 +
71610 + if (!s_tmp->ip_num) {
71611 + s_tmp->ips = NULL;
71612 + goto insert;
71613 + }
71614 +
71615 + i_tmp =
71616 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71617 + sizeof (struct acl_ip_label *));
71618 +
71619 + if (!i_tmp)
71620 + return ERR_PTR(-ENOMEM);
71621 +
71622 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71623 + *(i_tmp + i_num) =
71624 + (struct acl_ip_label *)
71625 + acl_alloc(sizeof (struct acl_ip_label));
71626 + if (!*(i_tmp + i_num))
71627 + return ERR_PTR(-ENOMEM);
71628 +
71629 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71630 + return ERR_PTR(-EFAULT);
71631 +
71632 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71633 + return ERR_PTR(-EFAULT);
71634 +
71635 + if ((*(i_tmp + i_num))->iface == NULL)
71636 + continue;
71637 +
71638 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71639 + if (err)
71640 + return ERR_PTR(err);
71641 + }
71642 +
71643 + s_tmp->ips = i_tmp;
71644 +
71645 +insert:
71646 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71647 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71648 + return ERR_PTR(-ENOMEM);
71649 +
71650 + return s_tmp;
71651 +}
71652 +
71653 +static int
71654 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71655 +{
71656 + struct acl_subject_label s_pre;
71657 + struct acl_subject_label * ret;
71658 + int err;
71659 +
71660 + while (userp) {
71661 + if (copy_acl_subject_label(&s_pre, userp))
71662 + return -EFAULT;
71663 +
71664 + ret = do_copy_user_subj(userp, role, NULL);
71665 +
71666 + err = PTR_ERR(ret);
71667 + if (IS_ERR(ret))
71668 + return err;
71669 +
71670 + insert_acl_subj_label(ret, role);
71671 +
71672 + userp = s_pre.prev;
71673 + }
71674 +
71675 + return 0;
71676 +}
71677 +
71678 +static int
71679 +copy_user_acl(struct gr_arg *arg)
71680 +{
71681 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71682 + struct acl_subject_label *subj_list;
71683 + struct sprole_pw *sptmp;
71684 + struct gr_hash_struct *ghash;
71685 + uid_t *domainlist;
71686 + unsigned int r_num;
71687 + int err = 0;
71688 + __u16 i;
71689 + __u32 num_subjs;
71690 +
71691 + /* we need a default and kernel role */
71692 + if (arg->role_db.num_roles < 2)
71693 + return -EINVAL;
71694 +
71695 + /* copy special role authentication info from userspace */
71696 +
71697 + polstate->num_sprole_pws = arg->num_sprole_pws;
71698 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71699 +
71700 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71701 + return -ENOMEM;
71702 +
71703 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71704 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71705 + if (!sptmp)
71706 + return -ENOMEM;
71707 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71708 + return -EFAULT;
71709 +
71710 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71711 + if (err)
71712 + return err;
71713 +
71714 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71715 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71716 +#endif
71717 +
71718 + polstate->acl_special_roles[i] = sptmp;
71719 + }
71720 +
71721 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71722 +
71723 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71724 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
71725 +
71726 + if (!r_tmp)
71727 + return -ENOMEM;
71728 +
71729 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71730 + return -EFAULT;
71731 +
71732 + if (copy_acl_role_label(r_tmp, r_utmp2))
71733 + return -EFAULT;
71734 +
71735 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71736 + if (err)
71737 + return err;
71738 +
71739 + if (!strcmp(r_tmp->rolename, "default")
71740 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71741 + polstate->default_role = r_tmp;
71742 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71743 + polstate->kernel_role = r_tmp;
71744 + }
71745 +
71746 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71747 + return -ENOMEM;
71748 +
71749 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
71750 + return -EFAULT;
71751 +
71752 + r_tmp->hash = ghash;
71753 +
71754 + num_subjs = count_user_subjs(r_tmp->hash->first);
71755 +
71756 + r_tmp->subj_hash_size = num_subjs;
71757 + r_tmp->subj_hash =
71758 + (struct acl_subject_label **)
71759 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71760 +
71761 + if (!r_tmp->subj_hash)
71762 + return -ENOMEM;
71763 +
71764 + err = copy_user_allowedips(r_tmp);
71765 + if (err)
71766 + return err;
71767 +
71768 + /* copy domain info */
71769 + if (r_tmp->domain_children != NULL) {
71770 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71771 + if (domainlist == NULL)
71772 + return -ENOMEM;
71773 +
71774 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71775 + return -EFAULT;
71776 +
71777 + r_tmp->domain_children = domainlist;
71778 + }
71779 +
71780 + err = copy_user_transitions(r_tmp);
71781 + if (err)
71782 + return err;
71783 +
71784 + memset(r_tmp->subj_hash, 0,
71785 + r_tmp->subj_hash_size *
71786 + sizeof (struct acl_subject_label *));
71787 +
71788 + /* acquire the list of subjects, then NULL out
71789 + the list prior to parsing the subjects for this role,
71790 + as during this parsing the list is replaced with a list
71791 + of *nested* subjects for the role
71792 + */
71793 + subj_list = r_tmp->hash->first;
71794 +
71795 + /* set nested subject list to null */
71796 + r_tmp->hash->first = NULL;
71797 +
71798 + err = copy_user_subjs(subj_list, r_tmp);
71799 +
71800 + if (err)
71801 + return err;
71802 +
71803 + insert_acl_role_label(r_tmp);
71804 + }
71805 +
71806 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71807 + return -EINVAL;
71808 +
71809 + return err;
71810 +}
71811 +
71812 +static int gracl_reload_apply_policies(void *reload)
71813 +{
71814 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71815 + struct task_struct *task, *task2;
71816 + struct acl_role_label *role, *rtmp;
71817 + struct acl_subject_label *subj;
71818 + const struct cred *cred;
71819 + int role_applied;
71820 + int ret = 0;
71821 +
71822 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71823 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71824 +
71825 + /* first make sure we'll be able to apply the new policy cleanly */
71826 + do_each_thread(task2, task) {
71827 + if (task->exec_file == NULL)
71828 + continue;
71829 + role_applied = 0;
71830 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71831 + /* preserve special roles */
71832 + FOR_EACH_ROLE_START(role)
71833 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71834 + rtmp = task->role;
71835 + task->role = role;
71836 + role_applied = 1;
71837 + break;
71838 + }
71839 + FOR_EACH_ROLE_END(role)
71840 + }
71841 + if (!role_applied) {
71842 + cred = __task_cred(task);
71843 + rtmp = task->role;
71844 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71845 + }
71846 + /* this handles non-nested inherited subjects, nested subjects will still
71847 + be dropped currently */
71848 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71849 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71850 + /* change the role back so that we've made no modifications to the policy */
71851 + task->role = rtmp;
71852 +
71853 + if (subj == NULL || task->tmpacl == NULL) {
71854 + ret = -EINVAL;
71855 + goto out;
71856 + }
71857 + } while_each_thread(task2, task);
71858 +
71859 + /* now actually apply the policy */
71860 +
71861 + do_each_thread(task2, task) {
71862 + if (task->exec_file) {
71863 + role_applied = 0;
71864 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71865 + /* preserve special roles */
71866 + FOR_EACH_ROLE_START(role)
71867 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71868 + task->role = role;
71869 + role_applied = 1;
71870 + break;
71871 + }
71872 + FOR_EACH_ROLE_END(role)
71873 + }
71874 + if (!role_applied) {
71875 + cred = __task_cred(task);
71876 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71877 + }
71878 + /* this handles non-nested inherited subjects, nested subjects will still
71879 + be dropped currently */
71880 + if (!reload_state->oldmode && task->inherited)
71881 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71882 + else {
71883 + /* looked up and tagged to the task previously */
71884 + subj = task->tmpacl;
71885 + }
71886 + /* subj will be non-null */
71887 + __gr_apply_subject_to_task(polstate, task, subj);
71888 + if (reload_state->oldmode) {
71889 + task->acl_role_id = 0;
71890 + task->acl_sp_role = 0;
71891 + task->inherited = 0;
71892 + }
71893 + } else {
71894 + // it's a kernel process
71895 + task->role = polstate->kernel_role;
71896 + task->acl = polstate->kernel_role->root_label;
71897 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71898 + task->acl->mode &= ~GR_PROCFIND;
71899 +#endif
71900 + }
71901 + } while_each_thread(task2, task);
71902 +
71903 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71904 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71905 +
71906 +out:
71907 +
71908 + return ret;
71909 +}
71910 +
71911 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71912 +{
71913 + struct gr_reload_state new_reload_state = { };
71914 + int err;
71915 +
71916 + new_reload_state.oldpolicy_ptr = polstate;
71917 + new_reload_state.oldalloc_ptr = current_alloc_state;
71918 + new_reload_state.oldmode = oldmode;
71919 +
71920 + current_alloc_state = &new_reload_state.newalloc;
71921 + polstate = &new_reload_state.newpolicy;
71922 +
71923 + /* everything relevant is now saved off, copy in the new policy */
71924 + if (init_variables(args, true)) {
71925 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71926 + err = -ENOMEM;
71927 + goto error;
71928 + }
71929 +
71930 + err = copy_user_acl(args);
71931 + free_init_variables();
71932 + if (err)
71933 + goto error;
71934 + /* the new policy is copied in, with the old policy available via saved_state
71935 + first go through applying roles, making sure to preserve special roles
71936 + then apply new subjects, making sure to preserve inherited and nested subjects,
71937 + though currently only inherited subjects will be preserved
71938 + */
71939 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71940 + if (err)
71941 + goto error;
71942 +
71943 + /* we've now applied the new policy, so restore the old policy state to free it */
71944 + polstate = &new_reload_state.oldpolicy;
71945 + current_alloc_state = &new_reload_state.oldalloc;
71946 + free_variables(true);
71947 +
71948 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71949 + to running_polstate/current_alloc_state inside stop_machine
71950 + */
71951 + err = 0;
71952 + goto out;
71953 +error:
71954 + /* on error of loading the new policy, we'll just keep the previous
71955 + policy set around
71956 + */
71957 + free_variables(true);
71958 +
71959 + /* doesn't affect runtime, but maintains consistent state */
71960 +out:
71961 + polstate = new_reload_state.oldpolicy_ptr;
71962 + current_alloc_state = new_reload_state.oldalloc_ptr;
71963 +
71964 + return err;
71965 +}
71966 +
71967 +static int
71968 +gracl_init(struct gr_arg *args)
71969 +{
71970 + int error = 0;
71971 +
71972 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71973 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71974 +
71975 + if (init_variables(args, false)) {
71976 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71977 + error = -ENOMEM;
71978 + goto out;
71979 + }
71980 +
71981 + error = copy_user_acl(args);
71982 + free_init_variables();
71983 + if (error)
71984 + goto out;
71985 +
71986 + error = gr_set_acls(0);
71987 + if (error)
71988 + goto out;
71989 +
71990 + gr_enable_rbac_system();
71991 +
71992 + return 0;
71993 +
71994 +out:
71995 + free_variables(false);
71996 + return error;
71997 +}
71998 +
71999 +static int
72000 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72001 + unsigned char **sum)
72002 +{
72003 + struct acl_role_label *r;
72004 + struct role_allowed_ip *ipp;
72005 + struct role_transition *trans;
72006 + unsigned int i;
72007 + int found = 0;
72008 + u32 curr_ip = current->signal->curr_ip;
72009 +
72010 + current->signal->saved_ip = curr_ip;
72011 +
72012 + /* check transition table */
72013 +
72014 + for (trans = current->role->transitions; trans; trans = trans->next) {
72015 + if (!strcmp(rolename, trans->rolename)) {
72016 + found = 1;
72017 + break;
72018 + }
72019 + }
72020 +
72021 + if (!found)
72022 + return 0;
72023 +
72024 + /* handle special roles that do not require authentication
72025 + and check ip */
72026 +
72027 + FOR_EACH_ROLE_START(r)
72028 + if (!strcmp(rolename, r->rolename) &&
72029 + (r->roletype & GR_ROLE_SPECIAL)) {
72030 + found = 0;
72031 + if (r->allowed_ips != NULL) {
72032 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72033 + if ((ntohl(curr_ip) & ipp->netmask) ==
72034 + (ntohl(ipp->addr) & ipp->netmask))
72035 + found = 1;
72036 + }
72037 + } else
72038 + found = 2;
72039 + if (!found)
72040 + return 0;
72041 +
72042 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72043 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72044 + *salt = NULL;
72045 + *sum = NULL;
72046 + return 1;
72047 + }
72048 + }
72049 + FOR_EACH_ROLE_END(r)
72050 +
72051 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72052 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72053 + *salt = polstate->acl_special_roles[i]->salt;
72054 + *sum = polstate->acl_special_roles[i]->sum;
72055 + return 1;
72056 + }
72057 + }
72058 +
72059 + return 0;
72060 +}
72061 +
72062 +int gr_check_secure_terminal(struct task_struct *task)
72063 +{
72064 + struct task_struct *p, *p2, *p3;
72065 + struct files_struct *files;
72066 + struct fdtable *fdt;
72067 + struct file *our_file = NULL, *file;
72068 + int i;
72069 +
72070 + if (task->signal->tty == NULL)
72071 + return 1;
72072 +
72073 + files = get_files_struct(task);
72074 + if (files != NULL) {
72075 + rcu_read_lock();
72076 + fdt = files_fdtable(files);
72077 + for (i=0; i < fdt->max_fds; i++) {
72078 + file = fcheck_files(files, i);
72079 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72080 + get_file(file);
72081 + our_file = file;
72082 + }
72083 + }
72084 + rcu_read_unlock();
72085 + put_files_struct(files);
72086 + }
72087 +
72088 + if (our_file == NULL)
72089 + return 1;
72090 +
72091 + read_lock(&tasklist_lock);
72092 + do_each_thread(p2, p) {
72093 + files = get_files_struct(p);
72094 + if (files == NULL ||
72095 + (p->signal && p->signal->tty == task->signal->tty)) {
72096 + if (files != NULL)
72097 + put_files_struct(files);
72098 + continue;
72099 + }
72100 + rcu_read_lock();
72101 + fdt = files_fdtable(files);
72102 + for (i=0; i < fdt->max_fds; i++) {
72103 + file = fcheck_files(files, i);
72104 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72105 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72106 + p3 = task;
72107 + while (task_pid_nr(p3) > 0) {
72108 + if (p3 == p)
72109 + break;
72110 + p3 = p3->real_parent;
72111 + }
72112 + if (p3 == p)
72113 + break;
72114 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72115 + gr_handle_alertkill(p);
72116 + rcu_read_unlock();
72117 + put_files_struct(files);
72118 + read_unlock(&tasklist_lock);
72119 + fput(our_file);
72120 + return 0;
72121 + }
72122 + }
72123 + rcu_read_unlock();
72124 + put_files_struct(files);
72125 + } while_each_thread(p2, p);
72126 + read_unlock(&tasklist_lock);
72127 +
72128 + fput(our_file);
72129 + return 1;
72130 +}
72131 +
72132 +ssize_t
72133 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72134 +{
72135 + struct gr_arg_wrapper uwrap;
72136 + unsigned char *sprole_salt = NULL;
72137 + unsigned char *sprole_sum = NULL;
72138 + int error = 0;
72139 + int error2 = 0;
72140 + size_t req_count = 0;
72141 + unsigned char oldmode = 0;
72142 +
72143 + mutex_lock(&gr_dev_mutex);
72144 +
72145 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72146 + error = -EPERM;
72147 + goto out;
72148 + }
72149 +
72150 +#ifdef CONFIG_COMPAT
72151 + pax_open_kernel();
72152 + if (is_compat_task()) {
72153 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72154 + copy_gr_arg = &copy_gr_arg_compat;
72155 + copy_acl_object_label = &copy_acl_object_label_compat;
72156 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72157 + copy_acl_role_label = &copy_acl_role_label_compat;
72158 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72159 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72160 + copy_role_transition = &copy_role_transition_compat;
72161 + copy_sprole_pw = &copy_sprole_pw_compat;
72162 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72163 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72164 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72165 + } else {
72166 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72167 + copy_gr_arg = &copy_gr_arg_normal;
72168 + copy_acl_object_label = &copy_acl_object_label_normal;
72169 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72170 + copy_acl_role_label = &copy_acl_role_label_normal;
72171 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72172 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72173 + copy_role_transition = &copy_role_transition_normal;
72174 + copy_sprole_pw = &copy_sprole_pw_normal;
72175 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72176 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72177 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72178 + }
72179 + pax_close_kernel();
72180 +#endif
72181 +
72182 + req_count = get_gr_arg_wrapper_size();
72183 +
72184 + if (count != req_count) {
72185 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72186 + error = -EINVAL;
72187 + goto out;
72188 + }
72189 +
72190 +
72191 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72192 + gr_auth_expires = 0;
72193 + gr_auth_attempts = 0;
72194 + }
72195 +
72196 + error = copy_gr_arg_wrapper(buf, &uwrap);
72197 + if (error)
72198 + goto out;
72199 +
72200 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72201 + if (error)
72202 + goto out;
72203 +
72204 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72205 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72206 + time_after(gr_auth_expires, get_seconds())) {
72207 + error = -EBUSY;
72208 + goto out;
72209 + }
72210 +
72211 + /* if non-root trying to do anything other than use a special role,
72212 + do not attempt authentication, do not count towards authentication
72213 + locking
72214 + */
72215 +
72216 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72217 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72218 + gr_is_global_nonroot(current_uid())) {
72219 + error = -EPERM;
72220 + goto out;
72221 + }
72222 +
72223 + /* ensure pw and special role name are null terminated */
72224 +
72225 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72226 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72227 +
72228 + /* Okay.
72229 + * We have our enough of the argument structure..(we have yet
72230 + * to copy_from_user the tables themselves) . Copy the tables
72231 + * only if we need them, i.e. for loading operations. */
72232 +
72233 + switch (gr_usermode.mode) {
72234 + case GR_STATUS:
72235 + if (gr_acl_is_enabled()) {
72236 + error = 1;
72237 + if (!gr_check_secure_terminal(current))
72238 + error = 3;
72239 + } else
72240 + error = 2;
72241 + goto out;
72242 + case GR_SHUTDOWN:
72243 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72244 + stop_machine(gr_rbac_disable, NULL, NULL);
72245 + free_variables(false);
72246 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72247 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72248 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72249 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72250 + } else if (gr_acl_is_enabled()) {
72251 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72252 + error = -EPERM;
72253 + } else {
72254 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72255 + error = -EAGAIN;
72256 + }
72257 + break;
72258 + case GR_ENABLE:
72259 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72260 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72261 + else {
72262 + if (gr_acl_is_enabled())
72263 + error = -EAGAIN;
72264 + else
72265 + error = error2;
72266 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72267 + }
72268 + break;
72269 + case GR_OLDRELOAD:
72270 + oldmode = 1;
72271 + case GR_RELOAD:
72272 + if (!gr_acl_is_enabled()) {
72273 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72274 + error = -EAGAIN;
72275 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72276 + error2 = gracl_reload(&gr_usermode, oldmode);
72277 + if (!error2)
72278 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72279 + else {
72280 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72281 + error = error2;
72282 + }
72283 + } else {
72284 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72285 + error = -EPERM;
72286 + }
72287 + break;
72288 + case GR_SEGVMOD:
72289 + if (unlikely(!gr_acl_is_enabled())) {
72290 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72291 + error = -EAGAIN;
72292 + break;
72293 + }
72294 +
72295 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72296 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72297 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72298 + struct acl_subject_label *segvacl;
72299 + segvacl =
72300 + lookup_acl_subj_label(gr_usermode.segv_inode,
72301 + gr_usermode.segv_device,
72302 + current->role);
72303 + if (segvacl) {
72304 + segvacl->crashes = 0;
72305 + segvacl->expires = 0;
72306 + }
72307 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72308 + gr_remove_uid(gr_usermode.segv_uid);
72309 + }
72310 + } else {
72311 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72312 + error = -EPERM;
72313 + }
72314 + break;
72315 + case GR_SPROLE:
72316 + case GR_SPROLEPAM:
72317 + if (unlikely(!gr_acl_is_enabled())) {
72318 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72319 + error = -EAGAIN;
72320 + break;
72321 + }
72322 +
72323 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72324 + current->role->expires = 0;
72325 + current->role->auth_attempts = 0;
72326 + }
72327 +
72328 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72329 + time_after(current->role->expires, get_seconds())) {
72330 + error = -EBUSY;
72331 + goto out;
72332 + }
72333 +
72334 + if (lookup_special_role_auth
72335 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72336 + && ((!sprole_salt && !sprole_sum)
72337 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72338 + char *p = "";
72339 + assign_special_role(gr_usermode.sp_role);
72340 + read_lock(&tasklist_lock);
72341 + if (current->real_parent)
72342 + p = current->real_parent->role->rolename;
72343 + read_unlock(&tasklist_lock);
72344 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72345 + p, acl_sp_role_value);
72346 + } else {
72347 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72348 + error = -EPERM;
72349 + if(!(current->role->auth_attempts++))
72350 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72351 +
72352 + goto out;
72353 + }
72354 + break;
72355 + case GR_UNSPROLE:
72356 + if (unlikely(!gr_acl_is_enabled())) {
72357 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72358 + error = -EAGAIN;
72359 + break;
72360 + }
72361 +
72362 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72363 + char *p = "";
72364 + int i = 0;
72365 +
72366 + read_lock(&tasklist_lock);
72367 + if (current->real_parent) {
72368 + p = current->real_parent->role->rolename;
72369 + i = current->real_parent->acl_role_id;
72370 + }
72371 + read_unlock(&tasklist_lock);
72372 +
72373 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72374 + gr_set_acls(1);
72375 + } else {
72376 + error = -EPERM;
72377 + goto out;
72378 + }
72379 + break;
72380 + default:
72381 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72382 + error = -EINVAL;
72383 + break;
72384 + }
72385 +
72386 + if (error != -EPERM)
72387 + goto out;
72388 +
72389 + if(!(gr_auth_attempts++))
72390 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72391 +
72392 + out:
72393 + mutex_unlock(&gr_dev_mutex);
72394 +
72395 + if (!error)
72396 + error = req_count;
72397 +
72398 + return error;
72399 +}
72400 +
72401 +int
72402 +gr_set_acls(const int type)
72403 +{
72404 + struct task_struct *task, *task2;
72405 + struct acl_role_label *role = current->role;
72406 + struct acl_subject_label *subj;
72407 + __u16 acl_role_id = current->acl_role_id;
72408 + const struct cred *cred;
72409 + int ret;
72410 +
72411 + rcu_read_lock();
72412 + read_lock(&tasklist_lock);
72413 + read_lock(&grsec_exec_file_lock);
72414 + do_each_thread(task2, task) {
72415 + /* check to see if we're called from the exit handler,
72416 + if so, only replace ACLs that have inherited the admin
72417 + ACL */
72418 +
72419 + if (type && (task->role != role ||
72420 + task->acl_role_id != acl_role_id))
72421 + continue;
72422 +
72423 + task->acl_role_id = 0;
72424 + task->acl_sp_role = 0;
72425 + task->inherited = 0;
72426 +
72427 + if (task->exec_file) {
72428 + cred = __task_cred(task);
72429 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72430 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72431 + if (subj == NULL) {
72432 + ret = -EINVAL;
72433 + read_unlock(&grsec_exec_file_lock);
72434 + read_unlock(&tasklist_lock);
72435 + rcu_read_unlock();
72436 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72437 + return ret;
72438 + }
72439 + __gr_apply_subject_to_task(polstate, task, subj);
72440 + } else {
72441 + // it's a kernel process
72442 + task->role = polstate->kernel_role;
72443 + task->acl = polstate->kernel_role->root_label;
72444 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72445 + task->acl->mode &= ~GR_PROCFIND;
72446 +#endif
72447 + }
72448 + } while_each_thread(task2, task);
72449 + read_unlock(&grsec_exec_file_lock);
72450 + read_unlock(&tasklist_lock);
72451 + rcu_read_unlock();
72452 +
72453 + return 0;
72454 +}
72455 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72456 new file mode 100644
72457 index 0000000..39645c9
72458 --- /dev/null
72459 +++ b/grsecurity/gracl_res.c
72460 @@ -0,0 +1,68 @@
72461 +#include <linux/kernel.h>
72462 +#include <linux/sched.h>
72463 +#include <linux/gracl.h>
72464 +#include <linux/grinternal.h>
72465 +
72466 +static const char *restab_log[] = {
72467 + [RLIMIT_CPU] = "RLIMIT_CPU",
72468 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72469 + [RLIMIT_DATA] = "RLIMIT_DATA",
72470 + [RLIMIT_STACK] = "RLIMIT_STACK",
72471 + [RLIMIT_CORE] = "RLIMIT_CORE",
72472 + [RLIMIT_RSS] = "RLIMIT_RSS",
72473 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
72474 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72475 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72476 + [RLIMIT_AS] = "RLIMIT_AS",
72477 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72478 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72479 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72480 + [RLIMIT_NICE] = "RLIMIT_NICE",
72481 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72482 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72483 + [GR_CRASH_RES] = "RLIMIT_CRASH"
72484 +};
72485 +
72486 +void
72487 +gr_log_resource(const struct task_struct *task,
72488 + const int res, const unsigned long wanted, const int gt)
72489 +{
72490 + const struct cred *cred;
72491 + unsigned long rlim;
72492 +
72493 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
72494 + return;
72495 +
72496 + // not yet supported resource
72497 + if (unlikely(!restab_log[res]))
72498 + return;
72499 +
72500 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72501 + rlim = task_rlimit_max(task, res);
72502 + else
72503 + rlim = task_rlimit(task, res);
72504 +
72505 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72506 + return;
72507 +
72508 + rcu_read_lock();
72509 + cred = __task_cred(task);
72510 +
72511 + if (res == RLIMIT_NPROC &&
72512 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72513 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72514 + goto out_rcu_unlock;
72515 + else if (res == RLIMIT_MEMLOCK &&
72516 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72517 + goto out_rcu_unlock;
72518 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72519 + goto out_rcu_unlock;
72520 + rcu_read_unlock();
72521 +
72522 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72523 +
72524 + return;
72525 +out_rcu_unlock:
72526 + rcu_read_unlock();
72527 + return;
72528 +}
72529 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72530 new file mode 100644
72531 index 0000000..2040e61
72532 --- /dev/null
72533 +++ b/grsecurity/gracl_segv.c
72534 @@ -0,0 +1,313 @@
72535 +#include <linux/kernel.h>
72536 +#include <linux/mm.h>
72537 +#include <asm/uaccess.h>
72538 +#include <asm/errno.h>
72539 +#include <asm/mman.h>
72540 +#include <net/sock.h>
72541 +#include <linux/file.h>
72542 +#include <linux/fs.h>
72543 +#include <linux/net.h>
72544 +#include <linux/in.h>
72545 +#include <linux/slab.h>
72546 +#include <linux/types.h>
72547 +#include <linux/sched.h>
72548 +#include <linux/timer.h>
72549 +#include <linux/gracl.h>
72550 +#include <linux/grsecurity.h>
72551 +#include <linux/grinternal.h>
72552 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72553 +#include <linux/magic.h>
72554 +#include <linux/pagemap.h>
72555 +#include "../fs/btrfs/async-thread.h"
72556 +#include "../fs/btrfs/ctree.h"
72557 +#include "../fs/btrfs/btrfs_inode.h"
72558 +#endif
72559 +
72560 +static struct crash_uid *uid_set;
72561 +static unsigned short uid_used;
72562 +static DEFINE_SPINLOCK(gr_uid_lock);
72563 +extern rwlock_t gr_inode_lock;
72564 +extern struct acl_subject_label *
72565 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72566 + struct acl_role_label *role);
72567 +
72568 +static inline dev_t __get_dev(const struct dentry *dentry)
72569 +{
72570 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72571 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72572 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
72573 + else
72574 +#endif
72575 + return dentry->d_sb->s_dev;
72576 +}
72577 +
72578 +int
72579 +gr_init_uidset(void)
72580 +{
72581 + uid_set =
72582 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72583 + uid_used = 0;
72584 +
72585 + return uid_set ? 1 : 0;
72586 +}
72587 +
72588 +void
72589 +gr_free_uidset(void)
72590 +{
72591 + if (uid_set) {
72592 + struct crash_uid *tmpset;
72593 + spin_lock(&gr_uid_lock);
72594 + tmpset = uid_set;
72595 + uid_set = NULL;
72596 + uid_used = 0;
72597 + spin_unlock(&gr_uid_lock);
72598 + if (tmpset)
72599 + kfree(tmpset);
72600 + }
72601 +
72602 + return;
72603 +}
72604 +
72605 +int
72606 +gr_find_uid(const uid_t uid)
72607 +{
72608 + struct crash_uid *tmp = uid_set;
72609 + uid_t buid;
72610 + int low = 0, high = uid_used - 1, mid;
72611 +
72612 + while (high >= low) {
72613 + mid = (low + high) >> 1;
72614 + buid = tmp[mid].uid;
72615 + if (buid == uid)
72616 + return mid;
72617 + if (buid > uid)
72618 + high = mid - 1;
72619 + if (buid < uid)
72620 + low = mid + 1;
72621 + }
72622 +
72623 + return -1;
72624 +}
72625 +
72626 +static __inline__ void
72627 +gr_insertsort(void)
72628 +{
72629 + unsigned short i, j;
72630 + struct crash_uid index;
72631 +
72632 + for (i = 1; i < uid_used; i++) {
72633 + index = uid_set[i];
72634 + j = i;
72635 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72636 + uid_set[j] = uid_set[j - 1];
72637 + j--;
72638 + }
72639 + uid_set[j] = index;
72640 + }
72641 +
72642 + return;
72643 +}
72644 +
72645 +static __inline__ void
72646 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72647 +{
72648 + int loc;
72649 + uid_t uid = GR_GLOBAL_UID(kuid);
72650 +
72651 + if (uid_used == GR_UIDTABLE_MAX)
72652 + return;
72653 +
72654 + loc = gr_find_uid(uid);
72655 +
72656 + if (loc >= 0) {
72657 + uid_set[loc].expires = expires;
72658 + return;
72659 + }
72660 +
72661 + uid_set[uid_used].uid = uid;
72662 + uid_set[uid_used].expires = expires;
72663 + uid_used++;
72664 +
72665 + gr_insertsort();
72666 +
72667 + return;
72668 +}
72669 +
72670 +void
72671 +gr_remove_uid(const unsigned short loc)
72672 +{
72673 + unsigned short i;
72674 +
72675 + for (i = loc + 1; i < uid_used; i++)
72676 + uid_set[i - 1] = uid_set[i];
72677 +
72678 + uid_used--;
72679 +
72680 + return;
72681 +}
72682 +
72683 +int
72684 +gr_check_crash_uid(const kuid_t kuid)
72685 +{
72686 + int loc;
72687 + int ret = 0;
72688 + uid_t uid;
72689 +
72690 + if (unlikely(!gr_acl_is_enabled()))
72691 + return 0;
72692 +
72693 + uid = GR_GLOBAL_UID(kuid);
72694 +
72695 + spin_lock(&gr_uid_lock);
72696 + loc = gr_find_uid(uid);
72697 +
72698 + if (loc < 0)
72699 + goto out_unlock;
72700 +
72701 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
72702 + gr_remove_uid(loc);
72703 + else
72704 + ret = 1;
72705 +
72706 +out_unlock:
72707 + spin_unlock(&gr_uid_lock);
72708 + return ret;
72709 +}
72710 +
72711 +static __inline__ int
72712 +proc_is_setxid(const struct cred *cred)
72713 +{
72714 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72715 + !uid_eq(cred->uid, cred->fsuid))
72716 + return 1;
72717 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72718 + !gid_eq(cred->gid, cred->fsgid))
72719 + return 1;
72720 +
72721 + return 0;
72722 +}
72723 +
72724 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
72725 +
72726 +void
72727 +gr_handle_crash(struct task_struct *task, const int sig)
72728 +{
72729 + struct acl_subject_label *curr;
72730 + struct task_struct *tsk, *tsk2;
72731 + const struct cred *cred;
72732 + const struct cred *cred2;
72733 +
72734 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72735 + return;
72736 +
72737 + if (unlikely(!gr_acl_is_enabled()))
72738 + return;
72739 +
72740 + curr = task->acl;
72741 +
72742 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
72743 + return;
72744 +
72745 + if (time_before_eq(curr->expires, get_seconds())) {
72746 + curr->expires = 0;
72747 + curr->crashes = 0;
72748 + }
72749 +
72750 + curr->crashes++;
72751 +
72752 + if (!curr->expires)
72753 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72754 +
72755 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72756 + time_after(curr->expires, get_seconds())) {
72757 + rcu_read_lock();
72758 + cred = __task_cred(task);
72759 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72760 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72761 + spin_lock(&gr_uid_lock);
72762 + gr_insert_uid(cred->uid, curr->expires);
72763 + spin_unlock(&gr_uid_lock);
72764 + curr->expires = 0;
72765 + curr->crashes = 0;
72766 + read_lock(&tasklist_lock);
72767 + do_each_thread(tsk2, tsk) {
72768 + cred2 = __task_cred(tsk);
72769 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
72770 + gr_fake_force_sig(SIGKILL, tsk);
72771 + } while_each_thread(tsk2, tsk);
72772 + read_unlock(&tasklist_lock);
72773 + } else {
72774 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72775 + read_lock(&tasklist_lock);
72776 + read_lock(&grsec_exec_file_lock);
72777 + do_each_thread(tsk2, tsk) {
72778 + if (likely(tsk != task)) {
72779 + // if this thread has the same subject as the one that triggered
72780 + // RES_CRASH and it's the same binary, kill it
72781 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72782 + gr_fake_force_sig(SIGKILL, tsk);
72783 + }
72784 + } while_each_thread(tsk2, tsk);
72785 + read_unlock(&grsec_exec_file_lock);
72786 + read_unlock(&tasklist_lock);
72787 + }
72788 + rcu_read_unlock();
72789 + }
72790 +
72791 + return;
72792 +}
72793 +
72794 +int
72795 +gr_check_crash_exec(const struct file *filp)
72796 +{
72797 + struct acl_subject_label *curr;
72798 +
72799 + if (unlikely(!gr_acl_is_enabled()))
72800 + return 0;
72801 +
72802 + read_lock(&gr_inode_lock);
72803 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72804 + __get_dev(filp->f_path.dentry),
72805 + current->role);
72806 + read_unlock(&gr_inode_lock);
72807 +
72808 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72809 + (!curr->crashes && !curr->expires))
72810 + return 0;
72811 +
72812 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72813 + time_after(curr->expires, get_seconds()))
72814 + return 1;
72815 + else if (time_before_eq(curr->expires, get_seconds())) {
72816 + curr->crashes = 0;
72817 + curr->expires = 0;
72818 + }
72819 +
72820 + return 0;
72821 +}
72822 +
72823 +void
72824 +gr_handle_alertkill(struct task_struct *task)
72825 +{
72826 + struct acl_subject_label *curracl;
72827 + __u32 curr_ip;
72828 + struct task_struct *p, *p2;
72829 +
72830 + if (unlikely(!gr_acl_is_enabled()))
72831 + return;
72832 +
72833 + curracl = task->acl;
72834 + curr_ip = task->signal->curr_ip;
72835 +
72836 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72837 + read_lock(&tasklist_lock);
72838 + do_each_thread(p2, p) {
72839 + if (p->signal->curr_ip == curr_ip)
72840 + gr_fake_force_sig(SIGKILL, p);
72841 + } while_each_thread(p2, p);
72842 + read_unlock(&tasklist_lock);
72843 + } else if (curracl->mode & GR_KILLPROC)
72844 + gr_fake_force_sig(SIGKILL, task);
72845 +
72846 + return;
72847 +}
72848 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72849 new file mode 100644
72850 index 0000000..98011b0
72851 --- /dev/null
72852 +++ b/grsecurity/gracl_shm.c
72853 @@ -0,0 +1,40 @@
72854 +#include <linux/kernel.h>
72855 +#include <linux/mm.h>
72856 +#include <linux/sched.h>
72857 +#include <linux/file.h>
72858 +#include <linux/ipc.h>
72859 +#include <linux/gracl.h>
72860 +#include <linux/grsecurity.h>
72861 +#include <linux/grinternal.h>
72862 +
72863 +int
72864 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72865 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72866 +{
72867 + struct task_struct *task;
72868 +
72869 + if (!gr_acl_is_enabled())
72870 + return 1;
72871 +
72872 + rcu_read_lock();
72873 + read_lock(&tasklist_lock);
72874 +
72875 + task = find_task_by_vpid(shm_cprid);
72876 +
72877 + if (unlikely(!task))
72878 + task = find_task_by_vpid(shm_lapid);
72879 +
72880 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72881 + (task_pid_nr(task) == shm_lapid)) &&
72882 + (task->acl->mode & GR_PROTSHM) &&
72883 + (task->acl != current->acl))) {
72884 + read_unlock(&tasklist_lock);
72885 + rcu_read_unlock();
72886 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72887 + return 0;
72888 + }
72889 + read_unlock(&tasklist_lock);
72890 + rcu_read_unlock();
72891 +
72892 + return 1;
72893 +}
72894 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72895 new file mode 100644
72896 index 0000000..bc0be01
72897 --- /dev/null
72898 +++ b/grsecurity/grsec_chdir.c
72899 @@ -0,0 +1,19 @@
72900 +#include <linux/kernel.h>
72901 +#include <linux/sched.h>
72902 +#include <linux/fs.h>
72903 +#include <linux/file.h>
72904 +#include <linux/grsecurity.h>
72905 +#include <linux/grinternal.h>
72906 +
72907 +void
72908 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72909 +{
72910 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72911 + if ((grsec_enable_chdir && grsec_enable_group &&
72912 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72913 + !grsec_enable_group)) {
72914 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72915 + }
72916 +#endif
72917 + return;
72918 +}
72919 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72920 new file mode 100644
72921 index 0000000..651d6c2
72922 --- /dev/null
72923 +++ b/grsecurity/grsec_chroot.c
72924 @@ -0,0 +1,370 @@
72925 +#include <linux/kernel.h>
72926 +#include <linux/module.h>
72927 +#include <linux/sched.h>
72928 +#include <linux/file.h>
72929 +#include <linux/fs.h>
72930 +#include <linux/mount.h>
72931 +#include <linux/types.h>
72932 +#include "../fs/mount.h"
72933 +#include <linux/grsecurity.h>
72934 +#include <linux/grinternal.h>
72935 +
72936 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72937 +int gr_init_ran;
72938 +#endif
72939 +
72940 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72941 +{
72942 +#ifdef CONFIG_GRKERNSEC
72943 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72944 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72945 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72946 + && gr_init_ran
72947 +#endif
72948 + )
72949 + task->gr_is_chrooted = 1;
72950 + else {
72951 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72952 + if (task_pid_nr(task) == 1 && !gr_init_ran)
72953 + gr_init_ran = 1;
72954 +#endif
72955 + task->gr_is_chrooted = 0;
72956 + }
72957 +
72958 + task->gr_chroot_dentry = path->dentry;
72959 +#endif
72960 + return;
72961 +}
72962 +
72963 +void gr_clear_chroot_entries(struct task_struct *task)
72964 +{
72965 +#ifdef CONFIG_GRKERNSEC
72966 + task->gr_is_chrooted = 0;
72967 + task->gr_chroot_dentry = NULL;
72968 +#endif
72969 + return;
72970 +}
72971 +
72972 +int
72973 +gr_handle_chroot_unix(const pid_t pid)
72974 +{
72975 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72976 + struct task_struct *p;
72977 +
72978 + if (unlikely(!grsec_enable_chroot_unix))
72979 + return 1;
72980 +
72981 + if (likely(!proc_is_chrooted(current)))
72982 + return 1;
72983 +
72984 + rcu_read_lock();
72985 + read_lock(&tasklist_lock);
72986 + p = find_task_by_vpid_unrestricted(pid);
72987 + if (unlikely(p && !have_same_root(current, p))) {
72988 + read_unlock(&tasklist_lock);
72989 + rcu_read_unlock();
72990 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72991 + return 0;
72992 + }
72993 + read_unlock(&tasklist_lock);
72994 + rcu_read_unlock();
72995 +#endif
72996 + return 1;
72997 +}
72998 +
72999 +int
73000 +gr_handle_chroot_nice(void)
73001 +{
73002 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73003 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73004 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73005 + return -EPERM;
73006 + }
73007 +#endif
73008 + return 0;
73009 +}
73010 +
73011 +int
73012 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73013 +{
73014 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73015 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73016 + && proc_is_chrooted(current)) {
73017 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73018 + return -EACCES;
73019 + }
73020 +#endif
73021 + return 0;
73022 +}
73023 +
73024 +int
73025 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73026 +{
73027 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73028 + struct task_struct *p;
73029 + int ret = 0;
73030 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73031 + return ret;
73032 +
73033 + read_lock(&tasklist_lock);
73034 + do_each_pid_task(pid, type, p) {
73035 + if (!have_same_root(current, p)) {
73036 + ret = 1;
73037 + goto out;
73038 + }
73039 + } while_each_pid_task(pid, type, p);
73040 +out:
73041 + read_unlock(&tasklist_lock);
73042 + return ret;
73043 +#endif
73044 + return 0;
73045 +}
73046 +
73047 +int
73048 +gr_pid_is_chrooted(struct task_struct *p)
73049 +{
73050 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73051 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73052 + return 0;
73053 +
73054 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73055 + !have_same_root(current, p)) {
73056 + return 1;
73057 + }
73058 +#endif
73059 + return 0;
73060 +}
73061 +
73062 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73063 +
73064 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73065 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73066 +{
73067 + struct path path, currentroot;
73068 + int ret = 0;
73069 +
73070 + path.dentry = (struct dentry *)u_dentry;
73071 + path.mnt = (struct vfsmount *)u_mnt;
73072 + get_fs_root(current->fs, &currentroot);
73073 + if (path_is_under(&path, &currentroot))
73074 + ret = 1;
73075 + path_put(&currentroot);
73076 +
73077 + return ret;
73078 +}
73079 +#endif
73080 +
73081 +int
73082 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73083 +{
73084 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73085 + if (!grsec_enable_chroot_fchdir)
73086 + return 1;
73087 +
73088 + if (!proc_is_chrooted(current))
73089 + return 1;
73090 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73091 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73092 + return 0;
73093 + }
73094 +#endif
73095 + return 1;
73096 +}
73097 +
73098 +int
73099 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73100 + const time_t shm_createtime)
73101 +{
73102 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73103 + struct task_struct *p;
73104 + time_t starttime;
73105 +
73106 + if (unlikely(!grsec_enable_chroot_shmat))
73107 + return 1;
73108 +
73109 + if (likely(!proc_is_chrooted(current)))
73110 + return 1;
73111 +
73112 + rcu_read_lock();
73113 + read_lock(&tasklist_lock);
73114 +
73115 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73116 + starttime = p->start_time.tv_sec;
73117 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73118 + if (have_same_root(current, p)) {
73119 + goto allow;
73120 + } else {
73121 + read_unlock(&tasklist_lock);
73122 + rcu_read_unlock();
73123 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73124 + return 0;
73125 + }
73126 + }
73127 + /* creator exited, pid reuse, fall through to next check */
73128 + }
73129 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73130 + if (unlikely(!have_same_root(current, p))) {
73131 + read_unlock(&tasklist_lock);
73132 + rcu_read_unlock();
73133 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73134 + return 0;
73135 + }
73136 + }
73137 +
73138 +allow:
73139 + read_unlock(&tasklist_lock);
73140 + rcu_read_unlock();
73141 +#endif
73142 + return 1;
73143 +}
73144 +
73145 +void
73146 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73147 +{
73148 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73149 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73150 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73151 +#endif
73152 + return;
73153 +}
73154 +
73155 +int
73156 +gr_handle_chroot_mknod(const struct dentry *dentry,
73157 + const struct vfsmount *mnt, const int mode)
73158 +{
73159 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73160 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73161 + proc_is_chrooted(current)) {
73162 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73163 + return -EPERM;
73164 + }
73165 +#endif
73166 + return 0;
73167 +}
73168 +
73169 +int
73170 +gr_handle_chroot_mount(const struct dentry *dentry,
73171 + const struct vfsmount *mnt, const char *dev_name)
73172 +{
73173 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73174 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73175 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73176 + return -EPERM;
73177 + }
73178 +#endif
73179 + return 0;
73180 +}
73181 +
73182 +int
73183 +gr_handle_chroot_pivot(void)
73184 +{
73185 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73186 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73187 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73188 + return -EPERM;
73189 + }
73190 +#endif
73191 + return 0;
73192 +}
73193 +
73194 +int
73195 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73196 +{
73197 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73198 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73199 + !gr_is_outside_chroot(dentry, mnt)) {
73200 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73201 + return -EPERM;
73202 + }
73203 +#endif
73204 + return 0;
73205 +}
73206 +
73207 +extern const char *captab_log[];
73208 +extern int captab_log_entries;
73209 +
73210 +int
73211 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73212 +{
73213 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73214 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73215 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73216 + if (cap_raised(chroot_caps, cap)) {
73217 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73218 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73219 + }
73220 + return 0;
73221 + }
73222 + }
73223 +#endif
73224 + return 1;
73225 +}
73226 +
73227 +int
73228 +gr_chroot_is_capable(const int cap)
73229 +{
73230 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73231 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73232 +#endif
73233 + return 1;
73234 +}
73235 +
73236 +int
73237 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73238 +{
73239 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73240 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73241 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73242 + if (cap_raised(chroot_caps, cap)) {
73243 + return 0;
73244 + }
73245 + }
73246 +#endif
73247 + return 1;
73248 +}
73249 +
73250 +int
73251 +gr_chroot_is_capable_nolog(const int cap)
73252 +{
73253 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73254 + return gr_task_chroot_is_capable_nolog(current, cap);
73255 +#endif
73256 + return 1;
73257 +}
73258 +
73259 +int
73260 +gr_handle_chroot_sysctl(const int op)
73261 +{
73262 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73263 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73264 + proc_is_chrooted(current))
73265 + return -EACCES;
73266 +#endif
73267 + return 0;
73268 +}
73269 +
73270 +void
73271 +gr_handle_chroot_chdir(const struct path *path)
73272 +{
73273 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73274 + if (grsec_enable_chroot_chdir)
73275 + set_fs_pwd(current->fs, path);
73276 +#endif
73277 + return;
73278 +}
73279 +
73280 +int
73281 +gr_handle_chroot_chmod(const struct dentry *dentry,
73282 + const struct vfsmount *mnt, const int mode)
73283 +{
73284 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73285 + /* allow chmod +s on directories, but not files */
73286 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73287 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73288 + proc_is_chrooted(current)) {
73289 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73290 + return -EPERM;
73291 + }
73292 +#endif
73293 + return 0;
73294 +}
73295 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73296 new file mode 100644
73297 index 0000000..4d6fce8
73298 --- /dev/null
73299 +++ b/grsecurity/grsec_disabled.c
73300 @@ -0,0 +1,433 @@
73301 +#include <linux/kernel.h>
73302 +#include <linux/module.h>
73303 +#include <linux/sched.h>
73304 +#include <linux/file.h>
73305 +#include <linux/fs.h>
73306 +#include <linux/kdev_t.h>
73307 +#include <linux/net.h>
73308 +#include <linux/in.h>
73309 +#include <linux/ip.h>
73310 +#include <linux/skbuff.h>
73311 +#include <linux/sysctl.h>
73312 +
73313 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73314 +void
73315 +pax_set_initial_flags(struct linux_binprm *bprm)
73316 +{
73317 + return;
73318 +}
73319 +#endif
73320 +
73321 +#ifdef CONFIG_SYSCTL
73322 +__u32
73323 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73324 +{
73325 + return 0;
73326 +}
73327 +#endif
73328 +
73329 +#ifdef CONFIG_TASKSTATS
73330 +int gr_is_taskstats_denied(int pid)
73331 +{
73332 + return 0;
73333 +}
73334 +#endif
73335 +
73336 +int
73337 +gr_acl_is_enabled(void)
73338 +{
73339 + return 0;
73340 +}
73341 +
73342 +void
73343 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73344 +{
73345 + return;
73346 +}
73347 +
73348 +int
73349 +gr_handle_rawio(const struct inode *inode)
73350 +{
73351 + return 0;
73352 +}
73353 +
73354 +void
73355 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73356 +{
73357 + return;
73358 +}
73359 +
73360 +int
73361 +gr_handle_ptrace(struct task_struct *task, const long request)
73362 +{
73363 + return 0;
73364 +}
73365 +
73366 +int
73367 +gr_handle_proc_ptrace(struct task_struct *task)
73368 +{
73369 + return 0;
73370 +}
73371 +
73372 +int
73373 +gr_set_acls(const int type)
73374 +{
73375 + return 0;
73376 +}
73377 +
73378 +int
73379 +gr_check_hidden_task(const struct task_struct *tsk)
73380 +{
73381 + return 0;
73382 +}
73383 +
73384 +int
73385 +gr_check_protected_task(const struct task_struct *task)
73386 +{
73387 + return 0;
73388 +}
73389 +
73390 +int
73391 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73392 +{
73393 + return 0;
73394 +}
73395 +
73396 +void
73397 +gr_copy_label(struct task_struct *tsk)
73398 +{
73399 + return;
73400 +}
73401 +
73402 +void
73403 +gr_set_pax_flags(struct task_struct *task)
73404 +{
73405 + return;
73406 +}
73407 +
73408 +int
73409 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73410 + const int unsafe_share)
73411 +{
73412 + return 0;
73413 +}
73414 +
73415 +void
73416 +gr_handle_delete(const ino_t ino, const dev_t dev)
73417 +{
73418 + return;
73419 +}
73420 +
73421 +void
73422 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73423 +{
73424 + return;
73425 +}
73426 +
73427 +void
73428 +gr_handle_crash(struct task_struct *task, const int sig)
73429 +{
73430 + return;
73431 +}
73432 +
73433 +int
73434 +gr_check_crash_exec(const struct file *filp)
73435 +{
73436 + return 0;
73437 +}
73438 +
73439 +int
73440 +gr_check_crash_uid(const kuid_t uid)
73441 +{
73442 + return 0;
73443 +}
73444 +
73445 +void
73446 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73447 + struct dentry *old_dentry,
73448 + struct dentry *new_dentry,
73449 + struct vfsmount *mnt, const __u8 replace)
73450 +{
73451 + return;
73452 +}
73453 +
73454 +int
73455 +gr_search_socket(const int family, const int type, const int protocol)
73456 +{
73457 + return 1;
73458 +}
73459 +
73460 +int
73461 +gr_search_connectbind(const int mode, const struct socket *sock,
73462 + const struct sockaddr_in *addr)
73463 +{
73464 + return 0;
73465 +}
73466 +
73467 +void
73468 +gr_handle_alertkill(struct task_struct *task)
73469 +{
73470 + return;
73471 +}
73472 +
73473 +__u32
73474 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73475 +{
73476 + return 1;
73477 +}
73478 +
73479 +__u32
73480 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73481 + const struct vfsmount * mnt)
73482 +{
73483 + return 1;
73484 +}
73485 +
73486 +__u32
73487 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73488 + int acc_mode)
73489 +{
73490 + return 1;
73491 +}
73492 +
73493 +__u32
73494 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73495 +{
73496 + return 1;
73497 +}
73498 +
73499 +__u32
73500 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73501 +{
73502 + return 1;
73503 +}
73504 +
73505 +int
73506 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73507 + unsigned int *vm_flags)
73508 +{
73509 + return 1;
73510 +}
73511 +
73512 +__u32
73513 +gr_acl_handle_truncate(const struct dentry * dentry,
73514 + const struct vfsmount * mnt)
73515 +{
73516 + return 1;
73517 +}
73518 +
73519 +__u32
73520 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73521 +{
73522 + return 1;
73523 +}
73524 +
73525 +__u32
73526 +gr_acl_handle_access(const struct dentry * dentry,
73527 + const struct vfsmount * mnt, const int fmode)
73528 +{
73529 + return 1;
73530 +}
73531 +
73532 +__u32
73533 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73534 + umode_t *mode)
73535 +{
73536 + return 1;
73537 +}
73538 +
73539 +__u32
73540 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73541 +{
73542 + return 1;
73543 +}
73544 +
73545 +__u32
73546 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73547 +{
73548 + return 1;
73549 +}
73550 +
73551 +__u32
73552 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73553 +{
73554 + return 1;
73555 +}
73556 +
73557 +void
73558 +grsecurity_init(void)
73559 +{
73560 + return;
73561 +}
73562 +
73563 +umode_t gr_acl_umask(void)
73564 +{
73565 + return 0;
73566 +}
73567 +
73568 +__u32
73569 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73570 + const struct dentry * parent_dentry,
73571 + const struct vfsmount * parent_mnt,
73572 + const int mode)
73573 +{
73574 + return 1;
73575 +}
73576 +
73577 +__u32
73578 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
73579 + const struct dentry * parent_dentry,
73580 + const struct vfsmount * parent_mnt)
73581 +{
73582 + return 1;
73583 +}
73584 +
73585 +__u32
73586 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73587 + const struct dentry * parent_dentry,
73588 + const struct vfsmount * parent_mnt, const struct filename *from)
73589 +{
73590 + return 1;
73591 +}
73592 +
73593 +__u32
73594 +gr_acl_handle_link(const struct dentry * new_dentry,
73595 + const struct dentry * parent_dentry,
73596 + const struct vfsmount * parent_mnt,
73597 + const struct dentry * old_dentry,
73598 + const struct vfsmount * old_mnt, const struct filename *to)
73599 +{
73600 + return 1;
73601 +}
73602 +
73603 +int
73604 +gr_acl_handle_rename(const struct dentry *new_dentry,
73605 + const struct dentry *parent_dentry,
73606 + const struct vfsmount *parent_mnt,
73607 + const struct dentry *old_dentry,
73608 + const struct inode *old_parent_inode,
73609 + const struct vfsmount *old_mnt, const struct filename *newname)
73610 +{
73611 + return 0;
73612 +}
73613 +
73614 +int
73615 +gr_acl_handle_filldir(const struct file *file, const char *name,
73616 + const int namelen, const ino_t ino)
73617 +{
73618 + return 1;
73619 +}
73620 +
73621 +int
73622 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73623 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73624 +{
73625 + return 1;
73626 +}
73627 +
73628 +int
73629 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73630 +{
73631 + return 0;
73632 +}
73633 +
73634 +int
73635 +gr_search_accept(const struct socket *sock)
73636 +{
73637 + return 0;
73638 +}
73639 +
73640 +int
73641 +gr_search_listen(const struct socket *sock)
73642 +{
73643 + return 0;
73644 +}
73645 +
73646 +int
73647 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73648 +{
73649 + return 0;
73650 +}
73651 +
73652 +__u32
73653 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73654 +{
73655 + return 1;
73656 +}
73657 +
73658 +__u32
73659 +gr_acl_handle_creat(const struct dentry * dentry,
73660 + const struct dentry * p_dentry,
73661 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73662 + const int imode)
73663 +{
73664 + return 1;
73665 +}
73666 +
73667 +void
73668 +gr_acl_handle_exit(void)
73669 +{
73670 + return;
73671 +}
73672 +
73673 +int
73674 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73675 +{
73676 + return 1;
73677 +}
73678 +
73679 +void
73680 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
73681 +{
73682 + return;
73683 +}
73684 +
73685 +int
73686 +gr_acl_handle_procpidmem(const struct task_struct *task)
73687 +{
73688 + return 0;
73689 +}
73690 +
73691 +int
73692 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73693 +{
73694 + return 0;
73695 +}
73696 +
73697 +int
73698 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73699 +{
73700 + return 0;
73701 +}
73702 +
73703 +int
73704 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73705 +{
73706 + return 0;
73707 +}
73708 +
73709 +int
73710 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73711 +{
73712 + return 0;
73713 +}
73714 +
73715 +int gr_acl_enable_at_secure(void)
73716 +{
73717 + return 0;
73718 +}
73719 +
73720 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73721 +{
73722 + return dentry->d_sb->s_dev;
73723 +}
73724 +
73725 +void gr_put_exec_file(struct task_struct *task)
73726 +{
73727 + return;
73728 +}
73729 +
73730 +#ifdef CONFIG_SECURITY
73731 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73732 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73733 +#endif
73734 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73735 new file mode 100644
73736 index 0000000..f35f454
73737 --- /dev/null
73738 +++ b/grsecurity/grsec_exec.c
73739 @@ -0,0 +1,187 @@
73740 +#include <linux/kernel.h>
73741 +#include <linux/sched.h>
73742 +#include <linux/file.h>
73743 +#include <linux/binfmts.h>
73744 +#include <linux/fs.h>
73745 +#include <linux/types.h>
73746 +#include <linux/grdefs.h>
73747 +#include <linux/grsecurity.h>
73748 +#include <linux/grinternal.h>
73749 +#include <linux/capability.h>
73750 +#include <linux/module.h>
73751 +#include <linux/compat.h>
73752 +
73753 +#include <asm/uaccess.h>
73754 +
73755 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73756 +static char gr_exec_arg_buf[132];
73757 +static DEFINE_MUTEX(gr_exec_arg_mutex);
73758 +#endif
73759 +
73760 +struct user_arg_ptr {
73761 +#ifdef CONFIG_COMPAT
73762 + bool is_compat;
73763 +#endif
73764 + union {
73765 + const char __user *const __user *native;
73766 +#ifdef CONFIG_COMPAT
73767 + const compat_uptr_t __user *compat;
73768 +#endif
73769 + } ptr;
73770 +};
73771 +
73772 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73773 +
73774 +void
73775 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73776 +{
73777 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73778 + char *grarg = gr_exec_arg_buf;
73779 + unsigned int i, x, execlen = 0;
73780 + char c;
73781 +
73782 + if (!((grsec_enable_execlog && grsec_enable_group &&
73783 + in_group_p(grsec_audit_gid))
73784 + || (grsec_enable_execlog && !grsec_enable_group)))
73785 + return;
73786 +
73787 + mutex_lock(&gr_exec_arg_mutex);
73788 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
73789 +
73790 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
73791 + const char __user *p;
73792 + unsigned int len;
73793 +
73794 + p = get_user_arg_ptr(argv, i);
73795 + if (IS_ERR(p))
73796 + goto log;
73797 +
73798 + len = strnlen_user(p, 128 - execlen);
73799 + if (len > 128 - execlen)
73800 + len = 128 - execlen;
73801 + else if (len > 0)
73802 + len--;
73803 + if (copy_from_user(grarg + execlen, p, len))
73804 + goto log;
73805 +
73806 + /* rewrite unprintable characters */
73807 + for (x = 0; x < len; x++) {
73808 + c = *(grarg + execlen + x);
73809 + if (c < 32 || c > 126)
73810 + *(grarg + execlen + x) = ' ';
73811 + }
73812 +
73813 + execlen += len;
73814 + *(grarg + execlen) = ' ';
73815 + *(grarg + execlen + 1) = '\0';
73816 + execlen++;
73817 + }
73818 +
73819 + log:
73820 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73821 + bprm->file->f_path.mnt, grarg);
73822 + mutex_unlock(&gr_exec_arg_mutex);
73823 +#endif
73824 + return;
73825 +}
73826 +
73827 +#ifdef CONFIG_GRKERNSEC
73828 +extern int gr_acl_is_capable(const int cap);
73829 +extern int gr_acl_is_capable_nolog(const int cap);
73830 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73831 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73832 +extern int gr_chroot_is_capable(const int cap);
73833 +extern int gr_chroot_is_capable_nolog(const int cap);
73834 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73835 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73836 +#endif
73837 +
73838 +const char *captab_log[] = {
73839 + "CAP_CHOWN",
73840 + "CAP_DAC_OVERRIDE",
73841 + "CAP_DAC_READ_SEARCH",
73842 + "CAP_FOWNER",
73843 + "CAP_FSETID",
73844 + "CAP_KILL",
73845 + "CAP_SETGID",
73846 + "CAP_SETUID",
73847 + "CAP_SETPCAP",
73848 + "CAP_LINUX_IMMUTABLE",
73849 + "CAP_NET_BIND_SERVICE",
73850 + "CAP_NET_BROADCAST",
73851 + "CAP_NET_ADMIN",
73852 + "CAP_NET_RAW",
73853 + "CAP_IPC_LOCK",
73854 + "CAP_IPC_OWNER",
73855 + "CAP_SYS_MODULE",
73856 + "CAP_SYS_RAWIO",
73857 + "CAP_SYS_CHROOT",
73858 + "CAP_SYS_PTRACE",
73859 + "CAP_SYS_PACCT",
73860 + "CAP_SYS_ADMIN",
73861 + "CAP_SYS_BOOT",
73862 + "CAP_SYS_NICE",
73863 + "CAP_SYS_RESOURCE",
73864 + "CAP_SYS_TIME",
73865 + "CAP_SYS_TTY_CONFIG",
73866 + "CAP_MKNOD",
73867 + "CAP_LEASE",
73868 + "CAP_AUDIT_WRITE",
73869 + "CAP_AUDIT_CONTROL",
73870 + "CAP_SETFCAP",
73871 + "CAP_MAC_OVERRIDE",
73872 + "CAP_MAC_ADMIN",
73873 + "CAP_SYSLOG",
73874 + "CAP_WAKE_ALARM"
73875 +};
73876 +
73877 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73878 +
73879 +int gr_is_capable(const int cap)
73880 +{
73881 +#ifdef CONFIG_GRKERNSEC
73882 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73883 + return 1;
73884 + return 0;
73885 +#else
73886 + return 1;
73887 +#endif
73888 +}
73889 +
73890 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73891 +{
73892 +#ifdef CONFIG_GRKERNSEC
73893 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73894 + return 1;
73895 + return 0;
73896 +#else
73897 + return 1;
73898 +#endif
73899 +}
73900 +
73901 +int gr_is_capable_nolog(const int cap)
73902 +{
73903 +#ifdef CONFIG_GRKERNSEC
73904 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73905 + return 1;
73906 + return 0;
73907 +#else
73908 + return 1;
73909 +#endif
73910 +}
73911 +
73912 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73913 +{
73914 +#ifdef CONFIG_GRKERNSEC
73915 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73916 + return 1;
73917 + return 0;
73918 +#else
73919 + return 1;
73920 +#endif
73921 +}
73922 +
73923 +EXPORT_SYMBOL_GPL(gr_is_capable);
73924 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73925 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
73926 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73927 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73928 new file mode 100644
73929 index 0000000..06cc6ea
73930 --- /dev/null
73931 +++ b/grsecurity/grsec_fifo.c
73932 @@ -0,0 +1,24 @@
73933 +#include <linux/kernel.h>
73934 +#include <linux/sched.h>
73935 +#include <linux/fs.h>
73936 +#include <linux/file.h>
73937 +#include <linux/grinternal.h>
73938 +
73939 +int
73940 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73941 + const struct dentry *dir, const int flag, const int acc_mode)
73942 +{
73943 +#ifdef CONFIG_GRKERNSEC_FIFO
73944 + const struct cred *cred = current_cred();
73945 +
73946 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73947 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73948 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73949 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73950 + if (!inode_permission(dentry->d_inode, acc_mode))
73951 + 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));
73952 + return -EACCES;
73953 + }
73954 +#endif
73955 + return 0;
73956 +}
73957 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73958 new file mode 100644
73959 index 0000000..8ca18bf
73960 --- /dev/null
73961 +++ b/grsecurity/grsec_fork.c
73962 @@ -0,0 +1,23 @@
73963 +#include <linux/kernel.h>
73964 +#include <linux/sched.h>
73965 +#include <linux/grsecurity.h>
73966 +#include <linux/grinternal.h>
73967 +#include <linux/errno.h>
73968 +
73969 +void
73970 +gr_log_forkfail(const int retval)
73971 +{
73972 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73973 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73974 + switch (retval) {
73975 + case -EAGAIN:
73976 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73977 + break;
73978 + case -ENOMEM:
73979 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73980 + break;
73981 + }
73982 + }
73983 +#endif
73984 + return;
73985 +}
73986 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73987 new file mode 100644
73988 index 0000000..ae6c028
73989 --- /dev/null
73990 +++ b/grsecurity/grsec_init.c
73991 @@ -0,0 +1,272 @@
73992 +#include <linux/kernel.h>
73993 +#include <linux/sched.h>
73994 +#include <linux/mm.h>
73995 +#include <linux/gracl.h>
73996 +#include <linux/slab.h>
73997 +#include <linux/vmalloc.h>
73998 +#include <linux/percpu.h>
73999 +#include <linux/module.h>
74000 +
74001 +int grsec_enable_ptrace_readexec;
74002 +int grsec_enable_setxid;
74003 +int grsec_enable_symlinkown;
74004 +kgid_t grsec_symlinkown_gid;
74005 +int grsec_enable_brute;
74006 +int grsec_enable_link;
74007 +int grsec_enable_dmesg;
74008 +int grsec_enable_harden_ptrace;
74009 +int grsec_enable_harden_ipc;
74010 +int grsec_enable_fifo;
74011 +int grsec_enable_execlog;
74012 +int grsec_enable_signal;
74013 +int grsec_enable_forkfail;
74014 +int grsec_enable_audit_ptrace;
74015 +int grsec_enable_time;
74016 +int grsec_enable_group;
74017 +kgid_t grsec_audit_gid;
74018 +int grsec_enable_chdir;
74019 +int grsec_enable_mount;
74020 +int grsec_enable_rofs;
74021 +int grsec_deny_new_usb;
74022 +int grsec_enable_chroot_findtask;
74023 +int grsec_enable_chroot_mount;
74024 +int grsec_enable_chroot_shmat;
74025 +int grsec_enable_chroot_fchdir;
74026 +int grsec_enable_chroot_double;
74027 +int grsec_enable_chroot_pivot;
74028 +int grsec_enable_chroot_chdir;
74029 +int grsec_enable_chroot_chmod;
74030 +int grsec_enable_chroot_mknod;
74031 +int grsec_enable_chroot_nice;
74032 +int grsec_enable_chroot_execlog;
74033 +int grsec_enable_chroot_caps;
74034 +int grsec_enable_chroot_sysctl;
74035 +int grsec_enable_chroot_unix;
74036 +int grsec_enable_tpe;
74037 +kgid_t grsec_tpe_gid;
74038 +int grsec_enable_blackhole;
74039 +#ifdef CONFIG_IPV6_MODULE
74040 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74041 +#endif
74042 +int grsec_lastack_retries;
74043 +int grsec_enable_tpe_all;
74044 +int grsec_enable_tpe_invert;
74045 +int grsec_enable_socket_all;
74046 +kgid_t grsec_socket_all_gid;
74047 +int grsec_enable_socket_client;
74048 +kgid_t grsec_socket_client_gid;
74049 +int grsec_enable_socket_server;
74050 +kgid_t grsec_socket_server_gid;
74051 +int grsec_resource_logging;
74052 +int grsec_disable_privio;
74053 +int grsec_enable_log_rwxmaps;
74054 +int grsec_lock;
74055 +
74056 +DEFINE_SPINLOCK(grsec_alert_lock);
74057 +unsigned long grsec_alert_wtime = 0;
74058 +unsigned long grsec_alert_fyet = 0;
74059 +
74060 +DEFINE_SPINLOCK(grsec_audit_lock);
74061 +
74062 +DEFINE_RWLOCK(grsec_exec_file_lock);
74063 +
74064 +char *gr_shared_page[4];
74065 +
74066 +char *gr_alert_log_fmt;
74067 +char *gr_audit_log_fmt;
74068 +char *gr_alert_log_buf;
74069 +char *gr_audit_log_buf;
74070 +
74071 +void __init
74072 +grsecurity_init(void)
74073 +{
74074 + int j;
74075 + /* create the per-cpu shared pages */
74076 +
74077 +#ifdef CONFIG_X86
74078 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74079 +#endif
74080 +
74081 + for (j = 0; j < 4; j++) {
74082 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74083 + if (gr_shared_page[j] == NULL) {
74084 + panic("Unable to allocate grsecurity shared page");
74085 + return;
74086 + }
74087 + }
74088 +
74089 + /* allocate log buffers */
74090 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74091 + if (!gr_alert_log_fmt) {
74092 + panic("Unable to allocate grsecurity alert log format buffer");
74093 + return;
74094 + }
74095 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74096 + if (!gr_audit_log_fmt) {
74097 + panic("Unable to allocate grsecurity audit log format buffer");
74098 + return;
74099 + }
74100 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74101 + if (!gr_alert_log_buf) {
74102 + panic("Unable to allocate grsecurity alert log buffer");
74103 + return;
74104 + }
74105 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74106 + if (!gr_audit_log_buf) {
74107 + panic("Unable to allocate grsecurity audit log buffer");
74108 + return;
74109 + }
74110 +
74111 +#ifdef CONFIG_GRKERNSEC_IO
74112 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74113 + grsec_disable_privio = 1;
74114 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74115 + grsec_disable_privio = 1;
74116 +#else
74117 + grsec_disable_privio = 0;
74118 +#endif
74119 +#endif
74120 +
74121 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74122 + /* for backward compatibility, tpe_invert always defaults to on if
74123 + enabled in the kernel
74124 + */
74125 + grsec_enable_tpe_invert = 1;
74126 +#endif
74127 +
74128 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74129 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74130 + grsec_lock = 1;
74131 +#endif
74132 +
74133 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74134 + grsec_enable_log_rwxmaps = 1;
74135 +#endif
74136 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74137 + grsec_enable_group = 1;
74138 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74139 +#endif
74140 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74141 + grsec_enable_ptrace_readexec = 1;
74142 +#endif
74143 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74144 + grsec_enable_chdir = 1;
74145 +#endif
74146 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74147 + grsec_enable_harden_ptrace = 1;
74148 +#endif
74149 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74150 + grsec_enable_harden_ipc = 1;
74151 +#endif
74152 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74153 + grsec_enable_mount = 1;
74154 +#endif
74155 +#ifdef CONFIG_GRKERNSEC_LINK
74156 + grsec_enable_link = 1;
74157 +#endif
74158 +#ifdef CONFIG_GRKERNSEC_BRUTE
74159 + grsec_enable_brute = 1;
74160 +#endif
74161 +#ifdef CONFIG_GRKERNSEC_DMESG
74162 + grsec_enable_dmesg = 1;
74163 +#endif
74164 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74165 + grsec_enable_blackhole = 1;
74166 + grsec_lastack_retries = 4;
74167 +#endif
74168 +#ifdef CONFIG_GRKERNSEC_FIFO
74169 + grsec_enable_fifo = 1;
74170 +#endif
74171 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74172 + grsec_enable_execlog = 1;
74173 +#endif
74174 +#ifdef CONFIG_GRKERNSEC_SETXID
74175 + grsec_enable_setxid = 1;
74176 +#endif
74177 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74178 + grsec_enable_signal = 1;
74179 +#endif
74180 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74181 + grsec_enable_forkfail = 1;
74182 +#endif
74183 +#ifdef CONFIG_GRKERNSEC_TIME
74184 + grsec_enable_time = 1;
74185 +#endif
74186 +#ifdef CONFIG_GRKERNSEC_RESLOG
74187 + grsec_resource_logging = 1;
74188 +#endif
74189 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74190 + grsec_enable_chroot_findtask = 1;
74191 +#endif
74192 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74193 + grsec_enable_chroot_unix = 1;
74194 +#endif
74195 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74196 + grsec_enable_chroot_mount = 1;
74197 +#endif
74198 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74199 + grsec_enable_chroot_fchdir = 1;
74200 +#endif
74201 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74202 + grsec_enable_chroot_shmat = 1;
74203 +#endif
74204 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74205 + grsec_enable_audit_ptrace = 1;
74206 +#endif
74207 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74208 + grsec_enable_chroot_double = 1;
74209 +#endif
74210 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74211 + grsec_enable_chroot_pivot = 1;
74212 +#endif
74213 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74214 + grsec_enable_chroot_chdir = 1;
74215 +#endif
74216 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74217 + grsec_enable_chroot_chmod = 1;
74218 +#endif
74219 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74220 + grsec_enable_chroot_mknod = 1;
74221 +#endif
74222 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74223 + grsec_enable_chroot_nice = 1;
74224 +#endif
74225 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74226 + grsec_enable_chroot_execlog = 1;
74227 +#endif
74228 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74229 + grsec_enable_chroot_caps = 1;
74230 +#endif
74231 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74232 + grsec_enable_chroot_sysctl = 1;
74233 +#endif
74234 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74235 + grsec_enable_symlinkown = 1;
74236 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74237 +#endif
74238 +#ifdef CONFIG_GRKERNSEC_TPE
74239 + grsec_enable_tpe = 1;
74240 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74241 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74242 + grsec_enable_tpe_all = 1;
74243 +#endif
74244 +#endif
74245 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74246 + grsec_enable_socket_all = 1;
74247 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74248 +#endif
74249 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74250 + grsec_enable_socket_client = 1;
74251 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74252 +#endif
74253 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74254 + grsec_enable_socket_server = 1;
74255 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74256 +#endif
74257 +#endif
74258 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74259 + grsec_deny_new_usb = 1;
74260 +#endif
74261 +
74262 + return;
74263 +}
74264 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74265 new file mode 100644
74266 index 0000000..1773300
74267 --- /dev/null
74268 +++ b/grsecurity/grsec_ipc.c
74269 @@ -0,0 +1,48 @@
74270 +#include <linux/kernel.h>
74271 +#include <linux/mm.h>
74272 +#include <linux/sched.h>
74273 +#include <linux/file.h>
74274 +#include <linux/ipc.h>
74275 +#include <linux/ipc_namespace.h>
74276 +#include <linux/grsecurity.h>
74277 +#include <linux/grinternal.h>
74278 +
74279 +int
74280 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74281 +{
74282 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74283 + int write;
74284 + int orig_granted_mode;
74285 + kuid_t euid;
74286 + kgid_t egid;
74287 +
74288 + if (!grsec_enable_harden_ipc)
74289 + return 1;
74290 +
74291 + euid = current_euid();
74292 + egid = current_egid();
74293 +
74294 + write = requested_mode & 00002;
74295 + orig_granted_mode = ipcp->mode;
74296 +
74297 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74298 + orig_granted_mode >>= 6;
74299 + else {
74300 + /* if likely wrong permissions, lock to user */
74301 + if (orig_granted_mode & 0007)
74302 + orig_granted_mode = 0;
74303 + /* otherwise do a egid-only check */
74304 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74305 + orig_granted_mode >>= 3;
74306 + /* otherwise, no access */
74307 + else
74308 + orig_granted_mode = 0;
74309 + }
74310 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74311 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74312 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74313 + return 0;
74314 + }
74315 +#endif
74316 + return 1;
74317 +}
74318 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74319 new file mode 100644
74320 index 0000000..5e05e20
74321 --- /dev/null
74322 +++ b/grsecurity/grsec_link.c
74323 @@ -0,0 +1,58 @@
74324 +#include <linux/kernel.h>
74325 +#include <linux/sched.h>
74326 +#include <linux/fs.h>
74327 +#include <linux/file.h>
74328 +#include <linux/grinternal.h>
74329 +
74330 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74331 +{
74332 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74333 + const struct inode *link_inode = link->dentry->d_inode;
74334 +
74335 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74336 + /* ignore root-owned links, e.g. /proc/self */
74337 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74338 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74339 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74340 + return 1;
74341 + }
74342 +#endif
74343 + return 0;
74344 +}
74345 +
74346 +int
74347 +gr_handle_follow_link(const struct inode *parent,
74348 + const struct inode *inode,
74349 + const struct dentry *dentry, const struct vfsmount *mnt)
74350 +{
74351 +#ifdef CONFIG_GRKERNSEC_LINK
74352 + const struct cred *cred = current_cred();
74353 +
74354 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74355 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74356 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74357 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74358 + return -EACCES;
74359 + }
74360 +#endif
74361 + return 0;
74362 +}
74363 +
74364 +int
74365 +gr_handle_hardlink(const struct dentry *dentry,
74366 + const struct vfsmount *mnt,
74367 + struct inode *inode, const int mode, const struct filename *to)
74368 +{
74369 +#ifdef CONFIG_GRKERNSEC_LINK
74370 + const struct cred *cred = current_cred();
74371 +
74372 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74373 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74374 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74375 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74376 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74377 + return -EPERM;
74378 + }
74379 +#endif
74380 + return 0;
74381 +}
74382 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74383 new file mode 100644
74384 index 0000000..dbe0a6b
74385 --- /dev/null
74386 +++ b/grsecurity/grsec_log.c
74387 @@ -0,0 +1,341 @@
74388 +#include <linux/kernel.h>
74389 +#include <linux/sched.h>
74390 +#include <linux/file.h>
74391 +#include <linux/tty.h>
74392 +#include <linux/fs.h>
74393 +#include <linux/mm.h>
74394 +#include <linux/grinternal.h>
74395 +
74396 +#ifdef CONFIG_TREE_PREEMPT_RCU
74397 +#define DISABLE_PREEMPT() preempt_disable()
74398 +#define ENABLE_PREEMPT() preempt_enable()
74399 +#else
74400 +#define DISABLE_PREEMPT()
74401 +#define ENABLE_PREEMPT()
74402 +#endif
74403 +
74404 +#define BEGIN_LOCKS(x) \
74405 + DISABLE_PREEMPT(); \
74406 + rcu_read_lock(); \
74407 + read_lock(&tasklist_lock); \
74408 + read_lock(&grsec_exec_file_lock); \
74409 + if (x != GR_DO_AUDIT) \
74410 + spin_lock(&grsec_alert_lock); \
74411 + else \
74412 + spin_lock(&grsec_audit_lock)
74413 +
74414 +#define END_LOCKS(x) \
74415 + if (x != GR_DO_AUDIT) \
74416 + spin_unlock(&grsec_alert_lock); \
74417 + else \
74418 + spin_unlock(&grsec_audit_lock); \
74419 + read_unlock(&grsec_exec_file_lock); \
74420 + read_unlock(&tasklist_lock); \
74421 + rcu_read_unlock(); \
74422 + ENABLE_PREEMPT(); \
74423 + if (x == GR_DONT_AUDIT) \
74424 + gr_handle_alertkill(current)
74425 +
74426 +enum {
74427 + FLOODING,
74428 + NO_FLOODING
74429 +};
74430 +
74431 +extern char *gr_alert_log_fmt;
74432 +extern char *gr_audit_log_fmt;
74433 +extern char *gr_alert_log_buf;
74434 +extern char *gr_audit_log_buf;
74435 +
74436 +static int gr_log_start(int audit)
74437 +{
74438 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74439 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74440 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74441 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74442 + unsigned long curr_secs = get_seconds();
74443 +
74444 + if (audit == GR_DO_AUDIT)
74445 + goto set_fmt;
74446 +
74447 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74448 + grsec_alert_wtime = curr_secs;
74449 + grsec_alert_fyet = 0;
74450 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74451 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74452 + grsec_alert_fyet++;
74453 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74454 + grsec_alert_wtime = curr_secs;
74455 + grsec_alert_fyet++;
74456 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74457 + return FLOODING;
74458 + }
74459 + else return FLOODING;
74460 +
74461 +set_fmt:
74462 +#endif
74463 + memset(buf, 0, PAGE_SIZE);
74464 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
74465 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74466 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74467 + } else if (current->signal->curr_ip) {
74468 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74469 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74470 + } else if (gr_acl_is_enabled()) {
74471 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74472 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74473 + } else {
74474 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
74475 + strcpy(buf, fmt);
74476 + }
74477 +
74478 + return NO_FLOODING;
74479 +}
74480 +
74481 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74482 + __attribute__ ((format (printf, 2, 0)));
74483 +
74484 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74485 +{
74486 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74487 + unsigned int len = strlen(buf);
74488 +
74489 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74490 +
74491 + return;
74492 +}
74493 +
74494 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74495 + __attribute__ ((format (printf, 2, 3)));
74496 +
74497 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74498 +{
74499 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74500 + unsigned int len = strlen(buf);
74501 + va_list ap;
74502 +
74503 + va_start(ap, msg);
74504 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74505 + va_end(ap);
74506 +
74507 + return;
74508 +}
74509 +
74510 +static void gr_log_end(int audit, int append_default)
74511 +{
74512 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74513 + if (append_default) {
74514 + struct task_struct *task = current;
74515 + struct task_struct *parent = task->real_parent;
74516 + const struct cred *cred = __task_cred(task);
74517 + const struct cred *pcred = __task_cred(parent);
74518 + unsigned int len = strlen(buf);
74519 +
74520 + 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));
74521 + }
74522 +
74523 + printk("%s\n", buf);
74524 +
74525 + return;
74526 +}
74527 +
74528 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74529 +{
74530 + int logtype;
74531 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74532 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74533 + void *voidptr = NULL;
74534 + int num1 = 0, num2 = 0;
74535 + unsigned long ulong1 = 0, ulong2 = 0;
74536 + struct dentry *dentry = NULL;
74537 + struct vfsmount *mnt = NULL;
74538 + struct file *file = NULL;
74539 + struct task_struct *task = NULL;
74540 + struct vm_area_struct *vma = NULL;
74541 + const struct cred *cred, *pcred;
74542 + va_list ap;
74543 +
74544 + BEGIN_LOCKS(audit);
74545 + logtype = gr_log_start(audit);
74546 + if (logtype == FLOODING) {
74547 + END_LOCKS(audit);
74548 + return;
74549 + }
74550 + va_start(ap, argtypes);
74551 + switch (argtypes) {
74552 + case GR_TTYSNIFF:
74553 + task = va_arg(ap, struct task_struct *);
74554 + 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));
74555 + break;
74556 + case GR_SYSCTL_HIDDEN:
74557 + str1 = va_arg(ap, char *);
74558 + gr_log_middle_varargs(audit, msg, result, str1);
74559 + break;
74560 + case GR_RBAC:
74561 + dentry = va_arg(ap, struct dentry *);
74562 + mnt = va_arg(ap, struct vfsmount *);
74563 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74564 + break;
74565 + case GR_RBAC_STR:
74566 + dentry = va_arg(ap, struct dentry *);
74567 + mnt = va_arg(ap, struct vfsmount *);
74568 + str1 = va_arg(ap, char *);
74569 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74570 + break;
74571 + case GR_STR_RBAC:
74572 + str1 = va_arg(ap, char *);
74573 + dentry = va_arg(ap, struct dentry *);
74574 + mnt = va_arg(ap, struct vfsmount *);
74575 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74576 + break;
74577 + case GR_RBAC_MODE2:
74578 + dentry = va_arg(ap, struct dentry *);
74579 + mnt = va_arg(ap, struct vfsmount *);
74580 + str1 = va_arg(ap, char *);
74581 + str2 = va_arg(ap, char *);
74582 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74583 + break;
74584 + case GR_RBAC_MODE3:
74585 + dentry = va_arg(ap, struct dentry *);
74586 + mnt = va_arg(ap, struct vfsmount *);
74587 + str1 = va_arg(ap, char *);
74588 + str2 = va_arg(ap, char *);
74589 + str3 = va_arg(ap, char *);
74590 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74591 + break;
74592 + case GR_FILENAME:
74593 + dentry = va_arg(ap, struct dentry *);
74594 + mnt = va_arg(ap, struct vfsmount *);
74595 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74596 + break;
74597 + case GR_STR_FILENAME:
74598 + str1 = va_arg(ap, char *);
74599 + dentry = va_arg(ap, struct dentry *);
74600 + mnt = va_arg(ap, struct vfsmount *);
74601 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74602 + break;
74603 + case GR_FILENAME_STR:
74604 + dentry = va_arg(ap, struct dentry *);
74605 + mnt = va_arg(ap, struct vfsmount *);
74606 + str1 = va_arg(ap, char *);
74607 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74608 + break;
74609 + case GR_FILENAME_TWO_INT:
74610 + dentry = va_arg(ap, struct dentry *);
74611 + mnt = va_arg(ap, struct vfsmount *);
74612 + num1 = va_arg(ap, int);
74613 + num2 = va_arg(ap, int);
74614 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74615 + break;
74616 + case GR_FILENAME_TWO_INT_STR:
74617 + dentry = va_arg(ap, struct dentry *);
74618 + mnt = va_arg(ap, struct vfsmount *);
74619 + num1 = va_arg(ap, int);
74620 + num2 = va_arg(ap, int);
74621 + str1 = va_arg(ap, char *);
74622 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74623 + break;
74624 + case GR_TEXTREL:
74625 + file = va_arg(ap, struct file *);
74626 + ulong1 = va_arg(ap, unsigned long);
74627 + ulong2 = va_arg(ap, unsigned long);
74628 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74629 + break;
74630 + case GR_PTRACE:
74631 + task = va_arg(ap, struct task_struct *);
74632 + 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));
74633 + break;
74634 + case GR_RESOURCE:
74635 + task = va_arg(ap, struct task_struct *);
74636 + cred = __task_cred(task);
74637 + pcred = __task_cred(task->real_parent);
74638 + ulong1 = va_arg(ap, unsigned long);
74639 + str1 = va_arg(ap, char *);
74640 + ulong2 = va_arg(ap, unsigned long);
74641 + 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));
74642 + break;
74643 + case GR_CAP:
74644 + task = va_arg(ap, struct task_struct *);
74645 + cred = __task_cred(task);
74646 + pcred = __task_cred(task->real_parent);
74647 + str1 = va_arg(ap, char *);
74648 + 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));
74649 + break;
74650 + case GR_SIG:
74651 + str1 = va_arg(ap, char *);
74652 + voidptr = va_arg(ap, void *);
74653 + gr_log_middle_varargs(audit, msg, str1, voidptr);
74654 + break;
74655 + case GR_SIG2:
74656 + task = va_arg(ap, struct task_struct *);
74657 + cred = __task_cred(task);
74658 + pcred = __task_cred(task->real_parent);
74659 + num1 = va_arg(ap, int);
74660 + 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));
74661 + break;
74662 + case GR_CRASH1:
74663 + task = va_arg(ap, struct task_struct *);
74664 + cred = __task_cred(task);
74665 + pcred = __task_cred(task->real_parent);
74666 + ulong1 = va_arg(ap, unsigned long);
74667 + 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);
74668 + break;
74669 + case GR_CRASH2:
74670 + task = va_arg(ap, struct task_struct *);
74671 + cred = __task_cred(task);
74672 + pcred = __task_cred(task->real_parent);
74673 + ulong1 = va_arg(ap, unsigned long);
74674 + 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);
74675 + break;
74676 + case GR_RWXMAP:
74677 + file = va_arg(ap, struct file *);
74678 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74679 + break;
74680 + case GR_RWXMAPVMA:
74681 + vma = va_arg(ap, struct vm_area_struct *);
74682 + if (vma->vm_file)
74683 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74684 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74685 + str1 = "<stack>";
74686 + else if (vma->vm_start <= current->mm->brk &&
74687 + vma->vm_end >= current->mm->start_brk)
74688 + str1 = "<heap>";
74689 + else
74690 + str1 = "<anonymous mapping>";
74691 + gr_log_middle_varargs(audit, msg, str1);
74692 + break;
74693 + case GR_PSACCT:
74694 + {
74695 + unsigned int wday, cday;
74696 + __u8 whr, chr;
74697 + __u8 wmin, cmin;
74698 + __u8 wsec, csec;
74699 + char cur_tty[64] = { 0 };
74700 + char parent_tty[64] = { 0 };
74701 +
74702 + task = va_arg(ap, struct task_struct *);
74703 + wday = va_arg(ap, unsigned int);
74704 + cday = va_arg(ap, unsigned int);
74705 + whr = va_arg(ap, int);
74706 + chr = va_arg(ap, int);
74707 + wmin = va_arg(ap, int);
74708 + cmin = va_arg(ap, int);
74709 + wsec = va_arg(ap, int);
74710 + csec = va_arg(ap, int);
74711 + ulong1 = va_arg(ap, unsigned long);
74712 + cred = __task_cred(task);
74713 + pcred = __task_cred(task->real_parent);
74714 +
74715 + 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));
74716 + }
74717 + break;
74718 + default:
74719 + gr_log_middle(audit, msg, ap);
74720 + }
74721 + va_end(ap);
74722 + // these don't need DEFAULTSECARGS printed on the end
74723 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74724 + gr_log_end(audit, 0);
74725 + else
74726 + gr_log_end(audit, 1);
74727 + END_LOCKS(audit);
74728 +}
74729 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74730 new file mode 100644
74731 index 0000000..0e39d8c
74732 --- /dev/null
74733 +++ b/grsecurity/grsec_mem.c
74734 @@ -0,0 +1,48 @@
74735 +#include <linux/kernel.h>
74736 +#include <linux/sched.h>
74737 +#include <linux/mm.h>
74738 +#include <linux/mman.h>
74739 +#include <linux/module.h>
74740 +#include <linux/grinternal.h>
74741 +
74742 +void gr_handle_msr_write(void)
74743 +{
74744 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74745 + return;
74746 +}
74747 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74748 +
74749 +void
74750 +gr_handle_ioperm(void)
74751 +{
74752 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74753 + return;
74754 +}
74755 +
74756 +void
74757 +gr_handle_iopl(void)
74758 +{
74759 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74760 + return;
74761 +}
74762 +
74763 +void
74764 +gr_handle_mem_readwrite(u64 from, u64 to)
74765 +{
74766 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74767 + return;
74768 +}
74769 +
74770 +void
74771 +gr_handle_vm86(void)
74772 +{
74773 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74774 + return;
74775 +}
74776 +
74777 +void
74778 +gr_log_badprocpid(const char *entry)
74779 +{
74780 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74781 + return;
74782 +}
74783 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74784 new file mode 100644
74785 index 0000000..cd9e124
74786 --- /dev/null
74787 +++ b/grsecurity/grsec_mount.c
74788 @@ -0,0 +1,65 @@
74789 +#include <linux/kernel.h>
74790 +#include <linux/sched.h>
74791 +#include <linux/mount.h>
74792 +#include <linux/major.h>
74793 +#include <linux/grsecurity.h>
74794 +#include <linux/grinternal.h>
74795 +
74796 +void
74797 +gr_log_remount(const char *devname, const int retval)
74798 +{
74799 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74800 + if (grsec_enable_mount && (retval >= 0))
74801 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74802 +#endif
74803 + return;
74804 +}
74805 +
74806 +void
74807 +gr_log_unmount(const char *devname, const int retval)
74808 +{
74809 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74810 + if (grsec_enable_mount && (retval >= 0))
74811 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74812 +#endif
74813 + return;
74814 +}
74815 +
74816 +void
74817 +gr_log_mount(const char *from, const char *to, const int retval)
74818 +{
74819 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74820 + if (grsec_enable_mount && (retval >= 0))
74821 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74822 +#endif
74823 + return;
74824 +}
74825 +
74826 +int
74827 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74828 +{
74829 +#ifdef CONFIG_GRKERNSEC_ROFS
74830 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74831 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74832 + return -EPERM;
74833 + } else
74834 + return 0;
74835 +#endif
74836 + return 0;
74837 +}
74838 +
74839 +int
74840 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74841 +{
74842 +#ifdef CONFIG_GRKERNSEC_ROFS
74843 + struct inode *inode = dentry->d_inode;
74844 +
74845 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74846 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74847 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74848 + return -EPERM;
74849 + } else
74850 + return 0;
74851 +#endif
74852 + return 0;
74853 +}
74854 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74855 new file mode 100644
74856 index 0000000..6ee9d50
74857 --- /dev/null
74858 +++ b/grsecurity/grsec_pax.c
74859 @@ -0,0 +1,45 @@
74860 +#include <linux/kernel.h>
74861 +#include <linux/sched.h>
74862 +#include <linux/mm.h>
74863 +#include <linux/file.h>
74864 +#include <linux/grinternal.h>
74865 +#include <linux/grsecurity.h>
74866 +
74867 +void
74868 +gr_log_textrel(struct vm_area_struct * vma)
74869 +{
74870 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74871 + if (grsec_enable_log_rwxmaps)
74872 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74873 +#endif
74874 + return;
74875 +}
74876 +
74877 +void gr_log_ptgnustack(struct file *file)
74878 +{
74879 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74880 + if (grsec_enable_log_rwxmaps)
74881 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74882 +#endif
74883 + return;
74884 +}
74885 +
74886 +void
74887 +gr_log_rwxmmap(struct file *file)
74888 +{
74889 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74890 + if (grsec_enable_log_rwxmaps)
74891 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74892 +#endif
74893 + return;
74894 +}
74895 +
74896 +void
74897 +gr_log_rwxmprotect(struct vm_area_struct *vma)
74898 +{
74899 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74900 + if (grsec_enable_log_rwxmaps)
74901 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74902 +#endif
74903 + return;
74904 +}
74905 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74906 new file mode 100644
74907 index 0000000..f7f29aa
74908 --- /dev/null
74909 +++ b/grsecurity/grsec_ptrace.c
74910 @@ -0,0 +1,30 @@
74911 +#include <linux/kernel.h>
74912 +#include <linux/sched.h>
74913 +#include <linux/grinternal.h>
74914 +#include <linux/security.h>
74915 +
74916 +void
74917 +gr_audit_ptrace(struct task_struct *task)
74918 +{
74919 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74920 + if (grsec_enable_audit_ptrace)
74921 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74922 +#endif
74923 + return;
74924 +}
74925 +
74926 +int
74927 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
74928 +{
74929 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74930 + const struct dentry *dentry = file->f_path.dentry;
74931 + const struct vfsmount *mnt = file->f_path.mnt;
74932 +
74933 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74934 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74935 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74936 + return -EACCES;
74937 + }
74938 +#endif
74939 + return 0;
74940 +}
74941 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74942 new file mode 100644
74943 index 0000000..3860c7e
74944 --- /dev/null
74945 +++ b/grsecurity/grsec_sig.c
74946 @@ -0,0 +1,236 @@
74947 +#include <linux/kernel.h>
74948 +#include <linux/sched.h>
74949 +#include <linux/fs.h>
74950 +#include <linux/delay.h>
74951 +#include <linux/grsecurity.h>
74952 +#include <linux/grinternal.h>
74953 +#include <linux/hardirq.h>
74954 +
74955 +char *signames[] = {
74956 + [SIGSEGV] = "Segmentation fault",
74957 + [SIGILL] = "Illegal instruction",
74958 + [SIGABRT] = "Abort",
74959 + [SIGBUS] = "Invalid alignment/Bus error"
74960 +};
74961 +
74962 +void
74963 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74964 +{
74965 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74966 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74967 + (sig == SIGABRT) || (sig == SIGBUS))) {
74968 + if (task_pid_nr(t) == task_pid_nr(current)) {
74969 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74970 + } else {
74971 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74972 + }
74973 + }
74974 +#endif
74975 + return;
74976 +}
74977 +
74978 +int
74979 +gr_handle_signal(const struct task_struct *p, const int sig)
74980 +{
74981 +#ifdef CONFIG_GRKERNSEC
74982 + /* ignore the 0 signal for protected task checks */
74983 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74984 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74985 + return -EPERM;
74986 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74987 + return -EPERM;
74988 + }
74989 +#endif
74990 + return 0;
74991 +}
74992 +
74993 +#ifdef CONFIG_GRKERNSEC
74994 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74995 +
74996 +int gr_fake_force_sig(int sig, struct task_struct *t)
74997 +{
74998 + unsigned long int flags;
74999 + int ret, blocked, ignored;
75000 + struct k_sigaction *action;
75001 +
75002 + spin_lock_irqsave(&t->sighand->siglock, flags);
75003 + action = &t->sighand->action[sig-1];
75004 + ignored = action->sa.sa_handler == SIG_IGN;
75005 + blocked = sigismember(&t->blocked, sig);
75006 + if (blocked || ignored) {
75007 + action->sa.sa_handler = SIG_DFL;
75008 + if (blocked) {
75009 + sigdelset(&t->blocked, sig);
75010 + recalc_sigpending_and_wake(t);
75011 + }
75012 + }
75013 + if (action->sa.sa_handler == SIG_DFL)
75014 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
75015 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75016 +
75017 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
75018 +
75019 + return ret;
75020 +}
75021 +#endif
75022 +
75023 +#define GR_USER_BAN_TIME (15 * 60)
75024 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
75025 +
75026 +void gr_handle_brute_attach(int dumpable)
75027 +{
75028 +#ifdef CONFIG_GRKERNSEC_BRUTE
75029 + struct task_struct *p = current;
75030 + kuid_t uid = GLOBAL_ROOT_UID;
75031 + int daemon = 0;
75032 +
75033 + if (!grsec_enable_brute)
75034 + return;
75035 +
75036 + rcu_read_lock();
75037 + read_lock(&tasklist_lock);
75038 + read_lock(&grsec_exec_file_lock);
75039 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75040 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75041 + p->real_parent->brute = 1;
75042 + daemon = 1;
75043 + } else {
75044 + const struct cred *cred = __task_cred(p), *cred2;
75045 + struct task_struct *tsk, *tsk2;
75046 +
75047 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75048 + struct user_struct *user;
75049 +
75050 + uid = cred->uid;
75051 +
75052 + /* this is put upon execution past expiration */
75053 + user = find_user(uid);
75054 + if (user == NULL)
75055 + goto unlock;
75056 + user->suid_banned = 1;
75057 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75058 + if (user->suid_ban_expires == ~0UL)
75059 + user->suid_ban_expires--;
75060 +
75061 + /* only kill other threads of the same binary, from the same user */
75062 + do_each_thread(tsk2, tsk) {
75063 + cred2 = __task_cred(tsk);
75064 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75065 + gr_fake_force_sig(SIGKILL, tsk);
75066 + } while_each_thread(tsk2, tsk);
75067 + }
75068 + }
75069 +unlock:
75070 + read_unlock(&grsec_exec_file_lock);
75071 + read_unlock(&tasklist_lock);
75072 + rcu_read_unlock();
75073 +
75074 + if (gr_is_global_nonroot(uid))
75075 + 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);
75076 + else if (daemon)
75077 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75078 +
75079 +#endif
75080 + return;
75081 +}
75082 +
75083 +void gr_handle_brute_check(void)
75084 +{
75085 +#ifdef CONFIG_GRKERNSEC_BRUTE
75086 + struct task_struct *p = current;
75087 +
75088 + if (unlikely(p->brute)) {
75089 + if (!grsec_enable_brute)
75090 + p->brute = 0;
75091 + else if (time_before(get_seconds(), p->brute_expires))
75092 + msleep(30 * 1000);
75093 + }
75094 +#endif
75095 + return;
75096 +}
75097 +
75098 +void gr_handle_kernel_exploit(void)
75099 +{
75100 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75101 + const struct cred *cred;
75102 + struct task_struct *tsk, *tsk2;
75103 + struct user_struct *user;
75104 + kuid_t uid;
75105 +
75106 + if (in_irq() || in_serving_softirq() || in_nmi())
75107 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75108 +
75109 + uid = current_uid();
75110 +
75111 + if (gr_is_global_root(uid))
75112 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
75113 + else {
75114 + /* kill all the processes of this user, hold a reference
75115 + to their creds struct, and prevent them from creating
75116 + another process until system reset
75117 + */
75118 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75119 + GR_GLOBAL_UID(uid));
75120 + /* we intentionally leak this ref */
75121 + user = get_uid(current->cred->user);
75122 + if (user)
75123 + user->kernel_banned = 1;
75124 +
75125 + /* kill all processes of this user */
75126 + read_lock(&tasklist_lock);
75127 + do_each_thread(tsk2, tsk) {
75128 + cred = __task_cred(tsk);
75129 + if (uid_eq(cred->uid, uid))
75130 + gr_fake_force_sig(SIGKILL, tsk);
75131 + } while_each_thread(tsk2, tsk);
75132 + read_unlock(&tasklist_lock);
75133 + }
75134 +#endif
75135 +}
75136 +
75137 +#ifdef CONFIG_GRKERNSEC_BRUTE
75138 +static bool suid_ban_expired(struct user_struct *user)
75139 +{
75140 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75141 + user->suid_banned = 0;
75142 + user->suid_ban_expires = 0;
75143 + free_uid(user);
75144 + return true;
75145 + }
75146 +
75147 + return false;
75148 +}
75149 +#endif
75150 +
75151 +int gr_process_kernel_exec_ban(void)
75152 +{
75153 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75154 + if (unlikely(current->cred->user->kernel_banned))
75155 + return -EPERM;
75156 +#endif
75157 + return 0;
75158 +}
75159 +
75160 +int gr_process_kernel_setuid_ban(struct user_struct *user)
75161 +{
75162 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75163 + if (unlikely(user->kernel_banned))
75164 + gr_fake_force_sig(SIGKILL, current);
75165 +#endif
75166 + return 0;
75167 +}
75168 +
75169 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75170 +{
75171 +#ifdef CONFIG_GRKERNSEC_BRUTE
75172 + struct user_struct *user = current->cred->user;
75173 + if (unlikely(user->suid_banned)) {
75174 + if (suid_ban_expired(user))
75175 + return 0;
75176 + /* disallow execution of suid binaries only */
75177 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75178 + return -EPERM;
75179 + }
75180 +#endif
75181 + return 0;
75182 +}
75183 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75184 new file mode 100644
75185 index 0000000..c0aef3a
75186 --- /dev/null
75187 +++ b/grsecurity/grsec_sock.c
75188 @@ -0,0 +1,244 @@
75189 +#include <linux/kernel.h>
75190 +#include <linux/module.h>
75191 +#include <linux/sched.h>
75192 +#include <linux/file.h>
75193 +#include <linux/net.h>
75194 +#include <linux/in.h>
75195 +#include <linux/ip.h>
75196 +#include <net/sock.h>
75197 +#include <net/inet_sock.h>
75198 +#include <linux/grsecurity.h>
75199 +#include <linux/grinternal.h>
75200 +#include <linux/gracl.h>
75201 +
75202 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75203 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75204 +
75205 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75206 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75207 +
75208 +#ifdef CONFIG_UNIX_MODULE
75209 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75210 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75211 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75212 +EXPORT_SYMBOL_GPL(gr_handle_create);
75213 +#endif
75214 +
75215 +#ifdef CONFIG_GRKERNSEC
75216 +#define gr_conn_table_size 32749
75217 +struct conn_table_entry {
75218 + struct conn_table_entry *next;
75219 + struct signal_struct *sig;
75220 +};
75221 +
75222 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75223 +DEFINE_SPINLOCK(gr_conn_table_lock);
75224 +
75225 +extern const char * gr_socktype_to_name(unsigned char type);
75226 +extern const char * gr_proto_to_name(unsigned char proto);
75227 +extern const char * gr_sockfamily_to_name(unsigned char family);
75228 +
75229 +static __inline__ int
75230 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75231 +{
75232 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75233 +}
75234 +
75235 +static __inline__ int
75236 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75237 + __u16 sport, __u16 dport)
75238 +{
75239 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75240 + sig->gr_sport == sport && sig->gr_dport == dport))
75241 + return 1;
75242 + else
75243 + return 0;
75244 +}
75245 +
75246 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75247 +{
75248 + struct conn_table_entry **match;
75249 + unsigned int index;
75250 +
75251 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75252 + sig->gr_sport, sig->gr_dport,
75253 + gr_conn_table_size);
75254 +
75255 + newent->sig = sig;
75256 +
75257 + match = &gr_conn_table[index];
75258 + newent->next = *match;
75259 + *match = newent;
75260 +
75261 + return;
75262 +}
75263 +
75264 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75265 +{
75266 + struct conn_table_entry *match, *last = NULL;
75267 + unsigned int index;
75268 +
75269 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75270 + sig->gr_sport, sig->gr_dport,
75271 + gr_conn_table_size);
75272 +
75273 + match = gr_conn_table[index];
75274 + while (match && !conn_match(match->sig,
75275 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75276 + sig->gr_dport)) {
75277 + last = match;
75278 + match = match->next;
75279 + }
75280 +
75281 + if (match) {
75282 + if (last)
75283 + last->next = match->next;
75284 + else
75285 + gr_conn_table[index] = NULL;
75286 + kfree(match);
75287 + }
75288 +
75289 + return;
75290 +}
75291 +
75292 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75293 + __u16 sport, __u16 dport)
75294 +{
75295 + struct conn_table_entry *match;
75296 + unsigned int index;
75297 +
75298 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75299 +
75300 + match = gr_conn_table[index];
75301 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75302 + match = match->next;
75303 +
75304 + if (match)
75305 + return match->sig;
75306 + else
75307 + return NULL;
75308 +}
75309 +
75310 +#endif
75311 +
75312 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75313 +{
75314 +#ifdef CONFIG_GRKERNSEC
75315 + struct signal_struct *sig = task->signal;
75316 + struct conn_table_entry *newent;
75317 +
75318 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75319 + if (newent == NULL)
75320 + return;
75321 + /* no bh lock needed since we are called with bh disabled */
75322 + spin_lock(&gr_conn_table_lock);
75323 + gr_del_task_from_ip_table_nolock(sig);
75324 + sig->gr_saddr = inet->inet_rcv_saddr;
75325 + sig->gr_daddr = inet->inet_daddr;
75326 + sig->gr_sport = inet->inet_sport;
75327 + sig->gr_dport = inet->inet_dport;
75328 + gr_add_to_task_ip_table_nolock(sig, newent);
75329 + spin_unlock(&gr_conn_table_lock);
75330 +#endif
75331 + return;
75332 +}
75333 +
75334 +void gr_del_task_from_ip_table(struct task_struct *task)
75335 +{
75336 +#ifdef CONFIG_GRKERNSEC
75337 + spin_lock_bh(&gr_conn_table_lock);
75338 + gr_del_task_from_ip_table_nolock(task->signal);
75339 + spin_unlock_bh(&gr_conn_table_lock);
75340 +#endif
75341 + return;
75342 +}
75343 +
75344 +void
75345 +gr_attach_curr_ip(const struct sock *sk)
75346 +{
75347 +#ifdef CONFIG_GRKERNSEC
75348 + struct signal_struct *p, *set;
75349 + const struct inet_sock *inet = inet_sk(sk);
75350 +
75351 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75352 + return;
75353 +
75354 + set = current->signal;
75355 +
75356 + spin_lock_bh(&gr_conn_table_lock);
75357 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75358 + inet->inet_dport, inet->inet_sport);
75359 + if (unlikely(p != NULL)) {
75360 + set->curr_ip = p->curr_ip;
75361 + set->used_accept = 1;
75362 + gr_del_task_from_ip_table_nolock(p);
75363 + spin_unlock_bh(&gr_conn_table_lock);
75364 + return;
75365 + }
75366 + spin_unlock_bh(&gr_conn_table_lock);
75367 +
75368 + set->curr_ip = inet->inet_daddr;
75369 + set->used_accept = 1;
75370 +#endif
75371 + return;
75372 +}
75373 +
75374 +int
75375 +gr_handle_sock_all(const int family, const int type, const int protocol)
75376 +{
75377 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75378 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75379 + (family != AF_UNIX)) {
75380 + if (family == AF_INET)
75381 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75382 + else
75383 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75384 + return -EACCES;
75385 + }
75386 +#endif
75387 + return 0;
75388 +}
75389 +
75390 +int
75391 +gr_handle_sock_server(const struct sockaddr *sck)
75392 +{
75393 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75394 + if (grsec_enable_socket_server &&
75395 + in_group_p(grsec_socket_server_gid) &&
75396 + sck && (sck->sa_family != AF_UNIX) &&
75397 + (sck->sa_family != AF_LOCAL)) {
75398 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75399 + return -EACCES;
75400 + }
75401 +#endif
75402 + return 0;
75403 +}
75404 +
75405 +int
75406 +gr_handle_sock_server_other(const struct sock *sck)
75407 +{
75408 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75409 + if (grsec_enable_socket_server &&
75410 + in_group_p(grsec_socket_server_gid) &&
75411 + sck && (sck->sk_family != AF_UNIX) &&
75412 + (sck->sk_family != AF_LOCAL)) {
75413 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75414 + return -EACCES;
75415 + }
75416 +#endif
75417 + return 0;
75418 +}
75419 +
75420 +int
75421 +gr_handle_sock_client(const struct sockaddr *sck)
75422 +{
75423 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75424 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75425 + sck && (sck->sa_family != AF_UNIX) &&
75426 + (sck->sa_family != AF_LOCAL)) {
75427 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75428 + return -EACCES;
75429 + }
75430 +#endif
75431 + return 0;
75432 +}
75433 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75434 new file mode 100644
75435 index 0000000..8159888
75436 --- /dev/null
75437 +++ b/grsecurity/grsec_sysctl.c
75438 @@ -0,0 +1,479 @@
75439 +#include <linux/kernel.h>
75440 +#include <linux/sched.h>
75441 +#include <linux/sysctl.h>
75442 +#include <linux/grsecurity.h>
75443 +#include <linux/grinternal.h>
75444 +
75445 +int
75446 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75447 +{
75448 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75449 + if (dirname == NULL || name == NULL)
75450 + return 0;
75451 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75452 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75453 + return -EACCES;
75454 + }
75455 +#endif
75456 + return 0;
75457 +}
75458 +
75459 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75460 +static int __maybe_unused __read_only one = 1;
75461 +#endif
75462 +
75463 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75464 + defined(CONFIG_GRKERNSEC_DENYUSB)
75465 +struct ctl_table grsecurity_table[] = {
75466 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75467 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75468 +#ifdef CONFIG_GRKERNSEC_IO
75469 + {
75470 + .procname = "disable_priv_io",
75471 + .data = &grsec_disable_privio,
75472 + .maxlen = sizeof(int),
75473 + .mode = 0600,
75474 + .proc_handler = &proc_dointvec,
75475 + },
75476 +#endif
75477 +#endif
75478 +#ifdef CONFIG_GRKERNSEC_LINK
75479 + {
75480 + .procname = "linking_restrictions",
75481 + .data = &grsec_enable_link,
75482 + .maxlen = sizeof(int),
75483 + .mode = 0600,
75484 + .proc_handler = &proc_dointvec,
75485 + },
75486 +#endif
75487 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75488 + {
75489 + .procname = "enforce_symlinksifowner",
75490 + .data = &grsec_enable_symlinkown,
75491 + .maxlen = sizeof(int),
75492 + .mode = 0600,
75493 + .proc_handler = &proc_dointvec,
75494 + },
75495 + {
75496 + .procname = "symlinkown_gid",
75497 + .data = &grsec_symlinkown_gid,
75498 + .maxlen = sizeof(int),
75499 + .mode = 0600,
75500 + .proc_handler = &proc_dointvec,
75501 + },
75502 +#endif
75503 +#ifdef CONFIG_GRKERNSEC_BRUTE
75504 + {
75505 + .procname = "deter_bruteforce",
75506 + .data = &grsec_enable_brute,
75507 + .maxlen = sizeof(int),
75508 + .mode = 0600,
75509 + .proc_handler = &proc_dointvec,
75510 + },
75511 +#endif
75512 +#ifdef CONFIG_GRKERNSEC_FIFO
75513 + {
75514 + .procname = "fifo_restrictions",
75515 + .data = &grsec_enable_fifo,
75516 + .maxlen = sizeof(int),
75517 + .mode = 0600,
75518 + .proc_handler = &proc_dointvec,
75519 + },
75520 +#endif
75521 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75522 + {
75523 + .procname = "ptrace_readexec",
75524 + .data = &grsec_enable_ptrace_readexec,
75525 + .maxlen = sizeof(int),
75526 + .mode = 0600,
75527 + .proc_handler = &proc_dointvec,
75528 + },
75529 +#endif
75530 +#ifdef CONFIG_GRKERNSEC_SETXID
75531 + {
75532 + .procname = "consistent_setxid",
75533 + .data = &grsec_enable_setxid,
75534 + .maxlen = sizeof(int),
75535 + .mode = 0600,
75536 + .proc_handler = &proc_dointvec,
75537 + },
75538 +#endif
75539 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75540 + {
75541 + .procname = "ip_blackhole",
75542 + .data = &grsec_enable_blackhole,
75543 + .maxlen = sizeof(int),
75544 + .mode = 0600,
75545 + .proc_handler = &proc_dointvec,
75546 + },
75547 + {
75548 + .procname = "lastack_retries",
75549 + .data = &grsec_lastack_retries,
75550 + .maxlen = sizeof(int),
75551 + .mode = 0600,
75552 + .proc_handler = &proc_dointvec,
75553 + },
75554 +#endif
75555 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75556 + {
75557 + .procname = "exec_logging",
75558 + .data = &grsec_enable_execlog,
75559 + .maxlen = sizeof(int),
75560 + .mode = 0600,
75561 + .proc_handler = &proc_dointvec,
75562 + },
75563 +#endif
75564 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75565 + {
75566 + .procname = "rwxmap_logging",
75567 + .data = &grsec_enable_log_rwxmaps,
75568 + .maxlen = sizeof(int),
75569 + .mode = 0600,
75570 + .proc_handler = &proc_dointvec,
75571 + },
75572 +#endif
75573 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75574 + {
75575 + .procname = "signal_logging",
75576 + .data = &grsec_enable_signal,
75577 + .maxlen = sizeof(int),
75578 + .mode = 0600,
75579 + .proc_handler = &proc_dointvec,
75580 + },
75581 +#endif
75582 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75583 + {
75584 + .procname = "forkfail_logging",
75585 + .data = &grsec_enable_forkfail,
75586 + .maxlen = sizeof(int),
75587 + .mode = 0600,
75588 + .proc_handler = &proc_dointvec,
75589 + },
75590 +#endif
75591 +#ifdef CONFIG_GRKERNSEC_TIME
75592 + {
75593 + .procname = "timechange_logging",
75594 + .data = &grsec_enable_time,
75595 + .maxlen = sizeof(int),
75596 + .mode = 0600,
75597 + .proc_handler = &proc_dointvec,
75598 + },
75599 +#endif
75600 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75601 + {
75602 + .procname = "chroot_deny_shmat",
75603 + .data = &grsec_enable_chroot_shmat,
75604 + .maxlen = sizeof(int),
75605 + .mode = 0600,
75606 + .proc_handler = &proc_dointvec,
75607 + },
75608 +#endif
75609 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75610 + {
75611 + .procname = "chroot_deny_unix",
75612 + .data = &grsec_enable_chroot_unix,
75613 + .maxlen = sizeof(int),
75614 + .mode = 0600,
75615 + .proc_handler = &proc_dointvec,
75616 + },
75617 +#endif
75618 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75619 + {
75620 + .procname = "chroot_deny_mount",
75621 + .data = &grsec_enable_chroot_mount,
75622 + .maxlen = sizeof(int),
75623 + .mode = 0600,
75624 + .proc_handler = &proc_dointvec,
75625 + },
75626 +#endif
75627 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75628 + {
75629 + .procname = "chroot_deny_fchdir",
75630 + .data = &grsec_enable_chroot_fchdir,
75631 + .maxlen = sizeof(int),
75632 + .mode = 0600,
75633 + .proc_handler = &proc_dointvec,
75634 + },
75635 +#endif
75636 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75637 + {
75638 + .procname = "chroot_deny_chroot",
75639 + .data = &grsec_enable_chroot_double,
75640 + .maxlen = sizeof(int),
75641 + .mode = 0600,
75642 + .proc_handler = &proc_dointvec,
75643 + },
75644 +#endif
75645 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75646 + {
75647 + .procname = "chroot_deny_pivot",
75648 + .data = &grsec_enable_chroot_pivot,
75649 + .maxlen = sizeof(int),
75650 + .mode = 0600,
75651 + .proc_handler = &proc_dointvec,
75652 + },
75653 +#endif
75654 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75655 + {
75656 + .procname = "chroot_enforce_chdir",
75657 + .data = &grsec_enable_chroot_chdir,
75658 + .maxlen = sizeof(int),
75659 + .mode = 0600,
75660 + .proc_handler = &proc_dointvec,
75661 + },
75662 +#endif
75663 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75664 + {
75665 + .procname = "chroot_deny_chmod",
75666 + .data = &grsec_enable_chroot_chmod,
75667 + .maxlen = sizeof(int),
75668 + .mode = 0600,
75669 + .proc_handler = &proc_dointvec,
75670 + },
75671 +#endif
75672 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75673 + {
75674 + .procname = "chroot_deny_mknod",
75675 + .data = &grsec_enable_chroot_mknod,
75676 + .maxlen = sizeof(int),
75677 + .mode = 0600,
75678 + .proc_handler = &proc_dointvec,
75679 + },
75680 +#endif
75681 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75682 + {
75683 + .procname = "chroot_restrict_nice",
75684 + .data = &grsec_enable_chroot_nice,
75685 + .maxlen = sizeof(int),
75686 + .mode = 0600,
75687 + .proc_handler = &proc_dointvec,
75688 + },
75689 +#endif
75690 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75691 + {
75692 + .procname = "chroot_execlog",
75693 + .data = &grsec_enable_chroot_execlog,
75694 + .maxlen = sizeof(int),
75695 + .mode = 0600,
75696 + .proc_handler = &proc_dointvec,
75697 + },
75698 +#endif
75699 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75700 + {
75701 + .procname = "chroot_caps",
75702 + .data = &grsec_enable_chroot_caps,
75703 + .maxlen = sizeof(int),
75704 + .mode = 0600,
75705 + .proc_handler = &proc_dointvec,
75706 + },
75707 +#endif
75708 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75709 + {
75710 + .procname = "chroot_deny_sysctl",
75711 + .data = &grsec_enable_chroot_sysctl,
75712 + .maxlen = sizeof(int),
75713 + .mode = 0600,
75714 + .proc_handler = &proc_dointvec,
75715 + },
75716 +#endif
75717 +#ifdef CONFIG_GRKERNSEC_TPE
75718 + {
75719 + .procname = "tpe",
75720 + .data = &grsec_enable_tpe,
75721 + .maxlen = sizeof(int),
75722 + .mode = 0600,
75723 + .proc_handler = &proc_dointvec,
75724 + },
75725 + {
75726 + .procname = "tpe_gid",
75727 + .data = &grsec_tpe_gid,
75728 + .maxlen = sizeof(int),
75729 + .mode = 0600,
75730 + .proc_handler = &proc_dointvec,
75731 + },
75732 +#endif
75733 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75734 + {
75735 + .procname = "tpe_invert",
75736 + .data = &grsec_enable_tpe_invert,
75737 + .maxlen = sizeof(int),
75738 + .mode = 0600,
75739 + .proc_handler = &proc_dointvec,
75740 + },
75741 +#endif
75742 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75743 + {
75744 + .procname = "tpe_restrict_all",
75745 + .data = &grsec_enable_tpe_all,
75746 + .maxlen = sizeof(int),
75747 + .mode = 0600,
75748 + .proc_handler = &proc_dointvec,
75749 + },
75750 +#endif
75751 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75752 + {
75753 + .procname = "socket_all",
75754 + .data = &grsec_enable_socket_all,
75755 + .maxlen = sizeof(int),
75756 + .mode = 0600,
75757 + .proc_handler = &proc_dointvec,
75758 + },
75759 + {
75760 + .procname = "socket_all_gid",
75761 + .data = &grsec_socket_all_gid,
75762 + .maxlen = sizeof(int),
75763 + .mode = 0600,
75764 + .proc_handler = &proc_dointvec,
75765 + },
75766 +#endif
75767 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75768 + {
75769 + .procname = "socket_client",
75770 + .data = &grsec_enable_socket_client,
75771 + .maxlen = sizeof(int),
75772 + .mode = 0600,
75773 + .proc_handler = &proc_dointvec,
75774 + },
75775 + {
75776 + .procname = "socket_client_gid",
75777 + .data = &grsec_socket_client_gid,
75778 + .maxlen = sizeof(int),
75779 + .mode = 0600,
75780 + .proc_handler = &proc_dointvec,
75781 + },
75782 +#endif
75783 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75784 + {
75785 + .procname = "socket_server",
75786 + .data = &grsec_enable_socket_server,
75787 + .maxlen = sizeof(int),
75788 + .mode = 0600,
75789 + .proc_handler = &proc_dointvec,
75790 + },
75791 + {
75792 + .procname = "socket_server_gid",
75793 + .data = &grsec_socket_server_gid,
75794 + .maxlen = sizeof(int),
75795 + .mode = 0600,
75796 + .proc_handler = &proc_dointvec,
75797 + },
75798 +#endif
75799 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75800 + {
75801 + .procname = "audit_group",
75802 + .data = &grsec_enable_group,
75803 + .maxlen = sizeof(int),
75804 + .mode = 0600,
75805 + .proc_handler = &proc_dointvec,
75806 + },
75807 + {
75808 + .procname = "audit_gid",
75809 + .data = &grsec_audit_gid,
75810 + .maxlen = sizeof(int),
75811 + .mode = 0600,
75812 + .proc_handler = &proc_dointvec,
75813 + },
75814 +#endif
75815 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75816 + {
75817 + .procname = "audit_chdir",
75818 + .data = &grsec_enable_chdir,
75819 + .maxlen = sizeof(int),
75820 + .mode = 0600,
75821 + .proc_handler = &proc_dointvec,
75822 + },
75823 +#endif
75824 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75825 + {
75826 + .procname = "audit_mount",
75827 + .data = &grsec_enable_mount,
75828 + .maxlen = sizeof(int),
75829 + .mode = 0600,
75830 + .proc_handler = &proc_dointvec,
75831 + },
75832 +#endif
75833 +#ifdef CONFIG_GRKERNSEC_DMESG
75834 + {
75835 + .procname = "dmesg",
75836 + .data = &grsec_enable_dmesg,
75837 + .maxlen = sizeof(int),
75838 + .mode = 0600,
75839 + .proc_handler = &proc_dointvec,
75840 + },
75841 +#endif
75842 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75843 + {
75844 + .procname = "chroot_findtask",
75845 + .data = &grsec_enable_chroot_findtask,
75846 + .maxlen = sizeof(int),
75847 + .mode = 0600,
75848 + .proc_handler = &proc_dointvec,
75849 + },
75850 +#endif
75851 +#ifdef CONFIG_GRKERNSEC_RESLOG
75852 + {
75853 + .procname = "resource_logging",
75854 + .data = &grsec_resource_logging,
75855 + .maxlen = sizeof(int),
75856 + .mode = 0600,
75857 + .proc_handler = &proc_dointvec,
75858 + },
75859 +#endif
75860 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75861 + {
75862 + .procname = "audit_ptrace",
75863 + .data = &grsec_enable_audit_ptrace,
75864 + .maxlen = sizeof(int),
75865 + .mode = 0600,
75866 + .proc_handler = &proc_dointvec,
75867 + },
75868 +#endif
75869 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75870 + {
75871 + .procname = "harden_ptrace",
75872 + .data = &grsec_enable_harden_ptrace,
75873 + .maxlen = sizeof(int),
75874 + .mode = 0600,
75875 + .proc_handler = &proc_dointvec,
75876 + },
75877 +#endif
75878 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75879 + {
75880 + .procname = "harden_ipc",
75881 + .data = &grsec_enable_harden_ipc,
75882 + .maxlen = sizeof(int),
75883 + .mode = 0600,
75884 + .proc_handler = &proc_dointvec,
75885 + },
75886 +#endif
75887 + {
75888 + .procname = "grsec_lock",
75889 + .data = &grsec_lock,
75890 + .maxlen = sizeof(int),
75891 + .mode = 0600,
75892 + .proc_handler = &proc_dointvec,
75893 + },
75894 +#endif
75895 +#ifdef CONFIG_GRKERNSEC_ROFS
75896 + {
75897 + .procname = "romount_protect",
75898 + .data = &grsec_enable_rofs,
75899 + .maxlen = sizeof(int),
75900 + .mode = 0600,
75901 + .proc_handler = &proc_dointvec_minmax,
75902 + .extra1 = &one,
75903 + .extra2 = &one,
75904 + },
75905 +#endif
75906 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75907 + {
75908 + .procname = "deny_new_usb",
75909 + .data = &grsec_deny_new_usb,
75910 + .maxlen = sizeof(int),
75911 + .mode = 0600,
75912 + .proc_handler = &proc_dointvec,
75913 + },
75914 +#endif
75915 + { }
75916 +};
75917 +#endif
75918 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75919 new file mode 100644
75920 index 0000000..61b514e
75921 --- /dev/null
75922 +++ b/grsecurity/grsec_time.c
75923 @@ -0,0 +1,16 @@
75924 +#include <linux/kernel.h>
75925 +#include <linux/sched.h>
75926 +#include <linux/grinternal.h>
75927 +#include <linux/module.h>
75928 +
75929 +void
75930 +gr_log_timechange(void)
75931 +{
75932 +#ifdef CONFIG_GRKERNSEC_TIME
75933 + if (grsec_enable_time)
75934 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75935 +#endif
75936 + return;
75937 +}
75938 +
75939 +EXPORT_SYMBOL_GPL(gr_log_timechange);
75940 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75941 new file mode 100644
75942 index 0000000..ee57dcf
75943 --- /dev/null
75944 +++ b/grsecurity/grsec_tpe.c
75945 @@ -0,0 +1,73 @@
75946 +#include <linux/kernel.h>
75947 +#include <linux/sched.h>
75948 +#include <linux/file.h>
75949 +#include <linux/fs.h>
75950 +#include <linux/grinternal.h>
75951 +
75952 +extern int gr_acl_tpe_check(void);
75953 +
75954 +int
75955 +gr_tpe_allow(const struct file *file)
75956 +{
75957 +#ifdef CONFIG_GRKERNSEC
75958 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75959 + const struct cred *cred = current_cred();
75960 + char *msg = NULL;
75961 + char *msg2 = NULL;
75962 +
75963 + // never restrict root
75964 + if (gr_is_global_root(cred->uid))
75965 + return 1;
75966 +
75967 + if (grsec_enable_tpe) {
75968 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75969 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75970 + msg = "not being in trusted group";
75971 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75972 + msg = "being in untrusted group";
75973 +#else
75974 + if (in_group_p(grsec_tpe_gid))
75975 + msg = "being in untrusted group";
75976 +#endif
75977 + }
75978 + if (!msg && gr_acl_tpe_check())
75979 + msg = "being in untrusted role";
75980 +
75981 + // not in any affected group/role
75982 + if (!msg)
75983 + goto next_check;
75984 +
75985 + if (gr_is_global_nonroot(inode->i_uid))
75986 + msg2 = "file in non-root-owned directory";
75987 + else if (inode->i_mode & S_IWOTH)
75988 + msg2 = "file in world-writable directory";
75989 + else if (inode->i_mode & S_IWGRP)
75990 + msg2 = "file in group-writable directory";
75991 +
75992 + if (msg && msg2) {
75993 + char fullmsg[70] = {0};
75994 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75995 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75996 + return 0;
75997 + }
75998 + msg = NULL;
75999 +next_check:
76000 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76001 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76002 + return 1;
76003 +
76004 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76005 + msg = "directory not owned by user";
76006 + else if (inode->i_mode & S_IWOTH)
76007 + msg = "file in world-writable directory";
76008 + else if (inode->i_mode & S_IWGRP)
76009 + msg = "file in group-writable directory";
76010 +
76011 + if (msg) {
76012 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76013 + return 0;
76014 + }
76015 +#endif
76016 +#endif
76017 + return 1;
76018 +}
76019 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76020 new file mode 100644
76021 index 0000000..ae02d8e
76022 --- /dev/null
76023 +++ b/grsecurity/grsec_usb.c
76024 @@ -0,0 +1,15 @@
76025 +#include <linux/kernel.h>
76026 +#include <linux/grinternal.h>
76027 +#include <linux/module.h>
76028 +
76029 +int gr_handle_new_usb(void)
76030 +{
76031 +#ifdef CONFIG_GRKERNSEC_DENYUSB
76032 + if (grsec_deny_new_usb) {
76033 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76034 + return 1;
76035 + }
76036 +#endif
76037 + return 0;
76038 +}
76039 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76040 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76041 new file mode 100644
76042 index 0000000..9f7b1ac
76043 --- /dev/null
76044 +++ b/grsecurity/grsum.c
76045 @@ -0,0 +1,61 @@
76046 +#include <linux/err.h>
76047 +#include <linux/kernel.h>
76048 +#include <linux/sched.h>
76049 +#include <linux/mm.h>
76050 +#include <linux/scatterlist.h>
76051 +#include <linux/crypto.h>
76052 +#include <linux/gracl.h>
76053 +
76054 +
76055 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76056 +#error "crypto and sha256 must be built into the kernel"
76057 +#endif
76058 +
76059 +int
76060 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76061 +{
76062 + char *p;
76063 + struct crypto_hash *tfm;
76064 + struct hash_desc desc;
76065 + struct scatterlist sg;
76066 + unsigned char temp_sum[GR_SHA_LEN];
76067 + volatile int retval = 0;
76068 + volatile int dummy = 0;
76069 + unsigned int i;
76070 +
76071 + sg_init_table(&sg, 1);
76072 +
76073 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76074 + if (IS_ERR(tfm)) {
76075 + /* should never happen, since sha256 should be built in */
76076 + return 1;
76077 + }
76078 +
76079 + desc.tfm = tfm;
76080 + desc.flags = 0;
76081 +
76082 + crypto_hash_init(&desc);
76083 +
76084 + p = salt;
76085 + sg_set_buf(&sg, p, GR_SALT_LEN);
76086 + crypto_hash_update(&desc, &sg, sg.length);
76087 +
76088 + p = entry->pw;
76089 + sg_set_buf(&sg, p, strlen(p));
76090 +
76091 + crypto_hash_update(&desc, &sg, sg.length);
76092 +
76093 + crypto_hash_final(&desc, temp_sum);
76094 +
76095 + memset(entry->pw, 0, GR_PW_LEN);
76096 +
76097 + for (i = 0; i < GR_SHA_LEN; i++)
76098 + if (sum[i] != temp_sum[i])
76099 + retval = 1;
76100 + else
76101 + dummy = 1; // waste a cycle
76102 +
76103 + crypto_free_hash(tfm);
76104 +
76105 + return retval;
76106 +}
76107 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76108 index 77ff547..181834f 100644
76109 --- a/include/asm-generic/4level-fixup.h
76110 +++ b/include/asm-generic/4level-fixup.h
76111 @@ -13,8 +13,10 @@
76112 #define pmd_alloc(mm, pud, address) \
76113 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76114 NULL: pmd_offset(pud, address))
76115 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76116
76117 #define pud_alloc(mm, pgd, address) (pgd)
76118 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76119 #define pud_offset(pgd, start) (pgd)
76120 #define pud_none(pud) 0
76121 #define pud_bad(pud) 0
76122 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76123 index b7babf0..97f4c4f 100644
76124 --- a/include/asm-generic/atomic-long.h
76125 +++ b/include/asm-generic/atomic-long.h
76126 @@ -22,6 +22,12 @@
76127
76128 typedef atomic64_t atomic_long_t;
76129
76130 +#ifdef CONFIG_PAX_REFCOUNT
76131 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
76132 +#else
76133 +typedef atomic64_t atomic_long_unchecked_t;
76134 +#endif
76135 +
76136 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76137
76138 static inline long atomic_long_read(atomic_long_t *l)
76139 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76140 return (long)atomic64_read(v);
76141 }
76142
76143 +#ifdef CONFIG_PAX_REFCOUNT
76144 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76145 +{
76146 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76147 +
76148 + return (long)atomic64_read_unchecked(v);
76149 +}
76150 +#endif
76151 +
76152 static inline void atomic_long_set(atomic_long_t *l, long i)
76153 {
76154 atomic64_t *v = (atomic64_t *)l;
76155 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76156 atomic64_set(v, i);
76157 }
76158
76159 +#ifdef CONFIG_PAX_REFCOUNT
76160 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76161 +{
76162 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76163 +
76164 + atomic64_set_unchecked(v, i);
76165 +}
76166 +#endif
76167 +
76168 static inline void atomic_long_inc(atomic_long_t *l)
76169 {
76170 atomic64_t *v = (atomic64_t *)l;
76171 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76172 atomic64_inc(v);
76173 }
76174
76175 +#ifdef CONFIG_PAX_REFCOUNT
76176 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76177 +{
76178 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76179 +
76180 + atomic64_inc_unchecked(v);
76181 +}
76182 +#endif
76183 +
76184 static inline void atomic_long_dec(atomic_long_t *l)
76185 {
76186 atomic64_t *v = (atomic64_t *)l;
76187 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76188 atomic64_dec(v);
76189 }
76190
76191 +#ifdef CONFIG_PAX_REFCOUNT
76192 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76193 +{
76194 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76195 +
76196 + atomic64_dec_unchecked(v);
76197 +}
76198 +#endif
76199 +
76200 static inline void atomic_long_add(long i, atomic_long_t *l)
76201 {
76202 atomic64_t *v = (atomic64_t *)l;
76203 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76204 atomic64_add(i, v);
76205 }
76206
76207 +#ifdef CONFIG_PAX_REFCOUNT
76208 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76209 +{
76210 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76211 +
76212 + atomic64_add_unchecked(i, v);
76213 +}
76214 +#endif
76215 +
76216 static inline void atomic_long_sub(long i, atomic_long_t *l)
76217 {
76218 atomic64_t *v = (atomic64_t *)l;
76219 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76220 atomic64_sub(i, v);
76221 }
76222
76223 +#ifdef CONFIG_PAX_REFCOUNT
76224 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76225 +{
76226 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76227 +
76228 + atomic64_sub_unchecked(i, v);
76229 +}
76230 +#endif
76231 +
76232 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76233 {
76234 atomic64_t *v = (atomic64_t *)l;
76235 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76236 return atomic64_add_negative(i, v);
76237 }
76238
76239 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
76240 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76241 {
76242 atomic64_t *v = (atomic64_t *)l;
76243
76244 return (long)atomic64_add_return(i, v);
76245 }
76246
76247 +#ifdef CONFIG_PAX_REFCOUNT
76248 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76249 +{
76250 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76251 +
76252 + return (long)atomic64_add_return_unchecked(i, v);
76253 +}
76254 +#endif
76255 +
76256 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76257 {
76258 atomic64_t *v = (atomic64_t *)l;
76259 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76260 return (long)atomic64_inc_return(v);
76261 }
76262
76263 +#ifdef CONFIG_PAX_REFCOUNT
76264 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76265 +{
76266 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76267 +
76268 + return (long)atomic64_inc_return_unchecked(v);
76269 +}
76270 +#endif
76271 +
76272 static inline long atomic_long_dec_return(atomic_long_t *l)
76273 {
76274 atomic64_t *v = (atomic64_t *)l;
76275 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76276
76277 typedef atomic_t atomic_long_t;
76278
76279 +#ifdef CONFIG_PAX_REFCOUNT
76280 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76281 +#else
76282 +typedef atomic_t atomic_long_unchecked_t;
76283 +#endif
76284 +
76285 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76286 static inline long atomic_long_read(atomic_long_t *l)
76287 {
76288 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76289 return (long)atomic_read(v);
76290 }
76291
76292 +#ifdef CONFIG_PAX_REFCOUNT
76293 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76294 +{
76295 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76296 +
76297 + return (long)atomic_read_unchecked(v);
76298 +}
76299 +#endif
76300 +
76301 static inline void atomic_long_set(atomic_long_t *l, long i)
76302 {
76303 atomic_t *v = (atomic_t *)l;
76304 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76305 atomic_set(v, i);
76306 }
76307
76308 +#ifdef CONFIG_PAX_REFCOUNT
76309 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76310 +{
76311 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76312 +
76313 + atomic_set_unchecked(v, i);
76314 +}
76315 +#endif
76316 +
76317 static inline void atomic_long_inc(atomic_long_t *l)
76318 {
76319 atomic_t *v = (atomic_t *)l;
76320 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76321 atomic_inc(v);
76322 }
76323
76324 +#ifdef CONFIG_PAX_REFCOUNT
76325 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76326 +{
76327 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76328 +
76329 + atomic_inc_unchecked(v);
76330 +}
76331 +#endif
76332 +
76333 static inline void atomic_long_dec(atomic_long_t *l)
76334 {
76335 atomic_t *v = (atomic_t *)l;
76336 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76337 atomic_dec(v);
76338 }
76339
76340 +#ifdef CONFIG_PAX_REFCOUNT
76341 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76342 +{
76343 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76344 +
76345 + atomic_dec_unchecked(v);
76346 +}
76347 +#endif
76348 +
76349 static inline void atomic_long_add(long i, atomic_long_t *l)
76350 {
76351 atomic_t *v = (atomic_t *)l;
76352 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76353 atomic_add(i, v);
76354 }
76355
76356 +#ifdef CONFIG_PAX_REFCOUNT
76357 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76358 +{
76359 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76360 +
76361 + atomic_add_unchecked(i, v);
76362 +}
76363 +#endif
76364 +
76365 static inline void atomic_long_sub(long i, atomic_long_t *l)
76366 {
76367 atomic_t *v = (atomic_t *)l;
76368 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76369 atomic_sub(i, v);
76370 }
76371
76372 +#ifdef CONFIG_PAX_REFCOUNT
76373 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76374 +{
76375 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76376 +
76377 + atomic_sub_unchecked(i, v);
76378 +}
76379 +#endif
76380 +
76381 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76382 {
76383 atomic_t *v = (atomic_t *)l;
76384 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76385 return (long)atomic_add_return(i, v);
76386 }
76387
76388 +#ifdef CONFIG_PAX_REFCOUNT
76389 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76390 +{
76391 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76392 +
76393 + return (long)atomic_add_return_unchecked(i, v);
76394 +}
76395 +
76396 +#endif
76397 +
76398 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76399 {
76400 atomic_t *v = (atomic_t *)l;
76401 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76402 return (long)atomic_inc_return(v);
76403 }
76404
76405 +#ifdef CONFIG_PAX_REFCOUNT
76406 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76407 +{
76408 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76409 +
76410 + return (long)atomic_inc_return_unchecked(v);
76411 +}
76412 +#endif
76413 +
76414 static inline long atomic_long_dec_return(atomic_long_t *l)
76415 {
76416 atomic_t *v = (atomic_t *)l;
76417 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76418
76419 #endif /* BITS_PER_LONG == 64 */
76420
76421 +#ifdef CONFIG_PAX_REFCOUNT
76422 +static inline void pax_refcount_needs_these_functions(void)
76423 +{
76424 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
76425 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76426 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76427 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76428 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76429 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76430 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76431 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76432 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76433 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76434 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76435 +#ifdef CONFIG_X86
76436 + atomic_clear_mask_unchecked(0, NULL);
76437 + atomic_set_mask_unchecked(0, NULL);
76438 +#endif
76439 +
76440 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76441 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76442 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76443 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76444 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76445 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76446 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76447 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76448 +}
76449 +#else
76450 +#define atomic_read_unchecked(v) atomic_read(v)
76451 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76452 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76453 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76454 +#define atomic_inc_unchecked(v) atomic_inc(v)
76455 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76456 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76457 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76458 +#define atomic_dec_unchecked(v) atomic_dec(v)
76459 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76460 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76461 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76462 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76463 +
76464 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
76465 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76466 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76467 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76468 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76469 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76470 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76471 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76472 +#endif
76473 +
76474 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76475 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76476 index 33bd2de..f31bff97 100644
76477 --- a/include/asm-generic/atomic.h
76478 +++ b/include/asm-generic/atomic.h
76479 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76480 * Atomically clears the bits set in @mask from @v
76481 */
76482 #ifndef atomic_clear_mask
76483 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76484 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76485 {
76486 unsigned long flags;
76487
76488 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76489 index b18ce4f..2ee2843 100644
76490 --- a/include/asm-generic/atomic64.h
76491 +++ b/include/asm-generic/atomic64.h
76492 @@ -16,6 +16,8 @@ typedef struct {
76493 long long counter;
76494 } atomic64_t;
76495
76496 +typedef atomic64_t atomic64_unchecked_t;
76497 +
76498 #define ATOMIC64_INIT(i) { (i) }
76499
76500 extern long long atomic64_read(const atomic64_t *v);
76501 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76502 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76503 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76504
76505 +#define atomic64_read_unchecked(v) atomic64_read(v)
76506 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76507 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76508 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76509 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76510 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
76511 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76512 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
76513 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76514 +
76515 #endif /* _ASM_GENERIC_ATOMIC64_H */
76516 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76517 index a60a7cc..0fe12f2 100644
76518 --- a/include/asm-generic/bitops/__fls.h
76519 +++ b/include/asm-generic/bitops/__fls.h
76520 @@ -9,7 +9,7 @@
76521 *
76522 * Undefined if no set bit exists, so code should check against 0 first.
76523 */
76524 -static __always_inline unsigned long __fls(unsigned long word)
76525 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76526 {
76527 int num = BITS_PER_LONG - 1;
76528
76529 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76530 index 0576d1f..dad6c71 100644
76531 --- a/include/asm-generic/bitops/fls.h
76532 +++ b/include/asm-generic/bitops/fls.h
76533 @@ -9,7 +9,7 @@
76534 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76535 */
76536
76537 -static __always_inline int fls(int x)
76538 +static __always_inline int __intentional_overflow(-1) fls(int x)
76539 {
76540 int r = 32;
76541
76542 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76543 index b097cf8..3d40e14 100644
76544 --- a/include/asm-generic/bitops/fls64.h
76545 +++ b/include/asm-generic/bitops/fls64.h
76546 @@ -15,7 +15,7 @@
76547 * at position 64.
76548 */
76549 #if BITS_PER_LONG == 32
76550 -static __always_inline int fls64(__u64 x)
76551 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76552 {
76553 __u32 h = x >> 32;
76554 if (h)
76555 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76556 return fls(x);
76557 }
76558 #elif BITS_PER_LONG == 64
76559 -static __always_inline int fls64(__u64 x)
76560 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76561 {
76562 if (x == 0)
76563 return 0;
76564 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76565 index 1bfcfe5..e04c5c9 100644
76566 --- a/include/asm-generic/cache.h
76567 +++ b/include/asm-generic/cache.h
76568 @@ -6,7 +6,7 @@
76569 * cache lines need to provide their own cache.h.
76570 */
76571
76572 -#define L1_CACHE_SHIFT 5
76573 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76574 +#define L1_CACHE_SHIFT 5UL
76575 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76576
76577 #endif /* __ASM_GENERIC_CACHE_H */
76578 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76579 index 0d68a1e..b74a761 100644
76580 --- a/include/asm-generic/emergency-restart.h
76581 +++ b/include/asm-generic/emergency-restart.h
76582 @@ -1,7 +1,7 @@
76583 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76584 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76585
76586 -static inline void machine_emergency_restart(void)
76587 +static inline __noreturn void machine_emergency_restart(void)
76588 {
76589 machine_restart(NULL);
76590 }
76591 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76592 index 90f99c7..00ce236 100644
76593 --- a/include/asm-generic/kmap_types.h
76594 +++ b/include/asm-generic/kmap_types.h
76595 @@ -2,9 +2,9 @@
76596 #define _ASM_GENERIC_KMAP_TYPES_H
76597
76598 #ifdef __WITH_KM_FENCE
76599 -# define KM_TYPE_NR 41
76600 +# define KM_TYPE_NR 42
76601 #else
76602 -# define KM_TYPE_NR 20
76603 +# define KM_TYPE_NR 21
76604 #endif
76605
76606 #endif
76607 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76608 index 9ceb03b..62b0b8f 100644
76609 --- a/include/asm-generic/local.h
76610 +++ b/include/asm-generic/local.h
76611 @@ -23,24 +23,37 @@ typedef struct
76612 atomic_long_t a;
76613 } local_t;
76614
76615 +typedef struct {
76616 + atomic_long_unchecked_t a;
76617 +} local_unchecked_t;
76618 +
76619 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76620
76621 #define local_read(l) atomic_long_read(&(l)->a)
76622 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76623 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76624 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76625 #define local_inc(l) atomic_long_inc(&(l)->a)
76626 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76627 #define local_dec(l) atomic_long_dec(&(l)->a)
76628 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76629 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76630 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76631 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76632 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76633
76634 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76635 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76636 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76637 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76638 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76639 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76640 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76641 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76642 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76643
76644 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76645 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76646 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76647 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76648 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76649 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76650 index 725612b..9cc513a 100644
76651 --- a/include/asm-generic/pgtable-nopmd.h
76652 +++ b/include/asm-generic/pgtable-nopmd.h
76653 @@ -1,14 +1,19 @@
76654 #ifndef _PGTABLE_NOPMD_H
76655 #define _PGTABLE_NOPMD_H
76656
76657 -#ifndef __ASSEMBLY__
76658 -
76659 #include <asm-generic/pgtable-nopud.h>
76660
76661 -struct mm_struct;
76662 -
76663 #define __PAGETABLE_PMD_FOLDED
76664
76665 +#define PMD_SHIFT PUD_SHIFT
76666 +#define PTRS_PER_PMD 1
76667 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76668 +#define PMD_MASK (~(PMD_SIZE-1))
76669 +
76670 +#ifndef __ASSEMBLY__
76671 +
76672 +struct mm_struct;
76673 +
76674 /*
76675 * Having the pmd type consist of a pud gets the size right, and allows
76676 * us to conceptually access the pud entry that this pmd is folded into
76677 @@ -16,11 +21,6 @@ struct mm_struct;
76678 */
76679 typedef struct { pud_t pud; } pmd_t;
76680
76681 -#define PMD_SHIFT PUD_SHIFT
76682 -#define PTRS_PER_PMD 1
76683 -#define PMD_SIZE (1UL << PMD_SHIFT)
76684 -#define PMD_MASK (~(PMD_SIZE-1))
76685 -
76686 /*
76687 * The "pud_xxx()" functions here are trivial for a folded two-level
76688 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76689 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76690 index 810431d..0ec4804f 100644
76691 --- a/include/asm-generic/pgtable-nopud.h
76692 +++ b/include/asm-generic/pgtable-nopud.h
76693 @@ -1,10 +1,15 @@
76694 #ifndef _PGTABLE_NOPUD_H
76695 #define _PGTABLE_NOPUD_H
76696
76697 -#ifndef __ASSEMBLY__
76698 -
76699 #define __PAGETABLE_PUD_FOLDED
76700
76701 +#define PUD_SHIFT PGDIR_SHIFT
76702 +#define PTRS_PER_PUD 1
76703 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76704 +#define PUD_MASK (~(PUD_SIZE-1))
76705 +
76706 +#ifndef __ASSEMBLY__
76707 +
76708 /*
76709 * Having the pud type consist of a pgd gets the size right, and allows
76710 * us to conceptually access the pgd entry that this pud is folded into
76711 @@ -12,11 +17,6 @@
76712 */
76713 typedef struct { pgd_t pgd; } pud_t;
76714
76715 -#define PUD_SHIFT PGDIR_SHIFT
76716 -#define PTRS_PER_PUD 1
76717 -#define PUD_SIZE (1UL << PUD_SHIFT)
76718 -#define PUD_MASK (~(PUD_SIZE-1))
76719 -
76720 /*
76721 * The "pgd_xxx()" functions here are trivial for a folded two-level
76722 * setup: the pud is never bad, and a pud always exists (as it's folded
76723 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76724 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76725
76726 #define pgd_populate(mm, pgd, pud) do { } while (0)
76727 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76728 /*
76729 * (puds are folded into pgds so this doesn't get actually called,
76730 * but the define is needed for a generic inline function.)
76731 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76732 index 34c7bdc..38d4f3b 100644
76733 --- a/include/asm-generic/pgtable.h
76734 +++ b/include/asm-generic/pgtable.h
76735 @@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
76736 }
76737 #endif /* CONFIG_NUMA_BALANCING */
76738
76739 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76740 +#ifdef CONFIG_PAX_KERNEXEC
76741 +#error KERNEXEC requires pax_open_kernel
76742 +#else
76743 +static inline unsigned long pax_open_kernel(void) { return 0; }
76744 +#endif
76745 +#endif
76746 +
76747 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76748 +#ifdef CONFIG_PAX_KERNEXEC
76749 +#error KERNEXEC requires pax_close_kernel
76750 +#else
76751 +static inline unsigned long pax_close_kernel(void) { return 0; }
76752 +#endif
76753 +#endif
76754 +
76755 #endif /* CONFIG_MMU */
76756
76757 #endif /* !__ASSEMBLY__ */
76758 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76759 index 72d8803..cb9749c 100644
76760 --- a/include/asm-generic/uaccess.h
76761 +++ b/include/asm-generic/uaccess.h
76762 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76763 return __clear_user(to, n);
76764 }
76765
76766 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76767 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76768 +#error UDEREF requires pax_open_userland
76769 +#else
76770 +static inline unsigned long pax_open_userland(void) { return 0; }
76771 +#endif
76772 +#endif
76773 +
76774 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76775 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76776 +#error UDEREF requires pax_close_userland
76777 +#else
76778 +static inline unsigned long pax_close_userland(void) { return 0; }
76779 +#endif
76780 +#endif
76781 +
76782 #endif /* __ASM_GENERIC_UACCESS_H */
76783 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76784 index bc2121f..2f41f9a 100644
76785 --- a/include/asm-generic/vmlinux.lds.h
76786 +++ b/include/asm-generic/vmlinux.lds.h
76787 @@ -232,6 +232,7 @@
76788 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76789 VMLINUX_SYMBOL(__start_rodata) = .; \
76790 *(.rodata) *(.rodata.*) \
76791 + *(.data..read_only) \
76792 *(__vermagic) /* Kernel version magic */ \
76793 . = ALIGN(8); \
76794 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76795 @@ -716,17 +717,18 @@
76796 * section in the linker script will go there too. @phdr should have
76797 * a leading colon.
76798 *
76799 - * Note that this macros defines __per_cpu_load as an absolute symbol.
76800 + * Note that this macros defines per_cpu_load as an absolute symbol.
76801 * If there is no need to put the percpu section at a predetermined
76802 * address, use PERCPU_SECTION.
76803 */
76804 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76805 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
76806 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76807 + per_cpu_load = .; \
76808 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76809 - LOAD_OFFSET) { \
76810 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76811 PERCPU_INPUT(cacheline) \
76812 } phdr \
76813 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76814 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76815
76816 /**
76817 * PERCPU_SECTION - define output section for percpu area, simple version
76818 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76819 index e73c19e..5b89e00 100644
76820 --- a/include/crypto/algapi.h
76821 +++ b/include/crypto/algapi.h
76822 @@ -34,7 +34,7 @@ struct crypto_type {
76823 unsigned int maskclear;
76824 unsigned int maskset;
76825 unsigned int tfmsize;
76826 -};
76827 +} __do_const;
76828
76829 struct crypto_instance {
76830 struct crypto_alg alg;
76831 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76832 index 04a7f31..668d424 100644
76833 --- a/include/drm/drmP.h
76834 +++ b/include/drm/drmP.h
76835 @@ -67,6 +67,7 @@
76836 #include <linux/workqueue.h>
76837 #include <linux/poll.h>
76838 #include <asm/pgalloc.h>
76839 +#include <asm/local.h>
76840 #include <drm/drm.h>
76841 #include <drm/drm_sarea.h>
76842 #include <drm/drm_vma_manager.h>
76843 @@ -297,10 +298,12 @@ do { \
76844 * \param cmd command.
76845 * \param arg argument.
76846 */
76847 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76848 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76849 + struct drm_file *file_priv);
76850 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76851 struct drm_file *file_priv);
76852
76853 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76854 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76855 unsigned long arg);
76856
76857 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76858 @@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76859 struct drm_ioctl_desc {
76860 unsigned int cmd;
76861 int flags;
76862 - drm_ioctl_t *func;
76863 + drm_ioctl_t func;
76864 unsigned int cmd_drv;
76865 const char *name;
76866 -};
76867 +} __do_const;
76868
76869 /**
76870 * Creates a driver or general drm_ioctl_desc array entry for the given
76871 @@ -1022,7 +1025,8 @@ struct drm_info_list {
76872 int (*show)(struct seq_file*, void*); /** show callback */
76873 u32 driver_features; /**< Required driver features for this entry */
76874 void *data;
76875 -};
76876 +} __do_const;
76877 +typedef struct drm_info_list __no_const drm_info_list_no_const;
76878
76879 /**
76880 * debugfs node structure. This structure represents a debugfs file.
76881 @@ -1106,7 +1110,7 @@ struct drm_device {
76882
76883 /** \name Usage Counters */
76884 /*@{ */
76885 - int open_count; /**< Outstanding files open */
76886 + local_t open_count; /**< Outstanding files open */
76887 int buf_use; /**< Buffers in use -- cannot alloc */
76888 atomic_t buf_alloc; /**< Buffer allocation in progress */
76889 /*@} */
76890 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76891 index b1388b5..e1d1163 100644
76892 --- a/include/drm/drm_crtc_helper.h
76893 +++ b/include/drm/drm_crtc_helper.h
76894 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76895 struct drm_connector *connector);
76896 /* disable encoder when not in use - more explicit than dpms off */
76897 void (*disable)(struct drm_encoder *encoder);
76898 -};
76899 +} __no_const;
76900
76901 /**
76902 * drm_connector_helper_funcs - helper operations for connectors
76903 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76904 index 940ece4..8cb727f 100644
76905 --- a/include/drm/i915_pciids.h
76906 +++ b/include/drm/i915_pciids.h
76907 @@ -37,7 +37,7 @@
76908 */
76909 #define INTEL_VGA_DEVICE(id, info) { \
76910 0x8086, id, \
76911 - ~0, ~0, \
76912 + PCI_ANY_ID, PCI_ANY_ID, \
76913 0x030000, 0xff0000, \
76914 (unsigned long) info }
76915
76916 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76917 index 72dcbe8..8db58d7 100644
76918 --- a/include/drm/ttm/ttm_memory.h
76919 +++ b/include/drm/ttm/ttm_memory.h
76920 @@ -48,7 +48,7 @@
76921
76922 struct ttm_mem_shrink {
76923 int (*do_shrink) (struct ttm_mem_shrink *);
76924 -};
76925 +} __no_const;
76926
76927 /**
76928 * struct ttm_mem_global - Global memory accounting structure.
76929 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76930 index 49a8284..9643967 100644
76931 --- a/include/drm/ttm/ttm_page_alloc.h
76932 +++ b/include/drm/ttm/ttm_page_alloc.h
76933 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
76934 */
76935 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76936
76937 +struct device;
76938 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76939 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76940
76941 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76942 index 4b840e8..155d235 100644
76943 --- a/include/keys/asymmetric-subtype.h
76944 +++ b/include/keys/asymmetric-subtype.h
76945 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76946 /* Verify the signature on a key of this subtype (optional) */
76947 int (*verify_signature)(const struct key *key,
76948 const struct public_key_signature *sig);
76949 -};
76950 +} __do_const;
76951
76952 /**
76953 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76954 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76955 index c1da539..1dcec55 100644
76956 --- a/include/linux/atmdev.h
76957 +++ b/include/linux/atmdev.h
76958 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76959 #endif
76960
76961 struct k_atm_aal_stats {
76962 -#define __HANDLE_ITEM(i) atomic_t i
76963 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
76964 __AAL_STAT_ITEMS
76965 #undef __HANDLE_ITEM
76966 };
76967 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76968 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76969 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76970 struct module *owner;
76971 -};
76972 +} __do_const ;
76973
76974 struct atmphy_ops {
76975 int (*start)(struct atm_dev *dev);
76976 diff --git a/include/linux/audit.h b/include/linux/audit.h
76977 index ec1464d..833274b 100644
76978 --- a/include/linux/audit.h
76979 +++ b/include/linux/audit.h
76980 @@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
76981 extern unsigned int audit_serial(void);
76982 extern int auditsc_get_stamp(struct audit_context *ctx,
76983 struct timespec *t, unsigned int *serial);
76984 -extern int audit_set_loginuid(kuid_t loginuid);
76985 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76986
76987 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76988 {
76989 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76990 index b4a745d..e3c0942 100644
76991 --- a/include/linux/binfmts.h
76992 +++ b/include/linux/binfmts.h
76993 @@ -45,7 +45,7 @@ struct linux_binprm {
76994 unsigned interp_data;
76995 unsigned long loader, exec;
76996 char tcomm[TASK_COMM_LEN];
76997 -};
76998 +} __randomize_layout;
76999
77000 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77001 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77002 @@ -74,8 +74,10 @@ struct linux_binfmt {
77003 int (*load_binary)(struct linux_binprm *);
77004 int (*load_shlib)(struct file *);
77005 int (*core_dump)(struct coredump_params *cprm);
77006 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77007 + void (*handle_mmap)(struct file *);
77008 unsigned long min_coredump; /* minimal dump size */
77009 -};
77010 +} __do_const __randomize_layout;
77011
77012 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77013
77014 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77015 index be5fd38..d71192a 100644
77016 --- a/include/linux/bitops.h
77017 +++ b/include/linux/bitops.h
77018 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77019 * @word: value to rotate
77020 * @shift: bits to roll
77021 */
77022 -static inline __u32 rol32(__u32 word, unsigned int shift)
77023 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77024 {
77025 return (word << shift) | (word >> (32 - shift));
77026 }
77027 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77028 * @word: value to rotate
77029 * @shift: bits to roll
77030 */
77031 -static inline __u32 ror32(__u32 word, unsigned int shift)
77032 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77033 {
77034 return (word >> shift) | (word << (32 - shift));
77035 }
77036 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77037 return (__s32)(value << shift) >> shift;
77038 }
77039
77040 -static inline unsigned fls_long(unsigned long l)
77041 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77042 {
77043 if (sizeof(l) == 4)
77044 return fls(l);
77045 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77046 index 4afa4f8..1ed7824 100644
77047 --- a/include/linux/blkdev.h
77048 +++ b/include/linux/blkdev.h
77049 @@ -1572,7 +1572,7 @@ struct block_device_operations {
77050 /* this callback is with swap_lock and sometimes page table lock held */
77051 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77052 struct module *owner;
77053 -};
77054 +} __do_const;
77055
77056 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77057 unsigned long);
77058 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77059 index afc1343..9735539 100644
77060 --- a/include/linux/blktrace_api.h
77061 +++ b/include/linux/blktrace_api.h
77062 @@ -25,7 +25,7 @@ struct blk_trace {
77063 struct dentry *dropped_file;
77064 struct dentry *msg_file;
77065 struct list_head running_list;
77066 - atomic_t dropped;
77067 + atomic_unchecked_t dropped;
77068 };
77069
77070 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77071 diff --git a/include/linux/cache.h b/include/linux/cache.h
77072 index 17e7e82..1d7da26 100644
77073 --- a/include/linux/cache.h
77074 +++ b/include/linux/cache.h
77075 @@ -16,6 +16,14 @@
77076 #define __read_mostly
77077 #endif
77078
77079 +#ifndef __read_only
77080 +#ifdef CONFIG_PAX_KERNEXEC
77081 +#error KERNEXEC requires __read_only
77082 +#else
77083 +#define __read_only __read_mostly
77084 +#endif
77085 +#endif
77086 +
77087 #ifndef ____cacheline_aligned
77088 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77089 #endif
77090 diff --git a/include/linux/capability.h b/include/linux/capability.h
77091 index a6ee1f9..e1ca49d 100644
77092 --- a/include/linux/capability.h
77093 +++ b/include/linux/capability.h
77094 @@ -212,8 +212,13 @@ extern bool capable(int cap);
77095 extern bool ns_capable(struct user_namespace *ns, int cap);
77096 extern bool inode_capable(const struct inode *inode, int cap);
77097 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77098 +extern bool capable_nolog(int cap);
77099 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77100 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
77101
77102 /* audit system wants to get cap info from files as well */
77103 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77104
77105 +extern int is_privileged_binary(const struct dentry *dentry);
77106 +
77107 #endif /* !_LINUX_CAPABILITY_H */
77108 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77109 index 8609d57..86e4d79 100644
77110 --- a/include/linux/cdrom.h
77111 +++ b/include/linux/cdrom.h
77112 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
77113
77114 /* driver specifications */
77115 const int capability; /* capability flags */
77116 - int n_minors; /* number of active minor devices */
77117 /* handle uniform packets for scsi type devices (scsi,atapi) */
77118 int (*generic_packet) (struct cdrom_device_info *,
77119 struct packet_command *);
77120 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77121 index 4ce9056..86caac6 100644
77122 --- a/include/linux/cleancache.h
77123 +++ b/include/linux/cleancache.h
77124 @@ -31,7 +31,7 @@ struct cleancache_ops {
77125 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77126 void (*invalidate_inode)(int, struct cleancache_filekey);
77127 void (*invalidate_fs)(int);
77128 -};
77129 +} __no_const;
77130
77131 extern struct cleancache_ops *
77132 cleancache_register_ops(struct cleancache_ops *ops);
77133 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77134 index 939533d..cf0a57c 100644
77135 --- a/include/linux/clk-provider.h
77136 +++ b/include/linux/clk-provider.h
77137 @@ -166,6 +166,7 @@ struct clk_ops {
77138 unsigned long parent_accuracy);
77139 void (*init)(struct clk_hw *hw);
77140 };
77141 +typedef struct clk_ops __no_const clk_ops_no_const;
77142
77143 /**
77144 * struct clk_init_data - holds init data that's common to all clocks and is
77145 diff --git a/include/linux/compat.h b/include/linux/compat.h
77146 index 3f448c6..df3ce1d 100644
77147 --- a/include/linux/compat.h
77148 +++ b/include/linux/compat.h
77149 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77150 compat_size_t __user *len_ptr);
77151
77152 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77153 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77154 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77155 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77156 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77157 compat_ssize_t msgsz, int msgflg);
77158 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77159 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77160 compat_ulong_t addr, compat_ulong_t data);
77161 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77162 - compat_long_t addr, compat_long_t data);
77163 + compat_ulong_t addr, compat_ulong_t data);
77164
77165 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77166 /*
77167 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77168 index 2507fd2..55203f8 100644
77169 --- a/include/linux/compiler-gcc4.h
77170 +++ b/include/linux/compiler-gcc4.h
77171 @@ -39,9 +39,34 @@
77172 # define __compiletime_warning(message) __attribute__((warning(message)))
77173 # define __compiletime_error(message) __attribute__((error(message)))
77174 #endif /* __CHECKER__ */
77175 +
77176 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77177 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77178 +#define __bos0(ptr) __bos((ptr), 0)
77179 +#define __bos1(ptr) __bos((ptr), 1)
77180 #endif /* GCC_VERSION >= 40300 */
77181
77182 #if GCC_VERSION >= 40500
77183 +
77184 +#ifdef RANDSTRUCT_PLUGIN
77185 +#define __randomize_layout __attribute__((randomize_layout))
77186 +#define __no_randomize_layout __attribute__((no_randomize_layout))
77187 +#endif
77188 +
77189 +#ifdef CONSTIFY_PLUGIN
77190 +#define __no_const __attribute__((no_const))
77191 +#define __do_const __attribute__((do_const))
77192 +#endif
77193 +
77194 +#ifdef SIZE_OVERFLOW_PLUGIN
77195 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77196 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77197 +#endif
77198 +
77199 +#ifdef LATENT_ENTROPY_PLUGIN
77200 +#define __latent_entropy __attribute__((latent_entropy))
77201 +#endif
77202 +
77203 /*
77204 * Mark a position in code as unreachable. This can be used to
77205 * suppress control flow warnings after asm blocks that transfer
77206 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77207 index 2472740..4857634 100644
77208 --- a/include/linux/compiler.h
77209 +++ b/include/linux/compiler.h
77210 @@ -5,11 +5,14 @@
77211
77212 #ifdef __CHECKER__
77213 # define __user __attribute__((noderef, address_space(1)))
77214 +# define __force_user __force __user
77215 # define __kernel __attribute__((address_space(0)))
77216 +# define __force_kernel __force __kernel
77217 # define __safe __attribute__((safe))
77218 # define __force __attribute__((force))
77219 # define __nocast __attribute__((nocast))
77220 # define __iomem __attribute__((noderef, address_space(2)))
77221 +# define __force_iomem __force __iomem
77222 # define __must_hold(x) __attribute__((context(x,1,1)))
77223 # define __acquires(x) __attribute__((context(x,0,1)))
77224 # define __releases(x) __attribute__((context(x,1,0)))
77225 @@ -17,20 +20,37 @@
77226 # define __release(x) __context__(x,-1)
77227 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77228 # define __percpu __attribute__((noderef, address_space(3)))
77229 +# define __force_percpu __force __percpu
77230 #ifdef CONFIG_SPARSE_RCU_POINTER
77231 # define __rcu __attribute__((noderef, address_space(4)))
77232 +# define __force_rcu __force __rcu
77233 #else
77234 # define __rcu
77235 +# define __force_rcu
77236 #endif
77237 extern void __chk_user_ptr(const volatile void __user *);
77238 extern void __chk_io_ptr(const volatile void __iomem *);
77239 #else
77240 -# define __user
77241 -# define __kernel
77242 +# ifdef CHECKER_PLUGIN
77243 +//# define __user
77244 +//# define __force_user
77245 +//# define __kernel
77246 +//# define __force_kernel
77247 +# else
77248 +# ifdef STRUCTLEAK_PLUGIN
77249 +# define __user __attribute__((user))
77250 +# else
77251 +# define __user
77252 +# endif
77253 +# define __force_user
77254 +# define __kernel
77255 +# define __force_kernel
77256 +# endif
77257 # define __safe
77258 # define __force
77259 # define __nocast
77260 # define __iomem
77261 +# define __force_iomem
77262 # define __chk_user_ptr(x) (void)0
77263 # define __chk_io_ptr(x) (void)0
77264 # define __builtin_warning(x, y...) (1)
77265 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77266 # define __release(x) (void)0
77267 # define __cond_lock(x,c) (c)
77268 # define __percpu
77269 +# define __force_percpu
77270 # define __rcu
77271 +# define __force_rcu
77272 #endif
77273
77274 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77275 @@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77276 # define __attribute_const__ /* unimplemented */
77277 #endif
77278
77279 +#ifndef __randomize_layout
77280 +# define __randomize_layout
77281 +#endif
77282 +
77283 +#ifndef __no_randomize_layout
77284 +# define __no_randomize_layout
77285 +#endif
77286 +
77287 +#ifndef __no_const
77288 +# define __no_const
77289 +#endif
77290 +
77291 +#ifndef __do_const
77292 +# define __do_const
77293 +#endif
77294 +
77295 +#ifndef __size_overflow
77296 +# define __size_overflow(...)
77297 +#endif
77298 +
77299 +#ifndef __intentional_overflow
77300 +# define __intentional_overflow(...)
77301 +#endif
77302 +
77303 +#ifndef __latent_entropy
77304 +# define __latent_entropy
77305 +#endif
77306 +
77307 /*
77308 * Tell gcc if a function is cold. The compiler will assume any path
77309 * directly leading to the call is unlikely.
77310 @@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77311 #define __cold
77312 #endif
77313
77314 +#ifndef __alloc_size
77315 +#define __alloc_size(...)
77316 +#endif
77317 +
77318 +#ifndef __bos
77319 +#define __bos(ptr, arg)
77320 +#endif
77321 +
77322 +#ifndef __bos0
77323 +#define __bos0(ptr)
77324 +#endif
77325 +
77326 +#ifndef __bos1
77327 +#define __bos1(ptr)
77328 +#endif
77329 +
77330 /* Simple shorthand for a section definition */
77331 #ifndef __section
77332 # define __section(S) __attribute__ ((__section__(#S)))
77333 @@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77334 * use is to mediate communication between process-level code and irq/NMI
77335 * handlers, all running on the same CPU.
77336 */
77337 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77338 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77339 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77340
77341 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77342 #ifdef CONFIG_KPROBES
77343 diff --git a/include/linux/completion.h b/include/linux/completion.h
77344 index 5d5aaae..0ea9b84 100644
77345 --- a/include/linux/completion.h
77346 +++ b/include/linux/completion.h
77347 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77348
77349 extern void wait_for_completion(struct completion *);
77350 extern void wait_for_completion_io(struct completion *);
77351 -extern int wait_for_completion_interruptible(struct completion *x);
77352 -extern int wait_for_completion_killable(struct completion *x);
77353 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77354 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77355 extern unsigned long wait_for_completion_timeout(struct completion *x,
77356 - unsigned long timeout);
77357 + unsigned long timeout) __intentional_overflow(-1);
77358 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77359 - unsigned long timeout);
77360 + unsigned long timeout) __intentional_overflow(-1);
77361 extern long wait_for_completion_interruptible_timeout(
77362 - struct completion *x, unsigned long timeout);
77363 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77364 extern long wait_for_completion_killable_timeout(
77365 - struct completion *x, unsigned long timeout);
77366 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77367 extern bool try_wait_for_completion(struct completion *x);
77368 extern bool completion_done(struct completion *x);
77369
77370 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77371 index 34025df..d94bbbc 100644
77372 --- a/include/linux/configfs.h
77373 +++ b/include/linux/configfs.h
77374 @@ -125,7 +125,7 @@ struct configfs_attribute {
77375 const char *ca_name;
77376 struct module *ca_owner;
77377 umode_t ca_mode;
77378 -};
77379 +} __do_const;
77380
77381 /*
77382 * Users often need to create attribute structures for their configurable
77383 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77384 index 4d89e0e..5281847 100644
77385 --- a/include/linux/cpufreq.h
77386 +++ b/include/linux/cpufreq.h
77387 @@ -191,6 +191,7 @@ struct global_attr {
77388 ssize_t (*store)(struct kobject *a, struct attribute *b,
77389 const char *c, size_t count);
77390 };
77391 +typedef struct global_attr __no_const global_attr_no_const;
77392
77393 #define define_one_global_ro(_name) \
77394 static struct global_attr _name = \
77395 @@ -232,7 +233,7 @@ struct cpufreq_driver {
77396 bool boost_supported;
77397 bool boost_enabled;
77398 int (*set_boost) (int state);
77399 -};
77400 +} __do_const;
77401
77402 /* flags */
77403 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77404 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77405 index 50fcbb0..9d2dbd9 100644
77406 --- a/include/linux/cpuidle.h
77407 +++ b/include/linux/cpuidle.h
77408 @@ -50,7 +50,8 @@ struct cpuidle_state {
77409 int index);
77410
77411 int (*enter_dead) (struct cpuidle_device *dev, int index);
77412 -};
77413 +} __do_const;
77414 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77415
77416 /* Idle State Flags */
77417 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77418 @@ -192,7 +193,7 @@ struct cpuidle_governor {
77419 void (*reflect) (struct cpuidle_device *dev, int index);
77420
77421 struct module *owner;
77422 -};
77423 +} __do_const;
77424
77425 #ifdef CONFIG_CPU_IDLE
77426 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77427 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77428 index d08e4d2..95fad61 100644
77429 --- a/include/linux/cpumask.h
77430 +++ b/include/linux/cpumask.h
77431 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77432 }
77433
77434 /* Valid inputs for n are -1 and 0. */
77435 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77436 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77437 {
77438 return n+1;
77439 }
77440
77441 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77442 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77443 {
77444 return n+1;
77445 }
77446
77447 -static inline unsigned int cpumask_next_and(int n,
77448 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77449 const struct cpumask *srcp,
77450 const struct cpumask *andp)
77451 {
77452 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77453 *
77454 * Returns >= nr_cpu_ids if no further cpus set.
77455 */
77456 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77457 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77458 {
77459 /* -1 is a legal arg here. */
77460 if (n != -1)
77461 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77462 *
77463 * Returns >= nr_cpu_ids if no further cpus unset.
77464 */
77465 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77466 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77467 {
77468 /* -1 is a legal arg here. */
77469 if (n != -1)
77470 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77471 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77472 }
77473
77474 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77475 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77476 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77477
77478 /**
77479 diff --git a/include/linux/cred.h b/include/linux/cred.h
77480 index 04421e8..117e17a 100644
77481 --- a/include/linux/cred.h
77482 +++ b/include/linux/cred.h
77483 @@ -35,7 +35,7 @@ struct group_info {
77484 int nblocks;
77485 kgid_t small_block[NGROUPS_SMALL];
77486 kgid_t *blocks[0];
77487 -};
77488 +} __randomize_layout;
77489
77490 /**
77491 * get_group_info - Get a reference to a group info structure
77492 @@ -136,7 +136,7 @@ struct cred {
77493 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77494 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77495 struct rcu_head rcu; /* RCU deletion hook */
77496 -};
77497 +} __randomize_layout;
77498
77499 extern void __put_cred(struct cred *);
77500 extern void exit_creds(struct task_struct *);
77501 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77502 static inline void validate_process_creds(void)
77503 {
77504 }
77505 +static inline void validate_task_creds(struct task_struct *task)
77506 +{
77507 +}
77508 #endif
77509
77510 /**
77511 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77512 index b92eadf..b4ecdc1 100644
77513 --- a/include/linux/crypto.h
77514 +++ b/include/linux/crypto.h
77515 @@ -373,7 +373,7 @@ struct cipher_tfm {
77516 const u8 *key, unsigned int keylen);
77517 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77518 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77519 -};
77520 +} __no_const;
77521
77522 struct hash_tfm {
77523 int (*init)(struct hash_desc *desc);
77524 @@ -394,13 +394,13 @@ struct compress_tfm {
77525 int (*cot_decompress)(struct crypto_tfm *tfm,
77526 const u8 *src, unsigned int slen,
77527 u8 *dst, unsigned int *dlen);
77528 -};
77529 +} __no_const;
77530
77531 struct rng_tfm {
77532 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77533 unsigned int dlen);
77534 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77535 -};
77536 +} __no_const;
77537
77538 #define crt_ablkcipher crt_u.ablkcipher
77539 #define crt_aead crt_u.aead
77540 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77541 index 653589e..4ef254a 100644
77542 --- a/include/linux/ctype.h
77543 +++ b/include/linux/ctype.h
77544 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77545 * Fast implementation of tolower() for internal usage. Do not use in your
77546 * code.
77547 */
77548 -static inline char _tolower(const char c)
77549 +static inline unsigned char _tolower(const unsigned char c)
77550 {
77551 return c | 0x20;
77552 }
77553 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77554 index bf72e9a..4ca7927 100644
77555 --- a/include/linux/dcache.h
77556 +++ b/include/linux/dcache.h
77557 @@ -133,7 +133,7 @@ struct dentry {
77558 } d_u;
77559 struct list_head d_subdirs; /* our children */
77560 struct hlist_node d_alias; /* inode alias list */
77561 -};
77562 +} __randomize_layout;
77563
77564 /*
77565 * dentry->d_lock spinlock nesting subclasses:
77566 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77567 index 7925bf0..d5143d2 100644
77568 --- a/include/linux/decompress/mm.h
77569 +++ b/include/linux/decompress/mm.h
77570 @@ -77,7 +77,7 @@ static void free(void *where)
77571 * warnings when not needed (indeed large_malloc / large_free are not
77572 * needed by inflate */
77573
77574 -#define malloc(a) kmalloc(a, GFP_KERNEL)
77575 +#define malloc(a) kmalloc((a), GFP_KERNEL)
77576 #define free(a) kfree(a)
77577
77578 #define large_malloc(a) vmalloc(a)
77579 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77580 index d48dc00..211ee54 100644
77581 --- a/include/linux/devfreq.h
77582 +++ b/include/linux/devfreq.h
77583 @@ -114,7 +114,7 @@ struct devfreq_governor {
77584 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77585 int (*event_handler)(struct devfreq *devfreq,
77586 unsigned int event, void *data);
77587 -};
77588 +} __do_const;
77589
77590 /**
77591 * struct devfreq - Device devfreq structure
77592 diff --git a/include/linux/device.h b/include/linux/device.h
77593 index 952b010..d5b7691 100644
77594 --- a/include/linux/device.h
77595 +++ b/include/linux/device.h
77596 @@ -310,7 +310,7 @@ struct subsys_interface {
77597 struct list_head node;
77598 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77599 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77600 -};
77601 +} __do_const;
77602
77603 int subsys_interface_register(struct subsys_interface *sif);
77604 void subsys_interface_unregister(struct subsys_interface *sif);
77605 @@ -506,7 +506,7 @@ struct device_type {
77606 void (*release)(struct device *dev);
77607
77608 const struct dev_pm_ops *pm;
77609 -};
77610 +} __do_const;
77611
77612 /* interface for exporting device attributes */
77613 struct device_attribute {
77614 @@ -516,11 +516,12 @@ struct device_attribute {
77615 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77616 const char *buf, size_t count);
77617 };
77618 +typedef struct device_attribute __no_const device_attribute_no_const;
77619
77620 struct dev_ext_attribute {
77621 struct device_attribute attr;
77622 void *var;
77623 -};
77624 +} __do_const;
77625
77626 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77627 char *buf);
77628 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77629 index fd4aee2..1f28db9 100644
77630 --- a/include/linux/dma-mapping.h
77631 +++ b/include/linux/dma-mapping.h
77632 @@ -54,7 +54,7 @@ struct dma_map_ops {
77633 u64 (*get_required_mask)(struct device *dev);
77634 #endif
77635 int is_phys;
77636 -};
77637 +} __do_const;
77638
77639 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77640
77641 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77642 index c5c92d5..6a5c2b2 100644
77643 --- a/include/linux/dmaengine.h
77644 +++ b/include/linux/dmaengine.h
77645 @@ -1150,9 +1150,9 @@ struct dma_pinned_list {
77646 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77647 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77648
77649 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77650 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77651 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77652 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77653 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77654 struct dma_pinned_list *pinned_list, struct page *page,
77655 unsigned int offset, size_t len);
77656
77657 diff --git a/include/linux/efi.h b/include/linux/efi.h
77658 index 0a819e7..8ed47f1 100644
77659 --- a/include/linux/efi.h
77660 +++ b/include/linux/efi.h
77661 @@ -768,6 +768,7 @@ struct efivar_operations {
77662 efi_set_variable_t *set_variable;
77663 efi_query_variable_store_t *query_variable_store;
77664 };
77665 +typedef struct efivar_operations __no_const efivar_operations_no_const;
77666
77667 struct efivars {
77668 /*
77669 diff --git a/include/linux/elf.h b/include/linux/elf.h
77670 index 67a5fa7..b817372 100644
77671 --- a/include/linux/elf.h
77672 +++ b/include/linux/elf.h
77673 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77674 #define elf_note elf32_note
77675 #define elf_addr_t Elf32_Off
77676 #define Elf_Half Elf32_Half
77677 +#define elf_dyn Elf32_Dyn
77678
77679 #else
77680
77681 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77682 #define elf_note elf64_note
77683 #define elf_addr_t Elf64_Off
77684 #define Elf_Half Elf64_Half
77685 +#define elf_dyn Elf64_Dyn
77686
77687 #endif
77688
77689 diff --git a/include/linux/err.h b/include/linux/err.h
77690 index 15f92e0..e825a8e 100644
77691 --- a/include/linux/err.h
77692 +++ b/include/linux/err.h
77693 @@ -19,12 +19,12 @@
77694
77695 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77696
77697 -static inline void * __must_check ERR_PTR(long error)
77698 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77699 {
77700 return (void *) error;
77701 }
77702
77703 -static inline long __must_check PTR_ERR(__force const void *ptr)
77704 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77705 {
77706 return (long) ptr;
77707 }
77708 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77709 index 21c59af..6057a03 100644
77710 --- a/include/linux/extcon.h
77711 +++ b/include/linux/extcon.h
77712 @@ -135,7 +135,7 @@ struct extcon_dev {
77713 /* /sys/class/extcon/.../mutually_exclusive/... */
77714 struct attribute_group attr_g_muex;
77715 struct attribute **attrs_muex;
77716 - struct device_attribute *d_attrs_muex;
77717 + device_attribute_no_const *d_attrs_muex;
77718 };
77719
77720 /**
77721 diff --git a/include/linux/fb.h b/include/linux/fb.h
77722 index fe6ac95..898d41d 100644
77723 --- a/include/linux/fb.h
77724 +++ b/include/linux/fb.h
77725 @@ -304,7 +304,7 @@ struct fb_ops {
77726 /* called at KDB enter and leave time to prepare the console */
77727 int (*fb_debug_enter)(struct fb_info *info);
77728 int (*fb_debug_leave)(struct fb_info *info);
77729 -};
77730 +} __do_const;
77731
77732 #ifdef CONFIG_FB_TILEBLITTING
77733 #define FB_TILE_CURSOR_NONE 0
77734 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77735 index 70e8e21..1939916 100644
77736 --- a/include/linux/fdtable.h
77737 +++ b/include/linux/fdtable.h
77738 @@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77739 void put_files_struct(struct files_struct *fs);
77740 void reset_files_struct(struct files_struct *);
77741 int unshare_files(struct files_struct **);
77742 -struct files_struct *dup_fd(struct files_struct *, int *);
77743 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77744 void do_close_on_exec(struct files_struct *);
77745 int iterate_fd(struct files_struct *, unsigned,
77746 int (*)(const void *, struct file *, unsigned),
77747 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77748 index 8293262..2b3b8bd 100644
77749 --- a/include/linux/frontswap.h
77750 +++ b/include/linux/frontswap.h
77751 @@ -11,7 +11,7 @@ struct frontswap_ops {
77752 int (*load)(unsigned, pgoff_t, struct page *);
77753 void (*invalidate_page)(unsigned, pgoff_t);
77754 void (*invalidate_area)(unsigned);
77755 -};
77756 +} __no_const;
77757
77758 extern bool frontswap_enabled;
77759 extern struct frontswap_ops *
77760 diff --git a/include/linux/fs.h b/include/linux/fs.h
77761 index 23b2a35..8764ab7 100644
77762 --- a/include/linux/fs.h
77763 +++ b/include/linux/fs.h
77764 @@ -426,7 +426,7 @@ struct address_space {
77765 spinlock_t private_lock; /* for use by the address_space */
77766 struct list_head private_list; /* ditto */
77767 void *private_data; /* ditto */
77768 -} __attribute__((aligned(sizeof(long))));
77769 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77770 /*
77771 * On most architectures that alignment is already the case; but
77772 * must be enforced here for CRIS, to let the least significant bit
77773 @@ -469,7 +469,7 @@ struct block_device {
77774 int bd_fsfreeze_count;
77775 /* Mutex for freeze */
77776 struct mutex bd_fsfreeze_mutex;
77777 -};
77778 +} __randomize_layout;
77779
77780 /*
77781 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77782 @@ -613,7 +613,7 @@ struct inode {
77783 atomic_t i_readcount; /* struct files open RO */
77784 #endif
77785 void *i_private; /* fs or device private pointer */
77786 -};
77787 +} __randomize_layout;
77788
77789 static inline int inode_unhashed(struct inode *inode)
77790 {
77791 @@ -812,7 +812,7 @@ struct file {
77792 #ifdef CONFIG_DEBUG_WRITECOUNT
77793 unsigned long f_mnt_write_state;
77794 #endif
77795 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
77796 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
77797
77798 struct file_handle {
77799 __u32 handle_bytes;
77800 @@ -982,7 +982,7 @@ struct file_lock {
77801 int state; /* state of grant or error if -ve */
77802 } afs;
77803 } fl_u;
77804 -};
77805 +} __randomize_layout;
77806
77807 /* The following constant reflects the upper bound of the file/locking space */
77808 #ifndef OFFSET_MAX
77809 @@ -1329,7 +1329,7 @@ struct super_block {
77810 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77811 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77812 struct rcu_head rcu;
77813 -};
77814 +} __randomize_layout;
77815
77816 extern struct timespec current_fs_time(struct super_block *sb);
77817
77818 @@ -1551,7 +1551,8 @@ struct file_operations {
77819 long (*fallocate)(struct file *file, int mode, loff_t offset,
77820 loff_t len);
77821 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77822 -};
77823 +} __do_const __randomize_layout;
77824 +typedef struct file_operations __no_const file_operations_no_const;
77825
77826 struct inode_operations {
77827 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77828 @@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
77829 return !IS_DEADDIR(inode);
77830 }
77831
77832 +static inline bool is_sidechannel_device(const struct inode *inode)
77833 +{
77834 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77835 + umode_t mode = inode->i_mode;
77836 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77837 +#else
77838 + return false;
77839 +#endif
77840 +}
77841 +
77842 #endif /* _LINUX_FS_H */
77843 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77844 index 0efc3e6..fd23610 100644
77845 --- a/include/linux/fs_struct.h
77846 +++ b/include/linux/fs_struct.h
77847 @@ -6,13 +6,13 @@
77848 #include <linux/seqlock.h>
77849
77850 struct fs_struct {
77851 - int users;
77852 + atomic_t users;
77853 spinlock_t lock;
77854 seqcount_t seq;
77855 int umask;
77856 int in_exec;
77857 struct path root, pwd;
77858 -};
77859 +} __randomize_layout;
77860
77861 extern struct kmem_cache *fs_cachep;
77862
77863 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77864 index 7714849..a4a5c7a 100644
77865 --- a/include/linux/fscache-cache.h
77866 +++ b/include/linux/fscache-cache.h
77867 @@ -113,7 +113,7 @@ struct fscache_operation {
77868 fscache_operation_release_t release;
77869 };
77870
77871 -extern atomic_t fscache_op_debug_id;
77872 +extern atomic_unchecked_t fscache_op_debug_id;
77873 extern void fscache_op_work_func(struct work_struct *work);
77874
77875 extern void fscache_enqueue_operation(struct fscache_operation *);
77876 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77877 INIT_WORK(&op->work, fscache_op_work_func);
77878 atomic_set(&op->usage, 1);
77879 op->state = FSCACHE_OP_ST_INITIALISED;
77880 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77881 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77882 op->processor = processor;
77883 op->release = release;
77884 INIT_LIST_HEAD(&op->pend_link);
77885 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77886 index 115bb81..e7b812b 100644
77887 --- a/include/linux/fscache.h
77888 +++ b/include/linux/fscache.h
77889 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
77890 * - this is mandatory for any object that may have data
77891 */
77892 void (*now_uncached)(void *cookie_netfs_data);
77893 -};
77894 +} __do_const;
77895
77896 /*
77897 * fscache cached network filesystem type
77898 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77899 index 1c804b0..1432c2b 100644
77900 --- a/include/linux/fsnotify.h
77901 +++ b/include/linux/fsnotify.h
77902 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77903 struct inode *inode = file_inode(file);
77904 __u32 mask = FS_ACCESS;
77905
77906 + if (is_sidechannel_device(inode))
77907 + return;
77908 +
77909 if (S_ISDIR(inode->i_mode))
77910 mask |= FS_ISDIR;
77911
77912 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77913 struct inode *inode = file_inode(file);
77914 __u32 mask = FS_MODIFY;
77915
77916 + if (is_sidechannel_device(inode))
77917 + return;
77918 +
77919 if (S_ISDIR(inode->i_mode))
77920 mask |= FS_ISDIR;
77921
77922 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77923 */
77924 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77925 {
77926 - return kstrdup(name, GFP_KERNEL);
77927 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77928 }
77929
77930 /*
77931 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77932 index 9f3c275..8bdff5d 100644
77933 --- a/include/linux/genhd.h
77934 +++ b/include/linux/genhd.h
77935 @@ -194,7 +194,7 @@ struct gendisk {
77936 struct kobject *slave_dir;
77937
77938 struct timer_rand_state *random;
77939 - atomic_t sync_io; /* RAID */
77940 + atomic_unchecked_t sync_io; /* RAID */
77941 struct disk_events *ev;
77942 #ifdef CONFIG_BLK_DEV_INTEGRITY
77943 struct blk_integrity *integrity;
77944 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77945 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77946
77947 /* drivers/char/random.c */
77948 -extern void add_disk_randomness(struct gendisk *disk);
77949 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77950 extern void rand_initialize_disk(struct gendisk *disk);
77951
77952 static inline sector_t get_start_sect(struct block_device *bdev)
77953 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77954 index c0894dd..2fbf10c 100644
77955 --- a/include/linux/genl_magic_func.h
77956 +++ b/include/linux/genl_magic_func.h
77957 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77958 },
77959
77960 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77961 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77962 +static struct genl_ops ZZZ_genl_ops[] = {
77963 #include GENL_MAGIC_INCLUDE_FILE
77964 };
77965
77966 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77967 index 39b81dc..819dc51 100644
77968 --- a/include/linux/gfp.h
77969 +++ b/include/linux/gfp.h
77970 @@ -36,6 +36,13 @@ struct vm_area_struct;
77971 #define ___GFP_NO_KSWAPD 0x400000u
77972 #define ___GFP_OTHER_NODE 0x800000u
77973 #define ___GFP_WRITE 0x1000000u
77974 +
77975 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77976 +#define ___GFP_USERCOPY 0x2000000u
77977 +#else
77978 +#define ___GFP_USERCOPY 0
77979 +#endif
77980 +
77981 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77982
77983 /*
77984 @@ -93,6 +100,7 @@ struct vm_area_struct;
77985 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77986 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77987 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77988 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77989
77990 /*
77991 * This may seem redundant, but it's a way of annotating false positives vs.
77992 @@ -100,7 +108,7 @@ struct vm_area_struct;
77993 */
77994 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77995
77996 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77997 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77998 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77999
78000 /* This equals 0, but use constants in case they ever change */
78001 @@ -158,6 +166,8 @@ struct vm_area_struct;
78002 /* 4GB DMA on some platforms */
78003 #define GFP_DMA32 __GFP_DMA32
78004
78005 +#define GFP_USERCOPY __GFP_USERCOPY
78006 +
78007 /* Convert GFP flags to their corresponding migrate type */
78008 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78009 {
78010 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78011 new file mode 100644
78012 index 0000000..edb2cb6
78013 --- /dev/null
78014 +++ b/include/linux/gracl.h
78015 @@ -0,0 +1,340 @@
78016 +#ifndef GR_ACL_H
78017 +#define GR_ACL_H
78018 +
78019 +#include <linux/grdefs.h>
78020 +#include <linux/resource.h>
78021 +#include <linux/capability.h>
78022 +#include <linux/dcache.h>
78023 +#include <asm/resource.h>
78024 +
78025 +/* Major status information */
78026 +
78027 +#define GR_VERSION "grsecurity 3.0"
78028 +#define GRSECURITY_VERSION 0x3000
78029 +
78030 +enum {
78031 + GR_SHUTDOWN = 0,
78032 + GR_ENABLE = 1,
78033 + GR_SPROLE = 2,
78034 + GR_OLDRELOAD = 3,
78035 + GR_SEGVMOD = 4,
78036 + GR_STATUS = 5,
78037 + GR_UNSPROLE = 6,
78038 + GR_PASSSET = 7,
78039 + GR_SPROLEPAM = 8,
78040 + GR_RELOAD = 9,
78041 +};
78042 +
78043 +/* Password setup definitions
78044 + * kernel/grhash.c */
78045 +enum {
78046 + GR_PW_LEN = 128,
78047 + GR_SALT_LEN = 16,
78048 + GR_SHA_LEN = 32,
78049 +};
78050 +
78051 +enum {
78052 + GR_SPROLE_LEN = 64,
78053 +};
78054 +
78055 +enum {
78056 + GR_NO_GLOB = 0,
78057 + GR_REG_GLOB,
78058 + GR_CREATE_GLOB
78059 +};
78060 +
78061 +#define GR_NLIMITS 32
78062 +
78063 +/* Begin Data Structures */
78064 +
78065 +struct sprole_pw {
78066 + unsigned char *rolename;
78067 + unsigned char salt[GR_SALT_LEN];
78068 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78069 +};
78070 +
78071 +struct name_entry {
78072 + __u32 key;
78073 + ino_t inode;
78074 + dev_t device;
78075 + char *name;
78076 + __u16 len;
78077 + __u8 deleted;
78078 + struct name_entry *prev;
78079 + struct name_entry *next;
78080 +};
78081 +
78082 +struct inodev_entry {
78083 + struct name_entry *nentry;
78084 + struct inodev_entry *prev;
78085 + struct inodev_entry *next;
78086 +};
78087 +
78088 +struct acl_role_db {
78089 + struct acl_role_label **r_hash;
78090 + __u32 r_size;
78091 +};
78092 +
78093 +struct inodev_db {
78094 + struct inodev_entry **i_hash;
78095 + __u32 i_size;
78096 +};
78097 +
78098 +struct name_db {
78099 + struct name_entry **n_hash;
78100 + __u32 n_size;
78101 +};
78102 +
78103 +struct crash_uid {
78104 + uid_t uid;
78105 + unsigned long expires;
78106 +};
78107 +
78108 +struct gr_hash_struct {
78109 + void **table;
78110 + void **nametable;
78111 + void *first;
78112 + __u32 table_size;
78113 + __u32 used_size;
78114 + int type;
78115 +};
78116 +
78117 +/* Userspace Grsecurity ACL data structures */
78118 +
78119 +struct acl_subject_label {
78120 + char *filename;
78121 + ino_t inode;
78122 + dev_t device;
78123 + __u32 mode;
78124 + kernel_cap_t cap_mask;
78125 + kernel_cap_t cap_lower;
78126 + kernel_cap_t cap_invert_audit;
78127 +
78128 + struct rlimit res[GR_NLIMITS];
78129 + __u32 resmask;
78130 +
78131 + __u8 user_trans_type;
78132 + __u8 group_trans_type;
78133 + uid_t *user_transitions;
78134 + gid_t *group_transitions;
78135 + __u16 user_trans_num;
78136 + __u16 group_trans_num;
78137 +
78138 + __u32 sock_families[2];
78139 + __u32 ip_proto[8];
78140 + __u32 ip_type;
78141 + struct acl_ip_label **ips;
78142 + __u32 ip_num;
78143 + __u32 inaddr_any_override;
78144 +
78145 + __u32 crashes;
78146 + unsigned long expires;
78147 +
78148 + struct acl_subject_label *parent_subject;
78149 + struct gr_hash_struct *hash;
78150 + struct acl_subject_label *prev;
78151 + struct acl_subject_label *next;
78152 +
78153 + struct acl_object_label **obj_hash;
78154 + __u32 obj_hash_size;
78155 + __u16 pax_flags;
78156 +};
78157 +
78158 +struct role_allowed_ip {
78159 + __u32 addr;
78160 + __u32 netmask;
78161 +
78162 + struct role_allowed_ip *prev;
78163 + struct role_allowed_ip *next;
78164 +};
78165 +
78166 +struct role_transition {
78167 + char *rolename;
78168 +
78169 + struct role_transition *prev;
78170 + struct role_transition *next;
78171 +};
78172 +
78173 +struct acl_role_label {
78174 + char *rolename;
78175 + uid_t uidgid;
78176 + __u16 roletype;
78177 +
78178 + __u16 auth_attempts;
78179 + unsigned long expires;
78180 +
78181 + struct acl_subject_label *root_label;
78182 + struct gr_hash_struct *hash;
78183 +
78184 + struct acl_role_label *prev;
78185 + struct acl_role_label *next;
78186 +
78187 + struct role_transition *transitions;
78188 + struct role_allowed_ip *allowed_ips;
78189 + uid_t *domain_children;
78190 + __u16 domain_child_num;
78191 +
78192 + umode_t umask;
78193 +
78194 + struct acl_subject_label **subj_hash;
78195 + __u32 subj_hash_size;
78196 +};
78197 +
78198 +struct user_acl_role_db {
78199 + struct acl_role_label **r_table;
78200 + __u32 num_pointers; /* Number of allocations to track */
78201 + __u32 num_roles; /* Number of roles */
78202 + __u32 num_domain_children; /* Number of domain children */
78203 + __u32 num_subjects; /* Number of subjects */
78204 + __u32 num_objects; /* Number of objects */
78205 +};
78206 +
78207 +struct acl_object_label {
78208 + char *filename;
78209 + ino_t inode;
78210 + dev_t device;
78211 + __u32 mode;
78212 +
78213 + struct acl_subject_label *nested;
78214 + struct acl_object_label *globbed;
78215 +
78216 + /* next two structures not used */
78217 +
78218 + struct acl_object_label *prev;
78219 + struct acl_object_label *next;
78220 +};
78221 +
78222 +struct acl_ip_label {
78223 + char *iface;
78224 + __u32 addr;
78225 + __u32 netmask;
78226 + __u16 low, high;
78227 + __u8 mode;
78228 + __u32 type;
78229 + __u32 proto[8];
78230 +
78231 + /* next two structures not used */
78232 +
78233 + struct acl_ip_label *prev;
78234 + struct acl_ip_label *next;
78235 +};
78236 +
78237 +struct gr_arg {
78238 + struct user_acl_role_db role_db;
78239 + unsigned char pw[GR_PW_LEN];
78240 + unsigned char salt[GR_SALT_LEN];
78241 + unsigned char sum[GR_SHA_LEN];
78242 + unsigned char sp_role[GR_SPROLE_LEN];
78243 + struct sprole_pw *sprole_pws;
78244 + dev_t segv_device;
78245 + ino_t segv_inode;
78246 + uid_t segv_uid;
78247 + __u16 num_sprole_pws;
78248 + __u16 mode;
78249 +};
78250 +
78251 +struct gr_arg_wrapper {
78252 + struct gr_arg *arg;
78253 + __u32 version;
78254 + __u32 size;
78255 +};
78256 +
78257 +struct subject_map {
78258 + struct acl_subject_label *user;
78259 + struct acl_subject_label *kernel;
78260 + struct subject_map *prev;
78261 + struct subject_map *next;
78262 +};
78263 +
78264 +struct acl_subj_map_db {
78265 + struct subject_map **s_hash;
78266 + __u32 s_size;
78267 +};
78268 +
78269 +struct gr_policy_state {
78270 + struct sprole_pw **acl_special_roles;
78271 + __u16 num_sprole_pws;
78272 + struct acl_role_label *kernel_role;
78273 + struct acl_role_label *role_list;
78274 + struct acl_role_label *default_role;
78275 + struct acl_role_db acl_role_set;
78276 + struct acl_subj_map_db subj_map_set;
78277 + struct name_db name_set;
78278 + struct inodev_db inodev_set;
78279 +};
78280 +
78281 +struct gr_alloc_state {
78282 + unsigned long alloc_stack_next;
78283 + unsigned long alloc_stack_size;
78284 + void **alloc_stack;
78285 +};
78286 +
78287 +struct gr_reload_state {
78288 + struct gr_policy_state oldpolicy;
78289 + struct gr_alloc_state oldalloc;
78290 + struct gr_policy_state newpolicy;
78291 + struct gr_alloc_state newalloc;
78292 + struct gr_policy_state *oldpolicy_ptr;
78293 + struct gr_alloc_state *oldalloc_ptr;
78294 + unsigned char oldmode;
78295 +};
78296 +
78297 +/* End Data Structures Section */
78298 +
78299 +/* Hash functions generated by empirical testing by Brad Spengler
78300 + Makes good use of the low bits of the inode. Generally 0-1 times
78301 + in loop for successful match. 0-3 for unsuccessful match.
78302 + Shift/add algorithm with modulus of table size and an XOR*/
78303 +
78304 +static __inline__ unsigned int
78305 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78306 +{
78307 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78308 +}
78309 +
78310 + static __inline__ unsigned int
78311 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78312 +{
78313 + return ((const unsigned long)userp % sz);
78314 +}
78315 +
78316 +static __inline__ unsigned int
78317 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78318 +{
78319 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78320 +}
78321 +
78322 +static __inline__ unsigned int
78323 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78324 +{
78325 + return full_name_hash((const unsigned char *)name, len) % sz;
78326 +}
78327 +
78328 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78329 + subj = NULL; \
78330 + iter = 0; \
78331 + while (iter < role->subj_hash_size) { \
78332 + if (subj == NULL) \
78333 + subj = role->subj_hash[iter]; \
78334 + if (subj == NULL) { \
78335 + iter++; \
78336 + continue; \
78337 + }
78338 +
78339 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78340 + subj = subj->next; \
78341 + if (subj == NULL) \
78342 + iter++; \
78343 + }
78344 +
78345 +
78346 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78347 + subj = role->hash->first; \
78348 + while (subj != NULL) {
78349 +
78350 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78351 + subj = subj->next; \
78352 + }
78353 +
78354 +#endif
78355 +
78356 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78357 new file mode 100644
78358 index 0000000..33ebd1f
78359 --- /dev/null
78360 +++ b/include/linux/gracl_compat.h
78361 @@ -0,0 +1,156 @@
78362 +#ifndef GR_ACL_COMPAT_H
78363 +#define GR_ACL_COMPAT_H
78364 +
78365 +#include <linux/resource.h>
78366 +#include <asm/resource.h>
78367 +
78368 +struct sprole_pw_compat {
78369 + compat_uptr_t rolename;
78370 + unsigned char salt[GR_SALT_LEN];
78371 + unsigned char sum[GR_SHA_LEN];
78372 +};
78373 +
78374 +struct gr_hash_struct_compat {
78375 + compat_uptr_t table;
78376 + compat_uptr_t nametable;
78377 + compat_uptr_t first;
78378 + __u32 table_size;
78379 + __u32 used_size;
78380 + int type;
78381 +};
78382 +
78383 +struct acl_subject_label_compat {
78384 + compat_uptr_t filename;
78385 + compat_ino_t inode;
78386 + __u32 device;
78387 + __u32 mode;
78388 + kernel_cap_t cap_mask;
78389 + kernel_cap_t cap_lower;
78390 + kernel_cap_t cap_invert_audit;
78391 +
78392 + struct compat_rlimit res[GR_NLIMITS];
78393 + __u32 resmask;
78394 +
78395 + __u8 user_trans_type;
78396 + __u8 group_trans_type;
78397 + compat_uptr_t user_transitions;
78398 + compat_uptr_t group_transitions;
78399 + __u16 user_trans_num;
78400 + __u16 group_trans_num;
78401 +
78402 + __u32 sock_families[2];
78403 + __u32 ip_proto[8];
78404 + __u32 ip_type;
78405 + compat_uptr_t ips;
78406 + __u32 ip_num;
78407 + __u32 inaddr_any_override;
78408 +
78409 + __u32 crashes;
78410 + compat_ulong_t expires;
78411 +
78412 + compat_uptr_t parent_subject;
78413 + compat_uptr_t hash;
78414 + compat_uptr_t prev;
78415 + compat_uptr_t next;
78416 +
78417 + compat_uptr_t obj_hash;
78418 + __u32 obj_hash_size;
78419 + __u16 pax_flags;
78420 +};
78421 +
78422 +struct role_allowed_ip_compat {
78423 + __u32 addr;
78424 + __u32 netmask;
78425 +
78426 + compat_uptr_t prev;
78427 + compat_uptr_t next;
78428 +};
78429 +
78430 +struct role_transition_compat {
78431 + compat_uptr_t rolename;
78432 +
78433 + compat_uptr_t prev;
78434 + compat_uptr_t next;
78435 +};
78436 +
78437 +struct acl_role_label_compat {
78438 + compat_uptr_t rolename;
78439 + uid_t uidgid;
78440 + __u16 roletype;
78441 +
78442 + __u16 auth_attempts;
78443 + compat_ulong_t expires;
78444 +
78445 + compat_uptr_t root_label;
78446 + compat_uptr_t hash;
78447 +
78448 + compat_uptr_t prev;
78449 + compat_uptr_t next;
78450 +
78451 + compat_uptr_t transitions;
78452 + compat_uptr_t allowed_ips;
78453 + compat_uptr_t domain_children;
78454 + __u16 domain_child_num;
78455 +
78456 + umode_t umask;
78457 +
78458 + compat_uptr_t subj_hash;
78459 + __u32 subj_hash_size;
78460 +};
78461 +
78462 +struct user_acl_role_db_compat {
78463 + compat_uptr_t r_table;
78464 + __u32 num_pointers;
78465 + __u32 num_roles;
78466 + __u32 num_domain_children;
78467 + __u32 num_subjects;
78468 + __u32 num_objects;
78469 +};
78470 +
78471 +struct acl_object_label_compat {
78472 + compat_uptr_t filename;
78473 + compat_ino_t inode;
78474 + __u32 device;
78475 + __u32 mode;
78476 +
78477 + compat_uptr_t nested;
78478 + compat_uptr_t globbed;
78479 +
78480 + compat_uptr_t prev;
78481 + compat_uptr_t next;
78482 +};
78483 +
78484 +struct acl_ip_label_compat {
78485 + compat_uptr_t iface;
78486 + __u32 addr;
78487 + __u32 netmask;
78488 + __u16 low, high;
78489 + __u8 mode;
78490 + __u32 type;
78491 + __u32 proto[8];
78492 +
78493 + compat_uptr_t prev;
78494 + compat_uptr_t next;
78495 +};
78496 +
78497 +struct gr_arg_compat {
78498 + struct user_acl_role_db_compat role_db;
78499 + unsigned char pw[GR_PW_LEN];
78500 + unsigned char salt[GR_SALT_LEN];
78501 + unsigned char sum[GR_SHA_LEN];
78502 + unsigned char sp_role[GR_SPROLE_LEN];
78503 + compat_uptr_t sprole_pws;
78504 + __u32 segv_device;
78505 + compat_ino_t segv_inode;
78506 + uid_t segv_uid;
78507 + __u16 num_sprole_pws;
78508 + __u16 mode;
78509 +};
78510 +
78511 +struct gr_arg_wrapper_compat {
78512 + compat_uptr_t arg;
78513 + __u32 version;
78514 + __u32 size;
78515 +};
78516 +
78517 +#endif
78518 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78519 new file mode 100644
78520 index 0000000..323ecf2
78521 --- /dev/null
78522 +++ b/include/linux/gralloc.h
78523 @@ -0,0 +1,9 @@
78524 +#ifndef __GRALLOC_H
78525 +#define __GRALLOC_H
78526 +
78527 +void acl_free_all(void);
78528 +int acl_alloc_stack_init(unsigned long size);
78529 +void *acl_alloc(unsigned long len);
78530 +void *acl_alloc_num(unsigned long num, unsigned long len);
78531 +
78532 +#endif
78533 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78534 new file mode 100644
78535 index 0000000..be66033
78536 --- /dev/null
78537 +++ b/include/linux/grdefs.h
78538 @@ -0,0 +1,140 @@
78539 +#ifndef GRDEFS_H
78540 +#define GRDEFS_H
78541 +
78542 +/* Begin grsecurity status declarations */
78543 +
78544 +enum {
78545 + GR_READY = 0x01,
78546 + GR_STATUS_INIT = 0x00 // disabled state
78547 +};
78548 +
78549 +/* Begin ACL declarations */
78550 +
78551 +/* Role flags */
78552 +
78553 +enum {
78554 + GR_ROLE_USER = 0x0001,
78555 + GR_ROLE_GROUP = 0x0002,
78556 + GR_ROLE_DEFAULT = 0x0004,
78557 + GR_ROLE_SPECIAL = 0x0008,
78558 + GR_ROLE_AUTH = 0x0010,
78559 + GR_ROLE_NOPW = 0x0020,
78560 + GR_ROLE_GOD = 0x0040,
78561 + GR_ROLE_LEARN = 0x0080,
78562 + GR_ROLE_TPE = 0x0100,
78563 + GR_ROLE_DOMAIN = 0x0200,
78564 + GR_ROLE_PAM = 0x0400,
78565 + GR_ROLE_PERSIST = 0x0800
78566 +};
78567 +
78568 +/* ACL Subject and Object mode flags */
78569 +enum {
78570 + GR_DELETED = 0x80000000
78571 +};
78572 +
78573 +/* ACL Object-only mode flags */
78574 +enum {
78575 + GR_READ = 0x00000001,
78576 + GR_APPEND = 0x00000002,
78577 + GR_WRITE = 0x00000004,
78578 + GR_EXEC = 0x00000008,
78579 + GR_FIND = 0x00000010,
78580 + GR_INHERIT = 0x00000020,
78581 + GR_SETID = 0x00000040,
78582 + GR_CREATE = 0x00000080,
78583 + GR_DELETE = 0x00000100,
78584 + GR_LINK = 0x00000200,
78585 + GR_AUDIT_READ = 0x00000400,
78586 + GR_AUDIT_APPEND = 0x00000800,
78587 + GR_AUDIT_WRITE = 0x00001000,
78588 + GR_AUDIT_EXEC = 0x00002000,
78589 + GR_AUDIT_FIND = 0x00004000,
78590 + GR_AUDIT_INHERIT= 0x00008000,
78591 + GR_AUDIT_SETID = 0x00010000,
78592 + GR_AUDIT_CREATE = 0x00020000,
78593 + GR_AUDIT_DELETE = 0x00040000,
78594 + GR_AUDIT_LINK = 0x00080000,
78595 + GR_PTRACERD = 0x00100000,
78596 + GR_NOPTRACE = 0x00200000,
78597 + GR_SUPPRESS = 0x00400000,
78598 + GR_NOLEARN = 0x00800000,
78599 + GR_INIT_TRANSFER= 0x01000000
78600 +};
78601 +
78602 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78603 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78604 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78605 +
78606 +/* ACL subject-only mode flags */
78607 +enum {
78608 + GR_KILL = 0x00000001,
78609 + GR_VIEW = 0x00000002,
78610 + GR_PROTECTED = 0x00000004,
78611 + GR_LEARN = 0x00000008,
78612 + GR_OVERRIDE = 0x00000010,
78613 + /* just a placeholder, this mode is only used in userspace */
78614 + GR_DUMMY = 0x00000020,
78615 + GR_PROTSHM = 0x00000040,
78616 + GR_KILLPROC = 0x00000080,
78617 + GR_KILLIPPROC = 0x00000100,
78618 + /* just a placeholder, this mode is only used in userspace */
78619 + GR_NOTROJAN = 0x00000200,
78620 + GR_PROTPROCFD = 0x00000400,
78621 + GR_PROCACCT = 0x00000800,
78622 + GR_RELAXPTRACE = 0x00001000,
78623 + //GR_NESTED = 0x00002000,
78624 + GR_INHERITLEARN = 0x00004000,
78625 + GR_PROCFIND = 0x00008000,
78626 + GR_POVERRIDE = 0x00010000,
78627 + GR_KERNELAUTH = 0x00020000,
78628 + GR_ATSECURE = 0x00040000,
78629 + GR_SHMEXEC = 0x00080000
78630 +};
78631 +
78632 +enum {
78633 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78634 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78635 + GR_PAX_ENABLE_MPROTECT = 0x0004,
78636 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
78637 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78638 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78639 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78640 + GR_PAX_DISABLE_MPROTECT = 0x0400,
78641 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
78642 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78643 +};
78644 +
78645 +enum {
78646 + GR_ID_USER = 0x01,
78647 + GR_ID_GROUP = 0x02,
78648 +};
78649 +
78650 +enum {
78651 + GR_ID_ALLOW = 0x01,
78652 + GR_ID_DENY = 0x02,
78653 +};
78654 +
78655 +#define GR_CRASH_RES 31
78656 +#define GR_UIDTABLE_MAX 500
78657 +
78658 +/* begin resource learning section */
78659 +enum {
78660 + GR_RLIM_CPU_BUMP = 60,
78661 + GR_RLIM_FSIZE_BUMP = 50000,
78662 + GR_RLIM_DATA_BUMP = 10000,
78663 + GR_RLIM_STACK_BUMP = 1000,
78664 + GR_RLIM_CORE_BUMP = 10000,
78665 + GR_RLIM_RSS_BUMP = 500000,
78666 + GR_RLIM_NPROC_BUMP = 1,
78667 + GR_RLIM_NOFILE_BUMP = 5,
78668 + GR_RLIM_MEMLOCK_BUMP = 50000,
78669 + GR_RLIM_AS_BUMP = 500000,
78670 + GR_RLIM_LOCKS_BUMP = 2,
78671 + GR_RLIM_SIGPENDING_BUMP = 5,
78672 + GR_RLIM_MSGQUEUE_BUMP = 10000,
78673 + GR_RLIM_NICE_BUMP = 1,
78674 + GR_RLIM_RTPRIO_BUMP = 1,
78675 + GR_RLIM_RTTIME_BUMP = 1000000
78676 +};
78677 +
78678 +#endif
78679 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78680 new file mode 100644
78681 index 0000000..d25522e
78682 --- /dev/null
78683 +++ b/include/linux/grinternal.h
78684 @@ -0,0 +1,229 @@
78685 +#ifndef __GRINTERNAL_H
78686 +#define __GRINTERNAL_H
78687 +
78688 +#ifdef CONFIG_GRKERNSEC
78689 +
78690 +#include <linux/fs.h>
78691 +#include <linux/mnt_namespace.h>
78692 +#include <linux/nsproxy.h>
78693 +#include <linux/gracl.h>
78694 +#include <linux/grdefs.h>
78695 +#include <linux/grmsg.h>
78696 +
78697 +void gr_add_learn_entry(const char *fmt, ...)
78698 + __attribute__ ((format (printf, 1, 2)));
78699 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78700 + const struct vfsmount *mnt);
78701 +__u32 gr_check_create(const struct dentry *new_dentry,
78702 + const struct dentry *parent,
78703 + const struct vfsmount *mnt, const __u32 mode);
78704 +int gr_check_protected_task(const struct task_struct *task);
78705 +__u32 to_gr_audit(const __u32 reqmode);
78706 +int gr_set_acls(const int type);
78707 +int gr_acl_is_enabled(void);
78708 +char gr_roletype_to_char(void);
78709 +
78710 +void gr_handle_alertkill(struct task_struct *task);
78711 +char *gr_to_filename(const struct dentry *dentry,
78712 + const struct vfsmount *mnt);
78713 +char *gr_to_filename1(const struct dentry *dentry,
78714 + const struct vfsmount *mnt);
78715 +char *gr_to_filename2(const struct dentry *dentry,
78716 + const struct vfsmount *mnt);
78717 +char *gr_to_filename3(const struct dentry *dentry,
78718 + const struct vfsmount *mnt);
78719 +
78720 +extern int grsec_enable_ptrace_readexec;
78721 +extern int grsec_enable_harden_ptrace;
78722 +extern int grsec_enable_link;
78723 +extern int grsec_enable_fifo;
78724 +extern int grsec_enable_execve;
78725 +extern int grsec_enable_shm;
78726 +extern int grsec_enable_execlog;
78727 +extern int grsec_enable_signal;
78728 +extern int grsec_enable_audit_ptrace;
78729 +extern int grsec_enable_forkfail;
78730 +extern int grsec_enable_time;
78731 +extern int grsec_enable_rofs;
78732 +extern int grsec_deny_new_usb;
78733 +extern int grsec_enable_chroot_shmat;
78734 +extern int grsec_enable_chroot_mount;
78735 +extern int grsec_enable_chroot_double;
78736 +extern int grsec_enable_chroot_pivot;
78737 +extern int grsec_enable_chroot_chdir;
78738 +extern int grsec_enable_chroot_chmod;
78739 +extern int grsec_enable_chroot_mknod;
78740 +extern int grsec_enable_chroot_fchdir;
78741 +extern int grsec_enable_chroot_nice;
78742 +extern int grsec_enable_chroot_execlog;
78743 +extern int grsec_enable_chroot_caps;
78744 +extern int grsec_enable_chroot_sysctl;
78745 +extern int grsec_enable_chroot_unix;
78746 +extern int grsec_enable_symlinkown;
78747 +extern kgid_t grsec_symlinkown_gid;
78748 +extern int grsec_enable_tpe;
78749 +extern kgid_t grsec_tpe_gid;
78750 +extern int grsec_enable_tpe_all;
78751 +extern int grsec_enable_tpe_invert;
78752 +extern int grsec_enable_socket_all;
78753 +extern kgid_t grsec_socket_all_gid;
78754 +extern int grsec_enable_socket_client;
78755 +extern kgid_t grsec_socket_client_gid;
78756 +extern int grsec_enable_socket_server;
78757 +extern kgid_t grsec_socket_server_gid;
78758 +extern kgid_t grsec_audit_gid;
78759 +extern int grsec_enable_group;
78760 +extern int grsec_enable_log_rwxmaps;
78761 +extern int grsec_enable_mount;
78762 +extern int grsec_enable_chdir;
78763 +extern int grsec_resource_logging;
78764 +extern int grsec_enable_blackhole;
78765 +extern int grsec_lastack_retries;
78766 +extern int grsec_enable_brute;
78767 +extern int grsec_enable_harden_ipc;
78768 +extern int grsec_lock;
78769 +
78770 +extern spinlock_t grsec_alert_lock;
78771 +extern unsigned long grsec_alert_wtime;
78772 +extern unsigned long grsec_alert_fyet;
78773 +
78774 +extern spinlock_t grsec_audit_lock;
78775 +
78776 +extern rwlock_t grsec_exec_file_lock;
78777 +
78778 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78779 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78780 + (tsk)->exec_file->f_path.mnt) : "/")
78781 +
78782 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78783 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78784 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78785 +
78786 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78787 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
78788 + (tsk)->exec_file->f_path.mnt) : "/")
78789 +
78790 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78791 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78792 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78793 +
78794 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78795 +
78796 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78797 +
78798 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78799 +{
78800 + if (file1 && file2) {
78801 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
78802 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
78803 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78804 + return true;
78805 + }
78806 +
78807 + return false;
78808 +}
78809 +
78810 +#define GR_CHROOT_CAPS {{ \
78811 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78812 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78813 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78814 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78815 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78816 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78817 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78818 +
78819 +#define security_learn(normal_msg,args...) \
78820 +({ \
78821 + read_lock(&grsec_exec_file_lock); \
78822 + gr_add_learn_entry(normal_msg "\n", ## args); \
78823 + read_unlock(&grsec_exec_file_lock); \
78824 +})
78825 +
78826 +enum {
78827 + GR_DO_AUDIT,
78828 + GR_DONT_AUDIT,
78829 + /* used for non-audit messages that we shouldn't kill the task on */
78830 + GR_DONT_AUDIT_GOOD
78831 +};
78832 +
78833 +enum {
78834 + GR_TTYSNIFF,
78835 + GR_RBAC,
78836 + GR_RBAC_STR,
78837 + GR_STR_RBAC,
78838 + GR_RBAC_MODE2,
78839 + GR_RBAC_MODE3,
78840 + GR_FILENAME,
78841 + GR_SYSCTL_HIDDEN,
78842 + GR_NOARGS,
78843 + GR_ONE_INT,
78844 + GR_ONE_INT_TWO_STR,
78845 + GR_ONE_STR,
78846 + GR_STR_INT,
78847 + GR_TWO_STR_INT,
78848 + GR_TWO_INT,
78849 + GR_TWO_U64,
78850 + GR_THREE_INT,
78851 + GR_FIVE_INT_TWO_STR,
78852 + GR_TWO_STR,
78853 + GR_THREE_STR,
78854 + GR_FOUR_STR,
78855 + GR_STR_FILENAME,
78856 + GR_FILENAME_STR,
78857 + GR_FILENAME_TWO_INT,
78858 + GR_FILENAME_TWO_INT_STR,
78859 + GR_TEXTREL,
78860 + GR_PTRACE,
78861 + GR_RESOURCE,
78862 + GR_CAP,
78863 + GR_SIG,
78864 + GR_SIG2,
78865 + GR_CRASH1,
78866 + GR_CRASH2,
78867 + GR_PSACCT,
78868 + GR_RWXMAP,
78869 + GR_RWXMAPVMA
78870 +};
78871 +
78872 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78873 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78874 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78875 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78876 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78877 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78878 +#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)
78879 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78880 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78881 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78882 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78883 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78884 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78885 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78886 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78887 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78888 +#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)
78889 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78890 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78891 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78892 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78893 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78894 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78895 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78896 +#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)
78897 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78898 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78899 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78900 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78901 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78902 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78903 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78904 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78905 +#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)
78906 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78907 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78908 +
78909 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78910 +
78911 +#endif
78912 +
78913 +#endif
78914 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78915 new file mode 100644
78916 index 0000000..ba93581
78917 --- /dev/null
78918 +++ b/include/linux/grmsg.h
78919 @@ -0,0 +1,116 @@
78920 +#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"
78921 +#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"
78922 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78923 +#define GR_STOPMOD_MSG "denied modification of module state by "
78924 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78925 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78926 +#define GR_IOPERM_MSG "denied use of ioperm() by "
78927 +#define GR_IOPL_MSG "denied use of iopl() by "
78928 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78929 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78930 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78931 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78932 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78933 +#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"
78934 +#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"
78935 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78936 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78937 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78938 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78939 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78940 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78941 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78942 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78943 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78944 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78945 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78946 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78947 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78948 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78949 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78950 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78951 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78952 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78953 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78954 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78955 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78956 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78957 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78958 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78959 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78960 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78961 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78962 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78963 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78964 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78965 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78966 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78967 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78968 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78969 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78970 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78971 +#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"
78972 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78973 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78974 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78975 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78976 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78977 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78978 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78979 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78980 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78981 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78982 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78983 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78984 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78985 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78986 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78987 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78988 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78989 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78990 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78991 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78992 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
78993 +#define GR_NICE_CHROOT_MSG "denied priority change by "
78994 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78995 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78996 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78997 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78998 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78999 +#define GR_TIME_MSG "time set by "
79000 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79001 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79002 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79003 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79004 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79005 +#define GR_BIND_MSG "denied bind() by "
79006 +#define GR_CONNECT_MSG "denied connect() by "
79007 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79008 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79009 +#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"
79010 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79011 +#define GR_CAP_ACL_MSG "use of %s denied for "
79012 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79013 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79014 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79015 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79016 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79017 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79018 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79019 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79020 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79021 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79022 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79023 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79024 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79025 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79026 +#define GR_VM86_MSG "denied use of vm86 by "
79027 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79028 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79029 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79030 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79031 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79032 +#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 "
79033 +#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 "
79034 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79035 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79036 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79037 new file mode 100644
79038 index 0000000..8108301
79039 --- /dev/null
79040 +++ b/include/linux/grsecurity.h
79041 @@ -0,0 +1,246 @@
79042 +#ifndef GR_SECURITY_H
79043 +#define GR_SECURITY_H
79044 +#include <linux/fs.h>
79045 +#include <linux/fs_struct.h>
79046 +#include <linux/binfmts.h>
79047 +#include <linux/gracl.h>
79048 +
79049 +/* notify of brain-dead configs */
79050 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79051 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79052 +#endif
79053 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79054 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79055 +#endif
79056 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79057 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79058 +#endif
79059 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79060 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
79061 +#endif
79062 +
79063 +int gr_handle_new_usb(void);
79064 +
79065 +void gr_handle_brute_attach(int dumpable);
79066 +void gr_handle_brute_check(void);
79067 +void gr_handle_kernel_exploit(void);
79068 +
79069 +char gr_roletype_to_char(void);
79070 +
79071 +int gr_acl_enable_at_secure(void);
79072 +
79073 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79074 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79075 +
79076 +void gr_del_task_from_ip_table(struct task_struct *p);
79077 +
79078 +int gr_pid_is_chrooted(struct task_struct *p);
79079 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79080 +int gr_handle_chroot_nice(void);
79081 +int gr_handle_chroot_sysctl(const int op);
79082 +int gr_handle_chroot_setpriority(struct task_struct *p,
79083 + const int niceval);
79084 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79085 +int gr_handle_chroot_chroot(const struct dentry *dentry,
79086 + const struct vfsmount *mnt);
79087 +void gr_handle_chroot_chdir(const struct path *path);
79088 +int gr_handle_chroot_chmod(const struct dentry *dentry,
79089 + const struct vfsmount *mnt, const int mode);
79090 +int gr_handle_chroot_mknod(const struct dentry *dentry,
79091 + const struct vfsmount *mnt, const int mode);
79092 +int gr_handle_chroot_mount(const struct dentry *dentry,
79093 + const struct vfsmount *mnt,
79094 + const char *dev_name);
79095 +int gr_handle_chroot_pivot(void);
79096 +int gr_handle_chroot_unix(const pid_t pid);
79097 +
79098 +int gr_handle_rawio(const struct inode *inode);
79099 +
79100 +void gr_handle_ioperm(void);
79101 +void gr_handle_iopl(void);
79102 +void gr_handle_msr_write(void);
79103 +
79104 +umode_t gr_acl_umask(void);
79105 +
79106 +int gr_tpe_allow(const struct file *file);
79107 +
79108 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79109 +void gr_clear_chroot_entries(struct task_struct *task);
79110 +
79111 +void gr_log_forkfail(const int retval);
79112 +void gr_log_timechange(void);
79113 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79114 +void gr_log_chdir(const struct dentry *dentry,
79115 + const struct vfsmount *mnt);
79116 +void gr_log_chroot_exec(const struct dentry *dentry,
79117 + const struct vfsmount *mnt);
79118 +void gr_log_remount(const char *devname, const int retval);
79119 +void gr_log_unmount(const char *devname, const int retval);
79120 +void gr_log_mount(const char *from, const char *to, const int retval);
79121 +void gr_log_textrel(struct vm_area_struct *vma);
79122 +void gr_log_ptgnustack(struct file *file);
79123 +void gr_log_rwxmmap(struct file *file);
79124 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
79125 +
79126 +int gr_handle_follow_link(const struct inode *parent,
79127 + const struct inode *inode,
79128 + const struct dentry *dentry,
79129 + const struct vfsmount *mnt);
79130 +int gr_handle_fifo(const struct dentry *dentry,
79131 + const struct vfsmount *mnt,
79132 + const struct dentry *dir, const int flag,
79133 + const int acc_mode);
79134 +int gr_handle_hardlink(const struct dentry *dentry,
79135 + const struct vfsmount *mnt,
79136 + struct inode *inode,
79137 + const int mode, const struct filename *to);
79138 +
79139 +int gr_is_capable(const int cap);
79140 +int gr_is_capable_nolog(const int cap);
79141 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79142 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79143 +
79144 +void gr_copy_label(struct task_struct *tsk);
79145 +void gr_handle_crash(struct task_struct *task, const int sig);
79146 +int gr_handle_signal(const struct task_struct *p, const int sig);
79147 +int gr_check_crash_uid(const kuid_t uid);
79148 +int gr_check_protected_task(const struct task_struct *task);
79149 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79150 +int gr_acl_handle_mmap(const struct file *file,
79151 + const unsigned long prot);
79152 +int gr_acl_handle_mprotect(const struct file *file,
79153 + const unsigned long prot);
79154 +int gr_check_hidden_task(const struct task_struct *tsk);
79155 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79156 + const struct vfsmount *mnt);
79157 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
79158 + const struct vfsmount *mnt);
79159 +__u32 gr_acl_handle_access(const struct dentry *dentry,
79160 + const struct vfsmount *mnt, const int fmode);
79161 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79162 + const struct vfsmount *mnt, umode_t *mode);
79163 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
79164 + const struct vfsmount *mnt);
79165 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79166 + const struct vfsmount *mnt);
79167 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79168 + const struct vfsmount *mnt);
79169 +int gr_handle_ptrace(struct task_struct *task, const long request);
79170 +int gr_handle_proc_ptrace(struct task_struct *task);
79171 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
79172 + const struct vfsmount *mnt);
79173 +int gr_check_crash_exec(const struct file *filp);
79174 +int gr_acl_is_enabled(void);
79175 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79176 + const kgid_t gid);
79177 +int gr_set_proc_label(const struct dentry *dentry,
79178 + const struct vfsmount *mnt,
79179 + const int unsafe_flags);
79180 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79181 + const struct vfsmount *mnt);
79182 +__u32 gr_acl_handle_open(const struct dentry *dentry,
79183 + const struct vfsmount *mnt, int acc_mode);
79184 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
79185 + const struct dentry *p_dentry,
79186 + const struct vfsmount *p_mnt,
79187 + int open_flags, int acc_mode, const int imode);
79188 +void gr_handle_create(const struct dentry *dentry,
79189 + const struct vfsmount *mnt);
79190 +void gr_handle_proc_create(const struct dentry *dentry,
79191 + const struct inode *inode);
79192 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79193 + const struct dentry *parent_dentry,
79194 + const struct vfsmount *parent_mnt,
79195 + const int mode);
79196 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79197 + const struct dentry *parent_dentry,
79198 + const struct vfsmount *parent_mnt);
79199 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79200 + const struct vfsmount *mnt);
79201 +void gr_handle_delete(const ino_t ino, const dev_t dev);
79202 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79203 + const struct vfsmount *mnt);
79204 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79205 + const struct dentry *parent_dentry,
79206 + const struct vfsmount *parent_mnt,
79207 + const struct filename *from);
79208 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79209 + const struct dentry *parent_dentry,
79210 + const struct vfsmount *parent_mnt,
79211 + const struct dentry *old_dentry,
79212 + const struct vfsmount *old_mnt, const struct filename *to);
79213 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79214 +int gr_acl_handle_rename(struct dentry *new_dentry,
79215 + struct dentry *parent_dentry,
79216 + const struct vfsmount *parent_mnt,
79217 + struct dentry *old_dentry,
79218 + struct inode *old_parent_inode,
79219 + struct vfsmount *old_mnt, const struct filename *newname);
79220 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79221 + struct dentry *old_dentry,
79222 + struct dentry *new_dentry,
79223 + struct vfsmount *mnt, const __u8 replace);
79224 +__u32 gr_check_link(const struct dentry *new_dentry,
79225 + const struct dentry *parent_dentry,
79226 + const struct vfsmount *parent_mnt,
79227 + const struct dentry *old_dentry,
79228 + const struct vfsmount *old_mnt);
79229 +int gr_acl_handle_filldir(const struct file *file, const char *name,
79230 + const unsigned int namelen, const ino_t ino);
79231 +
79232 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
79233 + const struct vfsmount *mnt);
79234 +void gr_acl_handle_exit(void);
79235 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
79236 +int gr_acl_handle_procpidmem(const struct task_struct *task);
79237 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79238 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79239 +void gr_audit_ptrace(struct task_struct *task);
79240 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79241 +void gr_put_exec_file(struct task_struct *task);
79242 +
79243 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79244 +
79245 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79246 +extern void gr_learn_resource(const struct task_struct *task, const int res,
79247 + const unsigned long wanted, const int gt);
79248 +#else
79249 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
79250 + const unsigned long wanted, const int gt)
79251 +{
79252 +}
79253 +#endif
79254 +
79255 +#ifdef CONFIG_GRKERNSEC_RESLOG
79256 +extern void gr_log_resource(const struct task_struct *task, const int res,
79257 + const unsigned long wanted, const int gt);
79258 +#else
79259 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79260 + const unsigned long wanted, const int gt)
79261 +{
79262 +}
79263 +#endif
79264 +
79265 +#ifdef CONFIG_GRKERNSEC
79266 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79267 +void gr_handle_vm86(void);
79268 +void gr_handle_mem_readwrite(u64 from, u64 to);
79269 +
79270 +void gr_log_badprocpid(const char *entry);
79271 +
79272 +extern int grsec_enable_dmesg;
79273 +extern int grsec_disable_privio;
79274 +
79275 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79276 +extern kgid_t grsec_proc_gid;
79277 +#endif
79278 +
79279 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79280 +extern int grsec_enable_chroot_findtask;
79281 +#endif
79282 +#ifdef CONFIG_GRKERNSEC_SETXID
79283 +extern int grsec_enable_setxid;
79284 +#endif
79285 +#endif
79286 +
79287 +#endif
79288 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79289 new file mode 100644
79290 index 0000000..e7ffaaf
79291 --- /dev/null
79292 +++ b/include/linux/grsock.h
79293 @@ -0,0 +1,19 @@
79294 +#ifndef __GRSOCK_H
79295 +#define __GRSOCK_H
79296 +
79297 +extern void gr_attach_curr_ip(const struct sock *sk);
79298 +extern int gr_handle_sock_all(const int family, const int type,
79299 + const int protocol);
79300 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79301 +extern int gr_handle_sock_server_other(const struct sock *sck);
79302 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79303 +extern int gr_search_connect(struct socket * sock,
79304 + struct sockaddr_in * addr);
79305 +extern int gr_search_bind(struct socket * sock,
79306 + struct sockaddr_in * addr);
79307 +extern int gr_search_listen(struct socket * sock);
79308 +extern int gr_search_accept(struct socket * sock);
79309 +extern int gr_search_socket(const int domain, const int type,
79310 + const int protocol);
79311 +
79312 +#endif
79313 diff --git a/include/linux/hash.h b/include/linux/hash.h
79314 index bd1754c..8240892 100644
79315 --- a/include/linux/hash.h
79316 +++ b/include/linux/hash.h
79317 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79318 struct fast_hash_ops {
79319 u32 (*hash)(const void *data, u32 len, u32 seed);
79320 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79321 -};
79322 +} __no_const;
79323
79324 /**
79325 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79326 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79327 index 7fb31da..08b5114 100644
79328 --- a/include/linux/highmem.h
79329 +++ b/include/linux/highmem.h
79330 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79331 kunmap_atomic(kaddr);
79332 }
79333
79334 +static inline void sanitize_highpage(struct page *page)
79335 +{
79336 + void *kaddr;
79337 + unsigned long flags;
79338 +
79339 + local_irq_save(flags);
79340 + kaddr = kmap_atomic(page);
79341 + clear_page(kaddr);
79342 + kunmap_atomic(kaddr);
79343 + local_irq_restore(flags);
79344 +}
79345 +
79346 static inline void zero_user_segments(struct page *page,
79347 unsigned start1, unsigned end1,
79348 unsigned start2, unsigned end2)
79349 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79350 index 1c7b89a..7dda400 100644
79351 --- a/include/linux/hwmon-sysfs.h
79352 +++ b/include/linux/hwmon-sysfs.h
79353 @@ -25,7 +25,8 @@
79354 struct sensor_device_attribute{
79355 struct device_attribute dev_attr;
79356 int index;
79357 -};
79358 +} __do_const;
79359 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79360 #define to_sensor_dev_attr(_dev_attr) \
79361 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79362
79363 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79364 struct device_attribute dev_attr;
79365 u8 index;
79366 u8 nr;
79367 -};
79368 +} __do_const;
79369 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79370 #define to_sensor_dev_attr_2(_dev_attr) \
79371 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79372
79373 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79374 index deddeb8..bcaf62d 100644
79375 --- a/include/linux/i2c.h
79376 +++ b/include/linux/i2c.h
79377 @@ -378,6 +378,7 @@ struct i2c_algorithm {
79378 /* To determine what the adapter supports */
79379 u32 (*functionality) (struct i2c_adapter *);
79380 };
79381 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79382
79383 /**
79384 * struct i2c_bus_recovery_info - I2C bus recovery information
79385 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79386 index d23c3c2..eb63c81 100644
79387 --- a/include/linux/i2o.h
79388 +++ b/include/linux/i2o.h
79389 @@ -565,7 +565,7 @@ struct i2o_controller {
79390 struct i2o_device *exec; /* Executive */
79391 #if BITS_PER_LONG == 64
79392 spinlock_t context_list_lock; /* lock for context_list */
79393 - atomic_t context_list_counter; /* needed for unique contexts */
79394 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79395 struct list_head context_list; /* list of context id's
79396 and pointers */
79397 #endif
79398 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79399 index aff7ad8..3942bbd 100644
79400 --- a/include/linux/if_pppox.h
79401 +++ b/include/linux/if_pppox.h
79402 @@ -76,7 +76,7 @@ struct pppox_proto {
79403 int (*ioctl)(struct socket *sock, unsigned int cmd,
79404 unsigned long arg);
79405 struct module *owner;
79406 -};
79407 +} __do_const;
79408
79409 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79410 extern void unregister_pppox_proto(int proto_num);
79411 diff --git a/include/linux/init.h b/include/linux/init.h
79412 index e168880..d9b489d 100644
79413 --- a/include/linux/init.h
79414 +++ b/include/linux/init.h
79415 @@ -37,9 +37,17 @@
79416 * section.
79417 */
79418
79419 +#define add_init_latent_entropy __latent_entropy
79420 +
79421 +#ifdef CONFIG_MEMORY_HOTPLUG
79422 +#define add_meminit_latent_entropy
79423 +#else
79424 +#define add_meminit_latent_entropy __latent_entropy
79425 +#endif
79426 +
79427 /* These are for everybody (although not all archs will actually
79428 discard it in modules) */
79429 -#define __init __section(.init.text) __cold notrace
79430 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79431 #define __initdata __section(.init.data)
79432 #define __initconst __constsection(.init.rodata)
79433 #define __exitdata __section(.exit.data)
79434 @@ -100,7 +108,7 @@
79435 #define __cpuexitconst
79436
79437 /* Used for MEMORY_HOTPLUG */
79438 -#define __meminit __section(.meminit.text) __cold notrace
79439 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79440 #define __meminitdata __section(.meminit.data)
79441 #define __meminitconst __constsection(.meminit.rodata)
79442 #define __memexit __section(.memexit.text) __exitused __cold notrace
79443 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79444 index 6df7f9f..d0bf699 100644
79445 --- a/include/linux/init_task.h
79446 +++ b/include/linux/init_task.h
79447 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79448
79449 #define INIT_TASK_COMM "swapper"
79450
79451 +#ifdef CONFIG_X86
79452 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79453 +#else
79454 +#define INIT_TASK_THREAD_INFO
79455 +#endif
79456 +
79457 #ifdef CONFIG_RT_MUTEXES
79458 # define INIT_RT_MUTEXES(tsk) \
79459 .pi_waiters = RB_ROOT, \
79460 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79461 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79462 .comm = INIT_TASK_COMM, \
79463 .thread = INIT_THREAD, \
79464 + INIT_TASK_THREAD_INFO \
79465 .fs = &init_fs, \
79466 .files = &init_files, \
79467 .signal = &init_signals, \
79468 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79469 index a2678d3..e411b1b 100644
79470 --- a/include/linux/interrupt.h
79471 +++ b/include/linux/interrupt.h
79472 @@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79473
79474 struct softirq_action
79475 {
79476 - void (*action)(struct softirq_action *);
79477 -};
79478 + void (*action)(void);
79479 +} __no_const;
79480
79481 asmlinkage void do_softirq(void);
79482 asmlinkage void __do_softirq(void);
79483 @@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
79484 }
79485 #endif
79486
79487 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79488 +extern void open_softirq(int nr, void (*action)(void));
79489 extern void softirq_init(void);
79490 extern void __raise_softirq_irqoff(unsigned int nr);
79491
79492 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79493 index b96a5b2..2732d1c 100644
79494 --- a/include/linux/iommu.h
79495 +++ b/include/linux/iommu.h
79496 @@ -131,7 +131,7 @@ struct iommu_ops {
79497 u32 (*domain_get_windows)(struct iommu_domain *domain);
79498
79499 unsigned long pgsize_bitmap;
79500 -};
79501 +} __do_const;
79502
79503 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79504 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79505 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79506 index 89b7c24..382af74 100644
79507 --- a/include/linux/ioport.h
79508 +++ b/include/linux/ioport.h
79509 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79510 int adjust_resource(struct resource *res, resource_size_t start,
79511 resource_size_t size);
79512 resource_size_t resource_alignment(struct resource *res);
79513 -static inline resource_size_t resource_size(const struct resource *res)
79514 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79515 {
79516 return res->end - res->start + 1;
79517 }
79518 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79519 index 35e7eca..6afb7ad 100644
79520 --- a/include/linux/ipc_namespace.h
79521 +++ b/include/linux/ipc_namespace.h
79522 @@ -69,7 +69,7 @@ struct ipc_namespace {
79523 struct user_namespace *user_ns;
79524
79525 unsigned int proc_inum;
79526 -};
79527 +} __randomize_layout;
79528
79529 extern struct ipc_namespace init_ipc_ns;
79530 extern atomic_t nr_ipc_ns;
79531 diff --git a/include/linux/irq.h b/include/linux/irq.h
79532 index 7dc1003..407327b 100644
79533 --- a/include/linux/irq.h
79534 +++ b/include/linux/irq.h
79535 @@ -338,7 +338,8 @@ struct irq_chip {
79536 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79537
79538 unsigned long flags;
79539 -};
79540 +} __do_const;
79541 +typedef struct irq_chip __no_const irq_chip_no_const;
79542
79543 /*
79544 * irq_chip specific flags
79545 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79546 index 0ceb389..eed3fb8 100644
79547 --- a/include/linux/irqchip/arm-gic.h
79548 +++ b/include/linux/irqchip/arm-gic.h
79549 @@ -73,9 +73,11 @@
79550
79551 #ifndef __ASSEMBLY__
79552
79553 +#include <linux/irq.h>
79554 +
79555 struct device_node;
79556
79557 -extern struct irq_chip gic_arch_extn;
79558 +extern irq_chip_no_const gic_arch_extn;
79559
79560 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79561 u32 offset, struct device_node *);
79562 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79563 index 1f44466..b481806 100644
79564 --- a/include/linux/jiffies.h
79565 +++ b/include/linux/jiffies.h
79566 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
79567 /*
79568 * Convert various time units to each other:
79569 */
79570 -extern unsigned int jiffies_to_msecs(const unsigned long j);
79571 -extern unsigned int jiffies_to_usecs(const unsigned long j);
79572 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79573 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79574
79575 -static inline u64 jiffies_to_nsecs(const unsigned long j)
79576 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
79577 {
79578 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
79579 }
79580
79581 -extern unsigned long msecs_to_jiffies(const unsigned int m);
79582 -extern unsigned long usecs_to_jiffies(const unsigned int u);
79583 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79584 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79585 extern unsigned long timespec_to_jiffies(const struct timespec *value);
79586 extern void jiffies_to_timespec(const unsigned long jiffies,
79587 - struct timespec *value);
79588 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
79589 + struct timespec *value) __intentional_overflow(-1);
79590 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79591 extern void jiffies_to_timeval(const unsigned long jiffies,
79592 struct timeval *value);
79593
79594 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79595 index 6883e19..e854fcb 100644
79596 --- a/include/linux/kallsyms.h
79597 +++ b/include/linux/kallsyms.h
79598 @@ -15,7 +15,8 @@
79599
79600 struct module;
79601
79602 -#ifdef CONFIG_KALLSYMS
79603 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79604 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79605 /* Lookup the address for a symbol. Returns 0 if not found. */
79606 unsigned long kallsyms_lookup_name(const char *name);
79607
79608 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79609 /* Stupid that this does nothing, but I didn't create this mess. */
79610 #define __print_symbol(fmt, addr)
79611 #endif /*CONFIG_KALLSYMS*/
79612 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79613 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79614 +extern unsigned long kallsyms_lookup_name(const char *name);
79615 +extern void __print_symbol(const char *fmt, unsigned long address);
79616 +extern int sprint_backtrace(char *buffer, unsigned long address);
79617 +extern int sprint_symbol(char *buffer, unsigned long address);
79618 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79619 +const char *kallsyms_lookup(unsigned long addr,
79620 + unsigned long *symbolsize,
79621 + unsigned long *offset,
79622 + char **modname, char *namebuf);
79623 +extern int kallsyms_lookup_size_offset(unsigned long addr,
79624 + unsigned long *symbolsize,
79625 + unsigned long *offset);
79626 +#endif
79627
79628 /* This macro allows us to keep printk typechecking */
79629 static __printf(1, 2)
79630 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79631 index a74c3a8..28d3f21 100644
79632 --- a/include/linux/key-type.h
79633 +++ b/include/linux/key-type.h
79634 @@ -131,7 +131,7 @@ struct key_type {
79635 /* internal fields */
79636 struct list_head link; /* link in types list */
79637 struct lock_class_key lock_class; /* key->sem lock class */
79638 -};
79639 +} __do_const;
79640
79641 extern struct key_type key_type_keyring;
79642
79643 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79644 index 6b06d37..c134867 100644
79645 --- a/include/linux/kgdb.h
79646 +++ b/include/linux/kgdb.h
79647 @@ -52,7 +52,7 @@ extern int kgdb_connected;
79648 extern int kgdb_io_module_registered;
79649
79650 extern atomic_t kgdb_setting_breakpoint;
79651 -extern atomic_t kgdb_cpu_doing_single_step;
79652 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79653
79654 extern struct task_struct *kgdb_usethread;
79655 extern struct task_struct *kgdb_contthread;
79656 @@ -254,7 +254,7 @@ struct kgdb_arch {
79657 void (*correct_hw_break)(void);
79658
79659 void (*enable_nmi)(bool on);
79660 -};
79661 +} __do_const;
79662
79663 /**
79664 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79665 @@ -279,7 +279,7 @@ struct kgdb_io {
79666 void (*pre_exception) (void);
79667 void (*post_exception) (void);
79668 int is_console;
79669 -};
79670 +} __do_const;
79671
79672 extern struct kgdb_arch arch_kgdb_ops;
79673
79674 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79675 index 0555cc6..40116ce 100644
79676 --- a/include/linux/kmod.h
79677 +++ b/include/linux/kmod.h
79678 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79679 * usually useless though. */
79680 extern __printf(2, 3)
79681 int __request_module(bool wait, const char *name, ...);
79682 +extern __printf(3, 4)
79683 +int ___request_module(bool wait, char *param_name, const char *name, ...);
79684 #define request_module(mod...) __request_module(true, mod)
79685 #define request_module_nowait(mod...) __request_module(false, mod)
79686 #define try_then_request_module(x, mod...) \
79687 @@ -57,6 +59,9 @@ struct subprocess_info {
79688 struct work_struct work;
79689 struct completion *complete;
79690 char *path;
79691 +#ifdef CONFIG_GRKERNSEC
79692 + char *origpath;
79693 +#endif
79694 char **argv;
79695 char **envp;
79696 int wait;
79697 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79698 index 926afb6..58dd6e5 100644
79699 --- a/include/linux/kobject.h
79700 +++ b/include/linux/kobject.h
79701 @@ -116,7 +116,7 @@ struct kobj_type {
79702 struct attribute **default_attrs;
79703 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79704 const void *(*namespace)(struct kobject *kobj);
79705 -};
79706 +} __do_const;
79707
79708 struct kobj_uevent_env {
79709 char *envp[UEVENT_NUM_ENVP];
79710 @@ -139,6 +139,7 @@ struct kobj_attribute {
79711 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79712 const char *buf, size_t count);
79713 };
79714 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79715
79716 extern const struct sysfs_ops kobj_sysfs_ops;
79717
79718 @@ -166,7 +167,7 @@ struct kset {
79719 spinlock_t list_lock;
79720 struct kobject kobj;
79721 const struct kset_uevent_ops *uevent_ops;
79722 -};
79723 +} __randomize_layout;
79724
79725 extern void kset_init(struct kset *kset);
79726 extern int __must_check kset_register(struct kset *kset);
79727 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79728 index df32d25..fb52e27 100644
79729 --- a/include/linux/kobject_ns.h
79730 +++ b/include/linux/kobject_ns.h
79731 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79732 const void *(*netlink_ns)(struct sock *sk);
79733 const void *(*initial_ns)(void);
79734 void (*drop_ns)(void *);
79735 -};
79736 +} __do_const;
79737
79738 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79739 int kobj_ns_type_registered(enum kobj_ns_type type);
79740 diff --git a/include/linux/kref.h b/include/linux/kref.h
79741 index 484604d..0f6c5b6 100644
79742 --- a/include/linux/kref.h
79743 +++ b/include/linux/kref.h
79744 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79745 static inline int kref_sub(struct kref *kref, unsigned int count,
79746 void (*release)(struct kref *kref))
79747 {
79748 - WARN_ON(release == NULL);
79749 + BUG_ON(release == NULL);
79750
79751 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79752 release(kref);
79753 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79754 index b8e9a43..632678d 100644
79755 --- a/include/linux/kvm_host.h
79756 +++ b/include/linux/kvm_host.h
79757 @@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
79758 {
79759 }
79760 #endif
79761 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79762 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79763 struct module *module);
79764 void kvm_exit(void);
79765
79766 @@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79767 struct kvm_guest_debug *dbg);
79768 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79769
79770 -int kvm_arch_init(void *opaque);
79771 +int kvm_arch_init(const void *opaque);
79772 void kvm_arch_exit(void);
79773
79774 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79775 diff --git a/include/linux/libata.h b/include/linux/libata.h
79776 index bec6dbe..2873d64 100644
79777 --- a/include/linux/libata.h
79778 +++ b/include/linux/libata.h
79779 @@ -975,7 +975,7 @@ struct ata_port_operations {
79780 * fields must be pointers.
79781 */
79782 const struct ata_port_operations *inherits;
79783 -};
79784 +} __do_const;
79785
79786 struct ata_port_info {
79787 unsigned long flags;
79788 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79789 index a6a42dd..6c5ebce 100644
79790 --- a/include/linux/linkage.h
79791 +++ b/include/linux/linkage.h
79792 @@ -36,6 +36,7 @@
79793 #endif
79794
79795 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79796 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79797 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79798
79799 /*
79800 diff --git a/include/linux/list.h b/include/linux/list.h
79801 index ef95941..82db65a 100644
79802 --- a/include/linux/list.h
79803 +++ b/include/linux/list.h
79804 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79805 extern void list_del(struct list_head *entry);
79806 #endif
79807
79808 +extern void __pax_list_add(struct list_head *new,
79809 + struct list_head *prev,
79810 + struct list_head *next);
79811 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
79812 +{
79813 + __pax_list_add(new, head, head->next);
79814 +}
79815 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79816 +{
79817 + __pax_list_add(new, head->prev, head);
79818 +}
79819 +extern void pax_list_del(struct list_head *entry);
79820 +
79821 /**
79822 * list_replace - replace old entry by new one
79823 * @old : the element to be replaced
79824 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79825 INIT_LIST_HEAD(entry);
79826 }
79827
79828 +extern void pax_list_del_init(struct list_head *entry);
79829 +
79830 /**
79831 * list_move - delete from one list and add as another's head
79832 * @list: the entry to move
79833 diff --git a/include/linux/math64.h b/include/linux/math64.h
79834 index c45c089..298841c 100644
79835 --- a/include/linux/math64.h
79836 +++ b/include/linux/math64.h
79837 @@ -15,7 +15,7 @@
79838 * This is commonly provided by 32bit archs to provide an optimized 64bit
79839 * divide.
79840 */
79841 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79842 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79843 {
79844 *remainder = dividend % divisor;
79845 return dividend / divisor;
79846 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79847 /**
79848 * div64_u64 - unsigned 64bit divide with 64bit divisor
79849 */
79850 -static inline u64 div64_u64(u64 dividend, u64 divisor)
79851 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79852 {
79853 return dividend / divisor;
79854 }
79855 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79856 #define div64_ul(x, y) div_u64((x), (y))
79857
79858 #ifndef div_u64_rem
79859 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79860 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79861 {
79862 *remainder = do_div(dividend, divisor);
79863 return dividend;
79864 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79865 #endif
79866
79867 #ifndef div64_u64
79868 -extern u64 div64_u64(u64 dividend, u64 divisor);
79869 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79870 #endif
79871
79872 #ifndef div64_s64
79873 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79874 * divide.
79875 */
79876 #ifndef div_u64
79877 -static inline u64 div_u64(u64 dividend, u32 divisor)
79878 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79879 {
79880 u32 remainder;
79881 return div_u64_rem(dividend, divisor, &remainder);
79882 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79883 index 5f1ea75..5125ac5 100644
79884 --- a/include/linux/mempolicy.h
79885 +++ b/include/linux/mempolicy.h
79886 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79887 }
79888
79889 #define vma_policy(vma) ((vma)->vm_policy)
79890 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79891 +{
79892 + vma->vm_policy = pol;
79893 +}
79894
79895 static inline void mpol_get(struct mempolicy *pol)
79896 {
79897 @@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
79898 }
79899
79900 #define vma_policy(vma) NULL
79901 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79902 +{
79903 +}
79904
79905 static inline int
79906 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79907 diff --git a/include/linux/mm.h b/include/linux/mm.h
79908 index c1b7414..5ea2ad8 100644
79909 --- a/include/linux/mm.h
79910 +++ b/include/linux/mm.h
79911 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
79912 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79913 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79914 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79915 +
79916 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79917 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79918 +#endif
79919 +
79920 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79921
79922 #ifdef CONFIG_MEM_SOFT_DIRTY
79923 @@ -229,8 +234,8 @@ struct vm_operations_struct {
79924 /* called by access_process_vm when get_user_pages() fails, typically
79925 * for use by special VMAs that can switch between memory and hardware
79926 */
79927 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
79928 - void *buf, int len, int write);
79929 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79930 + void *buf, size_t len, int write);
79931 #ifdef CONFIG_NUMA
79932 /*
79933 * set_policy() op must add a reference to any non-NULL @new mempolicy
79934 @@ -260,6 +265,7 @@ struct vm_operations_struct {
79935 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79936 unsigned long size, pgoff_t pgoff);
79937 };
79938 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79939
79940 struct mmu_gather;
79941 struct inode;
79942 @@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79943 unsigned long *pfn);
79944 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79945 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79946 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79947 - void *buf, int len, int write);
79948 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79949 + void *buf, size_t len, int write);
79950
79951 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79952 loff_t const holebegin, loff_t const holelen)
79953 @@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79954 }
79955 #endif
79956
79957 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79958 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79959 - void *buf, int len, int write);
79960 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79961 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79962 + void *buf, size_t len, int write);
79963
79964 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79965 unsigned long start, unsigned long nr_pages,
79966 @@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
79967 int set_page_dirty_lock(struct page *page);
79968 int clear_page_dirty_for_io(struct page *page);
79969
79970 -/* Is the vma a continuation of the stack vma above it? */
79971 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79972 -{
79973 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79974 -}
79975 -
79976 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
79977 - unsigned long addr)
79978 -{
79979 - return (vma->vm_flags & VM_GROWSDOWN) &&
79980 - (vma->vm_start == addr) &&
79981 - !vma_growsdown(vma->vm_prev, addr);
79982 -}
79983 -
79984 -/* Is the vma a continuation of the stack vma below it? */
79985 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79986 -{
79987 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79988 -}
79989 -
79990 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
79991 - unsigned long addr)
79992 -{
79993 - return (vma->vm_flags & VM_GROWSUP) &&
79994 - (vma->vm_end == addr) &&
79995 - !vma_growsup(vma->vm_next, addr);
79996 -}
79997 -
79998 extern pid_t
79999 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80000
80001 @@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80002 }
80003 #endif
80004
80005 +#ifdef CONFIG_MMU
80006 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80007 +#else
80008 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80009 +{
80010 + return __pgprot(0);
80011 +}
80012 +#endif
80013 +
80014 int vma_wants_writenotify(struct vm_area_struct *vma);
80015
80016 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80017 @@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80018 {
80019 return 0;
80020 }
80021 +
80022 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80023 + unsigned long address)
80024 +{
80025 + return 0;
80026 +}
80027 #else
80028 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80029 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80030 #endif
80031
80032 #ifdef __PAGETABLE_PMD_FOLDED
80033 @@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80034 {
80035 return 0;
80036 }
80037 +
80038 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80039 + unsigned long address)
80040 +{
80041 + return 0;
80042 +}
80043 #else
80044 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80045 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80046 #endif
80047
80048 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80049 @@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80050 NULL: pud_offset(pgd, address);
80051 }
80052
80053 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80054 +{
80055 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80056 + NULL: pud_offset(pgd, address);
80057 +}
80058 +
80059 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80060 {
80061 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80062 NULL: pmd_offset(pud, address);
80063 }
80064 +
80065 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80066 +{
80067 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80068 + NULL: pmd_offset(pud, address);
80069 +}
80070 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80071
80072 #if USE_SPLIT_PTE_PTLOCKS
80073 @@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80074 unsigned long addr, unsigned long len,
80075 unsigned long flags, struct page **pages);
80076
80077 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80078 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80079
80080 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80081 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80082 @@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80083 unsigned long len, unsigned long prot, unsigned long flags,
80084 unsigned long pgoff, unsigned long *populate);
80085 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80086 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80087
80088 #ifdef CONFIG_MMU
80089 extern int __mm_populate(unsigned long addr, unsigned long len,
80090 @@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80091 unsigned long high_limit;
80092 unsigned long align_mask;
80093 unsigned long align_offset;
80094 + unsigned long threadstack_offset;
80095 };
80096
80097 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80098 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80099 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80100 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80101
80102 /*
80103 * Search for an unmapped address range.
80104 @@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80105 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80106 */
80107 static inline unsigned long
80108 -vm_unmapped_area(struct vm_unmapped_area_info *info)
80109 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
80110 {
80111 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80112 return unmapped_area(info);
80113 @@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80114 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80115 struct vm_area_struct **pprev);
80116
80117 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80118 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80119 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80120 +
80121 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80122 NULL if none. Assume start_addr < end_addr. */
80123 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80124 @@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80125 return vma;
80126 }
80127
80128 -#ifdef CONFIG_MMU
80129 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
80130 -#else
80131 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80132 -{
80133 - return __pgprot(0);
80134 -}
80135 -#endif
80136 -
80137 #ifdef CONFIG_NUMA_BALANCING
80138 unsigned long change_prot_numa(struct vm_area_struct *vma,
80139 unsigned long start, unsigned long end);
80140 @@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80141 static inline void vm_stat_account(struct mm_struct *mm,
80142 unsigned long flags, struct file *file, long pages)
80143 {
80144 +
80145 +#ifdef CONFIG_PAX_RANDMMAP
80146 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80147 +#endif
80148 +
80149 mm->total_vm += pages;
80150 }
80151 #endif /* CONFIG_PROC_FS */
80152 @@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80153 extern int sysctl_memory_failure_early_kill;
80154 extern int sysctl_memory_failure_recovery;
80155 extern void shake_page(struct page *p, int access);
80156 -extern atomic_long_t num_poisoned_pages;
80157 +extern atomic_long_unchecked_t num_poisoned_pages;
80158 extern int soft_offline_page(struct page *page, int flags);
80159
80160 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80161 @@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80162 static inline void setup_nr_node_ids(void) {}
80163 #endif
80164
80165 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80166 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80167 +#else
80168 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80169 +#endif
80170 +
80171 #endif /* __KERNEL__ */
80172 #endif /* _LINUX_MM_H */
80173 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80174 index 290901a..e99b01c 100644
80175 --- a/include/linux/mm_types.h
80176 +++ b/include/linux/mm_types.h
80177 @@ -307,7 +307,9 @@ struct vm_area_struct {
80178 #ifdef CONFIG_NUMA
80179 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80180 #endif
80181 -};
80182 +
80183 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80184 +} __randomize_layout;
80185
80186 struct core_thread {
80187 struct task_struct *task;
80188 @@ -453,7 +455,25 @@ struct mm_struct {
80189 bool tlb_flush_pending;
80190 #endif
80191 struct uprobes_state uprobes_state;
80192 -};
80193 +
80194 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80195 + unsigned long pax_flags;
80196 +#endif
80197 +
80198 +#ifdef CONFIG_PAX_DLRESOLVE
80199 + unsigned long call_dl_resolve;
80200 +#endif
80201 +
80202 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80203 + unsigned long call_syscall;
80204 +#endif
80205 +
80206 +#ifdef CONFIG_PAX_ASLR
80207 + unsigned long delta_mmap; /* randomized offset */
80208 + unsigned long delta_stack; /* randomized offset */
80209 +#endif
80210 +
80211 +} __randomize_layout;
80212
80213 static inline void mm_init_cpumask(struct mm_struct *mm)
80214 {
80215 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80216 index c5d5278..f0b68c8 100644
80217 --- a/include/linux/mmiotrace.h
80218 +++ b/include/linux/mmiotrace.h
80219 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80220 /* Called from ioremap.c */
80221 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80222 void __iomem *addr);
80223 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
80224 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80225
80226 /* For anyone to insert markers. Remember trailing newline. */
80227 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80228 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80229 {
80230 }
80231
80232 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80233 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80234 {
80235 }
80236
80237 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80238 index 9b61b9b..52147d6b 100644
80239 --- a/include/linux/mmzone.h
80240 +++ b/include/linux/mmzone.h
80241 @@ -396,7 +396,7 @@ struct zone {
80242 unsigned long flags; /* zone flags, see below */
80243
80244 /* Zone statistics */
80245 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80246 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80247
80248 /*
80249 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80250 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80251 index 45e9214..a7227d6 100644
80252 --- a/include/linux/mod_devicetable.h
80253 +++ b/include/linux/mod_devicetable.h
80254 @@ -13,7 +13,7 @@
80255 typedef unsigned long kernel_ulong_t;
80256 #endif
80257
80258 -#define PCI_ANY_ID (~0)
80259 +#define PCI_ANY_ID ((__u16)~0)
80260
80261 struct pci_device_id {
80262 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80263 @@ -139,7 +139,7 @@ struct usb_device_id {
80264 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80265 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80266
80267 -#define HID_ANY_ID (~0)
80268 +#define HID_ANY_ID (~0U)
80269 #define HID_BUS_ANY 0xffff
80270 #define HID_GROUP_ANY 0x0000
80271
80272 @@ -467,7 +467,7 @@ struct dmi_system_id {
80273 const char *ident;
80274 struct dmi_strmatch matches[4];
80275 void *driver_data;
80276 -};
80277 +} __do_const;
80278 /*
80279 * struct dmi_device_id appears during expansion of
80280 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80281 diff --git a/include/linux/module.h b/include/linux/module.h
80282 index eaf60ff..641979a 100644
80283 --- a/include/linux/module.h
80284 +++ b/include/linux/module.h
80285 @@ -17,9 +17,11 @@
80286 #include <linux/moduleparam.h>
80287 #include <linux/tracepoint.h>
80288 #include <linux/export.h>
80289 +#include <linux/fs.h>
80290
80291 #include <linux/percpu.h>
80292 #include <asm/module.h>
80293 +#include <asm/pgtable.h>
80294
80295 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80296 #define MODULE_SIG_STRING "~Module signature appended~\n"
80297 @@ -42,7 +44,7 @@ struct module_kobject {
80298 struct kobject *drivers_dir;
80299 struct module_param_attrs *mp;
80300 struct completion *kobj_completion;
80301 -};
80302 +} __randomize_layout;
80303
80304 struct module_attribute {
80305 struct attribute attr;
80306 @@ -54,12 +56,13 @@ struct module_attribute {
80307 int (*test)(struct module *);
80308 void (*free)(struct module *);
80309 };
80310 +typedef struct module_attribute __no_const module_attribute_no_const;
80311
80312 struct module_version_attribute {
80313 struct module_attribute mattr;
80314 const char *module_name;
80315 const char *version;
80316 -} __attribute__ ((__aligned__(sizeof(void *))));
80317 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80318
80319 extern ssize_t __modver_version_show(struct module_attribute *,
80320 struct module_kobject *, char *);
80321 @@ -238,7 +241,7 @@ struct module {
80322
80323 /* Sysfs stuff. */
80324 struct module_kobject mkobj;
80325 - struct module_attribute *modinfo_attrs;
80326 + module_attribute_no_const *modinfo_attrs;
80327 const char *version;
80328 const char *srcversion;
80329 struct kobject *holders_dir;
80330 @@ -287,19 +290,16 @@ struct module {
80331 int (*init)(void);
80332
80333 /* If this is non-NULL, vfree after init() returns */
80334 - void *module_init;
80335 + void *module_init_rx, *module_init_rw;
80336
80337 /* Here is the actual code + data, vfree'd on unload. */
80338 - void *module_core;
80339 + void *module_core_rx, *module_core_rw;
80340
80341 /* Here are the sizes of the init and core sections */
80342 - unsigned int init_size, core_size;
80343 + unsigned int init_size_rw, core_size_rw;
80344
80345 /* The size of the executable code in each section. */
80346 - unsigned int init_text_size, core_text_size;
80347 -
80348 - /* Size of RO sections of the module (text+rodata) */
80349 - unsigned int init_ro_size, core_ro_size;
80350 + unsigned int init_size_rx, core_size_rx;
80351
80352 /* Arch-specific module values */
80353 struct mod_arch_specific arch;
80354 @@ -355,6 +355,10 @@ struct module {
80355 #ifdef CONFIG_EVENT_TRACING
80356 struct ftrace_event_call **trace_events;
80357 unsigned int num_trace_events;
80358 + struct file_operations trace_id;
80359 + struct file_operations trace_enable;
80360 + struct file_operations trace_format;
80361 + struct file_operations trace_filter;
80362 #endif
80363 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80364 unsigned int num_ftrace_callsites;
80365 @@ -378,7 +382,7 @@ struct module {
80366 ctor_fn_t *ctors;
80367 unsigned int num_ctors;
80368 #endif
80369 -};
80370 +} __randomize_layout;
80371 #ifndef MODULE_ARCH_INIT
80372 #define MODULE_ARCH_INIT {}
80373 #endif
80374 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80375 bool is_module_percpu_address(unsigned long addr);
80376 bool is_module_text_address(unsigned long addr);
80377
80378 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80379 +{
80380 +
80381 +#ifdef CONFIG_PAX_KERNEXEC
80382 + if (ktla_ktva(addr) >= (unsigned long)start &&
80383 + ktla_ktva(addr) < (unsigned long)start + size)
80384 + return 1;
80385 +#endif
80386 +
80387 + return ((void *)addr >= start && (void *)addr < start + size);
80388 +}
80389 +
80390 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80391 +{
80392 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80393 +}
80394 +
80395 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80396 +{
80397 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80398 +}
80399 +
80400 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80401 +{
80402 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80403 +}
80404 +
80405 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80406 +{
80407 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80408 +}
80409 +
80410 static inline int within_module_core(unsigned long addr, const struct module *mod)
80411 {
80412 - return (unsigned long)mod->module_core <= addr &&
80413 - addr < (unsigned long)mod->module_core + mod->core_size;
80414 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80415 }
80416
80417 static inline int within_module_init(unsigned long addr, const struct module *mod)
80418 {
80419 - return (unsigned long)mod->module_init <= addr &&
80420 - addr < (unsigned long)mod->module_init + mod->init_size;
80421 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80422 }
80423
80424 /* Search for module by name: must hold module_mutex. */
80425 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80426 index 560ca53..ef621ef 100644
80427 --- a/include/linux/moduleloader.h
80428 +++ b/include/linux/moduleloader.h
80429 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80430 sections. Returns NULL on failure. */
80431 void *module_alloc(unsigned long size);
80432
80433 +#ifdef CONFIG_PAX_KERNEXEC
80434 +void *module_alloc_exec(unsigned long size);
80435 +#else
80436 +#define module_alloc_exec(x) module_alloc(x)
80437 +#endif
80438 +
80439 /* Free memory returned from module_alloc. */
80440 void module_free(struct module *mod, void *module_region);
80441
80442 +#ifdef CONFIG_PAX_KERNEXEC
80443 +void module_free_exec(struct module *mod, void *module_region);
80444 +#else
80445 +#define module_free_exec(x, y) module_free((x), (y))
80446 +#endif
80447 +
80448 /*
80449 * Apply the given relocation to the (simplified) ELF. Return -error
80450 * or 0.
80451 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80452 unsigned int relsec,
80453 struct module *me)
80454 {
80455 +#ifdef CONFIG_MODULES
80456 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80457 +#endif
80458 return -ENOEXEC;
80459 }
80460 #endif
80461 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80462 unsigned int relsec,
80463 struct module *me)
80464 {
80465 +#ifdef CONFIG_MODULES
80466 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80467 +#endif
80468 return -ENOEXEC;
80469 }
80470 #endif
80471 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80472 index c3eb102..073c4a6 100644
80473 --- a/include/linux/moduleparam.h
80474 +++ b/include/linux/moduleparam.h
80475 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80476 * @len is usually just sizeof(string).
80477 */
80478 #define module_param_string(name, string, len, perm) \
80479 - static const struct kparam_string __param_string_##name \
80480 + static const struct kparam_string __param_string_##name __used \
80481 = { len, string }; \
80482 __module_param_call(MODULE_PARAM_PREFIX, name, \
80483 &param_ops_string, \
80484 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80485 */
80486 #define module_param_array_named(name, array, type, nump, perm) \
80487 param_check_##type(name, &(array)[0]); \
80488 - static const struct kparam_array __param_arr_##name \
80489 + static const struct kparam_array __param_arr_##name __used \
80490 = { .max = ARRAY_SIZE(array), .num = nump, \
80491 .ops = &param_ops_##type, \
80492 .elemsize = sizeof(array[0]), .elem = array }; \
80493 diff --git a/include/linux/mount.h b/include/linux/mount.h
80494 index 371d346..fba2819 100644
80495 --- a/include/linux/mount.h
80496 +++ b/include/linux/mount.h
80497 @@ -56,7 +56,7 @@ struct vfsmount {
80498 struct dentry *mnt_root; /* root of the mounted tree */
80499 struct super_block *mnt_sb; /* pointer to superblock */
80500 int mnt_flags;
80501 -};
80502 +} __randomize_layout;
80503
80504 struct file; /* forward dec */
80505
80506 diff --git a/include/linux/namei.h b/include/linux/namei.h
80507 index 492de72..1bddcd4 100644
80508 --- a/include/linux/namei.h
80509 +++ b/include/linux/namei.h
80510 @@ -19,7 +19,7 @@ struct nameidata {
80511 unsigned seq, m_seq;
80512 int last_type;
80513 unsigned depth;
80514 - char *saved_names[MAX_NESTED_LINKS + 1];
80515 + const char *saved_names[MAX_NESTED_LINKS + 1];
80516 };
80517
80518 /*
80519 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80520
80521 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80522
80523 -static inline void nd_set_link(struct nameidata *nd, char *path)
80524 +static inline void nd_set_link(struct nameidata *nd, const char *path)
80525 {
80526 nd->saved_names[nd->depth] = path;
80527 }
80528
80529 -static inline char *nd_get_link(struct nameidata *nd)
80530 +static inline const char *nd_get_link(const struct nameidata *nd)
80531 {
80532 return nd->saved_names[nd->depth];
80533 }
80534 diff --git a/include/linux/net.h b/include/linux/net.h
80535 index 94734a6..d8d6931 100644
80536 --- a/include/linux/net.h
80537 +++ b/include/linux/net.h
80538 @@ -192,7 +192,7 @@ struct net_proto_family {
80539 int (*create)(struct net *net, struct socket *sock,
80540 int protocol, int kern);
80541 struct module *owner;
80542 -};
80543 +} __do_const;
80544
80545 struct iovec;
80546 struct kvec;
80547 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80548 index daafd95..74c5d1e 100644
80549 --- a/include/linux/netdevice.h
80550 +++ b/include/linux/netdevice.h
80551 @@ -1146,6 +1146,7 @@ struct net_device_ops {
80552 struct net_device *dev,
80553 void *priv);
80554 };
80555 +typedef struct net_device_ops __no_const net_device_ops_no_const;
80556
80557 /*
80558 * The DEVICE structure.
80559 @@ -1228,7 +1229,7 @@ struct net_device {
80560 int iflink;
80561
80562 struct net_device_stats stats;
80563 - atomic_long_t rx_dropped; /* dropped packets by core network
80564 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80565 * Do not use this in drivers.
80566 */
80567
80568 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80569 index 2077489..a15e561 100644
80570 --- a/include/linux/netfilter.h
80571 +++ b/include/linux/netfilter.h
80572 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80573 #endif
80574 /* Use the module struct to lock set/get code in place */
80575 struct module *owner;
80576 -};
80577 +} __do_const;
80578
80579 /* Function to register/unregister hook points. */
80580 int nf_register_hook(struct nf_hook_ops *reg);
80581 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80582 index 28c7436..2d6156a 100644
80583 --- a/include/linux/netfilter/nfnetlink.h
80584 +++ b/include/linux/netfilter/nfnetlink.h
80585 @@ -19,7 +19,7 @@ struct nfnl_callback {
80586 const struct nlattr * const cda[]);
80587 const struct nla_policy *policy; /* netlink attribute policy */
80588 const u_int16_t attr_count; /* number of nlattr's */
80589 -};
80590 +} __do_const;
80591
80592 struct nfnetlink_subsystem {
80593 const char *name;
80594 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80595 new file mode 100644
80596 index 0000000..33f4af8
80597 --- /dev/null
80598 +++ b/include/linux/netfilter/xt_gradm.h
80599 @@ -0,0 +1,9 @@
80600 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
80601 +#define _LINUX_NETFILTER_XT_GRADM_H 1
80602 +
80603 +struct xt_gradm_mtinfo {
80604 + __u16 flags;
80605 + __u16 invflags;
80606 +};
80607 +
80608 +#endif
80609 diff --git a/include/linux/nls.h b/include/linux/nls.h
80610 index 520681b..1d67ed2 100644
80611 --- a/include/linux/nls.h
80612 +++ b/include/linux/nls.h
80613 @@ -31,7 +31,7 @@ struct nls_table {
80614 const unsigned char *charset2upper;
80615 struct module *owner;
80616 struct nls_table *next;
80617 -};
80618 +} __do_const;
80619
80620 /* this value hold the maximum octet of charset */
80621 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80622 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80623 index d14a4c3..a078786 100644
80624 --- a/include/linux/notifier.h
80625 +++ b/include/linux/notifier.h
80626 @@ -54,7 +54,8 @@ struct notifier_block {
80627 notifier_fn_t notifier_call;
80628 struct notifier_block __rcu *next;
80629 int priority;
80630 -};
80631 +} __do_const;
80632 +typedef struct notifier_block __no_const notifier_block_no_const;
80633
80634 struct atomic_notifier_head {
80635 spinlock_t lock;
80636 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80637 index b2a0f15..4d7da32 100644
80638 --- a/include/linux/oprofile.h
80639 +++ b/include/linux/oprofile.h
80640 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80641 int oprofilefs_create_ro_ulong(struct dentry * root,
80642 char const * name, ulong * val);
80643
80644 -/** Create a file for read-only access to an atomic_t. */
80645 +/** Create a file for read-only access to an atomic_unchecked_t. */
80646 int oprofilefs_create_ro_atomic(struct dentry * root,
80647 - char const * name, atomic_t * val);
80648 + char const * name, atomic_unchecked_t * val);
80649
80650 /** create a directory */
80651 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80652 diff --git a/include/linux/padata.h b/include/linux/padata.h
80653 index 4386946..f50c615 100644
80654 --- a/include/linux/padata.h
80655 +++ b/include/linux/padata.h
80656 @@ -129,7 +129,7 @@ struct parallel_data {
80657 struct padata_serial_queue __percpu *squeue;
80658 atomic_t reorder_objects;
80659 atomic_t refcnt;
80660 - atomic_t seq_nr;
80661 + atomic_unchecked_t seq_nr;
80662 struct padata_cpumask cpumask;
80663 spinlock_t lock ____cacheline_aligned;
80664 unsigned int processed;
80665 diff --git a/include/linux/path.h b/include/linux/path.h
80666 index d137218..be0c176 100644
80667 --- a/include/linux/path.h
80668 +++ b/include/linux/path.h
80669 @@ -1,13 +1,15 @@
80670 #ifndef _LINUX_PATH_H
80671 #define _LINUX_PATH_H
80672
80673 +#include <linux/compiler.h>
80674 +
80675 struct dentry;
80676 struct vfsmount;
80677
80678 struct path {
80679 struct vfsmount *mnt;
80680 struct dentry *dentry;
80681 -};
80682 +} __randomize_layout;
80683
80684 extern void path_get(const struct path *);
80685 extern void path_put(const struct path *);
80686 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80687 index 5f2e559..7d59314 100644
80688 --- a/include/linux/pci_hotplug.h
80689 +++ b/include/linux/pci_hotplug.h
80690 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80691 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80692 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80693 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80694 -};
80695 +} __do_const;
80696 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80697
80698 /**
80699 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80700 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80701 index e56b07f..aef789b 100644
80702 --- a/include/linux/perf_event.h
80703 +++ b/include/linux/perf_event.h
80704 @@ -328,8 +328,8 @@ struct perf_event {
80705
80706 enum perf_event_active_state state;
80707 unsigned int attach_state;
80708 - local64_t count;
80709 - atomic64_t child_count;
80710 + local64_t count; /* PaX: fix it one day */
80711 + atomic64_unchecked_t child_count;
80712
80713 /*
80714 * These are the total time in nanoseconds that the event
80715 @@ -380,8 +380,8 @@ struct perf_event {
80716 * These accumulate total time (in nanoseconds) that children
80717 * events have been enabled and running, respectively.
80718 */
80719 - atomic64_t child_total_time_enabled;
80720 - atomic64_t child_total_time_running;
80721 + atomic64_unchecked_t child_total_time_enabled;
80722 + atomic64_unchecked_t child_total_time_running;
80723
80724 /*
80725 * Protect attach/detach and child_list:
80726 @@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80727 entry->ip[entry->nr++] = ip;
80728 }
80729
80730 -extern int sysctl_perf_event_paranoid;
80731 +extern int sysctl_perf_event_legitimately_concerned;
80732 extern int sysctl_perf_event_mlock;
80733 extern int sysctl_perf_event_sample_rate;
80734 extern int sysctl_perf_cpu_time_max_percent;
80735 @@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80736 loff_t *ppos);
80737
80738
80739 +static inline bool perf_paranoid_any(void)
80740 +{
80741 + return sysctl_perf_event_legitimately_concerned > 2;
80742 +}
80743 +
80744 static inline bool perf_paranoid_tracepoint_raw(void)
80745 {
80746 - return sysctl_perf_event_paranoid > -1;
80747 + return sysctl_perf_event_legitimately_concerned > -1;
80748 }
80749
80750 static inline bool perf_paranoid_cpu(void)
80751 {
80752 - return sysctl_perf_event_paranoid > 0;
80753 + return sysctl_perf_event_legitimately_concerned > 0;
80754 }
80755
80756 static inline bool perf_paranoid_kernel(void)
80757 {
80758 - return sysctl_perf_event_paranoid > 1;
80759 + return sysctl_perf_event_legitimately_concerned > 1;
80760 }
80761
80762 extern void perf_event_init(void);
80763 @@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
80764 struct device_attribute attr;
80765 u64 id;
80766 const char *event_str;
80767 -};
80768 +} __do_const;
80769
80770 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80771 static struct perf_pmu_events_attr _var = { \
80772 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80773 index 7246ef3..1539ea4 100644
80774 --- a/include/linux/pid_namespace.h
80775 +++ b/include/linux/pid_namespace.h
80776 @@ -43,7 +43,7 @@ struct pid_namespace {
80777 int hide_pid;
80778 int reboot; /* group exit code if this pidns was rebooted */
80779 unsigned int proc_inum;
80780 -};
80781 +} __randomize_layout;
80782
80783 extern struct pid_namespace init_pid_ns;
80784
80785 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80786 index ab57526..94598804 100644
80787 --- a/include/linux/pipe_fs_i.h
80788 +++ b/include/linux/pipe_fs_i.h
80789 @@ -47,10 +47,10 @@ struct pipe_inode_info {
80790 struct mutex mutex;
80791 wait_queue_head_t wait;
80792 unsigned int nrbufs, curbuf, buffers;
80793 - unsigned int readers;
80794 - unsigned int writers;
80795 - unsigned int files;
80796 - unsigned int waiting_writers;
80797 + atomic_t readers;
80798 + atomic_t writers;
80799 + atomic_t files;
80800 + atomic_t waiting_writers;
80801 unsigned int r_counter;
80802 unsigned int w_counter;
80803 struct page *tmp_page;
80804 diff --git a/include/linux/pm.h b/include/linux/pm.h
80805 index 8c6583a..febb84c 100644
80806 --- a/include/linux/pm.h
80807 +++ b/include/linux/pm.h
80808 @@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80809 struct dev_pm_domain {
80810 struct dev_pm_ops ops;
80811 };
80812 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80813
80814 /*
80815 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80816 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80817 index 7c1d252..0e7061d 100644
80818 --- a/include/linux/pm_domain.h
80819 +++ b/include/linux/pm_domain.h
80820 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
80821 int (*thaw_early)(struct device *dev);
80822 int (*thaw)(struct device *dev);
80823 bool (*active_wakeup)(struct device *dev);
80824 -};
80825 +} __no_const;
80826
80827 struct gpd_cpu_data {
80828 unsigned int saved_exit_latency;
80829 - struct cpuidle_state *idle_state;
80830 + cpuidle_state_no_const *idle_state;
80831 };
80832
80833 struct generic_pm_domain {
80834 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80835 index 16c9a62..f9f0838 100644
80836 --- a/include/linux/pm_runtime.h
80837 +++ b/include/linux/pm_runtime.h
80838 @@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80839
80840 static inline void pm_runtime_mark_last_busy(struct device *dev)
80841 {
80842 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
80843 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80844 }
80845
80846 #else /* !CONFIG_PM_RUNTIME */
80847 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80848 index 195aafc..49a7bc2 100644
80849 --- a/include/linux/pnp.h
80850 +++ b/include/linux/pnp.h
80851 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80852 struct pnp_fixup {
80853 char id[7];
80854 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80855 -};
80856 +} __do_const;
80857
80858 /* config parameters */
80859 #define PNP_CONFIG_NORMAL 0x0001
80860 diff --git a/include/linux/poison.h b/include/linux/poison.h
80861 index 2110a81..13a11bb 100644
80862 --- a/include/linux/poison.h
80863 +++ b/include/linux/poison.h
80864 @@ -19,8 +19,8 @@
80865 * under normal circumstances, used to verify that nobody uses
80866 * non-initialized list entries.
80867 */
80868 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80869 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80870 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80871 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80872
80873 /********** include/linux/timer.h **********/
80874 /*
80875 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80876 index d8b187c3..9a9257a 100644
80877 --- a/include/linux/power/smartreflex.h
80878 +++ b/include/linux/power/smartreflex.h
80879 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
80880 int (*notify)(struct omap_sr *sr, u32 status);
80881 u8 notify_flags;
80882 u8 class_type;
80883 -};
80884 +} __do_const;
80885
80886 /**
80887 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80888 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80889 index 4ea1d37..80f4b33 100644
80890 --- a/include/linux/ppp-comp.h
80891 +++ b/include/linux/ppp-comp.h
80892 @@ -84,7 +84,7 @@ struct compressor {
80893 struct module *owner;
80894 /* Extra skb space needed by the compressor algorithm */
80895 unsigned int comp_extra;
80896 -};
80897 +} __do_const;
80898
80899 /*
80900 * The return value from decompress routine is the length of the
80901 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80902 index de83b4e..c4b997d 100644
80903 --- a/include/linux/preempt.h
80904 +++ b/include/linux/preempt.h
80905 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80906 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80907 #endif
80908
80909 +#define raw_preempt_count_add(val) __preempt_count_add(val)
80910 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80911 +
80912 #define __preempt_count_inc() __preempt_count_add(1)
80913 #define __preempt_count_dec() __preempt_count_sub(1)
80914
80915 #define preempt_count_inc() preempt_count_add(1)
80916 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
80917 #define preempt_count_dec() preempt_count_sub(1)
80918 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80919
80920 #ifdef CONFIG_PREEMPT_COUNT
80921
80922 @@ -41,6 +46,12 @@ do { \
80923 barrier(); \
80924 } while (0)
80925
80926 +#define raw_preempt_disable() \
80927 +do { \
80928 + raw_preempt_count_inc(); \
80929 + barrier(); \
80930 +} while (0)
80931 +
80932 #define sched_preempt_enable_no_resched() \
80933 do { \
80934 barrier(); \
80935 @@ -49,6 +60,12 @@ do { \
80936
80937 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80938
80939 +#define raw_preempt_enable_no_resched() \
80940 +do { \
80941 + barrier(); \
80942 + raw_preempt_count_dec(); \
80943 +} while (0)
80944 +
80945 #ifdef CONFIG_PREEMPT
80946 #define preempt_enable() \
80947 do { \
80948 @@ -113,8 +130,10 @@ do { \
80949 * region.
80950 */
80951 #define preempt_disable() barrier()
80952 +#define raw_preempt_disable() barrier()
80953 #define sched_preempt_enable_no_resched() barrier()
80954 #define preempt_enable_no_resched() barrier()
80955 +#define raw_preempt_enable_no_resched() barrier()
80956 #define preempt_enable() barrier()
80957 #define preempt_check_resched() do { } while (0)
80958
80959 @@ -128,11 +147,13 @@ do { \
80960 /*
80961 * Modules have no business playing preemption tricks.
80962 */
80963 +#ifndef CONFIG_PAX_KERNEXEC
80964 #undef sched_preempt_enable_no_resched
80965 #undef preempt_enable_no_resched
80966 #undef preempt_enable_no_resched_notrace
80967 #undef preempt_check_resched
80968 #endif
80969 +#endif
80970
80971 #define preempt_set_need_resched() \
80972 do { \
80973 diff --git a/include/linux/printk.h b/include/linux/printk.h
80974 index fa47e27..c08e034 100644
80975 --- a/include/linux/printk.h
80976 +++ b/include/linux/printk.h
80977 @@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
80978 void early_printk(const char *s, ...) { }
80979 #endif
80980
80981 +extern int kptr_restrict;
80982 +
80983 #ifdef CONFIG_PRINTK
80984 asmlinkage __printf(5, 0)
80985 int vprintk_emit(int facility, int level,
80986 @@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80987
80988 extern int printk_delay_msec;
80989 extern int dmesg_restrict;
80990 -extern int kptr_restrict;
80991
80992 extern void wake_up_klogd(void);
80993
80994 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80995 index 608e60a..c26f864 100644
80996 --- a/include/linux/proc_fs.h
80997 +++ b/include/linux/proc_fs.h
80998 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80999 return proc_create_data(name, mode, parent, proc_fops, NULL);
81000 }
81001
81002 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81003 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81004 +{
81005 +#ifdef CONFIG_GRKERNSEC_PROC_USER
81006 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81007 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81008 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81009 +#else
81010 + return proc_create_data(name, mode, parent, proc_fops, NULL);
81011 +#endif
81012 +}
81013 +
81014 +
81015 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81016 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81017 extern void *PDE_DATA(const struct inode *);
81018 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81019 index 34a1e10..70f6bde 100644
81020 --- a/include/linux/proc_ns.h
81021 +++ b/include/linux/proc_ns.h
81022 @@ -14,7 +14,7 @@ struct proc_ns_operations {
81023 void (*put)(void *ns);
81024 int (*install)(struct nsproxy *nsproxy, void *ns);
81025 unsigned int (*inum)(void *ns);
81026 -};
81027 +} __do_const __randomize_layout;
81028
81029 struct proc_ns {
81030 void *ns;
81031 diff --git a/include/linux/quota.h b/include/linux/quota.h
81032 index cc7494a..1e27036 100644
81033 --- a/include/linux/quota.h
81034 +++ b/include/linux/quota.h
81035 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81036
81037 extern bool qid_eq(struct kqid left, struct kqid right);
81038 extern bool qid_lt(struct kqid left, struct kqid right);
81039 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81040 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81041 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81042 extern bool qid_valid(struct kqid qid);
81043
81044 diff --git a/include/linux/random.h b/include/linux/random.h
81045 index 1cfce0e..b0b9235 100644
81046 --- a/include/linux/random.h
81047 +++ b/include/linux/random.h
81048 @@ -9,9 +9,19 @@
81049 #include <uapi/linux/random.h>
81050
81051 extern void add_device_randomness(const void *, unsigned int);
81052 +
81053 +static inline void add_latent_entropy(void)
81054 +{
81055 +
81056 +#ifdef LATENT_ENTROPY_PLUGIN
81057 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81058 +#endif
81059 +
81060 +}
81061 +
81062 extern void add_input_randomness(unsigned int type, unsigned int code,
81063 - unsigned int value);
81064 -extern void add_interrupt_randomness(int irq, int irq_flags);
81065 + unsigned int value) __latent_entropy;
81066 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81067
81068 extern void get_random_bytes(void *buf, int nbytes);
81069 extern void get_random_bytes_arch(void *buf, int nbytes);
81070 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81071 extern const struct file_operations random_fops, urandom_fops;
81072 #endif
81073
81074 -unsigned int get_random_int(void);
81075 +unsigned int __intentional_overflow(-1) get_random_int(void);
81076 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81077
81078 -u32 prandom_u32(void);
81079 +u32 prandom_u32(void) __intentional_overflow(-1);
81080 void prandom_bytes(void *buf, int nbytes);
81081 void prandom_seed(u32 seed);
81082 void prandom_reseed_late(void);
81083 @@ -37,6 +47,11 @@ struct rnd_state {
81084 u32 prandom_u32_state(struct rnd_state *state);
81085 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81086
81087 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81088 +{
81089 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81090 +}
81091 +
81092 /**
81093 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81094 * @ep_ro: right open interval endpoint
81095 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81096 index fea49b5..2ac22bb 100644
81097 --- a/include/linux/rbtree_augmented.h
81098 +++ b/include/linux/rbtree_augmented.h
81099 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81100 old->rbaugmented = rbcompute(old); \
81101 } \
81102 rbstatic const struct rb_augment_callbacks rbname = { \
81103 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81104 + .propagate = rbname ## _propagate, \
81105 + .copy = rbname ## _copy, \
81106 + .rotate = rbname ## _rotate \
81107 };
81108
81109
81110 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81111 index dbaf990..52e07b8 100644
81112 --- a/include/linux/rculist.h
81113 +++ b/include/linux/rculist.h
81114 @@ -29,8 +29,8 @@
81115 */
81116 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81117 {
81118 - ACCESS_ONCE(list->next) = list;
81119 - ACCESS_ONCE(list->prev) = list;
81120 + ACCESS_ONCE_RW(list->next) = list;
81121 + ACCESS_ONCE_RW(list->prev) = list;
81122 }
81123
81124 /*
81125 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81126 struct list_head *prev, struct list_head *next);
81127 #endif
81128
81129 +void __pax_list_add_rcu(struct list_head *new,
81130 + struct list_head *prev, struct list_head *next);
81131 +
81132 /**
81133 * list_add_rcu - add a new entry to rcu-protected list
81134 * @new: new entry to be added
81135 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81136 __list_add_rcu(new, head, head->next);
81137 }
81138
81139 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81140 +{
81141 + __pax_list_add_rcu(new, head, head->next);
81142 +}
81143 +
81144 /**
81145 * list_add_tail_rcu - add a new entry to rcu-protected list
81146 * @new: new entry to be added
81147 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81148 __list_add_rcu(new, head->prev, head);
81149 }
81150
81151 +static inline void pax_list_add_tail_rcu(struct list_head *new,
81152 + struct list_head *head)
81153 +{
81154 + __pax_list_add_rcu(new, head->prev, head);
81155 +}
81156 +
81157 /**
81158 * list_del_rcu - deletes entry from list without re-initialization
81159 * @entry: the element to delete from the list.
81160 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81161 entry->prev = LIST_POISON2;
81162 }
81163
81164 +extern void pax_list_del_rcu(struct list_head *entry);
81165 +
81166 /**
81167 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81168 * @n: the element to delete from the hash list.
81169 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81170 index 72bf3a0..853347f 100644
81171 --- a/include/linux/rcupdate.h
81172 +++ b/include/linux/rcupdate.h
81173 @@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81174 #define rcu_assign_pointer(p, v) \
81175 do { \
81176 smp_wmb(); \
81177 - ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81178 + ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81179 } while (0)
81180
81181
81182 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81183 index 9e7db9e..7d4fd72 100644
81184 --- a/include/linux/reboot.h
81185 +++ b/include/linux/reboot.h
81186 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81187 */
81188
81189 extern void migrate_to_reboot_cpu(void);
81190 -extern void machine_restart(char *cmd);
81191 -extern void machine_halt(void);
81192 -extern void machine_power_off(void);
81193 +extern void machine_restart(char *cmd) __noreturn;
81194 +extern void machine_halt(void) __noreturn;
81195 +extern void machine_power_off(void) __noreturn;
81196
81197 extern void machine_shutdown(void);
81198 struct pt_regs;
81199 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81200 */
81201
81202 extern void kernel_restart_prepare(char *cmd);
81203 -extern void kernel_restart(char *cmd);
81204 -extern void kernel_halt(void);
81205 -extern void kernel_power_off(void);
81206 +extern void kernel_restart(char *cmd) __noreturn;
81207 +extern void kernel_halt(void) __noreturn;
81208 +extern void kernel_power_off(void) __noreturn;
81209
81210 extern int C_A_D; /* for sysctl */
81211 void ctrl_alt_del(void);
81212 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81213 * Emergency restart, callable from an interrupt handler.
81214 */
81215
81216 -extern void emergency_restart(void);
81217 +extern void emergency_restart(void) __noreturn;
81218 #include <asm/emergency-restart.h>
81219
81220 #endif /* _LINUX_REBOOT_H */
81221 diff --git a/include/linux/regset.h b/include/linux/regset.h
81222 index 8e0c9fe..ac4d221 100644
81223 --- a/include/linux/regset.h
81224 +++ b/include/linux/regset.h
81225 @@ -161,7 +161,8 @@ struct user_regset {
81226 unsigned int align;
81227 unsigned int bias;
81228 unsigned int core_note_type;
81229 -};
81230 +} __do_const;
81231 +typedef struct user_regset __no_const user_regset_no_const;
81232
81233 /**
81234 * struct user_regset_view - available regsets
81235 diff --git a/include/linux/relay.h b/include/linux/relay.h
81236 index d7c8359..818daf5 100644
81237 --- a/include/linux/relay.h
81238 +++ b/include/linux/relay.h
81239 @@ -157,7 +157,7 @@ struct rchan_callbacks
81240 * The callback should return 0 if successful, negative if not.
81241 */
81242 int (*remove_buf_file)(struct dentry *dentry);
81243 -};
81244 +} __no_const;
81245
81246 /*
81247 * CONFIG_RELAY kernel API, kernel/relay.c
81248 diff --git a/include/linux/rio.h b/include/linux/rio.h
81249 index b71d573..2f940bd 100644
81250 --- a/include/linux/rio.h
81251 +++ b/include/linux/rio.h
81252 @@ -355,7 +355,7 @@ struct rio_ops {
81253 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81254 u64 rstart, u32 size, u32 flags);
81255 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81256 -};
81257 +} __no_const;
81258
81259 #define RIO_RESOURCE_MEM 0x00000100
81260 #define RIO_RESOURCE_DOORBELL 0x00000200
81261 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81262 index b66c211..13d2915 100644
81263 --- a/include/linux/rmap.h
81264 +++ b/include/linux/rmap.h
81265 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81266 void anon_vma_init(void); /* create anon_vma_cachep */
81267 int anon_vma_prepare(struct vm_area_struct *);
81268 void unlink_anon_vmas(struct vm_area_struct *);
81269 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81270 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81271 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81272 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81273
81274 static inline void anon_vma_merge(struct vm_area_struct *vma,
81275 struct vm_area_struct *next)
81276 diff --git a/include/linux/sched.h b/include/linux/sched.h
81277 index a781dec..be1d2a3 100644
81278 --- a/include/linux/sched.h
81279 +++ b/include/linux/sched.h
81280 @@ -129,6 +129,7 @@ struct fs_struct;
81281 struct perf_event_context;
81282 struct blk_plug;
81283 struct filename;
81284 +struct linux_binprm;
81285
81286 /*
81287 * List of flags we want to share for kernel threads,
81288 @@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
81289 extern int in_sched_functions(unsigned long addr);
81290
81291 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81292 -extern signed long schedule_timeout(signed long timeout);
81293 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81294 extern signed long schedule_timeout_interruptible(signed long timeout);
81295 extern signed long schedule_timeout_killable(signed long timeout);
81296 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81297 @@ -380,6 +381,19 @@ struct nsproxy;
81298 struct user_namespace;
81299
81300 #ifdef CONFIG_MMU
81301 +
81302 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81303 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81304 +#else
81305 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81306 +{
81307 + return 0;
81308 +}
81309 +#endif
81310 +
81311 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81312 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81313 +
81314 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81315 extern unsigned long
81316 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81317 @@ -677,6 +691,17 @@ struct signal_struct {
81318 #ifdef CONFIG_TASKSTATS
81319 struct taskstats *stats;
81320 #endif
81321 +
81322 +#ifdef CONFIG_GRKERNSEC
81323 + u32 curr_ip;
81324 + u32 saved_ip;
81325 + u32 gr_saddr;
81326 + u32 gr_daddr;
81327 + u16 gr_sport;
81328 + u16 gr_dport;
81329 + u8 used_accept:1;
81330 +#endif
81331 +
81332 #ifdef CONFIG_AUDIT
81333 unsigned audit_tty;
81334 unsigned audit_tty_log_passwd;
81335 @@ -703,7 +728,7 @@ struct signal_struct {
81336 struct mutex cred_guard_mutex; /* guard against foreign influences on
81337 * credential calculations
81338 * (notably. ptrace) */
81339 -};
81340 +} __randomize_layout;
81341
81342 /*
81343 * Bits in flags field of signal_struct.
81344 @@ -757,6 +782,14 @@ struct user_struct {
81345 struct key *session_keyring; /* UID's default session keyring */
81346 #endif
81347
81348 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81349 + unsigned char kernel_banned;
81350 +#endif
81351 +#ifdef CONFIG_GRKERNSEC_BRUTE
81352 + unsigned char suid_banned;
81353 + unsigned long suid_ban_expires;
81354 +#endif
81355 +
81356 /* Hash table maintenance information */
81357 struct hlist_node uidhash_node;
81358 kuid_t uid;
81359 @@ -764,7 +797,7 @@ struct user_struct {
81360 #ifdef CONFIG_PERF_EVENTS
81361 atomic_long_t locked_vm;
81362 #endif
81363 -};
81364 +} __randomize_layout;
81365
81366 extern int uids_sysfs_init(void);
81367
81368 @@ -1286,8 +1319,8 @@ struct task_struct {
81369 struct list_head thread_node;
81370
81371 struct completion *vfork_done; /* for vfork() */
81372 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81373 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81374 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81375 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81376
81377 cputime_t utime, stime, utimescaled, stimescaled;
81378 cputime_t gtime;
81379 @@ -1312,11 +1345,6 @@ struct task_struct {
81380 struct task_cputime cputime_expires;
81381 struct list_head cpu_timers[3];
81382
81383 -/* process credentials */
81384 - const struct cred __rcu *real_cred; /* objective and real subjective task
81385 - * credentials (COW) */
81386 - const struct cred __rcu *cred; /* effective (overridable) subjective task
81387 - * credentials (COW) */
81388 char comm[TASK_COMM_LEN]; /* executable name excluding path
81389 - access with [gs]et_task_comm (which lock
81390 it with task_lock())
81391 @@ -1333,6 +1361,10 @@ struct task_struct {
81392 #endif
81393 /* CPU-specific state of this task */
81394 struct thread_struct thread;
81395 +/* thread_info moved to task_struct */
81396 +#ifdef CONFIG_X86
81397 + struct thread_info tinfo;
81398 +#endif
81399 /* filesystem information */
81400 struct fs_struct *fs;
81401 /* open file information */
81402 @@ -1409,6 +1441,10 @@ struct task_struct {
81403 gfp_t lockdep_reclaim_gfp;
81404 #endif
81405
81406 +/* process credentials */
81407 + const struct cred __rcu *real_cred; /* objective and real subjective task
81408 + * credentials (COW) */
81409 +
81410 /* journalling filesystem info */
81411 void *journal_info;
81412
81413 @@ -1447,6 +1483,10 @@ struct task_struct {
81414 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81415 struct list_head cg_list;
81416 #endif
81417 +
81418 + const struct cred __rcu *cred; /* effective (overridable) subjective task
81419 + * credentials (COW) */
81420 +
81421 #ifdef CONFIG_FUTEX
81422 struct robust_list_head __user *robust_list;
81423 #ifdef CONFIG_COMPAT
81424 @@ -1581,7 +1621,78 @@ struct task_struct {
81425 unsigned int sequential_io;
81426 unsigned int sequential_io_avg;
81427 #endif
81428 -};
81429 +
81430 +#ifdef CONFIG_GRKERNSEC
81431 + /* grsecurity */
81432 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81433 + u64 exec_id;
81434 +#endif
81435 +#ifdef CONFIG_GRKERNSEC_SETXID
81436 + const struct cred *delayed_cred;
81437 +#endif
81438 + struct dentry *gr_chroot_dentry;
81439 + struct acl_subject_label *acl;
81440 + struct acl_subject_label *tmpacl;
81441 + struct acl_role_label *role;
81442 + struct file *exec_file;
81443 + unsigned long brute_expires;
81444 + u16 acl_role_id;
81445 + u8 inherited;
81446 + /* is this the task that authenticated to the special role */
81447 + u8 acl_sp_role;
81448 + u8 is_writable;
81449 + u8 brute;
81450 + u8 gr_is_chrooted;
81451 +#endif
81452 +
81453 +} __randomize_layout;
81454 +
81455 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81456 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81457 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81458 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81459 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81460 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81461 +
81462 +#ifdef CONFIG_PAX_SOFTMODE
81463 +extern int pax_softmode;
81464 +#endif
81465 +
81466 +extern int pax_check_flags(unsigned long *);
81467 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81468 +
81469 +/* if tsk != current then task_lock must be held on it */
81470 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81471 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
81472 +{
81473 + if (likely(tsk->mm))
81474 + return tsk->mm->pax_flags;
81475 + else
81476 + return 0UL;
81477 +}
81478 +
81479 +/* if tsk != current then task_lock must be held on it */
81480 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81481 +{
81482 + if (likely(tsk->mm)) {
81483 + tsk->mm->pax_flags = flags;
81484 + return 0;
81485 + }
81486 + return -EINVAL;
81487 +}
81488 +#endif
81489 +
81490 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81491 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
81492 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81493 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81494 +#endif
81495 +
81496 +struct path;
81497 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81498 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81499 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81500 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
81501
81502 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81503 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81504 @@ -1658,7 +1769,7 @@ struct pid_namespace;
81505 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81506 struct pid_namespace *ns);
81507
81508 -static inline pid_t task_pid_nr(struct task_struct *tsk)
81509 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
81510 {
81511 return tsk->pid;
81512 }
81513 @@ -2112,7 +2223,9 @@ void yield(void);
81514 extern struct exec_domain default_exec_domain;
81515
81516 union thread_union {
81517 +#ifndef CONFIG_X86
81518 struct thread_info thread_info;
81519 +#endif
81520 unsigned long stack[THREAD_SIZE/sizeof(long)];
81521 };
81522
81523 @@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
81524 */
81525
81526 extern struct task_struct *find_task_by_vpid(pid_t nr);
81527 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81528 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81529 struct pid_namespace *ns);
81530
81531 @@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81532 extern void exit_itimers(struct signal_struct *);
81533 extern void flush_itimer_signals(void);
81534
81535 -extern void do_group_exit(int);
81536 +extern __noreturn void do_group_exit(int);
81537
81538 extern int allow_signal(int);
81539 extern int disallow_signal(int);
81540 @@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81541
81542 #endif
81543
81544 -static inline int object_is_on_stack(void *obj)
81545 +static inline int object_starts_on_stack(void *obj)
81546 {
81547 - void *stack = task_stack_page(current);
81548 + const void *stack = task_stack_page(current);
81549
81550 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81551 }
81552 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81553 index 8045a55..c959cd5 100644
81554 --- a/include/linux/sched/sysctl.h
81555 +++ b/include/linux/sched/sysctl.h
81556 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81557 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81558
81559 extern int sysctl_max_map_count;
81560 +extern unsigned long sysctl_heap_stack_gap;
81561
81562 extern unsigned int sysctl_sched_latency;
81563 extern unsigned int sysctl_sched_min_granularity;
81564 diff --git a/include/linux/security.h b/include/linux/security.h
81565 index 2fc42d1..4d802f2 100644
81566 --- a/include/linux/security.h
81567 +++ b/include/linux/security.h
81568 @@ -27,6 +27,7 @@
81569 #include <linux/slab.h>
81570 #include <linux/err.h>
81571 #include <linux/string.h>
81572 +#include <linux/grsecurity.h>
81573
81574 struct linux_binprm;
81575 struct cred;
81576 @@ -116,8 +117,6 @@ struct seq_file;
81577
81578 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81579
81580 -void reset_security_ops(void);
81581 -
81582 #ifdef CONFIG_MMU
81583 extern unsigned long mmap_min_addr;
81584 extern unsigned long dac_mmap_min_addr;
81585 @@ -1719,7 +1718,7 @@ struct security_operations {
81586 struct audit_context *actx);
81587 void (*audit_rule_free) (void *lsmrule);
81588 #endif /* CONFIG_AUDIT */
81589 -};
81590 +} __randomize_layout;
81591
81592 /* prototypes */
81593 extern int security_init(void);
81594 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81595 index dc368b8..e895209 100644
81596 --- a/include/linux/semaphore.h
81597 +++ b/include/linux/semaphore.h
81598 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81599 }
81600
81601 extern void down(struct semaphore *sem);
81602 -extern int __must_check down_interruptible(struct semaphore *sem);
81603 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81604 extern int __must_check down_killable(struct semaphore *sem);
81605 extern int __must_check down_trylock(struct semaphore *sem);
81606 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81607 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81608 index 52e0097..09625ef 100644
81609 --- a/include/linux/seq_file.h
81610 +++ b/include/linux/seq_file.h
81611 @@ -27,6 +27,9 @@ struct seq_file {
81612 struct mutex lock;
81613 const struct seq_operations *op;
81614 int poll_event;
81615 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81616 + u64 exec_id;
81617 +#endif
81618 #ifdef CONFIG_USER_NS
81619 struct user_namespace *user_ns;
81620 #endif
81621 @@ -39,6 +42,7 @@ struct seq_operations {
81622 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81623 int (*show) (struct seq_file *m, void *v);
81624 };
81625 +typedef struct seq_operations __no_const seq_operations_no_const;
81626
81627 #define SEQ_SKIP 1
81628
81629 diff --git a/include/linux/shm.h b/include/linux/shm.h
81630 index 1e2cd2e..0288750 100644
81631 --- a/include/linux/shm.h
81632 +++ b/include/linux/shm.h
81633 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81634
81635 /* The task created the shm object. NULL if the task is dead. */
81636 struct task_struct *shm_creator;
81637 +#ifdef CONFIG_GRKERNSEC
81638 + time_t shm_createtime;
81639 + pid_t shm_lapid;
81640 +#endif
81641 };
81642
81643 /* shm_mode upper byte flags */
81644 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81645 index 15ede6a..80161c3 100644
81646 --- a/include/linux/skbuff.h
81647 +++ b/include/linux/skbuff.h
81648 @@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81649 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81650 int node);
81651 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81652 -static inline struct sk_buff *alloc_skb(unsigned int size,
81653 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81654 gfp_t priority)
81655 {
81656 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81657 @@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81658 return skb->inner_transport_header - skb->inner_network_header;
81659 }
81660
81661 -static inline int skb_network_offset(const struct sk_buff *skb)
81662 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81663 {
81664 return skb_network_header(skb) - skb->data;
81665 }
81666 @@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81667 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81668 */
81669 #ifndef NET_SKB_PAD
81670 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81671 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81672 #endif
81673
81674 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81675 @@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81676 int *err);
81677 unsigned int datagram_poll(struct file *file, struct socket *sock,
81678 struct poll_table_struct *wait);
81679 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81680 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81681 struct iovec *to, int size);
81682 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81683 struct iovec *iov);
81684 @@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
81685 nf_bridge_put(skb->nf_bridge);
81686 skb->nf_bridge = NULL;
81687 #endif
81688 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81689 + skb->nf_trace = 0;
81690 +#endif
81691 }
81692
81693 static inline void nf_reset_trace(struct sk_buff *skb)
81694 diff --git a/include/linux/slab.h b/include/linux/slab.h
81695 index b5b2df6..69f5734 100644
81696 --- a/include/linux/slab.h
81697 +++ b/include/linux/slab.h
81698 @@ -14,15 +14,29 @@
81699 #include <linux/gfp.h>
81700 #include <linux/types.h>
81701 #include <linux/workqueue.h>
81702 -
81703 +#include <linux/err.h>
81704
81705 /*
81706 * Flags to pass to kmem_cache_create().
81707 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81708 */
81709 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81710 +
81711 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81712 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81713 +#else
81714 +#define SLAB_USERCOPY 0x00000000UL
81715 +#endif
81716 +
81717 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81718 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81719 +
81720 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81721 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81722 +#else
81723 +#define SLAB_NO_SANITIZE 0x00000000UL
81724 +#endif
81725 +
81726 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81727 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81728 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81729 @@ -98,10 +112,13 @@
81730 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81731 * Both make kfree a no-op.
81732 */
81733 -#define ZERO_SIZE_PTR ((void *)16)
81734 +#define ZERO_SIZE_PTR \
81735 +({ \
81736 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81737 + (void *)(-MAX_ERRNO-1L); \
81738 +})
81739
81740 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81741 - (unsigned long)ZERO_SIZE_PTR)
81742 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81743
81744 #include <linux/kmemleak.h>
81745
81746 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81747 void kfree(const void *);
81748 void kzfree(const void *);
81749 size_t ksize(const void *);
81750 +const char *check_heap_object(const void *ptr, unsigned long n);
81751 +bool is_usercopy_object(const void *ptr);
81752
81753 /*
81754 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81755 @@ -174,7 +193,7 @@ struct kmem_cache {
81756 unsigned int align; /* Alignment as calculated */
81757 unsigned long flags; /* Active flags on the slab */
81758 const char *name; /* Slab name for sysfs */
81759 - int refcount; /* Use counter */
81760 + atomic_t refcount; /* Use counter */
81761 void (*ctor)(void *); /* Called on object slot creation */
81762 struct list_head list; /* List of all slab caches on the system */
81763 };
81764 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81765 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81766 #endif
81767
81768 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81769 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81770 +#endif
81771 +
81772 /*
81773 * Figure out which kmalloc slab an allocation of a certain size
81774 * belongs to.
81775 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81776 * 2 = 120 .. 192 bytes
81777 * n = 2^(n-1) .. 2^n -1
81778 */
81779 -static __always_inline int kmalloc_index(size_t size)
81780 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81781 {
81782 if (!size)
81783 return 0;
81784 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81785 }
81786 #endif /* !CONFIG_SLOB */
81787
81788 -void *__kmalloc(size_t size, gfp_t flags);
81789 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81790 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81791
81792 #ifdef CONFIG_NUMA
81793 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
81794 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81795 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81796 #else
81797 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81798 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81799 index 8235dfb..47ce586 100644
81800 --- a/include/linux/slab_def.h
81801 +++ b/include/linux/slab_def.h
81802 @@ -38,7 +38,7 @@ struct kmem_cache {
81803 /* 4) cache creation/removal */
81804 const char *name;
81805 struct list_head list;
81806 - int refcount;
81807 + atomic_t refcount;
81808 int object_size;
81809 int align;
81810
81811 @@ -54,10 +54,14 @@ struct kmem_cache {
81812 unsigned long node_allocs;
81813 unsigned long node_frees;
81814 unsigned long node_overflow;
81815 - atomic_t allochit;
81816 - atomic_t allocmiss;
81817 - atomic_t freehit;
81818 - atomic_t freemiss;
81819 + atomic_unchecked_t allochit;
81820 + atomic_unchecked_t allocmiss;
81821 + atomic_unchecked_t freehit;
81822 + atomic_unchecked_t freemiss;
81823 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81824 + atomic_unchecked_t sanitized;
81825 + atomic_unchecked_t not_sanitized;
81826 +#endif
81827
81828 /*
81829 * If debugging is enabled, then the allocator can add additional
81830 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81831 index f56bfa9..8378a26 100644
81832 --- a/include/linux/slub_def.h
81833 +++ b/include/linux/slub_def.h
81834 @@ -74,7 +74,7 @@ struct kmem_cache {
81835 struct kmem_cache_order_objects max;
81836 struct kmem_cache_order_objects min;
81837 gfp_t allocflags; /* gfp flags to use on each alloc */
81838 - int refcount; /* Refcount for slab cache destroy */
81839 + atomic_t refcount; /* Refcount for slab cache destroy */
81840 void (*ctor)(void *);
81841 int inuse; /* Offset to metadata */
81842 int align; /* Alignment */
81843 diff --git a/include/linux/smp.h b/include/linux/smp.h
81844 index 6ae004e..2743532 100644
81845 --- a/include/linux/smp.h
81846 +++ b/include/linux/smp.h
81847 @@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
81848 #endif
81849
81850 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81851 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81852 #define put_cpu() preempt_enable()
81853 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81854
81855 /*
81856 * Callback to arch code if there's nosmp or maxcpus=0 on the
81857 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81858 index 54f91d3..be2c379 100644
81859 --- a/include/linux/sock_diag.h
81860 +++ b/include/linux/sock_diag.h
81861 @@ -11,7 +11,7 @@ struct sock;
81862 struct sock_diag_handler {
81863 __u8 family;
81864 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81865 -};
81866 +} __do_const;
81867
81868 int sock_diag_register(const struct sock_diag_handler *h);
81869 void sock_diag_unregister(const struct sock_diag_handler *h);
81870 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81871 index 680f9a3..f13aeb0 100644
81872 --- a/include/linux/sonet.h
81873 +++ b/include/linux/sonet.h
81874 @@ -7,7 +7,7 @@
81875 #include <uapi/linux/sonet.h>
81876
81877 struct k_sonet_stats {
81878 -#define __HANDLE_ITEM(i) atomic_t i
81879 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81880 __SONET_ITEMS
81881 #undef __HANDLE_ITEM
81882 };
81883 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81884 index 07d8e53..dc934c9 100644
81885 --- a/include/linux/sunrpc/addr.h
81886 +++ b/include/linux/sunrpc/addr.h
81887 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81888 {
81889 switch (sap->sa_family) {
81890 case AF_INET:
81891 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
81892 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81893 case AF_INET6:
81894 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81895 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81896 }
81897 return 0;
81898 }
81899 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81900 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81901 const struct sockaddr *src)
81902 {
81903 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81904 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81905 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81906
81907 dsin->sin_family = ssin->sin_family;
81908 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81909 if (sa->sa_family != AF_INET6)
81910 return 0;
81911
81912 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81913 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81914 }
81915
81916 #endif /* _LINUX_SUNRPC_ADDR_H */
81917 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81918 index 8af2804..c7414ef 100644
81919 --- a/include/linux/sunrpc/clnt.h
81920 +++ b/include/linux/sunrpc/clnt.h
81921 @@ -97,7 +97,7 @@ struct rpc_procinfo {
81922 unsigned int p_timer; /* Which RTT timer to use */
81923 u32 p_statidx; /* Which procedure to account */
81924 const char * p_name; /* name of procedure */
81925 -};
81926 +} __do_const;
81927
81928 #ifdef __KERNEL__
81929
81930 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81931 index 04e7632..2e2a8a3 100644
81932 --- a/include/linux/sunrpc/svc.h
81933 +++ b/include/linux/sunrpc/svc.h
81934 @@ -412,7 +412,7 @@ struct svc_procedure {
81935 unsigned int pc_count; /* call count */
81936 unsigned int pc_cachetype; /* cache info (NFS) */
81937 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81938 -};
81939 +} __do_const;
81940
81941 /*
81942 * Function prototypes.
81943 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81944 index 0b8e3e6..33e0a01 100644
81945 --- a/include/linux/sunrpc/svc_rdma.h
81946 +++ b/include/linux/sunrpc/svc_rdma.h
81947 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81948 extern unsigned int svcrdma_max_requests;
81949 extern unsigned int svcrdma_max_req_size;
81950
81951 -extern atomic_t rdma_stat_recv;
81952 -extern atomic_t rdma_stat_read;
81953 -extern atomic_t rdma_stat_write;
81954 -extern atomic_t rdma_stat_sq_starve;
81955 -extern atomic_t rdma_stat_rq_starve;
81956 -extern atomic_t rdma_stat_rq_poll;
81957 -extern atomic_t rdma_stat_rq_prod;
81958 -extern atomic_t rdma_stat_sq_poll;
81959 -extern atomic_t rdma_stat_sq_prod;
81960 +extern atomic_unchecked_t rdma_stat_recv;
81961 +extern atomic_unchecked_t rdma_stat_read;
81962 +extern atomic_unchecked_t rdma_stat_write;
81963 +extern atomic_unchecked_t rdma_stat_sq_starve;
81964 +extern atomic_unchecked_t rdma_stat_rq_starve;
81965 +extern atomic_unchecked_t rdma_stat_rq_poll;
81966 +extern atomic_unchecked_t rdma_stat_rq_prod;
81967 +extern atomic_unchecked_t rdma_stat_sq_poll;
81968 +extern atomic_unchecked_t rdma_stat_sq_prod;
81969
81970 #define RPCRDMA_VERSION 1
81971
81972 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81973 index 8d71d65..f79586e 100644
81974 --- a/include/linux/sunrpc/svcauth.h
81975 +++ b/include/linux/sunrpc/svcauth.h
81976 @@ -120,7 +120,7 @@ struct auth_ops {
81977 int (*release)(struct svc_rqst *rq);
81978 void (*domain_release)(struct auth_domain *);
81979 int (*set_client)(struct svc_rqst *rq);
81980 -};
81981 +} __do_const;
81982
81983 #define SVC_GARBAGE 1
81984 #define SVC_SYSERR 2
81985 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81986 index a5ffd32..0935dea 100644
81987 --- a/include/linux/swiotlb.h
81988 +++ b/include/linux/swiotlb.h
81989 @@ -60,7 +60,8 @@ extern void
81990
81991 extern void
81992 swiotlb_free_coherent(struct device *hwdev, size_t size,
81993 - void *vaddr, dma_addr_t dma_handle);
81994 + void *vaddr, dma_addr_t dma_handle,
81995 + struct dma_attrs *attrs);
81996
81997 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81998 unsigned long offset, size_t size,
81999 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82000 index a747a77..9e14df7 100644
82001 --- a/include/linux/syscalls.h
82002 +++ b/include/linux/syscalls.h
82003 @@ -98,8 +98,14 @@ struct sigaltstack;
82004 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82005
82006 #define __SC_DECL(t, a) t a
82007 +#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))
82008 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82009 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82010 +#define __SC_LONG(t, a) __typeof( \
82011 + __builtin_choose_expr( \
82012 + sizeof(t) > sizeof(int), \
82013 + (t) 0, \
82014 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82015 + )) a
82016 #define __SC_CAST(t, a) (t) a
82017 #define __SC_ARGS(t, a) a
82018 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82019 @@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82020 asmlinkage long sys_fsync(unsigned int fd);
82021 asmlinkage long sys_fdatasync(unsigned int fd);
82022 asmlinkage long sys_bdflush(int func, long data);
82023 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82024 - char __user *type, unsigned long flags,
82025 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82026 + const char __user *type, unsigned long flags,
82027 void __user *data);
82028 -asmlinkage long sys_umount(char __user *name, int flags);
82029 -asmlinkage long sys_oldumount(char __user *name);
82030 +asmlinkage long sys_umount(const char __user *name, int flags);
82031 +asmlinkage long sys_oldumount(const char __user *name);
82032 asmlinkage long sys_truncate(const char __user *path, long length);
82033 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82034 asmlinkage long sys_stat(const char __user *filename,
82035 @@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82036 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82037 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82038 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82039 - struct sockaddr __user *, int);
82040 + struct sockaddr __user *, int) __intentional_overflow(0);
82041 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82042 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82043 unsigned int vlen, unsigned flags);
82044 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82045 index 27b3b0b..e093dd9 100644
82046 --- a/include/linux/syscore_ops.h
82047 +++ b/include/linux/syscore_ops.h
82048 @@ -16,7 +16,7 @@ struct syscore_ops {
82049 int (*suspend)(void);
82050 void (*resume)(void);
82051 void (*shutdown)(void);
82052 -};
82053 +} __do_const;
82054
82055 extern void register_syscore_ops(struct syscore_ops *ops);
82056 extern void unregister_syscore_ops(struct syscore_ops *ops);
82057 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82058 index 14a8ff2..fa95f3a 100644
82059 --- a/include/linux/sysctl.h
82060 +++ b/include/linux/sysctl.h
82061 @@ -34,13 +34,13 @@ struct ctl_table_root;
82062 struct ctl_table_header;
82063 struct ctl_dir;
82064
82065 -typedef struct ctl_table ctl_table;
82066 -
82067 typedef int proc_handler (struct ctl_table *ctl, int write,
82068 void __user *buffer, size_t *lenp, loff_t *ppos);
82069
82070 extern int proc_dostring(struct ctl_table *, int,
82071 void __user *, size_t *, loff_t *);
82072 +extern int proc_dostring_modpriv(struct ctl_table *, int,
82073 + void __user *, size_t *, loff_t *);
82074 extern int proc_dointvec(struct ctl_table *, int,
82075 void __user *, size_t *, loff_t *);
82076 extern int proc_dointvec_minmax(struct ctl_table *, int,
82077 @@ -115,7 +115,9 @@ struct ctl_table
82078 struct ctl_table_poll *poll;
82079 void *extra1;
82080 void *extra2;
82081 -};
82082 +} __do_const __randomize_layout;
82083 +typedef struct ctl_table __no_const ctl_table_no_const;
82084 +typedef struct ctl_table ctl_table;
82085
82086 struct ctl_node {
82087 struct rb_node node;
82088 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82089 index 30b2ebe..37412ef 100644
82090 --- a/include/linux/sysfs.h
82091 +++ b/include/linux/sysfs.h
82092 @@ -34,7 +34,8 @@ struct attribute {
82093 struct lock_class_key *key;
82094 struct lock_class_key skey;
82095 #endif
82096 -};
82097 +} __do_const;
82098 +typedef struct attribute __no_const attribute_no_const;
82099
82100 /**
82101 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82102 @@ -63,7 +64,8 @@ struct attribute_group {
82103 struct attribute *, int);
82104 struct attribute **attrs;
82105 struct bin_attribute **bin_attrs;
82106 -};
82107 +} __do_const;
82108 +typedef struct attribute_group __no_const attribute_group_no_const;
82109
82110 /**
82111 * Use these macros to make defining attributes easier. See include/linux/device.h
82112 @@ -127,7 +129,8 @@ struct bin_attribute {
82113 char *, loff_t, size_t);
82114 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82115 struct vm_area_struct *vma);
82116 -};
82117 +} __do_const;
82118 +typedef struct bin_attribute __no_const bin_attribute_no_const;
82119
82120 /**
82121 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82122 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82123 index 387fa7d..3fcde6b 100644
82124 --- a/include/linux/sysrq.h
82125 +++ b/include/linux/sysrq.h
82126 @@ -16,6 +16,7 @@
82127
82128 #include <linux/errno.h>
82129 #include <linux/types.h>
82130 +#include <linux/compiler.h>
82131
82132 /* Possible values of bitmask for enabling sysrq functions */
82133 /* 0x0001 is reserved for enable everything */
82134 @@ -33,7 +34,7 @@ struct sysrq_key_op {
82135 char *help_msg;
82136 char *action_msg;
82137 int enable_mask;
82138 -};
82139 +} __do_const;
82140
82141 #ifdef CONFIG_MAGIC_SYSRQ
82142
82143 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82144 index fddbe20..0312de8 100644
82145 --- a/include/linux/thread_info.h
82146 +++ b/include/linux/thread_info.h
82147 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82148 #error "no set_restore_sigmask() provided and default one won't work"
82149 #endif
82150
82151 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82152 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82153 +{
82154 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
82155 + if (!__builtin_constant_p(n))
82156 +#endif
82157 + __check_object_size(ptr, n, to_user);
82158 +}
82159 +
82160 #endif /* __KERNEL__ */
82161
82162 #endif /* _LINUX_THREAD_INFO_H */
82163 diff --git a/include/linux/tty.h b/include/linux/tty.h
82164 index b90b5c2..e23a512 100644
82165 --- a/include/linux/tty.h
82166 +++ b/include/linux/tty.h
82167 @@ -202,7 +202,7 @@ struct tty_port {
82168 const struct tty_port_operations *ops; /* Port operations */
82169 spinlock_t lock; /* Lock protecting tty field */
82170 int blocked_open; /* Waiting to open */
82171 - int count; /* Usage count */
82172 + atomic_t count; /* Usage count */
82173 wait_queue_head_t open_wait; /* Open waiters */
82174 wait_queue_head_t close_wait; /* Close waiters */
82175 wait_queue_head_t delta_msr_wait; /* Modem status change */
82176 @@ -284,7 +284,7 @@ struct tty_struct {
82177 /* If the tty has a pending do_SAK, queue it here - akpm */
82178 struct work_struct SAK_work;
82179 struct tty_port *port;
82180 -};
82181 +} __randomize_layout;
82182
82183 /* Each of a tty's open files has private_data pointing to tty_file_private */
82184 struct tty_file_private {
82185 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82186 struct tty_struct *tty, struct file *filp);
82187 static inline int tty_port_users(struct tty_port *port)
82188 {
82189 - return port->count + port->blocked_open;
82190 + return atomic_read(&port->count) + port->blocked_open;
82191 }
82192
82193 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82194 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82195 index 756a609..89db85e 100644
82196 --- a/include/linux/tty_driver.h
82197 +++ b/include/linux/tty_driver.h
82198 @@ -285,7 +285,7 @@ struct tty_operations {
82199 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82200 #endif
82201 const struct file_operations *proc_fops;
82202 -};
82203 +} __do_const __randomize_layout;
82204
82205 struct tty_driver {
82206 int magic; /* magic number for this structure */
82207 @@ -319,7 +319,7 @@ struct tty_driver {
82208
82209 const struct tty_operations *ops;
82210 struct list_head tty_drivers;
82211 -};
82212 +} __randomize_layout;
82213
82214 extern struct list_head tty_drivers;
82215
82216 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82217 index b8347c2..85d8b0f 100644
82218 --- a/include/linux/tty_ldisc.h
82219 +++ b/include/linux/tty_ldisc.h
82220 @@ -213,7 +213,7 @@ struct tty_ldisc_ops {
82221
82222 struct module *owner;
82223
82224 - int refcount;
82225 + atomic_t refcount;
82226 };
82227
82228 struct tty_ldisc {
82229 diff --git a/include/linux/types.h b/include/linux/types.h
82230 index 4d118ba..c3ee9bf 100644
82231 --- a/include/linux/types.h
82232 +++ b/include/linux/types.h
82233 @@ -176,10 +176,26 @@ typedef struct {
82234 int counter;
82235 } atomic_t;
82236
82237 +#ifdef CONFIG_PAX_REFCOUNT
82238 +typedef struct {
82239 + int counter;
82240 +} atomic_unchecked_t;
82241 +#else
82242 +typedef atomic_t atomic_unchecked_t;
82243 +#endif
82244 +
82245 #ifdef CONFIG_64BIT
82246 typedef struct {
82247 long counter;
82248 } atomic64_t;
82249 +
82250 +#ifdef CONFIG_PAX_REFCOUNT
82251 +typedef struct {
82252 + long counter;
82253 +} atomic64_unchecked_t;
82254 +#else
82255 +typedef atomic64_t atomic64_unchecked_t;
82256 +#endif
82257 #endif
82258
82259 struct list_head {
82260 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82261 index ecd3319..8a36ded 100644
82262 --- a/include/linux/uaccess.h
82263 +++ b/include/linux/uaccess.h
82264 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82265 long ret; \
82266 mm_segment_t old_fs = get_fs(); \
82267 \
82268 - set_fs(KERNEL_DS); \
82269 pagefault_disable(); \
82270 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82271 - pagefault_enable(); \
82272 + set_fs(KERNEL_DS); \
82273 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82274 set_fs(old_fs); \
82275 + pagefault_enable(); \
82276 ret; \
82277 })
82278
82279 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82280 index 2d1f9b6..d7a9fce 100644
82281 --- a/include/linux/uidgid.h
82282 +++ b/include/linux/uidgid.h
82283 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82284
82285 #endif /* CONFIG_USER_NS */
82286
82287 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82288 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82289 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82290 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82291 +
82292 #endif /* _LINUX_UIDGID_H */
82293 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82294 index 99c1b4d..562e6f3 100644
82295 --- a/include/linux/unaligned/access_ok.h
82296 +++ b/include/linux/unaligned/access_ok.h
82297 @@ -4,34 +4,34 @@
82298 #include <linux/kernel.h>
82299 #include <asm/byteorder.h>
82300
82301 -static inline u16 get_unaligned_le16(const void *p)
82302 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82303 {
82304 - return le16_to_cpup((__le16 *)p);
82305 + return le16_to_cpup((const __le16 *)p);
82306 }
82307
82308 -static inline u32 get_unaligned_le32(const void *p)
82309 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82310 {
82311 - return le32_to_cpup((__le32 *)p);
82312 + return le32_to_cpup((const __le32 *)p);
82313 }
82314
82315 -static inline u64 get_unaligned_le64(const void *p)
82316 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82317 {
82318 - return le64_to_cpup((__le64 *)p);
82319 + return le64_to_cpup((const __le64 *)p);
82320 }
82321
82322 -static inline u16 get_unaligned_be16(const void *p)
82323 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82324 {
82325 - return be16_to_cpup((__be16 *)p);
82326 + return be16_to_cpup((const __be16 *)p);
82327 }
82328
82329 -static inline u32 get_unaligned_be32(const void *p)
82330 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82331 {
82332 - return be32_to_cpup((__be32 *)p);
82333 + return be32_to_cpup((const __be32 *)p);
82334 }
82335
82336 -static inline u64 get_unaligned_be64(const void *p)
82337 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82338 {
82339 - return be64_to_cpup((__be64 *)p);
82340 + return be64_to_cpup((const __be64 *)p);
82341 }
82342
82343 static inline void put_unaligned_le16(u16 val, void *p)
82344 diff --git a/include/linux/usb.h b/include/linux/usb.h
82345 index 7f6eb85..656e806 100644
82346 --- a/include/linux/usb.h
82347 +++ b/include/linux/usb.h
82348 @@ -563,7 +563,7 @@ struct usb_device {
82349 int maxchild;
82350
82351 u32 quirks;
82352 - atomic_t urbnum;
82353 + atomic_unchecked_t urbnum;
82354
82355 unsigned long active_duration;
82356
82357 @@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82358
82359 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82360 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82361 - void *data, __u16 size, int timeout);
82362 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
82363 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82364 void *data, int len, int *actual_length, int timeout);
82365 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82366 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82367 index e452ba6..78f8e80 100644
82368 --- a/include/linux/usb/renesas_usbhs.h
82369 +++ b/include/linux/usb/renesas_usbhs.h
82370 @@ -39,7 +39,7 @@ enum {
82371 */
82372 struct renesas_usbhs_driver_callback {
82373 int (*notify_hotplug)(struct platform_device *pdev);
82374 -};
82375 +} __no_const;
82376
82377 /*
82378 * callback functions for platform
82379 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82380 index 4836ba3..603f6ee 100644
82381 --- a/include/linux/user_namespace.h
82382 +++ b/include/linux/user_namespace.h
82383 @@ -33,7 +33,7 @@ struct user_namespace {
82384 struct key *persistent_keyring_register;
82385 struct rw_semaphore persistent_keyring_register_sem;
82386 #endif
82387 -};
82388 +} __randomize_layout;
82389
82390 extern struct user_namespace init_user_ns;
82391
82392 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82393 index 239e277..22a5cf5 100644
82394 --- a/include/linux/utsname.h
82395 +++ b/include/linux/utsname.h
82396 @@ -24,7 +24,7 @@ struct uts_namespace {
82397 struct new_utsname name;
82398 struct user_namespace *user_ns;
82399 unsigned int proc_inum;
82400 -};
82401 +} __randomize_layout;
82402 extern struct uts_namespace init_uts_ns;
82403
82404 #ifdef CONFIG_UTS_NS
82405 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82406 index 6f8fbcf..4efc177 100644
82407 --- a/include/linux/vermagic.h
82408 +++ b/include/linux/vermagic.h
82409 @@ -25,9 +25,42 @@
82410 #define MODULE_ARCH_VERMAGIC ""
82411 #endif
82412
82413 +#ifdef CONFIG_PAX_REFCOUNT
82414 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
82415 +#else
82416 +#define MODULE_PAX_REFCOUNT ""
82417 +#endif
82418 +
82419 +#ifdef CONSTIFY_PLUGIN
82420 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82421 +#else
82422 +#define MODULE_CONSTIFY_PLUGIN ""
82423 +#endif
82424 +
82425 +#ifdef STACKLEAK_PLUGIN
82426 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82427 +#else
82428 +#define MODULE_STACKLEAK_PLUGIN ""
82429 +#endif
82430 +
82431 +#ifdef RANDSTRUCT_PLUGIN
82432 +#include <generated/randomize_layout_hash.h>
82433 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82434 +#else
82435 +#define MODULE_RANDSTRUCT_PLUGIN
82436 +#endif
82437 +
82438 +#ifdef CONFIG_GRKERNSEC
82439 +#define MODULE_GRSEC "GRSEC "
82440 +#else
82441 +#define MODULE_GRSEC ""
82442 +#endif
82443 +
82444 #define VERMAGIC_STRING \
82445 UTS_RELEASE " " \
82446 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82447 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82448 - MODULE_ARCH_VERMAGIC
82449 + MODULE_ARCH_VERMAGIC \
82450 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82451 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82452
82453 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82454 index 502073a..a7de024 100644
82455 --- a/include/linux/vga_switcheroo.h
82456 +++ b/include/linux/vga_switcheroo.h
82457 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82458
82459 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82460
82461 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82462 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82463 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82464 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82465 #else
82466
82467 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82468 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82469
82470 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82471
82472 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82473 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82474 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82475 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82476
82477 #endif
82478 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82479 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82480 index 4b8a891..cb8df6e 100644
82481 --- a/include/linux/vmalloc.h
82482 +++ b/include/linux/vmalloc.h
82483 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82484 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82485 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82486 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82487 +
82488 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82489 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82490 +#endif
82491 +
82492 /* bits [20..32] reserved for arch specific ioremap internals */
82493
82494 /*
82495 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82496
82497 /* for /dev/kmem */
82498 extern long vread(char *buf, char *addr, unsigned long count);
82499 -extern long vwrite(char *buf, char *addr, unsigned long count);
82500 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82501
82502 /*
82503 * Internals. Dont't use..
82504 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82505 index 67ce70c..d540954 100644
82506 --- a/include/linux/vmstat.h
82507 +++ b/include/linux/vmstat.h
82508 @@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
82509 /*
82510 * Zone based page accounting with per cpu differentials.
82511 */
82512 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82513 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82514
82515 static inline void zone_page_state_add(long x, struct zone *zone,
82516 enum zone_stat_item item)
82517 {
82518 - atomic_long_add(x, &zone->vm_stat[item]);
82519 - atomic_long_add(x, &vm_stat[item]);
82520 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82521 + atomic_long_add_unchecked(x, &vm_stat[item]);
82522 }
82523
82524 -static inline unsigned long global_page_state(enum zone_stat_item item)
82525 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82526 {
82527 - long x = atomic_long_read(&vm_stat[item]);
82528 + long x = atomic_long_read_unchecked(&vm_stat[item]);
82529 #ifdef CONFIG_SMP
82530 if (x < 0)
82531 x = 0;
82532 @@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82533 return x;
82534 }
82535
82536 -static inline unsigned long zone_page_state(struct zone *zone,
82537 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82538 enum zone_stat_item item)
82539 {
82540 - long x = atomic_long_read(&zone->vm_stat[item]);
82541 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82542 #ifdef CONFIG_SMP
82543 if (x < 0)
82544 x = 0;
82545 @@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82546 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82547 enum zone_stat_item item)
82548 {
82549 - long x = atomic_long_read(&zone->vm_stat[item]);
82550 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82551
82552 #ifdef CONFIG_SMP
82553 int cpu;
82554 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82555
82556 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82557 {
82558 - atomic_long_inc(&zone->vm_stat[item]);
82559 - atomic_long_inc(&vm_stat[item]);
82560 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
82561 + atomic_long_inc_unchecked(&vm_stat[item]);
82562 }
82563
82564 static inline void __inc_zone_page_state(struct page *page,
82565 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
82566
82567 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82568 {
82569 - atomic_long_dec(&zone->vm_stat[item]);
82570 - atomic_long_dec(&vm_stat[item]);
82571 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
82572 + atomic_long_dec_unchecked(&vm_stat[item]);
82573 }
82574
82575 static inline void __dec_zone_page_state(struct page *page,
82576 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82577 index 91b0a68..0e9adf6 100644
82578 --- a/include/linux/xattr.h
82579 +++ b/include/linux/xattr.h
82580 @@ -28,7 +28,7 @@ struct xattr_handler {
82581 size_t size, int handler_flags);
82582 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82583 size_t size, int flags, int handler_flags);
82584 -};
82585 +} __do_const;
82586
82587 struct xattr {
82588 const char *name;
82589 @@ -37,6 +37,9 @@ struct xattr {
82590 };
82591
82592 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82593 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82594 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
82595 +#endif
82596 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82597 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82598 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82599 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82600 index 9c5a6b4..09c9438 100644
82601 --- a/include/linux/zlib.h
82602 +++ b/include/linux/zlib.h
82603 @@ -31,6 +31,7 @@
82604 #define _ZLIB_H
82605
82606 #include <linux/zconf.h>
82607 +#include <linux/compiler.h>
82608
82609 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82610 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82611 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82612
82613 /* basic functions */
82614
82615 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82616 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82617 /*
82618 Returns the number of bytes that needs to be allocated for a per-
82619 stream workspace with the specified parameters. A pointer to this
82620 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82621 index c768c9f..bdcaa5a 100644
82622 --- a/include/media/v4l2-dev.h
82623 +++ b/include/media/v4l2-dev.h
82624 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
82625 int (*mmap) (struct file *, struct vm_area_struct *);
82626 int (*open) (struct file *);
82627 int (*release) (struct file *);
82628 -};
82629 +} __do_const;
82630
82631 /*
82632 * Newer version of video_device, handled by videodev2.c
82633 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82634 index c9b1593..a572459 100644
82635 --- a/include/media/v4l2-device.h
82636 +++ b/include/media/v4l2-device.h
82637 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82638 this function returns 0. If the name ends with a digit (e.g. cx18),
82639 then the name will be set to cx18-0 since cx180 looks really odd. */
82640 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82641 - atomic_t *instance);
82642 + atomic_unchecked_t *instance);
82643
82644 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82645 Since the parent disappears this ensures that v4l2_dev doesn't have an
82646 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82647 index 9a36d92..0aafe2a 100644
82648 --- a/include/net/9p/transport.h
82649 +++ b/include/net/9p/transport.h
82650 @@ -60,7 +60,7 @@ struct p9_trans_module {
82651 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82652 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82653 char *, char *, int , int, int, int);
82654 -};
82655 +} __do_const;
82656
82657 void v9fs_register_trans(struct p9_trans_module *m);
82658 void v9fs_unregister_trans(struct p9_trans_module *m);
82659 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82660 index a175ba4..196eb82 100644
82661 --- a/include/net/af_unix.h
82662 +++ b/include/net/af_unix.h
82663 @@ -36,7 +36,7 @@ struct unix_skb_parms {
82664 u32 secid; /* Security ID */
82665 #endif
82666 u32 consumed;
82667 -};
82668 +} __randomize_layout;
82669
82670 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82671 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82672 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82673 index dbc4a89..4a59b5d 100644
82674 --- a/include/net/bluetooth/l2cap.h
82675 +++ b/include/net/bluetooth/l2cap.h
82676 @@ -600,7 +600,7 @@ struct l2cap_ops {
82677 long (*get_sndtimeo) (struct l2cap_chan *chan);
82678 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82679 unsigned long len, int nb);
82680 -};
82681 +} __do_const;
82682
82683 struct l2cap_conn {
82684 struct hci_conn *hcon;
82685 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82686 index f2ae33d..c457cf0 100644
82687 --- a/include/net/caif/cfctrl.h
82688 +++ b/include/net/caif/cfctrl.h
82689 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
82690 void (*radioset_rsp)(void);
82691 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82692 struct cflayer *client_layer);
82693 -};
82694 +} __no_const;
82695
82696 /* Link Setup Parameters for CAIF-Links. */
82697 struct cfctrl_link_param {
82698 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
82699 struct cfctrl {
82700 struct cfsrvl serv;
82701 struct cfctrl_rsp res;
82702 - atomic_t req_seq_no;
82703 - atomic_t rsp_seq_no;
82704 + atomic_unchecked_t req_seq_no;
82705 + atomic_unchecked_t rsp_seq_no;
82706 struct list_head list;
82707 /* Protects from simultaneous access to first_req list */
82708 spinlock_t info_list_lock;
82709 diff --git a/include/net/flow.h b/include/net/flow.h
82710 index d23e7fa..e188307 100644
82711 --- a/include/net/flow.h
82712 +++ b/include/net/flow.h
82713 @@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82714
82715 void flow_cache_flush(void);
82716 void flow_cache_flush_deferred(void);
82717 -extern atomic_t flow_cache_genid;
82718 +extern atomic_unchecked_t flow_cache_genid;
82719
82720 #endif
82721 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82722 index 93695f0..766d71c 100644
82723 --- a/include/net/genetlink.h
82724 +++ b/include/net/genetlink.h
82725 @@ -120,7 +120,7 @@ struct genl_ops {
82726 u8 cmd;
82727 u8 internal_flags;
82728 u8 flags;
82729 -};
82730 +} __do_const;
82731
82732 int __genl_register_family(struct genl_family *family);
82733
82734 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82735 index 734d9b5..48a9a4b 100644
82736 --- a/include/net/gro_cells.h
82737 +++ b/include/net/gro_cells.h
82738 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82739 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82740
82741 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82742 - atomic_long_inc(&dev->rx_dropped);
82743 + atomic_long_inc_unchecked(&dev->rx_dropped);
82744 kfree_skb(skb);
82745 return;
82746 }
82747 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82748 index c55aeed..b3393f4 100644
82749 --- a/include/net/inet_connection_sock.h
82750 +++ b/include/net/inet_connection_sock.h
82751 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82752 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82753 int (*bind_conflict)(const struct sock *sk,
82754 const struct inet_bind_bucket *tb, bool relax);
82755 -};
82756 +} __do_const;
82757
82758 /** inet_connection_sock - INET connection oriented sock
82759 *
82760 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82761 index 6efe73c..fa94270 100644
82762 --- a/include/net/inetpeer.h
82763 +++ b/include/net/inetpeer.h
82764 @@ -47,8 +47,8 @@ struct inet_peer {
82765 */
82766 union {
82767 struct {
82768 - atomic_t rid; /* Frag reception counter */
82769 - atomic_t ip_id_count; /* IP ID for the next packet */
82770 + atomic_unchecked_t rid; /* Frag reception counter */
82771 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82772 };
82773 struct rcu_head rcu;
82774 struct inet_peer *gc_next;
82775 @@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82776 /* can be called with or without local BH being disabled */
82777 static inline int inet_getid(struct inet_peer *p, int more)
82778 {
82779 - int old, new;
82780 + int id;
82781 more++;
82782 inet_peer_refcheck(p);
82783 - do {
82784 - old = atomic_read(&p->ip_id_count);
82785 - new = old + more;
82786 - if (!new)
82787 - new = 1;
82788 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82789 - return new;
82790 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
82791 + if (!id)
82792 + id = atomic_inc_return_unchecked(&p->ip_id_count);
82793 + return id;
82794 }
82795
82796 #endif /* _NET_INETPEER_H */
82797 diff --git a/include/net/ip.h b/include/net/ip.h
82798 index 23be0fd..0cb3e2c 100644
82799 --- a/include/net/ip.h
82800 +++ b/include/net/ip.h
82801 @@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82802
82803 void inet_get_local_port_range(struct net *net, int *low, int *high);
82804
82805 -extern unsigned long *sysctl_local_reserved_ports;
82806 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82807 static inline int inet_is_reserved_local_port(int port)
82808 {
82809 return test_bit(port, sysctl_local_reserved_ports);
82810 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82811 index 9922093..a1755d6 100644
82812 --- a/include/net/ip_fib.h
82813 +++ b/include/net/ip_fib.h
82814 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82815
82816 #define FIB_RES_SADDR(net, res) \
82817 ((FIB_RES_NH(res).nh_saddr_genid == \
82818 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82819 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82820 FIB_RES_NH(res).nh_saddr : \
82821 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82822 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82823 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82824 index 5679d92..2e7a690 100644
82825 --- a/include/net/ip_vs.h
82826 +++ b/include/net/ip_vs.h
82827 @@ -558,7 +558,7 @@ struct ip_vs_conn {
82828 struct ip_vs_conn *control; /* Master control connection */
82829 atomic_t n_control; /* Number of controlled ones */
82830 struct ip_vs_dest *dest; /* real server */
82831 - atomic_t in_pkts; /* incoming packet counter */
82832 + atomic_unchecked_t in_pkts; /* incoming packet counter */
82833
82834 /* packet transmitter for different forwarding methods. If it
82835 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82836 @@ -705,7 +705,7 @@ struct ip_vs_dest {
82837 __be16 port; /* port number of the server */
82838 union nf_inet_addr addr; /* IP address of the server */
82839 volatile unsigned int flags; /* dest status flags */
82840 - atomic_t conn_flags; /* flags to copy to conn */
82841 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
82842 atomic_t weight; /* server weight */
82843
82844 atomic_t refcnt; /* reference counter */
82845 @@ -960,11 +960,11 @@ struct netns_ipvs {
82846 /* ip_vs_lblc */
82847 int sysctl_lblc_expiration;
82848 struct ctl_table_header *lblc_ctl_header;
82849 - struct ctl_table *lblc_ctl_table;
82850 + ctl_table_no_const *lblc_ctl_table;
82851 /* ip_vs_lblcr */
82852 int sysctl_lblcr_expiration;
82853 struct ctl_table_header *lblcr_ctl_header;
82854 - struct ctl_table *lblcr_ctl_table;
82855 + ctl_table_no_const *lblcr_ctl_table;
82856 /* ip_vs_est */
82857 struct list_head est_list; /* estimator list */
82858 spinlock_t est_lock;
82859 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82860 index 8d4f588..2e37ad2 100644
82861 --- a/include/net/irda/ircomm_tty.h
82862 +++ b/include/net/irda/ircomm_tty.h
82863 @@ -33,6 +33,7 @@
82864 #include <linux/termios.h>
82865 #include <linux/timer.h>
82866 #include <linux/tty.h> /* struct tty_struct */
82867 +#include <asm/local.h>
82868
82869 #include <net/irda/irias_object.h>
82870 #include <net/irda/ircomm_core.h>
82871 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82872 index 714cc9a..ea05f3e 100644
82873 --- a/include/net/iucv/af_iucv.h
82874 +++ b/include/net/iucv/af_iucv.h
82875 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
82876 struct iucv_sock_list {
82877 struct hlist_head head;
82878 rwlock_t lock;
82879 - atomic_t autobind_name;
82880 + atomic_unchecked_t autobind_name;
82881 };
82882
82883 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82884 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82885 index f3be818..bf46196 100644
82886 --- a/include/net/llc_c_ac.h
82887 +++ b/include/net/llc_c_ac.h
82888 @@ -87,7 +87,7 @@
82889 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82890 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82891
82892 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82893 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82894
82895 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82896 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82897 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82898 index 3948cf1..83b28c4 100644
82899 --- a/include/net/llc_c_ev.h
82900 +++ b/include/net/llc_c_ev.h
82901 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82902 return (struct llc_conn_state_ev *)skb->cb;
82903 }
82904
82905 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82906 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82907 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82908 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82909
82910 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82911 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82912 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82913 index 0e79cfb..f46db31 100644
82914 --- a/include/net/llc_c_st.h
82915 +++ b/include/net/llc_c_st.h
82916 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82917 u8 next_state;
82918 llc_conn_ev_qfyr_t *ev_qualifiers;
82919 llc_conn_action_t *ev_actions;
82920 -};
82921 +} __do_const;
82922
82923 struct llc_conn_state {
82924 u8 current_state;
82925 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82926 index a61b98c..aade1eb 100644
82927 --- a/include/net/llc_s_ac.h
82928 +++ b/include/net/llc_s_ac.h
82929 @@ -23,7 +23,7 @@
82930 #define SAP_ACT_TEST_IND 9
82931
82932 /* All action functions must look like this */
82933 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82934 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82935
82936 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82937 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82938 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82939 index 567c681..cd73ac0 100644
82940 --- a/include/net/llc_s_st.h
82941 +++ b/include/net/llc_s_st.h
82942 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82943 llc_sap_ev_t ev;
82944 u8 next_state;
82945 llc_sap_action_t *ev_actions;
82946 -};
82947 +} __do_const;
82948
82949 struct llc_sap_state {
82950 u8 curr_state;
82951 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82952 index f4ab2fb..71a85ba 100644
82953 --- a/include/net/mac80211.h
82954 +++ b/include/net/mac80211.h
82955 @@ -4476,7 +4476,7 @@ struct rate_control_ops {
82956 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82957 struct dentry *dir);
82958 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82959 -};
82960 +} __do_const;
82961
82962 static inline int rate_supported(struct ieee80211_sta *sta,
82963 enum ieee80211_band band,
82964 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82965 index 7277caf..fd095bc 100644
82966 --- a/include/net/neighbour.h
82967 +++ b/include/net/neighbour.h
82968 @@ -163,7 +163,7 @@ struct neigh_ops {
82969 void (*error_report)(struct neighbour *, struct sk_buff *);
82970 int (*output)(struct neighbour *, struct sk_buff *);
82971 int (*connected_output)(struct neighbour *, struct sk_buff *);
82972 -};
82973 +} __do_const;
82974
82975 struct pneigh_entry {
82976 struct pneigh_entry *next;
82977 @@ -203,7 +203,6 @@ struct neigh_table {
82978 void (*proxy_redo)(struct sk_buff *skb);
82979 char *id;
82980 struct neigh_parms parms;
82981 - /* HACK. gc_* should follow parms without a gap! */
82982 int gc_interval;
82983 int gc_thresh1;
82984 int gc_thresh2;
82985 @@ -218,7 +217,7 @@ struct neigh_table {
82986 struct neigh_statistics __percpu *stats;
82987 struct neigh_hash_table __rcu *nht;
82988 struct pneigh_entry **phash_buckets;
82989 -};
82990 +} __randomize_layout;
82991
82992 static inline int neigh_parms_family(struct neigh_parms *p)
82993 {
82994 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82995 index 991dcd9..ab58d00 100644
82996 --- a/include/net/net_namespace.h
82997 +++ b/include/net/net_namespace.h
82998 @@ -124,8 +124,8 @@ struct net {
82999 struct netns_ipvs *ipvs;
83000 #endif
83001 struct sock *diag_nlsk;
83002 - atomic_t fnhe_genid;
83003 -};
83004 + atomic_unchecked_t fnhe_genid;
83005 +} __randomize_layout;
83006
83007 /*
83008 * ifindex generation is per-net namespace, and loopback is
83009 @@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83010 #define __net_init __init
83011 #define __net_exit __exit_refok
83012 #define __net_initdata __initdata
83013 +#ifdef CONSTIFY_PLUGIN
83014 #define __net_initconst __initconst
83015 +#else
83016 +#define __net_initconst __initdata
83017 +#endif
83018 #endif
83019
83020 struct pernet_operations {
83021 @@ -299,7 +303,7 @@ struct pernet_operations {
83022 void (*exit_batch)(struct list_head *net_exit_list);
83023 int *id;
83024 size_t size;
83025 -};
83026 +} __do_const;
83027
83028 /*
83029 * Use these carefully. If you implement a network device and it
83030 @@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83031
83032 static inline int rt_genid_ipv4(struct net *net)
83033 {
83034 - return atomic_read(&net->ipv4.rt_genid);
83035 + return atomic_read_unchecked(&net->ipv4.rt_genid);
83036 }
83037
83038 static inline void rt_genid_bump_ipv4(struct net *net)
83039 {
83040 - atomic_inc(&net->ipv4.rt_genid);
83041 + atomic_inc_unchecked(&net->ipv4.rt_genid);
83042 }
83043
83044 #if IS_ENABLED(CONFIG_IPV6)
83045 static inline int rt_genid_ipv6(struct net *net)
83046 {
83047 - return atomic_read(&net->ipv6.rt_genid);
83048 + return atomic_read_unchecked(&net->ipv6.rt_genid);
83049 }
83050
83051 static inline void rt_genid_bump_ipv6(struct net *net)
83052 {
83053 - atomic_inc(&net->ipv6.rt_genid);
83054 + atomic_inc_unchecked(&net->ipv6.rt_genid);
83055 }
83056 #else
83057 static inline int rt_genid_ipv6(struct net *net)
83058 @@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83059
83060 static inline int fnhe_genid(struct net *net)
83061 {
83062 - return atomic_read(&net->fnhe_genid);
83063 + return atomic_read_unchecked(&net->fnhe_genid);
83064 }
83065
83066 static inline void fnhe_genid_bump(struct net *net)
83067 {
83068 - atomic_inc(&net->fnhe_genid);
83069 + atomic_inc_unchecked(&net->fnhe_genid);
83070 }
83071
83072 #endif /* __NET_NET_NAMESPACE_H */
83073 diff --git a/include/net/netdma.h b/include/net/netdma.h
83074 index 8ba8ce2..99b7fff 100644
83075 --- a/include/net/netdma.h
83076 +++ b/include/net/netdma.h
83077 @@ -24,7 +24,7 @@
83078 #include <linux/dmaengine.h>
83079 #include <linux/skbuff.h>
83080
83081 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83082 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83083 struct sk_buff *skb, int offset, struct iovec *to,
83084 size_t len, struct dma_pinned_list *pinned_list);
83085
83086 diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83087 index 956b175..55d1504 100644
83088 --- a/include/net/netfilter/nf_conntrack_extend.h
83089 +++ b/include/net/netfilter/nf_conntrack_extend.h
83090 @@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83091 /* Extensions: optional stuff which isn't permanently in struct. */
83092 struct nf_ct_ext {
83093 struct rcu_head rcu;
83094 - u8 offset[NF_CT_EXT_NUM];
83095 - u8 len;
83096 + u16 offset[NF_CT_EXT_NUM];
83097 + u16 len;
83098 char data[0];
83099 };
83100
83101 diff --git a/include/net/netlink.h b/include/net/netlink.h
83102 index 2b47eaa..6d5bcc2 100644
83103 --- a/include/net/netlink.h
83104 +++ b/include/net/netlink.h
83105 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83106 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83107 {
83108 if (mark)
83109 - skb_trim(skb, (unsigned char *) mark - skb->data);
83110 + skb_trim(skb, (const unsigned char *) mark - skb->data);
83111 }
83112
83113 /**
83114 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83115 index fbcc7fa..03c7e51 100644
83116 --- a/include/net/netns/conntrack.h
83117 +++ b/include/net/netns/conntrack.h
83118 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83119 struct nf_proto_net {
83120 #ifdef CONFIG_SYSCTL
83121 struct ctl_table_header *ctl_table_header;
83122 - struct ctl_table *ctl_table;
83123 + ctl_table_no_const *ctl_table;
83124 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83125 struct ctl_table_header *ctl_compat_header;
83126 - struct ctl_table *ctl_compat_table;
83127 + ctl_table_no_const *ctl_compat_table;
83128 #endif
83129 #endif
83130 unsigned int users;
83131 @@ -58,7 +58,7 @@ struct nf_ip_net {
83132 struct nf_icmp_net icmpv6;
83133 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83134 struct ctl_table_header *ctl_table_header;
83135 - struct ctl_table *ctl_table;
83136 + ctl_table_no_const *ctl_table;
83137 #endif
83138 };
83139
83140 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83141 index 80f500a..f0c23c2 100644
83142 --- a/include/net/netns/ipv4.h
83143 +++ b/include/net/netns/ipv4.h
83144 @@ -74,7 +74,7 @@ struct netns_ipv4 {
83145
83146 kgid_t sysctl_ping_group_range[2];
83147
83148 - atomic_t dev_addr_genid;
83149 + atomic_unchecked_t dev_addr_genid;
83150
83151 #ifdef CONFIG_IP_MROUTE
83152 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83153 @@ -84,6 +84,6 @@ struct netns_ipv4 {
83154 struct fib_rules_ops *mr_rules_ops;
83155 #endif
83156 #endif
83157 - atomic_t rt_genid;
83158 + atomic_unchecked_t rt_genid;
83159 };
83160 #endif
83161 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83162 index 21edaf1..4c5faae 100644
83163 --- a/include/net/netns/ipv6.h
83164 +++ b/include/net/netns/ipv6.h
83165 @@ -73,8 +73,8 @@ struct netns_ipv6 {
83166 struct fib_rules_ops *mr6_rules_ops;
83167 #endif
83168 #endif
83169 - atomic_t dev_addr_genid;
83170 - atomic_t rt_genid;
83171 + atomic_unchecked_t dev_addr_genid;
83172 + atomic_unchecked_t rt_genid;
83173 };
83174
83175 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83176 diff --git a/include/net/ping.h b/include/net/ping.h
83177 index 026479b..d9b2829 100644
83178 --- a/include/net/ping.h
83179 +++ b/include/net/ping.h
83180 @@ -54,7 +54,7 @@ struct ping_iter_state {
83181
83182 extern struct proto ping_prot;
83183 #if IS_ENABLED(CONFIG_IPV6)
83184 -extern struct pingv6_ops pingv6_ops;
83185 +extern struct pingv6_ops *pingv6_ops;
83186 #endif
83187
83188 struct pingfakehdr {
83189 diff --git a/include/net/protocol.h b/include/net/protocol.h
83190 index a7e986b..dc67bce 100644
83191 --- a/include/net/protocol.h
83192 +++ b/include/net/protocol.h
83193 @@ -49,7 +49,7 @@ struct net_protocol {
83194 * socket lookup?
83195 */
83196 icmp_strict_tag_validation:1;
83197 -};
83198 +} __do_const;
83199
83200 #if IS_ENABLED(CONFIG_IPV6)
83201 struct inet6_protocol {
83202 @@ -62,7 +62,7 @@ struct inet6_protocol {
83203 u8 type, u8 code, int offset,
83204 __be32 info);
83205 unsigned int flags; /* INET6_PROTO_xxx */
83206 -};
83207 +} __do_const;
83208
83209 #define INET6_PROTO_NOPOLICY 0x1
83210 #define INET6_PROTO_FINAL 0x2
83211 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83212 index 661e45d..54c39df 100644
83213 --- a/include/net/rtnetlink.h
83214 +++ b/include/net/rtnetlink.h
83215 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
83216 int (*fill_slave_info)(struct sk_buff *skb,
83217 const struct net_device *dev,
83218 const struct net_device *slave_dev);
83219 -};
83220 +} __do_const;
83221
83222 int __rtnl_link_register(struct rtnl_link_ops *ops);
83223 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83224 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83225 index 4a5b9a3..ca27d73 100644
83226 --- a/include/net/sctp/checksum.h
83227 +++ b/include/net/sctp/checksum.h
83228 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83229 unsigned int offset)
83230 {
83231 struct sctphdr *sh = sctp_hdr(skb);
83232 - __le32 ret, old = sh->checksum;
83233 - const struct skb_checksum_ops ops = {
83234 + __le32 ret, old = sh->checksum;
83235 + static const struct skb_checksum_ops ops = {
83236 .update = sctp_csum_update,
83237 .combine = sctp_csum_combine,
83238 };
83239 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83240 index 7f4eeb3..37e8fe1 100644
83241 --- a/include/net/sctp/sm.h
83242 +++ b/include/net/sctp/sm.h
83243 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83244 typedef struct {
83245 sctp_state_fn_t *fn;
83246 const char *name;
83247 -} sctp_sm_table_entry_t;
83248 +} __do_const sctp_sm_table_entry_t;
83249
83250 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83251 * currently in use.
83252 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83253 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83254
83255 /* Extern declarations for major data structures. */
83256 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83257 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83258
83259
83260 /* Get the size of a DATA chunk payload. */
83261 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83262 index 6ee76c8..45f2609 100644
83263 --- a/include/net/sctp/structs.h
83264 +++ b/include/net/sctp/structs.h
83265 @@ -507,7 +507,7 @@ struct sctp_pf {
83266 struct sctp_association *asoc);
83267 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83268 struct sctp_af *af;
83269 -};
83270 +} __do_const;
83271
83272
83273 /* Structure to track chunk fragments that have been acked, but peer
83274 diff --git a/include/net/sock.h b/include/net/sock.h
83275 index b9586a1..b2948c0 100644
83276 --- a/include/net/sock.h
83277 +++ b/include/net/sock.h
83278 @@ -348,7 +348,7 @@ struct sock {
83279 unsigned int sk_napi_id;
83280 unsigned int sk_ll_usec;
83281 #endif
83282 - atomic_t sk_drops;
83283 + atomic_unchecked_t sk_drops;
83284 int sk_rcvbuf;
83285
83286 struct sk_filter __rcu *sk_filter;
83287 @@ -1036,7 +1036,7 @@ struct proto {
83288 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83289 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83290 #endif
83291 -};
83292 +} __randomize_layout;
83293
83294 /*
83295 * Bits in struct cg_proto.flags
83296 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83297 return ret >> PAGE_SHIFT;
83298 }
83299
83300 -static inline long
83301 +static inline long __intentional_overflow(-1)
83302 sk_memory_allocated(const struct sock *sk)
83303 {
83304 struct proto *prot = sk->sk_prot;
83305 @@ -1368,7 +1368,7 @@ struct sock_iocb {
83306 struct scm_cookie *scm;
83307 struct msghdr *msg, async_msg;
83308 struct kiocb *kiocb;
83309 -};
83310 +} __randomize_layout;
83311
83312 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83313 {
83314 @@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83315 }
83316
83317 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83318 - char __user *from, char *to,
83319 + char __user *from, unsigned char *to,
83320 int copy, int offset)
83321 {
83322 if (skb->ip_summed == CHECKSUM_NONE) {
83323 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83324 }
83325 }
83326
83327 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83328 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83329
83330 /**
83331 * sk_page_frag - return an appropriate page_frag
83332 diff --git a/include/net/tcp.h b/include/net/tcp.h
83333 index 743acce..44a58b0 100644
83334 --- a/include/net/tcp.h
83335 +++ b/include/net/tcp.h
83336 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83337 void tcp_xmit_retransmit_queue(struct sock *);
83338 void tcp_simple_retransmit(struct sock *);
83339 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83340 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83341 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83342
83343 void tcp_send_probe0(struct sock *);
83344 void tcp_send_partial(struct sock *);
83345 @@ -710,8 +710,8 @@ struct tcp_skb_cb {
83346 struct inet6_skb_parm h6;
83347 #endif
83348 } header; /* For incoming frames */
83349 - __u32 seq; /* Starting sequence number */
83350 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83351 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
83352 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83353 __u32 when; /* used to compute rtt's */
83354 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83355
83356 @@ -725,7 +725,7 @@ struct tcp_skb_cb {
83357
83358 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83359 /* 1 byte hole */
83360 - __u32 ack_seq; /* Sequence number ACK'd */
83361 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83362 };
83363
83364 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83365 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83366 index fb5654a..4457522 100644
83367 --- a/include/net/xfrm.h
83368 +++ b/include/net/xfrm.h
83369 @@ -286,7 +286,6 @@ struct xfrm_dst;
83370 struct xfrm_policy_afinfo {
83371 unsigned short family;
83372 struct dst_ops *dst_ops;
83373 - void (*garbage_collect)(struct net *net);
83374 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83375 const xfrm_address_t *saddr,
83376 const xfrm_address_t *daddr);
83377 @@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
83378 struct net_device *dev,
83379 const struct flowi *fl);
83380 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83381 -};
83382 +} __do_const;
83383
83384 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83385 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83386 @@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
83387 int (*transport_finish)(struct sk_buff *skb,
83388 int async);
83389 void (*local_error)(struct sk_buff *skb, u32 mtu);
83390 -};
83391 +} __do_const;
83392
83393 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83394 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83395 @@ -428,7 +427,7 @@ struct xfrm_mode {
83396 struct module *owner;
83397 unsigned int encap;
83398 int flags;
83399 -};
83400 +} __do_const;
83401
83402 /* Flags for xfrm_mode. */
83403 enum {
83404 @@ -525,7 +524,7 @@ struct xfrm_policy {
83405 struct timer_list timer;
83406
83407 struct flow_cache_object flo;
83408 - atomic_t genid;
83409 + atomic_unchecked_t genid;
83410 u32 priority;
83411 u32 index;
83412 struct xfrm_mark mark;
83413 @@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83414 }
83415
83416 void xfrm_garbage_collect(struct net *net);
83417 +void xfrm_garbage_collect_deferred(struct net *net);
83418
83419 #else
83420
83421 @@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83422 static inline void xfrm_garbage_collect(struct net *net)
83423 {
83424 }
83425 +static inline void xfrm_garbage_collect_deferred(struct net *net)
83426 +{
83427 +}
83428 #endif
83429
83430 static __inline__
83431 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83432 index 1017e0b..227aa4d 100644
83433 --- a/include/rdma/iw_cm.h
83434 +++ b/include/rdma/iw_cm.h
83435 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
83436 int backlog);
83437
83438 int (*destroy_listen)(struct iw_cm_id *cm_id);
83439 -};
83440 +} __no_const;
83441
83442 /**
83443 * iw_create_cm_id - Create an IW CM identifier.
83444 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83445 index 52beadf..598734c 100644
83446 --- a/include/scsi/libfc.h
83447 +++ b/include/scsi/libfc.h
83448 @@ -771,6 +771,7 @@ struct libfc_function_template {
83449 */
83450 void (*disc_stop_final) (struct fc_lport *);
83451 };
83452 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83453
83454 /**
83455 * struct fc_disc - Discovery context
83456 @@ -875,7 +876,7 @@ struct fc_lport {
83457 struct fc_vport *vport;
83458
83459 /* Operational Information */
83460 - struct libfc_function_template tt;
83461 + libfc_function_template_no_const tt;
83462 u8 link_up;
83463 u8 qfull;
83464 enum fc_lport_state state;
83465 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83466 index d65fbec..f80fef2 100644
83467 --- a/include/scsi/scsi_device.h
83468 +++ b/include/scsi/scsi_device.h
83469 @@ -180,9 +180,9 @@ struct scsi_device {
83470 unsigned int max_device_blocked; /* what device_blocked counts down from */
83471 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83472
83473 - atomic_t iorequest_cnt;
83474 - atomic_t iodone_cnt;
83475 - atomic_t ioerr_cnt;
83476 + atomic_unchecked_t iorequest_cnt;
83477 + atomic_unchecked_t iodone_cnt;
83478 + atomic_unchecked_t ioerr_cnt;
83479
83480 struct device sdev_gendev,
83481 sdev_dev;
83482 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83483 index b797e8f..8e2c3aa 100644
83484 --- a/include/scsi/scsi_transport_fc.h
83485 +++ b/include/scsi/scsi_transport_fc.h
83486 @@ -751,7 +751,8 @@ struct fc_function_template {
83487 unsigned long show_host_system_hostname:1;
83488
83489 unsigned long disable_target_scan:1;
83490 -};
83491 +} __do_const;
83492 +typedef struct fc_function_template __no_const fc_function_template_no_const;
83493
83494
83495 /**
83496 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83497 index ae6c3b8..fd748ac 100644
83498 --- a/include/sound/compress_driver.h
83499 +++ b/include/sound/compress_driver.h
83500 @@ -128,7 +128,7 @@ struct snd_compr_ops {
83501 struct snd_compr_caps *caps);
83502 int (*get_codec_caps) (struct snd_compr_stream *stream,
83503 struct snd_compr_codec_caps *codec);
83504 -};
83505 +} __no_const;
83506
83507 /**
83508 * struct snd_compr: Compressed device
83509 diff --git a/include/sound/soc.h b/include/sound/soc.h
83510 index 9a00147..d814573 100644
83511 --- a/include/sound/soc.h
83512 +++ b/include/sound/soc.h
83513 @@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
83514 /* probe ordering - for components with runtime dependencies */
83515 int probe_order;
83516 int remove_order;
83517 -};
83518 +} __do_const;
83519
83520 /* SoC platform interface */
83521 struct snd_soc_platform_driver {
83522 @@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
83523 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83524 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83525 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83526 -};
83527 +} __do_const;
83528
83529 struct snd_soc_platform {
83530 const char *name;
83531 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83532 index 1772fad..282e3e2 100644
83533 --- a/include/target/target_core_base.h
83534 +++ b/include/target/target_core_base.h
83535 @@ -754,7 +754,7 @@ struct se_device {
83536 atomic_long_t write_bytes;
83537 /* Active commands on this virtual SE device */
83538 atomic_t simple_cmds;
83539 - atomic_t dev_ordered_id;
83540 + atomic_unchecked_t dev_ordered_id;
83541 atomic_t dev_ordered_sync;
83542 atomic_t dev_qf_count;
83543 int export_count;
83544 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83545 new file mode 100644
83546 index 0000000..fb634b7
83547 --- /dev/null
83548 +++ b/include/trace/events/fs.h
83549 @@ -0,0 +1,53 @@
83550 +#undef TRACE_SYSTEM
83551 +#define TRACE_SYSTEM fs
83552 +
83553 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83554 +#define _TRACE_FS_H
83555 +
83556 +#include <linux/fs.h>
83557 +#include <linux/tracepoint.h>
83558 +
83559 +TRACE_EVENT(do_sys_open,
83560 +
83561 + TP_PROTO(const char *filename, int flags, int mode),
83562 +
83563 + TP_ARGS(filename, flags, mode),
83564 +
83565 + TP_STRUCT__entry(
83566 + __string( filename, filename )
83567 + __field( int, flags )
83568 + __field( int, mode )
83569 + ),
83570 +
83571 + TP_fast_assign(
83572 + __assign_str(filename, filename);
83573 + __entry->flags = flags;
83574 + __entry->mode = mode;
83575 + ),
83576 +
83577 + TP_printk("\"%s\" %x %o",
83578 + __get_str(filename), __entry->flags, __entry->mode)
83579 +);
83580 +
83581 +TRACE_EVENT(open_exec,
83582 +
83583 + TP_PROTO(const char *filename),
83584 +
83585 + TP_ARGS(filename),
83586 +
83587 + TP_STRUCT__entry(
83588 + __string( filename, filename )
83589 + ),
83590 +
83591 + TP_fast_assign(
83592 + __assign_str(filename, filename);
83593 + ),
83594 +
83595 + TP_printk("\"%s\"",
83596 + __get_str(filename))
83597 +);
83598 +
83599 +#endif /* _TRACE_FS_H */
83600 +
83601 +/* This part must be outside protection */
83602 +#include <trace/define_trace.h>
83603 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83604 index 1c09820..7f5ec79 100644
83605 --- a/include/trace/events/irq.h
83606 +++ b/include/trace/events/irq.h
83607 @@ -36,7 +36,7 @@ struct softirq_action;
83608 */
83609 TRACE_EVENT(irq_handler_entry,
83610
83611 - TP_PROTO(int irq, struct irqaction *action),
83612 + TP_PROTO(int irq, const struct irqaction *action),
83613
83614 TP_ARGS(irq, action),
83615
83616 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83617 */
83618 TRACE_EVENT(irq_handler_exit,
83619
83620 - TP_PROTO(int irq, struct irqaction *action, int ret),
83621 + TP_PROTO(int irq, const struct irqaction *action, int ret),
83622
83623 TP_ARGS(irq, action, ret),
83624
83625 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83626 index 7caf44c..23c6f27 100644
83627 --- a/include/uapi/linux/a.out.h
83628 +++ b/include/uapi/linux/a.out.h
83629 @@ -39,6 +39,14 @@ enum machine_type {
83630 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83631 };
83632
83633 +/* Constants for the N_FLAGS field */
83634 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83635 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83636 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83637 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83638 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83639 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83640 +
83641 #if !defined (N_MAGIC)
83642 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83643 #endif
83644 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
83645 index 22b6ad3..aeba37e 100644
83646 --- a/include/uapi/linux/bcache.h
83647 +++ b/include/uapi/linux/bcache.h
83648 @@ -5,6 +5,7 @@
83649 * Bcache on disk data structures
83650 */
83651
83652 +#include <linux/compiler.h>
83653 #include <asm/types.h>
83654
83655 #define BITMASK(name, type, field, offset, size) \
83656 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
83657 /* Btree keys - all units are in sectors */
83658
83659 struct bkey {
83660 - __u64 high;
83661 - __u64 low;
83662 + __u64 high __intentional_overflow(-1);
83663 + __u64 low __intentional_overflow(-1);
83664 __u64 ptr[];
83665 };
83666
83667 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83668 index d876736..ccce5c0 100644
83669 --- a/include/uapi/linux/byteorder/little_endian.h
83670 +++ b/include/uapi/linux/byteorder/little_endian.h
83671 @@ -42,51 +42,51 @@
83672
83673 static inline __le64 __cpu_to_le64p(const __u64 *p)
83674 {
83675 - return (__force __le64)*p;
83676 + return (__force const __le64)*p;
83677 }
83678 -static inline __u64 __le64_to_cpup(const __le64 *p)
83679 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83680 {
83681 - return (__force __u64)*p;
83682 + return (__force const __u64)*p;
83683 }
83684 static inline __le32 __cpu_to_le32p(const __u32 *p)
83685 {
83686 - return (__force __le32)*p;
83687 + return (__force const __le32)*p;
83688 }
83689 static inline __u32 __le32_to_cpup(const __le32 *p)
83690 {
83691 - return (__force __u32)*p;
83692 + return (__force const __u32)*p;
83693 }
83694 static inline __le16 __cpu_to_le16p(const __u16 *p)
83695 {
83696 - return (__force __le16)*p;
83697 + return (__force const __le16)*p;
83698 }
83699 static inline __u16 __le16_to_cpup(const __le16 *p)
83700 {
83701 - return (__force __u16)*p;
83702 + return (__force const __u16)*p;
83703 }
83704 static inline __be64 __cpu_to_be64p(const __u64 *p)
83705 {
83706 - return (__force __be64)__swab64p(p);
83707 + return (__force const __be64)__swab64p(p);
83708 }
83709 static inline __u64 __be64_to_cpup(const __be64 *p)
83710 {
83711 - return __swab64p((__u64 *)p);
83712 + return __swab64p((const __u64 *)p);
83713 }
83714 static inline __be32 __cpu_to_be32p(const __u32 *p)
83715 {
83716 - return (__force __be32)__swab32p(p);
83717 + return (__force const __be32)__swab32p(p);
83718 }
83719 -static inline __u32 __be32_to_cpup(const __be32 *p)
83720 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83721 {
83722 - return __swab32p((__u32 *)p);
83723 + return __swab32p((const __u32 *)p);
83724 }
83725 static inline __be16 __cpu_to_be16p(const __u16 *p)
83726 {
83727 - return (__force __be16)__swab16p(p);
83728 + return (__force const __be16)__swab16p(p);
83729 }
83730 static inline __u16 __be16_to_cpup(const __be16 *p)
83731 {
83732 - return __swab16p((__u16 *)p);
83733 + return __swab16p((const __u16 *)p);
83734 }
83735 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83736 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83737 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83738 index ef6103b..d4e65dd 100644
83739 --- a/include/uapi/linux/elf.h
83740 +++ b/include/uapi/linux/elf.h
83741 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83742 #define PT_GNU_EH_FRAME 0x6474e550
83743
83744 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83745 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83746 +
83747 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83748 +
83749 +/* Constants for the e_flags field */
83750 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83751 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83752 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83753 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83754 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83755 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83756
83757 /*
83758 * Extended Numbering
83759 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83760 #define DT_DEBUG 21
83761 #define DT_TEXTREL 22
83762 #define DT_JMPREL 23
83763 +#define DT_FLAGS 30
83764 + #define DF_TEXTREL 0x00000004
83765 #define DT_ENCODING 32
83766 #define OLD_DT_LOOS 0x60000000
83767 #define DT_LOOS 0x6000000d
83768 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83769 #define PF_W 0x2
83770 #define PF_X 0x1
83771
83772 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83773 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83774 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83775 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83776 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83777 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83778 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83779 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83780 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83781 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83782 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83783 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83784 +
83785 typedef struct elf32_phdr{
83786 Elf32_Word p_type;
83787 Elf32_Off p_offset;
83788 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83789 #define EI_OSABI 7
83790 #define EI_PAD 8
83791
83792 +#define EI_PAX 14
83793 +
83794 #define ELFMAG0 0x7f /* EI_MAG */
83795 #define ELFMAG1 'E'
83796 #define ELFMAG2 'L'
83797 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83798 index aa169c4..6a2771d 100644
83799 --- a/include/uapi/linux/personality.h
83800 +++ b/include/uapi/linux/personality.h
83801 @@ -30,6 +30,7 @@ enum {
83802 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83803 ADDR_NO_RANDOMIZE | \
83804 ADDR_COMPAT_LAYOUT | \
83805 + ADDR_LIMIT_3GB | \
83806 MMAP_PAGE_ZERO)
83807
83808 /*
83809 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83810 index 7530e74..e714828 100644
83811 --- a/include/uapi/linux/screen_info.h
83812 +++ b/include/uapi/linux/screen_info.h
83813 @@ -43,7 +43,8 @@ struct screen_info {
83814 __u16 pages; /* 0x32 */
83815 __u16 vesa_attributes; /* 0x34 */
83816 __u32 capabilities; /* 0x36 */
83817 - __u8 _reserved[6]; /* 0x3a */
83818 + __u16 vesapm_size; /* 0x3a */
83819 + __u8 _reserved[4]; /* 0x3c */
83820 } __attribute__((packed));
83821
83822 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83823 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83824 index 0e011eb..82681b1 100644
83825 --- a/include/uapi/linux/swab.h
83826 +++ b/include/uapi/linux/swab.h
83827 @@ -43,7 +43,7 @@
83828 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83829 */
83830
83831 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
83832 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83833 {
83834 #ifdef __HAVE_BUILTIN_BSWAP16__
83835 return __builtin_bswap16(val);
83836 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83837 #endif
83838 }
83839
83840 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
83841 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83842 {
83843 #ifdef __HAVE_BUILTIN_BSWAP32__
83844 return __builtin_bswap32(val);
83845 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83846 #endif
83847 }
83848
83849 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
83850 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83851 {
83852 #ifdef __HAVE_BUILTIN_BSWAP64__
83853 return __builtin_bswap64(val);
83854 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83855 index 6d67213..552fdd9 100644
83856 --- a/include/uapi/linux/sysctl.h
83857 +++ b/include/uapi/linux/sysctl.h
83858 @@ -155,8 +155,6 @@ enum
83859 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83860 };
83861
83862 -
83863 -
83864 /* CTL_VM names: */
83865 enum
83866 {
83867 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83868 index 6ae7bbe..1e487fe 100644
83869 --- a/include/uapi/linux/videodev2.h
83870 +++ b/include/uapi/linux/videodev2.h
83871 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83872 union {
83873 __s32 value;
83874 __s64 value64;
83875 - char *string;
83876 + char __user *string;
83877 };
83878 } __attribute__ ((packed));
83879
83880 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83881 index 40bbc04..e30d9a2 100644
83882 --- a/include/uapi/linux/xattr.h
83883 +++ b/include/uapi/linux/xattr.h
83884 @@ -66,5 +66,9 @@
83885 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83886 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83887
83888 +/* User namespace */
83889 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83890 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
83891 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83892
83893 #endif /* _UAPI_LINUX_XATTR_H */
83894 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83895 index f9466fa..f4e2b81 100644
83896 --- a/include/video/udlfb.h
83897 +++ b/include/video/udlfb.h
83898 @@ -53,10 +53,10 @@ struct dlfb_data {
83899 u32 pseudo_palette[256];
83900 int blank_mode; /*one of FB_BLANK_ */
83901 /* blit-only rendering path metrics, exposed through sysfs */
83902 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83903 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83904 - atomic_t bytes_sent; /* to usb, after compression including overhead */
83905 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83906 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83907 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83908 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83909 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83910 };
83911
83912 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83913 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83914 index 30f5362..8ed8ac9 100644
83915 --- a/include/video/uvesafb.h
83916 +++ b/include/video/uvesafb.h
83917 @@ -122,6 +122,7 @@ struct uvesafb_par {
83918 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83919 u8 pmi_setpal; /* PMI for palette changes */
83920 u16 *pmi_base; /* protected mode interface location */
83921 + u8 *pmi_code; /* protected mode code location */
83922 void *pmi_start;
83923 void *pmi_pal;
83924 u8 *vbe_state_orig; /*
83925 diff --git a/init/Kconfig b/init/Kconfig
83926 index d56cb03..7e6d5dc 100644
83927 --- a/init/Kconfig
83928 +++ b/init/Kconfig
83929 @@ -1079,6 +1079,7 @@ endif # CGROUPS
83930
83931 config CHECKPOINT_RESTORE
83932 bool "Checkpoint/restore support" if EXPERT
83933 + depends on !GRKERNSEC
83934 default n
83935 help
83936 Enables additional kernel features in a sake of checkpoint/restore.
83937 @@ -1545,7 +1546,7 @@ config SLUB_DEBUG
83938
83939 config COMPAT_BRK
83940 bool "Disable heap randomization"
83941 - default y
83942 + default n
83943 help
83944 Randomizing heap placement makes heap exploits harder, but it
83945 also breaks ancient binaries (including anything libc5 based).
83946 @@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
83947 config STOP_MACHINE
83948 bool
83949 default y
83950 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83951 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83952 help
83953 Need stop_machine() primitive.
83954
83955 diff --git a/init/Makefile b/init/Makefile
83956 index 7bc47ee..6da2dc7 100644
83957 --- a/init/Makefile
83958 +++ b/init/Makefile
83959 @@ -2,6 +2,9 @@
83960 # Makefile for the linux kernel.
83961 #
83962
83963 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
83964 +asflags-y := $(GCC_PLUGINS_AFLAGS)
83965 +
83966 obj-y := main.o version.o mounts.o
83967 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83968 obj-y += noinitramfs.o
83969 diff --git a/init/do_mounts.c b/init/do_mounts.c
83970 index 8e5addc..c96ea61 100644
83971 --- a/init/do_mounts.c
83972 +++ b/init/do_mounts.c
83973 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83974 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83975 {
83976 struct super_block *s;
83977 - int err = sys_mount(name, "/root", fs, flags, data);
83978 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83979 if (err)
83980 return err;
83981
83982 - sys_chdir("/root");
83983 + sys_chdir((const char __force_user *)"/root");
83984 s = current->fs->pwd.dentry->d_sb;
83985 ROOT_DEV = s->s_dev;
83986 printk(KERN_INFO
83987 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83988 va_start(args, fmt);
83989 vsprintf(buf, fmt, args);
83990 va_end(args);
83991 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83992 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83993 if (fd >= 0) {
83994 sys_ioctl(fd, FDEJECT, 0);
83995 sys_close(fd);
83996 }
83997 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83998 - fd = sys_open("/dev/console", O_RDWR, 0);
83999 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84000 if (fd >= 0) {
84001 sys_ioctl(fd, TCGETS, (long)&termios);
84002 termios.c_lflag &= ~ICANON;
84003 sys_ioctl(fd, TCSETSF, (long)&termios);
84004 - sys_read(fd, &c, 1);
84005 + sys_read(fd, (char __user *)&c, 1);
84006 termios.c_lflag |= ICANON;
84007 sys_ioctl(fd, TCSETSF, (long)&termios);
84008 sys_close(fd);
84009 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84010 mount_root();
84011 out:
84012 devtmpfs_mount("dev");
84013 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84014 - sys_chroot(".");
84015 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84016 + sys_chroot((const char __force_user *)".");
84017 }
84018
84019 static bool is_tmpfs;
84020 diff --git a/init/do_mounts.h b/init/do_mounts.h
84021 index f5b978a..69dbfe8 100644
84022 --- a/init/do_mounts.h
84023 +++ b/init/do_mounts.h
84024 @@ -15,15 +15,15 @@ extern int root_mountflags;
84025
84026 static inline int create_dev(char *name, dev_t dev)
84027 {
84028 - sys_unlink(name);
84029 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84030 + sys_unlink((char __force_user *)name);
84031 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84032 }
84033
84034 #if BITS_PER_LONG == 32
84035 static inline u32 bstat(char *name)
84036 {
84037 struct stat64 stat;
84038 - if (sys_stat64(name, &stat) != 0)
84039 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84040 return 0;
84041 if (!S_ISBLK(stat.st_mode))
84042 return 0;
84043 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84044 static inline u32 bstat(char *name)
84045 {
84046 struct stat stat;
84047 - if (sys_newstat(name, &stat) != 0)
84048 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84049 return 0;
84050 if (!S_ISBLK(stat.st_mode))
84051 return 0;
84052 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84053 index 3e0878e..8a9d7a0 100644
84054 --- a/init/do_mounts_initrd.c
84055 +++ b/init/do_mounts_initrd.c
84056 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84057 {
84058 sys_unshare(CLONE_FS | CLONE_FILES);
84059 /* stdin/stdout/stderr for /linuxrc */
84060 - sys_open("/dev/console", O_RDWR, 0);
84061 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84062 sys_dup(0);
84063 sys_dup(0);
84064 /* move initrd over / and chdir/chroot in initrd root */
84065 - sys_chdir("/root");
84066 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84067 - sys_chroot(".");
84068 + sys_chdir((const char __force_user *)"/root");
84069 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84070 + sys_chroot((const char __force_user *)".");
84071 sys_setsid();
84072 return 0;
84073 }
84074 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84075 create_dev("/dev/root.old", Root_RAM0);
84076 /* mount initrd on rootfs' /root */
84077 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84078 - sys_mkdir("/old", 0700);
84079 - sys_chdir("/old");
84080 + sys_mkdir((const char __force_user *)"/old", 0700);
84081 + sys_chdir((const char __force_user *)"/old");
84082
84083 /* try loading default modules from initrd */
84084 load_default_modules();
84085 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84086 current->flags &= ~PF_FREEZER_SKIP;
84087
84088 /* move initrd to rootfs' /old */
84089 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
84090 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84091 /* switch root and cwd back to / of rootfs */
84092 - sys_chroot("..");
84093 + sys_chroot((const char __force_user *)"..");
84094
84095 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84096 - sys_chdir("/old");
84097 + sys_chdir((const char __force_user *)"/old");
84098 return;
84099 }
84100
84101 - sys_chdir("/");
84102 + sys_chdir((const char __force_user *)"/");
84103 ROOT_DEV = new_decode_dev(real_root_dev);
84104 mount_root();
84105
84106 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84107 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84108 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84109 if (!error)
84110 printk("okay\n");
84111 else {
84112 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
84113 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84114 if (error == -ENOENT)
84115 printk("/initrd does not exist. Ignored.\n");
84116 else
84117 printk("failed\n");
84118 printk(KERN_NOTICE "Unmounting old root\n");
84119 - sys_umount("/old", MNT_DETACH);
84120 + sys_umount((char __force_user *)"/old", MNT_DETACH);
84121 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84122 if (fd < 0) {
84123 error = fd;
84124 @@ -127,11 +127,11 @@ int __init initrd_load(void)
84125 * mounted in the normal path.
84126 */
84127 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84128 - sys_unlink("/initrd.image");
84129 + sys_unlink((const char __force_user *)"/initrd.image");
84130 handle_initrd();
84131 return 1;
84132 }
84133 }
84134 - sys_unlink("/initrd.image");
84135 + sys_unlink((const char __force_user *)"/initrd.image");
84136 return 0;
84137 }
84138 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84139 index 8cb6db5..d729f50 100644
84140 --- a/init/do_mounts_md.c
84141 +++ b/init/do_mounts_md.c
84142 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84143 partitioned ? "_d" : "", minor,
84144 md_setup_args[ent].device_names);
84145
84146 - fd = sys_open(name, 0, 0);
84147 + fd = sys_open((char __force_user *)name, 0, 0);
84148 if (fd < 0) {
84149 printk(KERN_ERR "md: open failed - cannot start "
84150 "array %s\n", name);
84151 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84152 * array without it
84153 */
84154 sys_close(fd);
84155 - fd = sys_open(name, 0, 0);
84156 + fd = sys_open((char __force_user *)name, 0, 0);
84157 sys_ioctl(fd, BLKRRPART, 0);
84158 }
84159 sys_close(fd);
84160 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84161
84162 wait_for_device_probe();
84163
84164 - fd = sys_open("/dev/md0", 0, 0);
84165 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84166 if (fd >= 0) {
84167 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84168 sys_close(fd);
84169 diff --git a/init/init_task.c b/init/init_task.c
84170 index ba0a7f36..2bcf1d5 100644
84171 --- a/init/init_task.c
84172 +++ b/init/init_task.c
84173 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84174 * Initial thread structure. Alignment of this is handled by a special
84175 * linker map entry.
84176 */
84177 +#ifdef CONFIG_X86
84178 +union thread_union init_thread_union __init_task_data;
84179 +#else
84180 union thread_union init_thread_union __init_task_data =
84181 { INIT_THREAD_INFO(init_task) };
84182 +#endif
84183 diff --git a/init/initramfs.c b/init/initramfs.c
84184 index 93b6139..8d628b7 100644
84185 --- a/init/initramfs.c
84186 +++ b/init/initramfs.c
84187 @@ -84,7 +84,7 @@ static void __init free_hash(void)
84188 }
84189 }
84190
84191 -static long __init do_utime(char *filename, time_t mtime)
84192 +static long __init do_utime(char __force_user *filename, time_t mtime)
84193 {
84194 struct timespec t[2];
84195
84196 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
84197 struct dir_entry *de, *tmp;
84198 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84199 list_del(&de->list);
84200 - do_utime(de->name, de->mtime);
84201 + do_utime((char __force_user *)de->name, de->mtime);
84202 kfree(de->name);
84203 kfree(de);
84204 }
84205 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
84206 if (nlink >= 2) {
84207 char *old = find_link(major, minor, ino, mode, collected);
84208 if (old)
84209 - return (sys_link(old, collected) < 0) ? -1 : 1;
84210 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84211 }
84212 return 0;
84213 }
84214 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84215 {
84216 struct stat st;
84217
84218 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84219 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84220 if (S_ISDIR(st.st_mode))
84221 - sys_rmdir(path);
84222 + sys_rmdir((char __force_user *)path);
84223 else
84224 - sys_unlink(path);
84225 + sys_unlink((char __force_user *)path);
84226 }
84227 }
84228
84229 @@ -315,7 +315,7 @@ static int __init do_name(void)
84230 int openflags = O_WRONLY|O_CREAT;
84231 if (ml != 1)
84232 openflags |= O_TRUNC;
84233 - wfd = sys_open(collected, openflags, mode);
84234 + wfd = sys_open((char __force_user *)collected, openflags, mode);
84235
84236 if (wfd >= 0) {
84237 sys_fchown(wfd, uid, gid);
84238 @@ -327,17 +327,17 @@ static int __init do_name(void)
84239 }
84240 }
84241 } else if (S_ISDIR(mode)) {
84242 - sys_mkdir(collected, mode);
84243 - sys_chown(collected, uid, gid);
84244 - sys_chmod(collected, mode);
84245 + sys_mkdir((char __force_user *)collected, mode);
84246 + sys_chown((char __force_user *)collected, uid, gid);
84247 + sys_chmod((char __force_user *)collected, mode);
84248 dir_add(collected, mtime);
84249 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84250 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84251 if (maybe_link() == 0) {
84252 - sys_mknod(collected, mode, rdev);
84253 - sys_chown(collected, uid, gid);
84254 - sys_chmod(collected, mode);
84255 - do_utime(collected, mtime);
84256 + sys_mknod((char __force_user *)collected, mode, rdev);
84257 + sys_chown((char __force_user *)collected, uid, gid);
84258 + sys_chmod((char __force_user *)collected, mode);
84259 + do_utime((char __force_user *)collected, mtime);
84260 }
84261 }
84262 return 0;
84263 @@ -346,15 +346,15 @@ static int __init do_name(void)
84264 static int __init do_copy(void)
84265 {
84266 if (count >= body_len) {
84267 - sys_write(wfd, victim, body_len);
84268 + sys_write(wfd, (char __force_user *)victim, body_len);
84269 sys_close(wfd);
84270 - do_utime(vcollected, mtime);
84271 + do_utime((char __force_user *)vcollected, mtime);
84272 kfree(vcollected);
84273 eat(body_len);
84274 state = SkipIt;
84275 return 0;
84276 } else {
84277 - sys_write(wfd, victim, count);
84278 + sys_write(wfd, (char __force_user *)victim, count);
84279 body_len -= count;
84280 eat(count);
84281 return 1;
84282 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
84283 {
84284 collected[N_ALIGN(name_len) + body_len] = '\0';
84285 clean_path(collected, 0);
84286 - sys_symlink(collected + N_ALIGN(name_len), collected);
84287 - sys_lchown(collected, uid, gid);
84288 - do_utime(collected, mtime);
84289 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84290 + sys_lchown((char __force_user *)collected, uid, gid);
84291 + do_utime((char __force_user *)collected, mtime);
84292 state = SkipIt;
84293 next_state = Reset;
84294 return 0;
84295 diff --git a/init/main.c b/init/main.c
84296 index 9c7fd4c..650b4f1 100644
84297 --- a/init/main.c
84298 +++ b/init/main.c
84299 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84300 static inline void mark_rodata_ro(void) { }
84301 #endif
84302
84303 +extern void grsecurity_init(void);
84304 +
84305 /*
84306 * Debug helper: via this flag we know that we are in 'early bootup code'
84307 * where only the boot processor is running with IRQ disabled. This means
84308 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84309
84310 __setup("reset_devices", set_reset_devices);
84311
84312 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84313 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84314 +static int __init setup_grsec_proc_gid(char *str)
84315 +{
84316 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84317 + return 1;
84318 +}
84319 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84320 +#endif
84321 +
84322 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84323 +unsigned long pax_user_shadow_base __read_only;
84324 +EXPORT_SYMBOL(pax_user_shadow_base);
84325 +extern char pax_enter_kernel_user[];
84326 +extern char pax_exit_kernel_user[];
84327 +#endif
84328 +
84329 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84330 +static int __init setup_pax_nouderef(char *str)
84331 +{
84332 +#ifdef CONFIG_X86_32
84333 + unsigned int cpu;
84334 + struct desc_struct *gdt;
84335 +
84336 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84337 + gdt = get_cpu_gdt_table(cpu);
84338 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84339 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84340 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84341 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84342 + }
84343 + loadsegment(ds, __KERNEL_DS);
84344 + loadsegment(es, __KERNEL_DS);
84345 + loadsegment(ss, __KERNEL_DS);
84346 +#else
84347 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84348 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84349 + clone_pgd_mask = ~(pgdval_t)0UL;
84350 + pax_user_shadow_base = 0UL;
84351 + setup_clear_cpu_cap(X86_FEATURE_PCID);
84352 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84353 +#endif
84354 +
84355 + return 0;
84356 +}
84357 +early_param("pax_nouderef", setup_pax_nouderef);
84358 +
84359 +#ifdef CONFIG_X86_64
84360 +static int __init setup_pax_weakuderef(char *str)
84361 +{
84362 + if (clone_pgd_mask != ~(pgdval_t)0UL)
84363 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84364 + return 1;
84365 +}
84366 +__setup("pax_weakuderef", setup_pax_weakuderef);
84367 +#endif
84368 +#endif
84369 +
84370 +#ifdef CONFIG_PAX_SOFTMODE
84371 +int pax_softmode;
84372 +
84373 +static int __init setup_pax_softmode(char *str)
84374 +{
84375 + get_option(&str, &pax_softmode);
84376 + return 1;
84377 +}
84378 +__setup("pax_softmode=", setup_pax_softmode);
84379 +#endif
84380 +
84381 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84382 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84383 static const char *panic_later, *panic_param;
84384 @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84385 {
84386 int count = preempt_count();
84387 int ret;
84388 - char msgbuf[64];
84389 + const char *msg1 = "", *msg2 = "";
84390
84391 if (initcall_debug)
84392 ret = do_one_initcall_debug(fn);
84393 else
84394 ret = fn();
84395
84396 - msgbuf[0] = 0;
84397 -
84398 if (preempt_count() != count) {
84399 - sprintf(msgbuf, "preemption imbalance ");
84400 + msg1 = " preemption imbalance";
84401 preempt_count_set(count);
84402 }
84403 if (irqs_disabled()) {
84404 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84405 + msg2 = " disabled interrupts";
84406 local_irq_enable();
84407 }
84408 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84409 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84410
84411 + add_latent_entropy();
84412 return ret;
84413 }
84414
84415 @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84416 {
84417 argv_init[0] = init_filename;
84418 return do_execve(getname_kernel(init_filename),
84419 - (const char __user *const __user *)argv_init,
84420 - (const char __user *const __user *)envp_init);
84421 + (const char __user *const __force_user *)argv_init,
84422 + (const char __user *const __force_user *)envp_init);
84423 }
84424
84425 static int try_to_run_init_process(const char *init_filename)
84426 @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84427 return ret;
84428 }
84429
84430 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84431 +extern int gr_init_ran;
84432 +#endif
84433 +
84434 static noinline void __init kernel_init_freeable(void);
84435
84436 static int __ref kernel_init(void *unused)
84437 @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
84438 ramdisk_execute_command, ret);
84439 }
84440
84441 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84442 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
84443 + gr_init_ran = 1;
84444 +#endif
84445 +
84446 /*
84447 * We try each of these until one succeeds.
84448 *
84449 @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
84450 do_basic_setup();
84451
84452 /* Open the /dev/console on the rootfs, this should never fail */
84453 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84454 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84455 pr_err("Warning: unable to open an initial console.\n");
84456
84457 (void) sys_dup(0);
84458 @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
84459 if (!ramdisk_execute_command)
84460 ramdisk_execute_command = "/init";
84461
84462 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84463 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84464 ramdisk_execute_command = NULL;
84465 prepare_namespace();
84466 }
84467
84468 + grsecurity_init();
84469 +
84470 /*
84471 * Ok, we have completed the initial bootup, and
84472 * we're essentially up and running. Get rid of the
84473 diff --git a/ipc/compat.c b/ipc/compat.c
84474 index f486b00..442867f 100644
84475 --- a/ipc/compat.c
84476 +++ b/ipc/compat.c
84477 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84478 COMPAT_SHMLBA);
84479 if (err < 0)
84480 return err;
84481 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84482 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84483 }
84484 case SHMDT:
84485 return sys_shmdt(compat_ptr(ptr));
84486 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84487 index 1702864..797fa84 100644
84488 --- a/ipc/ipc_sysctl.c
84489 +++ b/ipc/ipc_sysctl.c
84490 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84491 static int proc_ipc_dointvec(ctl_table *table, int write,
84492 void __user *buffer, size_t *lenp, loff_t *ppos)
84493 {
84494 - struct ctl_table ipc_table;
84495 + ctl_table_no_const ipc_table;
84496
84497 memcpy(&ipc_table, table, sizeof(ipc_table));
84498 ipc_table.data = get_ipc(table);
84499 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84500 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84501 void __user *buffer, size_t *lenp, loff_t *ppos)
84502 {
84503 - struct ctl_table ipc_table;
84504 + ctl_table_no_const ipc_table;
84505
84506 memcpy(&ipc_table, table, sizeof(ipc_table));
84507 ipc_table.data = get_ipc(table);
84508 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84509 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84510 void __user *buffer, size_t *lenp, loff_t *ppos)
84511 {
84512 - struct ctl_table ipc_table;
84513 + ctl_table_no_const ipc_table;
84514 size_t lenp_bef = *lenp;
84515 int rc;
84516
84517 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84518 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84519 void __user *buffer, size_t *lenp, loff_t *ppos)
84520 {
84521 - struct ctl_table ipc_table;
84522 + ctl_table_no_const ipc_table;
84523 memcpy(&ipc_table, table, sizeof(ipc_table));
84524 ipc_table.data = get_ipc(table);
84525
84526 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84527 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84528 void __user *buffer, size_t *lenp, loff_t *ppos)
84529 {
84530 - struct ctl_table ipc_table;
84531 + ctl_table_no_const ipc_table;
84532 size_t lenp_bef = *lenp;
84533 int oldval;
84534 int rc;
84535 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84536 index 5bb8bfe..a38ec05 100644
84537 --- a/ipc/mq_sysctl.c
84538 +++ b/ipc/mq_sysctl.c
84539 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84540 static int proc_mq_dointvec(ctl_table *table, int write,
84541 void __user *buffer, size_t *lenp, loff_t *ppos)
84542 {
84543 - struct ctl_table mq_table;
84544 + ctl_table_no_const mq_table;
84545 memcpy(&mq_table, table, sizeof(mq_table));
84546 mq_table.data = get_mq(table);
84547
84548 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84549 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84550 void __user *buffer, size_t *lenp, loff_t *ppos)
84551 {
84552 - struct ctl_table mq_table;
84553 + ctl_table_no_const mq_table;
84554 memcpy(&mq_table, table, sizeof(mq_table));
84555 mq_table.data = get_mq(table);
84556
84557 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84558 index c3b3117..1efa933 100644
84559 --- a/ipc/mqueue.c
84560 +++ b/ipc/mqueue.c
84561 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84562 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84563 info->attr.mq_msgsize);
84564
84565 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84566 spin_lock(&mq_lock);
84567 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84568 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84569 diff --git a/ipc/msg.c b/ipc/msg.c
84570 index 6498531..b0ff3c8 100644
84571 --- a/ipc/msg.c
84572 +++ b/ipc/msg.c
84573 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84574 return security_msg_queue_associate(msq, msgflg);
84575 }
84576
84577 +static struct ipc_ops msg_ops = {
84578 + .getnew = newque,
84579 + .associate = msg_security,
84580 + .more_checks = NULL
84581 +};
84582 +
84583 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84584 {
84585 struct ipc_namespace *ns;
84586 - struct ipc_ops msg_ops;
84587 struct ipc_params msg_params;
84588
84589 ns = current->nsproxy->ipc_ns;
84590
84591 - msg_ops.getnew = newque;
84592 - msg_ops.associate = msg_security;
84593 - msg_ops.more_checks = NULL;
84594 -
84595 msg_params.key = key;
84596 msg_params.flg = msgflg;
84597
84598 diff --git a/ipc/sem.c b/ipc/sem.c
84599 index bee5554..e9af81dd 100644
84600 --- a/ipc/sem.c
84601 +++ b/ipc/sem.c
84602 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84603 return 0;
84604 }
84605
84606 +static struct ipc_ops sem_ops = {
84607 + .getnew = newary,
84608 + .associate = sem_security,
84609 + .more_checks = sem_more_checks
84610 +};
84611 +
84612 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84613 {
84614 struct ipc_namespace *ns;
84615 - struct ipc_ops sem_ops;
84616 struct ipc_params sem_params;
84617
84618 ns = current->nsproxy->ipc_ns;
84619 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84620 if (nsems < 0 || nsems > ns->sc_semmsl)
84621 return -EINVAL;
84622
84623 - sem_ops.getnew = newary;
84624 - sem_ops.associate = sem_security;
84625 - sem_ops.more_checks = sem_more_checks;
84626 -
84627 sem_params.key = key;
84628 sem_params.flg = semflg;
84629 sem_params.u.nsems = nsems;
84630 diff --git a/ipc/shm.c b/ipc/shm.c
84631 index 7645961..afc7f02 100644
84632 --- a/ipc/shm.c
84633 +++ b/ipc/shm.c
84634 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
84635 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84636 #endif
84637
84638 +#ifdef CONFIG_GRKERNSEC
84639 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84640 + const time_t shm_createtime, const kuid_t cuid,
84641 + const int shmid);
84642 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84643 + const time_t shm_createtime);
84644 +#endif
84645 +
84646 void shm_init_ns(struct ipc_namespace *ns)
84647 {
84648 ns->shm_ctlmax = SHMMAX;
84649 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84650 shp->shm_lprid = 0;
84651 shp->shm_atim = shp->shm_dtim = 0;
84652 shp->shm_ctim = get_seconds();
84653 +#ifdef CONFIG_GRKERNSEC
84654 + {
84655 + struct timespec timeval;
84656 + do_posix_clock_monotonic_gettime(&timeval);
84657 +
84658 + shp->shm_createtime = timeval.tv_sec;
84659 + }
84660 +#endif
84661 shp->shm_segsz = size;
84662 shp->shm_nattch = 0;
84663 shp->shm_file = file;
84664 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84665 return 0;
84666 }
84667
84668 +static struct ipc_ops shm_ops = {
84669 + .getnew = newseg,
84670 + .associate = shm_security,
84671 + .more_checks = shm_more_checks
84672 +};
84673 +
84674 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84675 {
84676 struct ipc_namespace *ns;
84677 - struct ipc_ops shm_ops;
84678 struct ipc_params shm_params;
84679
84680 ns = current->nsproxy->ipc_ns;
84681
84682 - shm_ops.getnew = newseg;
84683 - shm_ops.associate = shm_security;
84684 - shm_ops.more_checks = shm_more_checks;
84685 -
84686 shm_params.key = key;
84687 shm_params.flg = shmflg;
84688 shm_params.u.size = size;
84689 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84690 f_mode = FMODE_READ | FMODE_WRITE;
84691 }
84692 if (shmflg & SHM_EXEC) {
84693 +
84694 +#ifdef CONFIG_PAX_MPROTECT
84695 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
84696 + goto out;
84697 +#endif
84698 +
84699 prot |= PROT_EXEC;
84700 acc_mode |= S_IXUGO;
84701 }
84702 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84703 if (err)
84704 goto out_unlock;
84705
84706 +#ifdef CONFIG_GRKERNSEC
84707 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84708 + shp->shm_perm.cuid, shmid) ||
84709 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84710 + err = -EACCES;
84711 + goto out_unlock;
84712 + }
84713 +#endif
84714 +
84715 ipc_lock_object(&shp->shm_perm);
84716
84717 /* check if shm_destroy() is tearing down shp */
84718 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84719 path = shp->shm_file->f_path;
84720 path_get(&path);
84721 shp->shm_nattch++;
84722 +#ifdef CONFIG_GRKERNSEC
84723 + shp->shm_lapid = current->pid;
84724 +#endif
84725 size = i_size_read(path.dentry->d_inode);
84726 ipc_unlock_object(&shp->shm_perm);
84727 rcu_read_unlock();
84728 diff --git a/ipc/util.c b/ipc/util.c
84729 index e1b4c6d..8174204 100644
84730 --- a/ipc/util.c
84731 +++ b/ipc/util.c
84732 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
84733 int (*show)(struct seq_file *, void *);
84734 };
84735
84736 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84737 +
84738 static void ipc_memory_notifier(struct work_struct *work)
84739 {
84740 ipcns_notify(IPCNS_MEMCHANGED);
84741 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84742 granted_mode >>= 6;
84743 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84744 granted_mode >>= 3;
84745 +
84746 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84747 + return -1;
84748 +
84749 /* is there some bit set in requested_mode but not in granted_mode? */
84750 if ((requested_mode & ~granted_mode & 0007) &&
84751 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84752 diff --git a/kernel/acct.c b/kernel/acct.c
84753 index 8d6e145..33e0b1e 100644
84754 --- a/kernel/acct.c
84755 +++ b/kernel/acct.c
84756 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84757 */
84758 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84759 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84760 - file->f_op->write(file, (char *)&ac,
84761 + file->f_op->write(file, (char __force_user *)&ac,
84762 sizeof(acct_t), &file->f_pos);
84763 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84764 set_fs(fs);
84765 diff --git a/kernel/audit.c b/kernel/audit.c
84766 index 95a20f3..e1cb300 100644
84767 --- a/kernel/audit.c
84768 +++ b/kernel/audit.c
84769 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
84770 3) suppressed due to audit_rate_limit
84771 4) suppressed due to audit_backlog_limit
84772 */
84773 -static atomic_t audit_lost = ATOMIC_INIT(0);
84774 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84775
84776 /* The netlink socket. */
84777 static struct sock *audit_sock;
84778 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
84779 unsigned long now;
84780 int print;
84781
84782 - atomic_inc(&audit_lost);
84783 + atomic_inc_unchecked(&audit_lost);
84784
84785 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84786
84787 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
84788 if (print) {
84789 if (printk_ratelimit())
84790 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
84791 - atomic_read(&audit_lost),
84792 + atomic_read_unchecked(&audit_lost),
84793 audit_rate_limit,
84794 audit_backlog_limit);
84795 audit_panic(message);
84796 @@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84797 s.pid = audit_pid;
84798 s.rate_limit = audit_rate_limit;
84799 s.backlog_limit = audit_backlog_limit;
84800 - s.lost = atomic_read(&audit_lost);
84801 + s.lost = atomic_read_unchecked(&audit_lost);
84802 s.backlog = skb_queue_len(&audit_skb_queue);
84803 s.version = AUDIT_VERSION_LATEST;
84804 s.backlog_wait_time = audit_backlog_wait_time;
84805 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84806 index 7aef2f4..db6ced2 100644
84807 --- a/kernel/auditsc.c
84808 +++ b/kernel/auditsc.c
84809 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84810 }
84811
84812 /* global counter which is incremented every time something logs in */
84813 -static atomic_t session_id = ATOMIC_INIT(0);
84814 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84815
84816 static int audit_set_loginuid_perm(kuid_t loginuid)
84817 {
84818 @@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
84819
84820 /* are we setting or clearing? */
84821 if (uid_valid(loginuid))
84822 - sessionid = (unsigned int)atomic_inc_return(&session_id);
84823 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
84824
84825 task->sessionid = sessionid;
84826 task->loginuid = loginuid;
84827 diff --git a/kernel/capability.c b/kernel/capability.c
84828 index 34019c5..363f279 100644
84829 --- a/kernel/capability.c
84830 +++ b/kernel/capability.c
84831 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84832 * before modification is attempted and the application
84833 * fails.
84834 */
84835 + if (tocopy > ARRAY_SIZE(kdata))
84836 + return -EFAULT;
84837 +
84838 if (copy_to_user(dataptr, kdata, tocopy
84839 * sizeof(struct __user_cap_data_struct))) {
84840 return -EFAULT;
84841 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84842 int ret;
84843
84844 rcu_read_lock();
84845 - ret = security_capable(__task_cred(t), ns, cap);
84846 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84847 + gr_task_is_capable(t, __task_cred(t), cap);
84848 rcu_read_unlock();
84849
84850 - return (ret == 0);
84851 + return ret;
84852 }
84853
84854 /**
84855 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84856 int ret;
84857
84858 rcu_read_lock();
84859 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
84860 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84861 rcu_read_unlock();
84862
84863 - return (ret == 0);
84864 + return ret;
84865 }
84866
84867 /**
84868 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84869 BUG();
84870 }
84871
84872 - if (security_capable(current_cred(), ns, cap) == 0) {
84873 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84874 current->flags |= PF_SUPERPRIV;
84875 return true;
84876 }
84877 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84878 }
84879 EXPORT_SYMBOL(ns_capable);
84880
84881 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
84882 +{
84883 + if (unlikely(!cap_valid(cap))) {
84884 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84885 + BUG();
84886 + }
84887 +
84888 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84889 + current->flags |= PF_SUPERPRIV;
84890 + return true;
84891 + }
84892 + return false;
84893 +}
84894 +EXPORT_SYMBOL(ns_capable_nolog);
84895 +
84896 /**
84897 * file_ns_capable - Determine if the file's opener had a capability in effect
84898 * @file: The file we want to check
84899 @@ -432,6 +451,12 @@ bool capable(int cap)
84900 }
84901 EXPORT_SYMBOL(capable);
84902
84903 +bool capable_nolog(int cap)
84904 +{
84905 + return ns_capable_nolog(&init_user_ns, cap);
84906 +}
84907 +EXPORT_SYMBOL(capable_nolog);
84908 +
84909 /**
84910 * inode_capable - Check superior capability over inode
84911 * @inode: The inode in question
84912 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84913 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84914 }
84915 EXPORT_SYMBOL(inode_capable);
84916 +
84917 +bool inode_capable_nolog(const struct inode *inode, int cap)
84918 +{
84919 + struct user_namespace *ns = current_user_ns();
84920 +
84921 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84922 +}
84923 +EXPORT_SYMBOL(inode_capable_nolog);
84924 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84925 index 0c753dd..dd7d3d6 100644
84926 --- a/kernel/cgroup.c
84927 +++ b/kernel/cgroup.c
84928 @@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
84929 struct css_set *cset = link->cset;
84930 struct task_struct *task;
84931 int count = 0;
84932 - seq_printf(seq, "css_set %p\n", cset);
84933 + seq_printf(seq, "css_set %pK\n", cset);
84934 list_for_each_entry(task, &cset->tasks, cg_list) {
84935 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84936 seq_puts(seq, " ...\n");
84937 diff --git a/kernel/compat.c b/kernel/compat.c
84938 index 0a09e48..b46b3d78 100644
84939 --- a/kernel/compat.c
84940 +++ b/kernel/compat.c
84941 @@ -13,6 +13,7 @@
84942
84943 #include <linux/linkage.h>
84944 #include <linux/compat.h>
84945 +#include <linux/module.h>
84946 #include <linux/errno.h>
84947 #include <linux/time.h>
84948 #include <linux/signal.h>
84949 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84950 mm_segment_t oldfs;
84951 long ret;
84952
84953 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84954 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84955 oldfs = get_fs();
84956 set_fs(KERNEL_DS);
84957 ret = hrtimer_nanosleep_restart(restart);
84958 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84959 oldfs = get_fs();
84960 set_fs(KERNEL_DS);
84961 ret = hrtimer_nanosleep(&tu,
84962 - rmtp ? (struct timespec __user *)&rmt : NULL,
84963 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
84964 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84965 set_fs(oldfs);
84966
84967 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84968 mm_segment_t old_fs = get_fs();
84969
84970 set_fs(KERNEL_DS);
84971 - ret = sys_sigpending((old_sigset_t __user *) &s);
84972 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
84973 set_fs(old_fs);
84974 if (ret == 0)
84975 ret = put_user(s, set);
84976 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84977 mm_segment_t old_fs = get_fs();
84978
84979 set_fs(KERNEL_DS);
84980 - ret = sys_old_getrlimit(resource, &r);
84981 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84982 set_fs(old_fs);
84983
84984 if (!ret) {
84985 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84986 set_fs (KERNEL_DS);
84987 ret = sys_wait4(pid,
84988 (stat_addr ?
84989 - (unsigned int __user *) &status : NULL),
84990 - options, (struct rusage __user *) &r);
84991 + (unsigned int __force_user *) &status : NULL),
84992 + options, (struct rusage __force_user *) &r);
84993 set_fs (old_fs);
84994
84995 if (ret > 0) {
84996 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84997 memset(&info, 0, sizeof(info));
84998
84999 set_fs(KERNEL_DS);
85000 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85001 - uru ? (struct rusage __user *)&ru : NULL);
85002 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85003 + uru ? (struct rusage __force_user *)&ru : NULL);
85004 set_fs(old_fs);
85005
85006 if ((ret < 0) || (info.si_signo == 0))
85007 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85008 oldfs = get_fs();
85009 set_fs(KERNEL_DS);
85010 err = sys_timer_settime(timer_id, flags,
85011 - (struct itimerspec __user *) &newts,
85012 - (struct itimerspec __user *) &oldts);
85013 + (struct itimerspec __force_user *) &newts,
85014 + (struct itimerspec __force_user *) &oldts);
85015 set_fs(oldfs);
85016 if (!err && old && put_compat_itimerspec(old, &oldts))
85017 return -EFAULT;
85018 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85019 oldfs = get_fs();
85020 set_fs(KERNEL_DS);
85021 err = sys_timer_gettime(timer_id,
85022 - (struct itimerspec __user *) &ts);
85023 + (struct itimerspec __force_user *) &ts);
85024 set_fs(oldfs);
85025 if (!err && put_compat_itimerspec(setting, &ts))
85026 return -EFAULT;
85027 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85028 oldfs = get_fs();
85029 set_fs(KERNEL_DS);
85030 err = sys_clock_settime(which_clock,
85031 - (struct timespec __user *) &ts);
85032 + (struct timespec __force_user *) &ts);
85033 set_fs(oldfs);
85034 return err;
85035 }
85036 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85037 oldfs = get_fs();
85038 set_fs(KERNEL_DS);
85039 err = sys_clock_gettime(which_clock,
85040 - (struct timespec __user *) &ts);
85041 + (struct timespec __force_user *) &ts);
85042 set_fs(oldfs);
85043 if (!err && put_compat_timespec(&ts, tp))
85044 return -EFAULT;
85045 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85046
85047 oldfs = get_fs();
85048 set_fs(KERNEL_DS);
85049 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85050 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85051 set_fs(oldfs);
85052
85053 err = compat_put_timex(utp, &txc);
85054 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85055 oldfs = get_fs();
85056 set_fs(KERNEL_DS);
85057 err = sys_clock_getres(which_clock,
85058 - (struct timespec __user *) &ts);
85059 + (struct timespec __force_user *) &ts);
85060 set_fs(oldfs);
85061 if (!err && tp && put_compat_timespec(&ts, tp))
85062 return -EFAULT;
85063 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85064 long err;
85065 mm_segment_t oldfs;
85066 struct timespec tu;
85067 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85068 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85069
85070 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85071 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85072 oldfs = get_fs();
85073 set_fs(KERNEL_DS);
85074 err = clock_nanosleep_restart(restart);
85075 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85076 oldfs = get_fs();
85077 set_fs(KERNEL_DS);
85078 err = sys_clock_nanosleep(which_clock, flags,
85079 - (struct timespec __user *) &in,
85080 - (struct timespec __user *) &out);
85081 + (struct timespec __force_user *) &in,
85082 + (struct timespec __force_user *) &out);
85083 set_fs(oldfs);
85084
85085 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85086 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85087 mm_segment_t old_fs = get_fs();
85088
85089 set_fs(KERNEL_DS);
85090 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85091 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85092 set_fs(old_fs);
85093 if (put_compat_timespec(&t, interval))
85094 return -EFAULT;
85095 diff --git a/kernel/configs.c b/kernel/configs.c
85096 index c18b1f1..b9a0132 100644
85097 --- a/kernel/configs.c
85098 +++ b/kernel/configs.c
85099 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85100 struct proc_dir_entry *entry;
85101
85102 /* create the current config file */
85103 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85104 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85105 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85106 + &ikconfig_file_ops);
85107 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85108 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85109 + &ikconfig_file_ops);
85110 +#endif
85111 +#else
85112 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85113 &ikconfig_file_ops);
85114 +#endif
85115 +
85116 if (!entry)
85117 return -ENOMEM;
85118
85119 diff --git a/kernel/cred.c b/kernel/cred.c
85120 index e0573a4..3874e41 100644
85121 --- a/kernel/cred.c
85122 +++ b/kernel/cred.c
85123 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85124 validate_creds(cred);
85125 alter_cred_subscribers(cred, -1);
85126 put_cred(cred);
85127 +
85128 +#ifdef CONFIG_GRKERNSEC_SETXID
85129 + cred = (struct cred *) tsk->delayed_cred;
85130 + if (cred != NULL) {
85131 + tsk->delayed_cred = NULL;
85132 + validate_creds(cred);
85133 + alter_cred_subscribers(cred, -1);
85134 + put_cred(cred);
85135 + }
85136 +#endif
85137 }
85138
85139 /**
85140 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85141 * Always returns 0 thus allowing this function to be tail-called at the end
85142 * of, say, sys_setgid().
85143 */
85144 -int commit_creds(struct cred *new)
85145 +static int __commit_creds(struct cred *new)
85146 {
85147 struct task_struct *task = current;
85148 const struct cred *old = task->real_cred;
85149 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85150
85151 get_cred(new); /* we will require a ref for the subj creds too */
85152
85153 + gr_set_role_label(task, new->uid, new->gid);
85154 +
85155 /* dumpability changes */
85156 if (!uid_eq(old->euid, new->euid) ||
85157 !gid_eq(old->egid, new->egid) ||
85158 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85159 put_cred(old);
85160 return 0;
85161 }
85162 +#ifdef CONFIG_GRKERNSEC_SETXID
85163 +extern int set_user(struct cred *new);
85164 +
85165 +void gr_delayed_cred_worker(void)
85166 +{
85167 + const struct cred *new = current->delayed_cred;
85168 + struct cred *ncred;
85169 +
85170 + current->delayed_cred = NULL;
85171 +
85172 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85173 + // from doing get_cred on it when queueing this
85174 + put_cred(new);
85175 + return;
85176 + } else if (new == NULL)
85177 + return;
85178 +
85179 + ncred = prepare_creds();
85180 + if (!ncred)
85181 + goto die;
85182 + // uids
85183 + ncred->uid = new->uid;
85184 + ncred->euid = new->euid;
85185 + ncred->suid = new->suid;
85186 + ncred->fsuid = new->fsuid;
85187 + // gids
85188 + ncred->gid = new->gid;
85189 + ncred->egid = new->egid;
85190 + ncred->sgid = new->sgid;
85191 + ncred->fsgid = new->fsgid;
85192 + // groups
85193 + if (set_groups(ncred, new->group_info) < 0) {
85194 + abort_creds(ncred);
85195 + goto die;
85196 + }
85197 + // caps
85198 + ncred->securebits = new->securebits;
85199 + ncred->cap_inheritable = new->cap_inheritable;
85200 + ncred->cap_permitted = new->cap_permitted;
85201 + ncred->cap_effective = new->cap_effective;
85202 + ncred->cap_bset = new->cap_bset;
85203 +
85204 + if (set_user(ncred)) {
85205 + abort_creds(ncred);
85206 + goto die;
85207 + }
85208 +
85209 + // from doing get_cred on it when queueing this
85210 + put_cred(new);
85211 +
85212 + __commit_creds(ncred);
85213 + return;
85214 +die:
85215 + // from doing get_cred on it when queueing this
85216 + put_cred(new);
85217 + do_group_exit(SIGKILL);
85218 +}
85219 +#endif
85220 +
85221 +int commit_creds(struct cred *new)
85222 +{
85223 +#ifdef CONFIG_GRKERNSEC_SETXID
85224 + int ret;
85225 + int schedule_it = 0;
85226 + struct task_struct *t;
85227 +
85228 + /* we won't get called with tasklist_lock held for writing
85229 + and interrupts disabled as the cred struct in that case is
85230 + init_cred
85231 + */
85232 + if (grsec_enable_setxid && !current_is_single_threaded() &&
85233 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85234 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85235 + schedule_it = 1;
85236 + }
85237 + ret = __commit_creds(new);
85238 + if (schedule_it) {
85239 + rcu_read_lock();
85240 + read_lock(&tasklist_lock);
85241 + for (t = next_thread(current); t != current;
85242 + t = next_thread(t)) {
85243 + if (t->delayed_cred == NULL) {
85244 + t->delayed_cred = get_cred(new);
85245 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85246 + set_tsk_need_resched(t);
85247 + }
85248 + }
85249 + read_unlock(&tasklist_lock);
85250 + rcu_read_unlock();
85251 + }
85252 + return ret;
85253 +#else
85254 + return __commit_creds(new);
85255 +#endif
85256 +}
85257 +
85258 EXPORT_SYMBOL(commit_creds);
85259
85260 /**
85261 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85262 index 334b398..9145fb1 100644
85263 --- a/kernel/debug/debug_core.c
85264 +++ b/kernel/debug/debug_core.c
85265 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85266 */
85267 static atomic_t masters_in_kgdb;
85268 static atomic_t slaves_in_kgdb;
85269 -static atomic_t kgdb_break_tasklet_var;
85270 +static atomic_unchecked_t kgdb_break_tasklet_var;
85271 atomic_t kgdb_setting_breakpoint;
85272
85273 struct task_struct *kgdb_usethread;
85274 @@ -133,7 +133,7 @@ int kgdb_single_step;
85275 static pid_t kgdb_sstep_pid;
85276
85277 /* to keep track of the CPU which is doing the single stepping*/
85278 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85279 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85280
85281 /*
85282 * If you are debugging a problem where roundup (the collection of
85283 @@ -541,7 +541,7 @@ return_normal:
85284 * kernel will only try for the value of sstep_tries before
85285 * giving up and continuing on.
85286 */
85287 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85288 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85289 (kgdb_info[cpu].task &&
85290 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85291 atomic_set(&kgdb_active, -1);
85292 @@ -639,8 +639,8 @@ cpu_master_loop:
85293 }
85294
85295 kgdb_restore:
85296 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85297 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85298 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85299 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85300 if (kgdb_info[sstep_cpu].task)
85301 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85302 else
85303 @@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
85304 static void kgdb_tasklet_bpt(unsigned long ing)
85305 {
85306 kgdb_breakpoint();
85307 - atomic_set(&kgdb_break_tasklet_var, 0);
85308 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85309 }
85310
85311 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85312
85313 void kgdb_schedule_breakpoint(void)
85314 {
85315 - if (atomic_read(&kgdb_break_tasklet_var) ||
85316 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85317 atomic_read(&kgdb_active) != -1 ||
85318 atomic_read(&kgdb_setting_breakpoint))
85319 return;
85320 - atomic_inc(&kgdb_break_tasklet_var);
85321 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
85322 tasklet_schedule(&kgdb_tasklet_breakpoint);
85323 }
85324 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85325 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85326 index 0b097c8..11dd5c5 100644
85327 --- a/kernel/debug/kdb/kdb_main.c
85328 +++ b/kernel/debug/kdb/kdb_main.c
85329 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85330 continue;
85331
85332 kdb_printf("%-20s%8u 0x%p ", mod->name,
85333 - mod->core_size, (void *)mod);
85334 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
85335 #ifdef CONFIG_MODULE_UNLOAD
85336 kdb_printf("%4ld ", module_refcount(mod));
85337 #endif
85338 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85339 kdb_printf(" (Loading)");
85340 else
85341 kdb_printf(" (Live)");
85342 - kdb_printf(" 0x%p", mod->module_core);
85343 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85344
85345 #ifdef CONFIG_MODULE_UNLOAD
85346 {
85347 diff --git a/kernel/events/core.c b/kernel/events/core.c
85348 index fa0b2d4..67a1c7a 100644
85349 --- a/kernel/events/core.c
85350 +++ b/kernel/events/core.c
85351 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85352 * 0 - disallow raw tracepoint access for unpriv
85353 * 1 - disallow cpu events for unpriv
85354 * 2 - disallow kernel profiling for unpriv
85355 + * 3 - disallow all unpriv perf event use
85356 */
85357 -int sysctl_perf_event_paranoid __read_mostly = 1;
85358 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85359 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85360 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85361 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85362 +#else
85363 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85364 +#endif
85365
85366 /* Minimum for 512 kiB + 1 user control page */
85367 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85368 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85369
85370 tmp *= sysctl_perf_cpu_time_max_percent;
85371 do_div(tmp, 100);
85372 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85373 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85374 }
85375
85376 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85377 @@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85378 update_perf_cpu_limits();
85379 }
85380
85381 -static atomic64_t perf_event_id;
85382 +static atomic64_unchecked_t perf_event_id;
85383
85384 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85385 enum event_type_t event_type);
85386 @@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
85387
85388 static inline u64 perf_event_count(struct perf_event *event)
85389 {
85390 - return local64_read(&event->count) + atomic64_read(&event->child_count);
85391 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85392 }
85393
85394 static u64 perf_event_read(struct perf_event *event)
85395 @@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85396 mutex_lock(&event->child_mutex);
85397 total += perf_event_read(event);
85398 *enabled += event->total_time_enabled +
85399 - atomic64_read(&event->child_total_time_enabled);
85400 + atomic64_read_unchecked(&event->child_total_time_enabled);
85401 *running += event->total_time_running +
85402 - atomic64_read(&event->child_total_time_running);
85403 + atomic64_read_unchecked(&event->child_total_time_running);
85404
85405 list_for_each_entry(child, &event->child_list, child_list) {
85406 total += perf_event_read(child);
85407 @@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
85408 userpg->offset -= local64_read(&event->hw.prev_count);
85409
85410 userpg->time_enabled = enabled +
85411 - atomic64_read(&event->child_total_time_enabled);
85412 + atomic64_read_unchecked(&event->child_total_time_enabled);
85413
85414 userpg->time_running = running +
85415 - atomic64_read(&event->child_total_time_running);
85416 + atomic64_read_unchecked(&event->child_total_time_running);
85417
85418 arch_perf_update_userpage(userpg, now);
85419
85420 @@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85421
85422 /* Data. */
85423 sp = perf_user_stack_pointer(regs);
85424 - rem = __output_copy_user(handle, (void *) sp, dump_size);
85425 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85426 dyn_size = dump_size - rem;
85427
85428 perf_output_skip(handle, rem);
85429 @@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85430 values[n++] = perf_event_count(event);
85431 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85432 values[n++] = enabled +
85433 - atomic64_read(&event->child_total_time_enabled);
85434 + atomic64_read_unchecked(&event->child_total_time_enabled);
85435 }
85436 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85437 values[n++] = running +
85438 - atomic64_read(&event->child_total_time_running);
85439 + atomic64_read_unchecked(&event->child_total_time_running);
85440 }
85441 if (read_format & PERF_FORMAT_ID)
85442 values[n++] = primary_event_id(event);
85443 @@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85444 event->parent = parent_event;
85445
85446 event->ns = get_pid_ns(task_active_pid_ns(current));
85447 - event->id = atomic64_inc_return(&perf_event_id);
85448 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
85449
85450 event->state = PERF_EVENT_STATE_INACTIVE;
85451
85452 @@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
85453 if (flags & ~PERF_FLAG_ALL)
85454 return -EINVAL;
85455
85456 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85457 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85458 + return -EACCES;
85459 +#endif
85460 +
85461 err = perf_copy_attr(attr_uptr, &attr);
85462 if (err)
85463 return err;
85464 @@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
85465 /*
85466 * Add back the child's count to the parent's count:
85467 */
85468 - atomic64_add(child_val, &parent_event->child_count);
85469 - atomic64_add(child_event->total_time_enabled,
85470 + atomic64_add_unchecked(child_val, &parent_event->child_count);
85471 + atomic64_add_unchecked(child_event->total_time_enabled,
85472 &parent_event->child_total_time_enabled);
85473 - atomic64_add(child_event->total_time_running,
85474 + atomic64_add_unchecked(child_event->total_time_running,
85475 &parent_event->child_total_time_running);
85476
85477 /*
85478 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85479 index 569b2187..19940d9 100644
85480 --- a/kernel/events/internal.h
85481 +++ b/kernel/events/internal.h
85482 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85483 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85484 }
85485
85486 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85487 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85488 static inline unsigned long \
85489 func_name(struct perf_output_handle *handle, \
85490 - const void *buf, unsigned long len) \
85491 + const void user *buf, unsigned long len) \
85492 { \
85493 unsigned long size, written; \
85494 \
85495 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85496 return 0;
85497 }
85498
85499 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85500 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85501
85502 static inline unsigned long
85503 memcpy_skip(void *dst, const void *src, unsigned long n)
85504 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85505 return 0;
85506 }
85507
85508 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85509 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85510
85511 #ifndef arch_perf_out_copy_user
85512 #define arch_perf_out_copy_user arch_perf_out_copy_user
85513 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85514 }
85515 #endif
85516
85517 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85518 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85519
85520 /* Callchain handling */
85521 extern struct perf_callchain_entry *
85522 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85523 index 307d87c..6466cbe 100644
85524 --- a/kernel/events/uprobes.c
85525 +++ b/kernel/events/uprobes.c
85526 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85527 {
85528 struct page *page;
85529 uprobe_opcode_t opcode;
85530 - int result;
85531 + long result;
85532
85533 pagefault_disable();
85534 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85535 diff --git a/kernel/exit.c b/kernel/exit.c
85536 index 81b3d67..ef189a4 100644
85537 --- a/kernel/exit.c
85538 +++ b/kernel/exit.c
85539 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
85540 struct task_struct *leader;
85541 int zap_leader;
85542 repeat:
85543 +#ifdef CONFIG_NET
85544 + gr_del_task_from_ip_table(p);
85545 +#endif
85546 +
85547 /* don't need to get the RCU readlock here - the process is dead and
85548 * can't be modifying its own credentials. But shut RCU-lockdep up */
85549 rcu_read_lock();
85550 @@ -330,7 +334,7 @@ int allow_signal(int sig)
85551 * know it'll be handled, so that they don't get converted to
85552 * SIGKILL or just silently dropped.
85553 */
85554 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85555 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85556 recalc_sigpending();
85557 spin_unlock_irq(&current->sighand->siglock);
85558 return 0;
85559 @@ -706,6 +710,8 @@ void do_exit(long code)
85560 struct task_struct *tsk = current;
85561 int group_dead;
85562
85563 + set_fs(USER_DS);
85564 +
85565 profile_task_exit(tsk);
85566
85567 WARN_ON(blk_needs_flush_plug(tsk));
85568 @@ -722,7 +728,6 @@ void do_exit(long code)
85569 * mm_release()->clear_child_tid() from writing to a user-controlled
85570 * kernel address.
85571 */
85572 - set_fs(USER_DS);
85573
85574 ptrace_event(PTRACE_EVENT_EXIT, code);
85575
85576 @@ -781,6 +786,9 @@ void do_exit(long code)
85577 tsk->exit_code = code;
85578 taskstats_exit(tsk, group_dead);
85579
85580 + gr_acl_handle_psacct(tsk, code);
85581 + gr_acl_handle_exit();
85582 +
85583 exit_mm(tsk);
85584
85585 if (group_dead)
85586 @@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85587 * Take down every thread in the group. This is called by fatal signals
85588 * as well as by sys_exit_group (below).
85589 */
85590 -void
85591 +__noreturn void
85592 do_group_exit(int exit_code)
85593 {
85594 struct signal_struct *sig = current->signal;
85595 diff --git a/kernel/fork.c b/kernel/fork.c
85596 index a17621c..b77fef8 100644
85597 --- a/kernel/fork.c
85598 +++ b/kernel/fork.c
85599 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85600 *stackend = STACK_END_MAGIC; /* for overflow detection */
85601
85602 #ifdef CONFIG_CC_STACKPROTECTOR
85603 - tsk->stack_canary = get_random_int();
85604 + tsk->stack_canary = pax_get_random_long();
85605 #endif
85606
85607 /*
85608 @@ -345,12 +345,80 @@ free_tsk:
85609 }
85610
85611 #ifdef CONFIG_MMU
85612 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85613 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85614 +{
85615 + struct vm_area_struct *tmp;
85616 + unsigned long charge;
85617 + struct file *file;
85618 + int retval;
85619 +
85620 + charge = 0;
85621 + if (mpnt->vm_flags & VM_ACCOUNT) {
85622 + unsigned long len = vma_pages(mpnt);
85623 +
85624 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85625 + goto fail_nomem;
85626 + charge = len;
85627 + }
85628 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85629 + if (!tmp)
85630 + goto fail_nomem;
85631 + *tmp = *mpnt;
85632 + tmp->vm_mm = mm;
85633 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
85634 + retval = vma_dup_policy(mpnt, tmp);
85635 + if (retval)
85636 + goto fail_nomem_policy;
85637 + if (anon_vma_fork(tmp, mpnt))
85638 + goto fail_nomem_anon_vma_fork;
85639 + tmp->vm_flags &= ~VM_LOCKED;
85640 + tmp->vm_next = tmp->vm_prev = NULL;
85641 + tmp->vm_mirror = NULL;
85642 + file = tmp->vm_file;
85643 + if (file) {
85644 + struct inode *inode = file_inode(file);
85645 + struct address_space *mapping = file->f_mapping;
85646 +
85647 + get_file(file);
85648 + if (tmp->vm_flags & VM_DENYWRITE)
85649 + atomic_dec(&inode->i_writecount);
85650 + mutex_lock(&mapping->i_mmap_mutex);
85651 + if (tmp->vm_flags & VM_SHARED)
85652 + mapping->i_mmap_writable++;
85653 + flush_dcache_mmap_lock(mapping);
85654 + /* insert tmp into the share list, just after mpnt */
85655 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85656 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85657 + else
85658 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85659 + flush_dcache_mmap_unlock(mapping);
85660 + mutex_unlock(&mapping->i_mmap_mutex);
85661 + }
85662 +
85663 + /*
85664 + * Clear hugetlb-related page reserves for children. This only
85665 + * affects MAP_PRIVATE mappings. Faults generated by the child
85666 + * are not guaranteed to succeed, even if read-only
85667 + */
85668 + if (is_vm_hugetlb_page(tmp))
85669 + reset_vma_resv_huge_pages(tmp);
85670 +
85671 + return tmp;
85672 +
85673 +fail_nomem_anon_vma_fork:
85674 + mpol_put(vma_policy(tmp));
85675 +fail_nomem_policy:
85676 + kmem_cache_free(vm_area_cachep, tmp);
85677 +fail_nomem:
85678 + vm_unacct_memory(charge);
85679 + return NULL;
85680 +}
85681 +
85682 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85683 {
85684 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85685 struct rb_node **rb_link, *rb_parent;
85686 int retval;
85687 - unsigned long charge;
85688
85689 uprobe_start_dup_mmap();
85690 down_write(&oldmm->mmap_sem);
85691 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85692
85693 prev = NULL;
85694 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85695 - struct file *file;
85696 -
85697 if (mpnt->vm_flags & VM_DONTCOPY) {
85698 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85699 -vma_pages(mpnt));
85700 continue;
85701 }
85702 - charge = 0;
85703 - if (mpnt->vm_flags & VM_ACCOUNT) {
85704 - unsigned long len = vma_pages(mpnt);
85705 -
85706 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85707 - goto fail_nomem;
85708 - charge = len;
85709 - }
85710 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85711 - if (!tmp)
85712 - goto fail_nomem;
85713 - *tmp = *mpnt;
85714 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
85715 - retval = vma_dup_policy(mpnt, tmp);
85716 - if (retval)
85717 - goto fail_nomem_policy;
85718 - tmp->vm_mm = mm;
85719 - if (anon_vma_fork(tmp, mpnt))
85720 - goto fail_nomem_anon_vma_fork;
85721 - tmp->vm_flags &= ~VM_LOCKED;
85722 - tmp->vm_next = tmp->vm_prev = NULL;
85723 - file = tmp->vm_file;
85724 - if (file) {
85725 - struct inode *inode = file_inode(file);
85726 - struct address_space *mapping = file->f_mapping;
85727 -
85728 - get_file(file);
85729 - if (tmp->vm_flags & VM_DENYWRITE)
85730 - atomic_dec(&inode->i_writecount);
85731 - mutex_lock(&mapping->i_mmap_mutex);
85732 - if (tmp->vm_flags & VM_SHARED)
85733 - mapping->i_mmap_writable++;
85734 - flush_dcache_mmap_lock(mapping);
85735 - /* insert tmp into the share list, just after mpnt */
85736 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85737 - vma_nonlinear_insert(tmp,
85738 - &mapping->i_mmap_nonlinear);
85739 - else
85740 - vma_interval_tree_insert_after(tmp, mpnt,
85741 - &mapping->i_mmap);
85742 - flush_dcache_mmap_unlock(mapping);
85743 - mutex_unlock(&mapping->i_mmap_mutex);
85744 + tmp = dup_vma(mm, oldmm, mpnt);
85745 + if (!tmp) {
85746 + retval = -ENOMEM;
85747 + goto out;
85748 }
85749
85750 /*
85751 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85752 if (retval)
85753 goto out;
85754 }
85755 +
85756 +#ifdef CONFIG_PAX_SEGMEXEC
85757 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85758 + struct vm_area_struct *mpnt_m;
85759 +
85760 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85761 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85762 +
85763 + if (!mpnt->vm_mirror)
85764 + continue;
85765 +
85766 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85767 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85768 + mpnt->vm_mirror = mpnt_m;
85769 + } else {
85770 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85771 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85772 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85773 + mpnt->vm_mirror->vm_mirror = mpnt;
85774 + }
85775 + }
85776 + BUG_ON(mpnt_m);
85777 + }
85778 +#endif
85779 +
85780 /* a new mm has just been created */
85781 arch_dup_mmap(oldmm, mm);
85782 retval = 0;
85783 @@ -468,14 +521,6 @@ out:
85784 up_write(&oldmm->mmap_sem);
85785 uprobe_end_dup_mmap();
85786 return retval;
85787 -fail_nomem_anon_vma_fork:
85788 - mpol_put(vma_policy(tmp));
85789 -fail_nomem_policy:
85790 - kmem_cache_free(vm_area_cachep, tmp);
85791 -fail_nomem:
85792 - retval = -ENOMEM;
85793 - vm_unacct_memory(charge);
85794 - goto out;
85795 }
85796
85797 static inline int mm_alloc_pgd(struct mm_struct *mm)
85798 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85799 return ERR_PTR(err);
85800
85801 mm = get_task_mm(task);
85802 - if (mm && mm != current->mm &&
85803 - !ptrace_may_access(task, mode)) {
85804 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85805 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85806 mmput(mm);
85807 mm = ERR_PTR(-EACCES);
85808 }
85809 @@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85810 spin_unlock(&fs->lock);
85811 return -EAGAIN;
85812 }
85813 - fs->users++;
85814 + atomic_inc(&fs->users);
85815 spin_unlock(&fs->lock);
85816 return 0;
85817 }
85818 tsk->fs = copy_fs_struct(fs);
85819 if (!tsk->fs)
85820 return -ENOMEM;
85821 + /* Carry through gr_chroot_dentry and is_chrooted instead
85822 + of recomputing it here. Already copied when the task struct
85823 + is duplicated. This allows pivot_root to not be treated as
85824 + a chroot
85825 + */
85826 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
85827 +
85828 return 0;
85829 }
85830
85831 @@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85832 * parts of the process environment (as per the clone
85833 * flags). The actual kick-off is left to the caller.
85834 */
85835 -static struct task_struct *copy_process(unsigned long clone_flags,
85836 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85837 unsigned long stack_start,
85838 unsigned long stack_size,
85839 int __user *child_tidptr,
85840 @@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85841 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85842 #endif
85843 retval = -EAGAIN;
85844 +
85845 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85846 +
85847 if (atomic_read(&p->real_cred->user->processes) >=
85848 task_rlimit(p, RLIMIT_NPROC)) {
85849 if (p->real_cred->user != INIT_USER &&
85850 @@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85851 goto bad_fork_free_pid;
85852 }
85853
85854 + /* synchronizes with gr_set_acls()
85855 + we need to call this past the point of no return for fork()
85856 + */
85857 + gr_copy_label(p);
85858 +
85859 if (likely(p->pid)) {
85860 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85861
85862 @@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
85863 bad_fork_free:
85864 free_task(p);
85865 fork_out:
85866 + gr_log_forkfail(retval);
85867 +
85868 return ERR_PTR(retval);
85869 }
85870
85871 @@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
85872
85873 p = copy_process(clone_flags, stack_start, stack_size,
85874 child_tidptr, NULL, trace);
85875 + add_latent_entropy();
85876 /*
85877 * Do this prior waking up the new thread - the thread pointer
85878 * might get invalid after that point, if the thread exits quickly.
85879 @@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
85880 if (clone_flags & CLONE_PARENT_SETTID)
85881 put_user(nr, parent_tidptr);
85882
85883 + gr_handle_brute_check();
85884 +
85885 if (clone_flags & CLONE_VFORK) {
85886 p->vfork_done = &vfork;
85887 init_completion(&vfork);
85888 @@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
85889 mm_cachep = kmem_cache_create("mm_struct",
85890 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85891 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85892 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85893 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85894 mmap_init();
85895 nsproxy_cache_init();
85896 }
85897 @@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85898 return 0;
85899
85900 /* don't need lock here; in the worst case we'll do useless copy */
85901 - if (fs->users == 1)
85902 + if (atomic_read(&fs->users) == 1)
85903 return 0;
85904
85905 *new_fsp = copy_fs_struct(fs);
85906 @@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85907 fs = current->fs;
85908 spin_lock(&fs->lock);
85909 current->fs = new_fs;
85910 - if (--fs->users)
85911 + gr_set_chroot_entries(current, &current->fs->root);
85912 + if (atomic_dec_return(&fs->users))
85913 new_fs = NULL;
85914 else
85915 new_fs = fs;
85916 diff --git a/kernel/futex.c b/kernel/futex.c
85917 index 6801b37..bb6becca 100644
85918 --- a/kernel/futex.c
85919 +++ b/kernel/futex.c
85920 @@ -54,6 +54,7 @@
85921 #include <linux/mount.h>
85922 #include <linux/pagemap.h>
85923 #include <linux/syscalls.h>
85924 +#include <linux/ptrace.h>
85925 #include <linux/signal.h>
85926 #include <linux/export.h>
85927 #include <linux/magic.h>
85928 @@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85929 struct page *page, *page_head;
85930 int err, ro = 0;
85931
85932 +#ifdef CONFIG_PAX_SEGMEXEC
85933 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85934 + return -EFAULT;
85935 +#endif
85936 +
85937 /*
85938 * The futex address must be "naturally" aligned.
85939 */
85940 @@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85941
85942 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85943 {
85944 - int ret;
85945 + unsigned long ret;
85946
85947 pagefault_disable();
85948 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85949 @@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
85950 {
85951 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
85952 u32 curval;
85953 + mm_segment_t oldfs;
85954
85955 /*
85956 * This will fail and we want it. Some arch implementations do
85957 @@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
85958 * implementation, the non-functional ones will return
85959 * -ENOSYS.
85960 */
85961 + oldfs = get_fs();
85962 + set_fs(USER_DS);
85963 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85964 futex_cmpxchg_enabled = 1;
85965 + set_fs(oldfs);
85966 #endif
85967 }
85968
85969 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85970 index f9f44fd..29885e4 100644
85971 --- a/kernel/futex_compat.c
85972 +++ b/kernel/futex_compat.c
85973 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85974 return 0;
85975 }
85976
85977 -static void __user *futex_uaddr(struct robust_list __user *entry,
85978 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85979 compat_long_t futex_offset)
85980 {
85981 compat_uptr_t base = ptr_to_compat(entry);
85982 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85983 index f45b75b..bfac6d5 100644
85984 --- a/kernel/gcov/base.c
85985 +++ b/kernel/gcov/base.c
85986 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
85987 }
85988
85989 #ifdef CONFIG_MODULES
85990 -static inline int within(void *addr, void *start, unsigned long size)
85991 -{
85992 - return ((addr >= start) && (addr < start + size));
85993 -}
85994 -
85995 /* Update list and generate events when modules are unloaded. */
85996 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85997 void *data)
85998 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85999
86000 /* Remove entries located in module from linked list. */
86001 while ((info = gcov_info_next(info))) {
86002 - if (within(info, mod->module_core, mod->core_size)) {
86003 + if (within_module_core_rw((unsigned long)info, mod)) {
86004 gcov_info_unlink(prev, info);
86005 if (gcov_events_enabled)
86006 gcov_event(GCOV_REMOVE, info);
86007 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86008 index 0909436..6037d22 100644
86009 --- a/kernel/hrtimer.c
86010 +++ b/kernel/hrtimer.c
86011 @@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86012 local_irq_restore(flags);
86013 }
86014
86015 -static void run_hrtimer_softirq(struct softirq_action *h)
86016 +static __latent_entropy void run_hrtimer_softirq(void)
86017 {
86018 hrtimer_peek_ahead_timers();
86019 }
86020 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86021 index 55fcce6..0e4cf34 100644
86022 --- a/kernel/irq_work.c
86023 +++ b/kernel/irq_work.c
86024 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86025 return NOTIFY_OK;
86026 }
86027
86028 -static struct notifier_block cpu_notify;
86029 +static struct notifier_block cpu_notify = {
86030 + .notifier_call = irq_work_cpu_notify,
86031 + .priority = 0,
86032 +};
86033
86034 static __init int irq_work_init_cpu_notifier(void)
86035 {
86036 - cpu_notify.notifier_call = irq_work_cpu_notify;
86037 - cpu_notify.priority = 0;
86038 register_cpu_notifier(&cpu_notify);
86039 return 0;
86040 }
86041 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86042 index 9019f15..9a3c42e 100644
86043 --- a/kernel/jump_label.c
86044 +++ b/kernel/jump_label.c
86045 @@ -14,6 +14,7 @@
86046 #include <linux/err.h>
86047 #include <linux/static_key.h>
86048 #include <linux/jump_label_ratelimit.h>
86049 +#include <linux/mm.h>
86050
86051 #ifdef HAVE_JUMP_LABEL
86052
86053 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86054
86055 size = (((unsigned long)stop - (unsigned long)start)
86056 / sizeof(struct jump_entry));
86057 + pax_open_kernel();
86058 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86059 + pax_close_kernel();
86060 }
86061
86062 static void jump_label_update(struct static_key *key, int enable);
86063 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86064 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86065 struct jump_entry *iter;
86066
86067 + pax_open_kernel();
86068 for (iter = iter_start; iter < iter_stop; iter++) {
86069 if (within_module_init(iter->code, mod))
86070 iter->code = 0;
86071 }
86072 + pax_close_kernel();
86073 }
86074
86075 static int
86076 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86077 index 3127ad5..159d880 100644
86078 --- a/kernel/kallsyms.c
86079 +++ b/kernel/kallsyms.c
86080 @@ -11,6 +11,9 @@
86081 * Changed the compression method from stem compression to "table lookup"
86082 * compression (see scripts/kallsyms.c for a more complete description)
86083 */
86084 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86085 +#define __INCLUDED_BY_HIDESYM 1
86086 +#endif
86087 #include <linux/kallsyms.h>
86088 #include <linux/module.h>
86089 #include <linux/init.h>
86090 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86091
86092 static inline int is_kernel_inittext(unsigned long addr)
86093 {
86094 + if (system_state != SYSTEM_BOOTING)
86095 + return 0;
86096 +
86097 if (addr >= (unsigned long)_sinittext
86098 && addr <= (unsigned long)_einittext)
86099 return 1;
86100 return 0;
86101 }
86102
86103 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86104 +#ifdef CONFIG_MODULES
86105 +static inline int is_module_text(unsigned long addr)
86106 +{
86107 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86108 + return 1;
86109 +
86110 + addr = ktla_ktva(addr);
86111 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86112 +}
86113 +#else
86114 +static inline int is_module_text(unsigned long addr)
86115 +{
86116 + return 0;
86117 +}
86118 +#endif
86119 +#endif
86120 +
86121 static inline int is_kernel_text(unsigned long addr)
86122 {
86123 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86124 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86125
86126 static inline int is_kernel(unsigned long addr)
86127 {
86128 +
86129 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86130 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
86131 + return 1;
86132 +
86133 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86134 +#else
86135 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86136 +#endif
86137 +
86138 return 1;
86139 return in_gate_area_no_mm(addr);
86140 }
86141
86142 static int is_ksym_addr(unsigned long addr)
86143 {
86144 +
86145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86146 + if (is_module_text(addr))
86147 + return 0;
86148 +#endif
86149 +
86150 if (all_var)
86151 return is_kernel(addr);
86152
86153 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86154
86155 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86156 {
86157 - iter->name[0] = '\0';
86158 iter->nameoff = get_symbol_offset(new_pos);
86159 iter->pos = new_pos;
86160 }
86161 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86162 {
86163 struct kallsym_iter *iter = m->private;
86164
86165 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86166 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86167 + return 0;
86168 +#endif
86169 +
86170 /* Some debugging symbols have no name. Ignore them. */
86171 if (!iter->name[0])
86172 return 0;
86173 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86174 */
86175 type = iter->exported ? toupper(iter->type) :
86176 tolower(iter->type);
86177 +
86178 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86179 type, iter->name, iter->module_name);
86180 } else
86181 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86182 struct kallsym_iter *iter;
86183 int ret;
86184
86185 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86186 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86187 if (!iter)
86188 return -ENOMEM;
86189 reset_iter(iter, 0);
86190 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86191 index e30ac0f..3528cac 100644
86192 --- a/kernel/kcmp.c
86193 +++ b/kernel/kcmp.c
86194 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86195 struct task_struct *task1, *task2;
86196 int ret;
86197
86198 +#ifdef CONFIG_GRKERNSEC
86199 + return -ENOSYS;
86200 +#endif
86201 +
86202 rcu_read_lock();
86203
86204 /*
86205 diff --git a/kernel/kexec.c b/kernel/kexec.c
86206 index 60bafbe..a120f4f 100644
86207 --- a/kernel/kexec.c
86208 +++ b/kernel/kexec.c
86209 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86210 unsigned long flags)
86211 {
86212 struct compat_kexec_segment in;
86213 - struct kexec_segment out, __user *ksegments;
86214 + struct kexec_segment out;
86215 + struct kexec_segment __user *ksegments;
86216 unsigned long i, result;
86217
86218 /* Don't allow clients that don't understand the native
86219 diff --git a/kernel/kmod.c b/kernel/kmod.c
86220 index 6b375af..eaff670 100644
86221 --- a/kernel/kmod.c
86222 +++ b/kernel/kmod.c
86223 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86224 kfree(info->argv);
86225 }
86226
86227 -static int call_modprobe(char *module_name, int wait)
86228 +static int call_modprobe(char *module_name, char *module_param, int wait)
86229 {
86230 struct subprocess_info *info;
86231 static char *envp[] = {
86232 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86233 NULL
86234 };
86235
86236 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86237 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86238 if (!argv)
86239 goto out;
86240
86241 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86242 argv[1] = "-q";
86243 argv[2] = "--";
86244 argv[3] = module_name; /* check free_modprobe_argv() */
86245 - argv[4] = NULL;
86246 + argv[4] = module_param;
86247 + argv[5] = NULL;
86248
86249 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86250 NULL, free_modprobe_argv, NULL);
86251 @@ -129,9 +130,8 @@ out:
86252 * If module auto-loading support is disabled then this function
86253 * becomes a no-operation.
86254 */
86255 -int __request_module(bool wait, const char *fmt, ...)
86256 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86257 {
86258 - va_list args;
86259 char module_name[MODULE_NAME_LEN];
86260 unsigned int max_modprobes;
86261 int ret;
86262 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86263 if (!modprobe_path[0])
86264 return 0;
86265
86266 - va_start(args, fmt);
86267 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86268 - va_end(args);
86269 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86270 if (ret >= MODULE_NAME_LEN)
86271 return -ENAMETOOLONG;
86272
86273 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86274 if (ret)
86275 return ret;
86276
86277 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86278 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86279 + /* hack to workaround consolekit/udisks stupidity */
86280 + read_lock(&tasklist_lock);
86281 + if (!strcmp(current->comm, "mount") &&
86282 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86283 + read_unlock(&tasklist_lock);
86284 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86285 + return -EPERM;
86286 + }
86287 + read_unlock(&tasklist_lock);
86288 + }
86289 +#endif
86290 +
86291 /* If modprobe needs a service that is in a module, we get a recursive
86292 * loop. Limit the number of running kmod threads to max_threads/2 or
86293 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86294 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86295
86296 trace_module_request(module_name, wait, _RET_IP_);
86297
86298 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86299 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86300
86301 atomic_dec(&kmod_concurrent);
86302 return ret;
86303 }
86304 +
86305 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86306 +{
86307 + va_list args;
86308 + int ret;
86309 +
86310 + va_start(args, fmt);
86311 + ret = ____request_module(wait, module_param, fmt, args);
86312 + va_end(args);
86313 +
86314 + return ret;
86315 +}
86316 +
86317 +int __request_module(bool wait, const char *fmt, ...)
86318 +{
86319 + va_list args;
86320 + int ret;
86321 +
86322 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86323 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86324 + char module_param[MODULE_NAME_LEN];
86325 +
86326 + memset(module_param, 0, sizeof(module_param));
86327 +
86328 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86329 +
86330 + va_start(args, fmt);
86331 + ret = ____request_module(wait, module_param, fmt, args);
86332 + va_end(args);
86333 +
86334 + return ret;
86335 + }
86336 +#endif
86337 +
86338 + va_start(args, fmt);
86339 + ret = ____request_module(wait, NULL, fmt, args);
86340 + va_end(args);
86341 +
86342 + return ret;
86343 +}
86344 +
86345 EXPORT_SYMBOL(__request_module);
86346 #endif /* CONFIG_MODULES */
86347
86348 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86349 */
86350 set_user_nice(current, 0);
86351
86352 +#ifdef CONFIG_GRKERNSEC
86353 + /* this is race-free as far as userland is concerned as we copied
86354 + out the path to be used prior to this point and are now operating
86355 + on that copy
86356 + */
86357 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86358 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86359 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86360 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86361 + retval = -EPERM;
86362 + goto fail;
86363 + }
86364 +#endif
86365 +
86366 retval = -ENOMEM;
86367 new = prepare_kernel_cred(current);
86368 if (!new)
86369 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86370 commit_creds(new);
86371
86372 retval = do_execve(getname_kernel(sub_info->path),
86373 - (const char __user *const __user *)sub_info->argv,
86374 - (const char __user *const __user *)sub_info->envp);
86375 + (const char __user *const __force_user *)sub_info->argv,
86376 + (const char __user *const __force_user *)sub_info->envp);
86377 if (!retval)
86378 return 0;
86379
86380 @@ -260,6 +327,10 @@ static int call_helper(void *data)
86381
86382 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86383 {
86384 +#ifdef CONFIG_GRKERNSEC
86385 + kfree(info->path);
86386 + info->path = info->origpath;
86387 +#endif
86388 if (info->cleanup)
86389 (*info->cleanup)(info);
86390 kfree(info);
86391 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86392 *
86393 * Thus the __user pointer cast is valid here.
86394 */
86395 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
86396 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86397
86398 /*
86399 * If ret is 0, either ____call_usermodehelper failed and the
86400 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86401 goto out;
86402
86403 INIT_WORK(&sub_info->work, __call_usermodehelper);
86404 +#ifdef CONFIG_GRKERNSEC
86405 + sub_info->origpath = path;
86406 + sub_info->path = kstrdup(path, gfp_mask);
86407 +#else
86408 sub_info->path = path;
86409 +#endif
86410 sub_info->argv = argv;
86411 sub_info->envp = envp;
86412
86413 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86414 static int proc_cap_handler(struct ctl_table *table, int write,
86415 void __user *buffer, size_t *lenp, loff_t *ppos)
86416 {
86417 - struct ctl_table t;
86418 + ctl_table_no_const t;
86419 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86420 kernel_cap_t new_cap;
86421 int err, i;
86422 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86423 index ceeadfc..11c18b6 100644
86424 --- a/kernel/kprobes.c
86425 +++ b/kernel/kprobes.c
86426 @@ -31,6 +31,9 @@
86427 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86428 * <prasanna@in.ibm.com> added function-return probes.
86429 */
86430 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86431 +#define __INCLUDED_BY_HIDESYM 1
86432 +#endif
86433 #include <linux/kprobes.h>
86434 #include <linux/hash.h>
86435 #include <linux/init.h>
86436 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
86437
86438 static void *alloc_insn_page(void)
86439 {
86440 - return module_alloc(PAGE_SIZE);
86441 + return module_alloc_exec(PAGE_SIZE);
86442 }
86443
86444 static void free_insn_page(void *page)
86445 {
86446 - module_free(NULL, page);
86447 + module_free_exec(NULL, page);
86448 }
86449
86450 struct kprobe_insn_cache kprobe_insn_slots = {
86451 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86452 kprobe_type = "k";
86453
86454 if (sym)
86455 - seq_printf(pi, "%p %s %s+0x%x %s ",
86456 + seq_printf(pi, "%pK %s %s+0x%x %s ",
86457 p->addr, kprobe_type, sym, offset,
86458 (modname ? modname : " "));
86459 else
86460 - seq_printf(pi, "%p %s %p ",
86461 + seq_printf(pi, "%pK %s %pK ",
86462 p->addr, kprobe_type, p->addr);
86463
86464 if (!pp)
86465 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86466 index d945a94..0b7f45f 100644
86467 --- a/kernel/ksysfs.c
86468 +++ b/kernel/ksysfs.c
86469 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86470 {
86471 if (count+1 > UEVENT_HELPER_PATH_LEN)
86472 return -ENOENT;
86473 + if (!capable(CAP_SYS_ADMIN))
86474 + return -EPERM;
86475 memcpy(uevent_helper, buf, count);
86476 uevent_helper[count] = '\0';
86477 if (count && uevent_helper[count-1] == '\n')
86478 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86479 return count;
86480 }
86481
86482 -static struct bin_attribute notes_attr = {
86483 +static bin_attribute_no_const notes_attr __read_only = {
86484 .attr = {
86485 .name = "notes",
86486 .mode = S_IRUGO,
86487 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86488 index eb8a547..321d8e1 100644
86489 --- a/kernel/locking/lockdep.c
86490 +++ b/kernel/locking/lockdep.c
86491 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
86492 end = (unsigned long) &_end,
86493 addr = (unsigned long) obj;
86494
86495 +#ifdef CONFIG_PAX_KERNEXEC
86496 + start = ktla_ktva(start);
86497 +#endif
86498 +
86499 /*
86500 * static variable?
86501 */
86502 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86503 if (!static_obj(lock->key)) {
86504 debug_locks_off();
86505 printk("INFO: trying to register non-static key.\n");
86506 + printk("lock:%pS key:%pS.\n", lock, lock->key);
86507 printk("the code is fine but needs lockdep annotation.\n");
86508 printk("turning off the locking correctness validator.\n");
86509 dump_stack();
86510 @@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86511 if (!class)
86512 return 0;
86513 }
86514 - atomic_inc((atomic_t *)&class->ops);
86515 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86516 if (very_verbose(class)) {
86517 printk("\nacquire class [%p] %s", class->key, class->name);
86518 if (class->name_version > 1)
86519 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86520 index ef43ac4..2720dfa 100644
86521 --- a/kernel/locking/lockdep_proc.c
86522 +++ b/kernel/locking/lockdep_proc.c
86523 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86524 return 0;
86525 }
86526
86527 - seq_printf(m, "%p", class->key);
86528 + seq_printf(m, "%pK", class->key);
86529 #ifdef CONFIG_DEBUG_LOCKDEP
86530 seq_printf(m, " OPS:%8ld", class->ops);
86531 #endif
86532 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86533
86534 list_for_each_entry(entry, &class->locks_after, entry) {
86535 if (entry->distance == 1) {
86536 - seq_printf(m, " -> [%p] ", entry->class->key);
86537 + seq_printf(m, " -> [%pK] ", entry->class->key);
86538 print_name(m, entry->class);
86539 seq_puts(m, "\n");
86540 }
86541 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86542 if (!class->key)
86543 continue;
86544
86545 - seq_printf(m, "[%p] ", class->key);
86546 + seq_printf(m, "[%pK] ", class->key);
86547 print_name(m, class);
86548 seq_puts(m, "\n");
86549 }
86550 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86551 if (!i)
86552 seq_line(m, '-', 40-namelen, namelen);
86553
86554 - snprintf(ip, sizeof(ip), "[<%p>]",
86555 + snprintf(ip, sizeof(ip), "[<%pK>]",
86556 (void *)class->contention_point[i]);
86557 seq_printf(m, "%40s %14lu %29s %pS\n",
86558 name, stats->contention_point[i],
86559 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86560 if (!i)
86561 seq_line(m, '-', 40-namelen, namelen);
86562
86563 - snprintf(ip, sizeof(ip), "[<%p>]",
86564 + snprintf(ip, sizeof(ip), "[<%pK>]",
86565 (void *)class->contending_point[i]);
86566 seq_printf(m, "%40s %14lu %29s %pS\n",
86567 name, stats->contending_point[i],
86568 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86569 index faf6f5b..dc9070a 100644
86570 --- a/kernel/locking/mutex-debug.c
86571 +++ b/kernel/locking/mutex-debug.c
86572 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86573 }
86574
86575 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86576 - struct thread_info *ti)
86577 + struct task_struct *task)
86578 {
86579 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86580
86581 /* Mark the current thread as blocked on the lock: */
86582 - ti->task->blocked_on = waiter;
86583 + task->blocked_on = waiter;
86584 }
86585
86586 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86587 - struct thread_info *ti)
86588 + struct task_struct *task)
86589 {
86590 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86591 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86592 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86593 - ti->task->blocked_on = NULL;
86594 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
86595 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86596 + task->blocked_on = NULL;
86597
86598 list_del_init(&waiter->list);
86599 waiter->task = NULL;
86600 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86601 index 0799fd3..d06ae3b 100644
86602 --- a/kernel/locking/mutex-debug.h
86603 +++ b/kernel/locking/mutex-debug.h
86604 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86605 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86606 extern void debug_mutex_add_waiter(struct mutex *lock,
86607 struct mutex_waiter *waiter,
86608 - struct thread_info *ti);
86609 + struct task_struct *task);
86610 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86611 - struct thread_info *ti);
86612 + struct task_struct *task);
86613 extern void debug_mutex_unlock(struct mutex *lock);
86614 extern void debug_mutex_init(struct mutex *lock, const char *name,
86615 struct lock_class_key *key);
86616 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86617 index 4dd6e4c..df52693 100644
86618 --- a/kernel/locking/mutex.c
86619 +++ b/kernel/locking/mutex.c
86620 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86621 node->locked = 1;
86622 return;
86623 }
86624 - ACCESS_ONCE(prev->next) = node;
86625 + ACCESS_ONCE_RW(prev->next) = node;
86626 smp_wmb();
86627 /* Wait until the lock holder passes the lock down */
86628 while (!ACCESS_ONCE(node->locked))
86629 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86630 while (!(next = ACCESS_ONCE(node->next)))
86631 arch_mutex_cpu_relax();
86632 }
86633 - ACCESS_ONCE(next->locked) = 1;
86634 + ACCESS_ONCE_RW(next->locked) = 1;
86635 smp_wmb();
86636 }
86637
86638 @@ -520,7 +520,7 @@ slowpath:
86639 goto skip_wait;
86640
86641 debug_mutex_lock_common(lock, &waiter);
86642 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86643 + debug_mutex_add_waiter(lock, &waiter, task);
86644
86645 /* add waiting tasks to the end of the waitqueue (FIFO): */
86646 list_add_tail(&waiter.list, &lock->wait_list);
86647 @@ -564,7 +564,7 @@ slowpath:
86648 schedule_preempt_disabled();
86649 spin_lock_mutex(&lock->wait_lock, flags);
86650 }
86651 - mutex_remove_waiter(lock, &waiter, current_thread_info());
86652 + mutex_remove_waiter(lock, &waiter, task);
86653 /* set it to 0 if there are no waiters left: */
86654 if (likely(list_empty(&lock->wait_list)))
86655 atomic_set(&lock->count, 0);
86656 @@ -601,7 +601,7 @@ skip_wait:
86657 return 0;
86658
86659 err:
86660 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86661 + mutex_remove_waiter(lock, &waiter, task);
86662 spin_unlock_mutex(&lock->wait_lock, flags);
86663 debug_mutex_free_waiter(&waiter);
86664 mutex_release(&lock->dep_map, 1, ip);
86665 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86666 index 1d96dd0..994ff19 100644
86667 --- a/kernel/locking/rtmutex-tester.c
86668 +++ b/kernel/locking/rtmutex-tester.c
86669 @@ -22,7 +22,7 @@
86670 #define MAX_RT_TEST_MUTEXES 8
86671
86672 static spinlock_t rttest_lock;
86673 -static atomic_t rttest_event;
86674 +static atomic_unchecked_t rttest_event;
86675
86676 struct test_thread_data {
86677 int opcode;
86678 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86679
86680 case RTTEST_LOCKCONT:
86681 td->mutexes[td->opdata] = 1;
86682 - td->event = atomic_add_return(1, &rttest_event);
86683 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86684 return 0;
86685
86686 case RTTEST_RESET:
86687 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86688 return 0;
86689
86690 case RTTEST_RESETEVENT:
86691 - atomic_set(&rttest_event, 0);
86692 + atomic_set_unchecked(&rttest_event, 0);
86693 return 0;
86694
86695 default:
86696 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86697 return ret;
86698
86699 td->mutexes[id] = 1;
86700 - td->event = atomic_add_return(1, &rttest_event);
86701 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86702 rt_mutex_lock(&mutexes[id]);
86703 - td->event = atomic_add_return(1, &rttest_event);
86704 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86705 td->mutexes[id] = 4;
86706 return 0;
86707
86708 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86709 return ret;
86710
86711 td->mutexes[id] = 1;
86712 - td->event = atomic_add_return(1, &rttest_event);
86713 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86714 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86715 - td->event = atomic_add_return(1, &rttest_event);
86716 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86717 td->mutexes[id] = ret ? 0 : 4;
86718 return ret ? -EINTR : 0;
86719
86720 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86721 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86722 return ret;
86723
86724 - td->event = atomic_add_return(1, &rttest_event);
86725 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86726 rt_mutex_unlock(&mutexes[id]);
86727 - td->event = atomic_add_return(1, &rttest_event);
86728 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86729 td->mutexes[id] = 0;
86730 return 0;
86731
86732 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86733 break;
86734
86735 td->mutexes[dat] = 2;
86736 - td->event = atomic_add_return(1, &rttest_event);
86737 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86738 break;
86739
86740 default:
86741 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86742 return;
86743
86744 td->mutexes[dat] = 3;
86745 - td->event = atomic_add_return(1, &rttest_event);
86746 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86747 break;
86748
86749 case RTTEST_LOCKNOWAIT:
86750 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86751 return;
86752
86753 td->mutexes[dat] = 1;
86754 - td->event = atomic_add_return(1, &rttest_event);
86755 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86756 return;
86757
86758 default:
86759 diff --git a/kernel/module.c b/kernel/module.c
86760 index d24fcf2..2af3fd9 100644
86761 --- a/kernel/module.c
86762 +++ b/kernel/module.c
86763 @@ -61,6 +61,7 @@
86764 #include <linux/pfn.h>
86765 #include <linux/bsearch.h>
86766 #include <linux/fips.h>
86767 +#include <linux/grsecurity.h>
86768 #include <uapi/linux/module.h>
86769 #include "module-internal.h"
86770
86771 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86772
86773 /* Bounds of module allocation, for speeding __module_address.
86774 * Protected by module_mutex. */
86775 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86776 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86777 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86778
86779 int register_module_notifier(struct notifier_block * nb)
86780 {
86781 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86782 return true;
86783
86784 list_for_each_entry_rcu(mod, &modules, list) {
86785 - struct symsearch arr[] = {
86786 + struct symsearch modarr[] = {
86787 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86788 NOT_GPL_ONLY, false },
86789 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86790 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86791 if (mod->state == MODULE_STATE_UNFORMED)
86792 continue;
86793
86794 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86795 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86796 return true;
86797 }
86798 return false;
86799 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86800 if (!pcpusec->sh_size)
86801 return 0;
86802
86803 - if (align > PAGE_SIZE) {
86804 + if (align-1 >= PAGE_SIZE) {
86805 pr_warn("%s: per-cpu alignment %li > %li\n",
86806 mod->name, align, PAGE_SIZE);
86807 align = PAGE_SIZE;
86808 @@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
86809 static ssize_t show_coresize(struct module_attribute *mattr,
86810 struct module_kobject *mk, char *buffer)
86811 {
86812 - return sprintf(buffer, "%u\n", mk->mod->core_size);
86813 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86814 }
86815
86816 static struct module_attribute modinfo_coresize =
86817 @@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
86818 static ssize_t show_initsize(struct module_attribute *mattr,
86819 struct module_kobject *mk, char *buffer)
86820 {
86821 - return sprintf(buffer, "%u\n", mk->mod->init_size);
86822 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86823 }
86824
86825 static struct module_attribute modinfo_initsize =
86826 @@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
86827 goto bad_version;
86828 }
86829
86830 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86831 + /*
86832 + * avoid potentially printing jibberish on attempted load
86833 + * of a module randomized with a different seed
86834 + */
86835 + pr_warn("no symbol version for %s\n", symname);
86836 +#else
86837 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86838 +#endif
86839 return 0;
86840
86841 bad_version:
86842 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86843 + /*
86844 + * avoid potentially printing jibberish on attempted load
86845 + * of a module randomized with a different seed
86846 + */
86847 + printk("attempted module disagrees about version of symbol %s\n",
86848 + symname);
86849 +#else
86850 printk("%s: disagrees about version of symbol %s\n",
86851 mod->name, symname);
86852 +#endif
86853 return 0;
86854 }
86855
86856 @@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
86857 */
86858 #ifdef CONFIG_SYSFS
86859
86860 -#ifdef CONFIG_KALLSYMS
86861 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86862 static inline bool sect_empty(const Elf_Shdr *sect)
86863 {
86864 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86865 @@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86866 {
86867 unsigned int notes, loaded, i;
86868 struct module_notes_attrs *notes_attrs;
86869 - struct bin_attribute *nattr;
86870 + bin_attribute_no_const *nattr;
86871
86872 /* failed to create section attributes, so can't create notes */
86873 if (!mod->sect_attrs)
86874 @@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
86875 static int module_add_modinfo_attrs(struct module *mod)
86876 {
86877 struct module_attribute *attr;
86878 - struct module_attribute *temp_attr;
86879 + module_attribute_no_const *temp_attr;
86880 int error = 0;
86881 int i;
86882
86883 @@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
86884
86885 static void unset_module_core_ro_nx(struct module *mod)
86886 {
86887 - set_page_attributes(mod->module_core + mod->core_text_size,
86888 - mod->module_core + mod->core_size,
86889 + set_page_attributes(mod->module_core_rw,
86890 + mod->module_core_rw + mod->core_size_rw,
86891 set_memory_x);
86892 - set_page_attributes(mod->module_core,
86893 - mod->module_core + mod->core_ro_size,
86894 + set_page_attributes(mod->module_core_rx,
86895 + mod->module_core_rx + mod->core_size_rx,
86896 set_memory_rw);
86897 }
86898
86899 static void unset_module_init_ro_nx(struct module *mod)
86900 {
86901 - set_page_attributes(mod->module_init + mod->init_text_size,
86902 - mod->module_init + mod->init_size,
86903 + set_page_attributes(mod->module_init_rw,
86904 + mod->module_init_rw + mod->init_size_rw,
86905 set_memory_x);
86906 - set_page_attributes(mod->module_init,
86907 - mod->module_init + mod->init_ro_size,
86908 + set_page_attributes(mod->module_init_rx,
86909 + mod->module_init_rx + mod->init_size_rx,
86910 set_memory_rw);
86911 }
86912
86913 @@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
86914 list_for_each_entry_rcu(mod, &modules, list) {
86915 if (mod->state == MODULE_STATE_UNFORMED)
86916 continue;
86917 - if ((mod->module_core) && (mod->core_text_size)) {
86918 - set_page_attributes(mod->module_core,
86919 - mod->module_core + mod->core_text_size,
86920 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86921 + set_page_attributes(mod->module_core_rx,
86922 + mod->module_core_rx + mod->core_size_rx,
86923 set_memory_rw);
86924 }
86925 - if ((mod->module_init) && (mod->init_text_size)) {
86926 - set_page_attributes(mod->module_init,
86927 - mod->module_init + mod->init_text_size,
86928 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86929 + set_page_attributes(mod->module_init_rx,
86930 + mod->module_init_rx + mod->init_size_rx,
86931 set_memory_rw);
86932 }
86933 }
86934 @@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
86935 list_for_each_entry_rcu(mod, &modules, list) {
86936 if (mod->state == MODULE_STATE_UNFORMED)
86937 continue;
86938 - if ((mod->module_core) && (mod->core_text_size)) {
86939 - set_page_attributes(mod->module_core,
86940 - mod->module_core + mod->core_text_size,
86941 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86942 + set_page_attributes(mod->module_core_rx,
86943 + mod->module_core_rx + mod->core_size_rx,
86944 set_memory_ro);
86945 }
86946 - if ((mod->module_init) && (mod->init_text_size)) {
86947 - set_page_attributes(mod->module_init,
86948 - mod->module_init + mod->init_text_size,
86949 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86950 + set_page_attributes(mod->module_init_rx,
86951 + mod->module_init_rx + mod->init_size_rx,
86952 set_memory_ro);
86953 }
86954 }
86955 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
86956
86957 /* This may be NULL, but that's OK */
86958 unset_module_init_ro_nx(mod);
86959 - module_free(mod, mod->module_init);
86960 + module_free(mod, mod->module_init_rw);
86961 + module_free_exec(mod, mod->module_init_rx);
86962 kfree(mod->args);
86963 percpu_modfree(mod);
86964
86965 /* Free lock-classes: */
86966 - lockdep_free_key_range(mod->module_core, mod->core_size);
86967 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86968 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86969
86970 /* Finally, free the core (containing the module structure) */
86971 unset_module_core_ro_nx(mod);
86972 - module_free(mod, mod->module_core);
86973 + module_free_exec(mod, mod->module_core_rx);
86974 + module_free(mod, mod->module_core_rw);
86975
86976 #ifdef CONFIG_MPU
86977 update_protections(current->mm);
86978 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86979 int ret = 0;
86980 const struct kernel_symbol *ksym;
86981
86982 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86983 + int is_fs_load = 0;
86984 + int register_filesystem_found = 0;
86985 + char *p;
86986 +
86987 + p = strstr(mod->args, "grsec_modharden_fs");
86988 + if (p) {
86989 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86990 + /* copy \0 as well */
86991 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86992 + is_fs_load = 1;
86993 + }
86994 +#endif
86995 +
86996 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86997 const char *name = info->strtab + sym[i].st_name;
86998
86999 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87000 + /* it's a real shame this will never get ripped and copied
87001 + upstream! ;(
87002 + */
87003 + if (is_fs_load && !strcmp(name, "register_filesystem"))
87004 + register_filesystem_found = 1;
87005 +#endif
87006 +
87007 switch (sym[i].st_shndx) {
87008 case SHN_COMMON:
87009 /* We compiled with -fno-common. These are not
87010 @@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87011 ksym = resolve_symbol_wait(mod, info, name);
87012 /* Ok if resolved. */
87013 if (ksym && !IS_ERR(ksym)) {
87014 + pax_open_kernel();
87015 sym[i].st_value = ksym->value;
87016 + pax_close_kernel();
87017 break;
87018 }
87019
87020 @@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87021 secbase = (unsigned long)mod_percpu(mod);
87022 else
87023 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87024 + pax_open_kernel();
87025 sym[i].st_value += secbase;
87026 + pax_close_kernel();
87027 break;
87028 }
87029 }
87030
87031 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87032 + if (is_fs_load && !register_filesystem_found) {
87033 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87034 + ret = -EPERM;
87035 + }
87036 +#endif
87037 +
87038 return ret;
87039 }
87040
87041 @@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87042 || s->sh_entsize != ~0UL
87043 || strstarts(sname, ".init"))
87044 continue;
87045 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87046 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87047 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87048 + else
87049 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87050 pr_debug("\t%s\n", sname);
87051 }
87052 - switch (m) {
87053 - case 0: /* executable */
87054 - mod->core_size = debug_align(mod->core_size);
87055 - mod->core_text_size = mod->core_size;
87056 - break;
87057 - case 1: /* RO: text and ro-data */
87058 - mod->core_size = debug_align(mod->core_size);
87059 - mod->core_ro_size = mod->core_size;
87060 - break;
87061 - case 3: /* whole core */
87062 - mod->core_size = debug_align(mod->core_size);
87063 - break;
87064 - }
87065 }
87066
87067 pr_debug("Init section allocation order:\n");
87068 @@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87069 || s->sh_entsize != ~0UL
87070 || !strstarts(sname, ".init"))
87071 continue;
87072 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87073 - | INIT_OFFSET_MASK);
87074 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87075 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87076 + else
87077 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87078 + s->sh_entsize |= INIT_OFFSET_MASK;
87079 pr_debug("\t%s\n", sname);
87080 }
87081 - switch (m) {
87082 - case 0: /* executable */
87083 - mod->init_size = debug_align(mod->init_size);
87084 - mod->init_text_size = mod->init_size;
87085 - break;
87086 - case 1: /* RO: text and ro-data */
87087 - mod->init_size = debug_align(mod->init_size);
87088 - mod->init_ro_size = mod->init_size;
87089 - break;
87090 - case 3: /* whole init */
87091 - mod->init_size = debug_align(mod->init_size);
87092 - break;
87093 - }
87094 }
87095 }
87096
87097 @@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87098
87099 /* Put symbol section at end of init part of module. */
87100 symsect->sh_flags |= SHF_ALLOC;
87101 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87102 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87103 info->index.sym) | INIT_OFFSET_MASK;
87104 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87105
87106 @@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87107 }
87108
87109 /* Append room for core symbols at end of core part. */
87110 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87111 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87112 - mod->core_size += strtab_size;
87113 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87114 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87115 + mod->core_size_rx += strtab_size;
87116
87117 /* Put string table section at end of init part of module. */
87118 strsect->sh_flags |= SHF_ALLOC;
87119 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87120 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87121 info->index.str) | INIT_OFFSET_MASK;
87122 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87123 }
87124 @@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87125 /* Make sure we get permanent strtab: don't use info->strtab. */
87126 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87127
87128 + pax_open_kernel();
87129 +
87130 /* Set types up while we still have access to sections. */
87131 for (i = 0; i < mod->num_symtab; i++)
87132 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87133
87134 - mod->core_symtab = dst = mod->module_core + info->symoffs;
87135 - mod->core_strtab = s = mod->module_core + info->stroffs;
87136 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87137 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87138 src = mod->symtab;
87139 for (ndst = i = 0; i < mod->num_symtab; i++) {
87140 if (i == 0 ||
87141 @@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87142 }
87143 }
87144 mod->core_num_syms = ndst;
87145 +
87146 + pax_close_kernel();
87147 }
87148 #else
87149 static inline void layout_symtab(struct module *mod, struct load_info *info)
87150 @@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87151 return vmalloc_exec(size);
87152 }
87153
87154 -static void *module_alloc_update_bounds(unsigned long size)
87155 +static void *module_alloc_update_bounds_rw(unsigned long size)
87156 {
87157 void *ret = module_alloc(size);
87158
87159 if (ret) {
87160 mutex_lock(&module_mutex);
87161 /* Update module bounds. */
87162 - if ((unsigned long)ret < module_addr_min)
87163 - module_addr_min = (unsigned long)ret;
87164 - if ((unsigned long)ret + size > module_addr_max)
87165 - module_addr_max = (unsigned long)ret + size;
87166 + if ((unsigned long)ret < module_addr_min_rw)
87167 + module_addr_min_rw = (unsigned long)ret;
87168 + if ((unsigned long)ret + size > module_addr_max_rw)
87169 + module_addr_max_rw = (unsigned long)ret + size;
87170 + mutex_unlock(&module_mutex);
87171 + }
87172 + return ret;
87173 +}
87174 +
87175 +static void *module_alloc_update_bounds_rx(unsigned long size)
87176 +{
87177 + void *ret = module_alloc_exec(size);
87178 +
87179 + if (ret) {
87180 + mutex_lock(&module_mutex);
87181 + /* Update module bounds. */
87182 + if ((unsigned long)ret < module_addr_min_rx)
87183 + module_addr_min_rx = (unsigned long)ret;
87184 + if ((unsigned long)ret + size > module_addr_max_rx)
87185 + module_addr_max_rx = (unsigned long)ret + size;
87186 mutex_unlock(&module_mutex);
87187 }
87188 return ret;
87189 @@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87190 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87191
87192 if (info->index.sym == 0) {
87193 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87194 + /*
87195 + * avoid potentially printing jibberish on attempted load
87196 + * of a module randomized with a different seed
87197 + */
87198 + pr_warn("module has no symbols (stripped?)\n");
87199 +#else
87200 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87201 +#endif
87202 return ERR_PTR(-ENOEXEC);
87203 }
87204
87205 @@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87206 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87207 {
87208 const char *modmagic = get_modinfo(info, "vermagic");
87209 + const char *license = get_modinfo(info, "license");
87210 int err;
87211
87212 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87213 + if (!license || !license_is_gpl_compatible(license))
87214 + return -ENOEXEC;
87215 +#endif
87216 +
87217 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87218 modmagic = NULL;
87219
87220 @@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87221 }
87222
87223 /* Set up license info based on the info section */
87224 - set_license(mod, get_modinfo(info, "license"));
87225 + set_license(mod, license);
87226
87227 return 0;
87228 }
87229 @@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87230 void *ptr;
87231
87232 /* Do the allocs. */
87233 - ptr = module_alloc_update_bounds(mod->core_size);
87234 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87235 /*
87236 * The pointer to this block is stored in the module structure
87237 * which is inside the block. Just mark it as not being a
87238 @@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87239 if (!ptr)
87240 return -ENOMEM;
87241
87242 - memset(ptr, 0, mod->core_size);
87243 - mod->module_core = ptr;
87244 + memset(ptr, 0, mod->core_size_rw);
87245 + mod->module_core_rw = ptr;
87246
87247 - if (mod->init_size) {
87248 - ptr = module_alloc_update_bounds(mod->init_size);
87249 + if (mod->init_size_rw) {
87250 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87251 /*
87252 * The pointer to this block is stored in the module structure
87253 * which is inside the block. This block doesn't need to be
87254 @@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
87255 */
87256 kmemleak_ignore(ptr);
87257 if (!ptr) {
87258 - module_free(mod, mod->module_core);
87259 + module_free(mod, mod->module_core_rw);
87260 return -ENOMEM;
87261 }
87262 - memset(ptr, 0, mod->init_size);
87263 - mod->module_init = ptr;
87264 + memset(ptr, 0, mod->init_size_rw);
87265 + mod->module_init_rw = ptr;
87266 } else
87267 - mod->module_init = NULL;
87268 + mod->module_init_rw = NULL;
87269 +
87270 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87271 + kmemleak_not_leak(ptr);
87272 + if (!ptr) {
87273 + if (mod->module_init_rw)
87274 + module_free(mod, mod->module_init_rw);
87275 + module_free(mod, mod->module_core_rw);
87276 + return -ENOMEM;
87277 + }
87278 +
87279 + pax_open_kernel();
87280 + memset(ptr, 0, mod->core_size_rx);
87281 + pax_close_kernel();
87282 + mod->module_core_rx = ptr;
87283 +
87284 + if (mod->init_size_rx) {
87285 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87286 + kmemleak_ignore(ptr);
87287 + if (!ptr && mod->init_size_rx) {
87288 + module_free_exec(mod, mod->module_core_rx);
87289 + if (mod->module_init_rw)
87290 + module_free(mod, mod->module_init_rw);
87291 + module_free(mod, mod->module_core_rw);
87292 + return -ENOMEM;
87293 + }
87294 +
87295 + pax_open_kernel();
87296 + memset(ptr, 0, mod->init_size_rx);
87297 + pax_close_kernel();
87298 + mod->module_init_rx = ptr;
87299 + } else
87300 + mod->module_init_rx = NULL;
87301
87302 /* Transfer each section which specifies SHF_ALLOC */
87303 pr_debug("final section addresses:\n");
87304 @@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
87305 if (!(shdr->sh_flags & SHF_ALLOC))
87306 continue;
87307
87308 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
87309 - dest = mod->module_init
87310 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87311 - else
87312 - dest = mod->module_core + shdr->sh_entsize;
87313 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87314 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87315 + dest = mod->module_init_rw
87316 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87317 + else
87318 + dest = mod->module_init_rx
87319 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87320 + } else {
87321 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87322 + dest = mod->module_core_rw + shdr->sh_entsize;
87323 + else
87324 + dest = mod->module_core_rx + shdr->sh_entsize;
87325 + }
87326 +
87327 + if (shdr->sh_type != SHT_NOBITS) {
87328 +
87329 +#ifdef CONFIG_PAX_KERNEXEC
87330 +#ifdef CONFIG_X86_64
87331 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87332 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87333 +#endif
87334 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87335 + pax_open_kernel();
87336 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87337 + pax_close_kernel();
87338 + } else
87339 +#endif
87340
87341 - if (shdr->sh_type != SHT_NOBITS)
87342 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87343 + }
87344 /* Update sh_addr to point to copy in image. */
87345 - shdr->sh_addr = (unsigned long)dest;
87346 +
87347 +#ifdef CONFIG_PAX_KERNEXEC
87348 + if (shdr->sh_flags & SHF_EXECINSTR)
87349 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
87350 + else
87351 +#endif
87352 +
87353 + shdr->sh_addr = (unsigned long)dest;
87354 pr_debug("\t0x%lx %s\n",
87355 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87356 }
87357 @@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
87358 * Do it before processing of module parameters, so the module
87359 * can provide parameter accessor functions of its own.
87360 */
87361 - if (mod->module_init)
87362 - flush_icache_range((unsigned long)mod->module_init,
87363 - (unsigned long)mod->module_init
87364 - + mod->init_size);
87365 - flush_icache_range((unsigned long)mod->module_core,
87366 - (unsigned long)mod->module_core + mod->core_size);
87367 + if (mod->module_init_rx)
87368 + flush_icache_range((unsigned long)mod->module_init_rx,
87369 + (unsigned long)mod->module_init_rx
87370 + + mod->init_size_rx);
87371 + flush_icache_range((unsigned long)mod->module_core_rx,
87372 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
87373
87374 set_fs(old_fs);
87375 }
87376 @@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87377 static void module_deallocate(struct module *mod, struct load_info *info)
87378 {
87379 percpu_modfree(mod);
87380 - module_free(mod, mod->module_init);
87381 - module_free(mod, mod->module_core);
87382 + module_free_exec(mod, mod->module_init_rx);
87383 + module_free_exec(mod, mod->module_core_rx);
87384 + module_free(mod, mod->module_init_rw);
87385 + module_free(mod, mod->module_core_rw);
87386 }
87387
87388 int __weak module_finalize(const Elf_Ehdr *hdr,
87389 @@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87390 static int post_relocation(struct module *mod, const struct load_info *info)
87391 {
87392 /* Sort exception table now relocations are done. */
87393 + pax_open_kernel();
87394 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87395 + pax_close_kernel();
87396
87397 /* Copy relocated percpu area over. */
87398 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87399 @@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
87400 MODULE_STATE_COMING, mod);
87401
87402 /* Set RO and NX regions for core */
87403 - set_section_ro_nx(mod->module_core,
87404 - mod->core_text_size,
87405 - mod->core_ro_size,
87406 - mod->core_size);
87407 + set_section_ro_nx(mod->module_core_rx,
87408 + mod->core_size_rx,
87409 + mod->core_size_rx,
87410 + mod->core_size_rx);
87411
87412 /* Set RO and NX regions for init */
87413 - set_section_ro_nx(mod->module_init,
87414 - mod->init_text_size,
87415 - mod->init_ro_size,
87416 - mod->init_size);
87417 + set_section_ro_nx(mod->module_init_rx,
87418 + mod->init_size_rx,
87419 + mod->init_size_rx,
87420 + mod->init_size_rx);
87421
87422 do_mod_ctors(mod);
87423 /* Start the module */
87424 @@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
87425 mod->strtab = mod->core_strtab;
87426 #endif
87427 unset_module_init_ro_nx(mod);
87428 - module_free(mod, mod->module_init);
87429 - mod->module_init = NULL;
87430 - mod->init_size = 0;
87431 - mod->init_ro_size = 0;
87432 - mod->init_text_size = 0;
87433 + module_free(mod, mod->module_init_rw);
87434 + module_free_exec(mod, mod->module_init_rx);
87435 + mod->module_init_rw = NULL;
87436 + mod->module_init_rx = NULL;
87437 + mod->init_size_rw = 0;
87438 + mod->init_size_rx = 0;
87439 mutex_unlock(&module_mutex);
87440 wake_up_all(&module_wq);
87441
87442 @@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87443 if (err)
87444 goto free_unload;
87445
87446 + /* Now copy in args */
87447 + mod->args = strndup_user(uargs, ~0UL >> 1);
87448 + if (IS_ERR(mod->args)) {
87449 + err = PTR_ERR(mod->args);
87450 + goto free_unload;
87451 + }
87452 +
87453 /* Set up MODINFO_ATTR fields */
87454 setup_modinfo(mod, info);
87455
87456 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87457 + {
87458 + char *p, *p2;
87459 +
87460 + if (strstr(mod->args, "grsec_modharden_netdev")) {
87461 + 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);
87462 + err = -EPERM;
87463 + goto free_modinfo;
87464 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87465 + p += sizeof("grsec_modharden_normal") - 1;
87466 + p2 = strstr(p, "_");
87467 + if (p2) {
87468 + *p2 = '\0';
87469 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87470 + *p2 = '_';
87471 + }
87472 + err = -EPERM;
87473 + goto free_modinfo;
87474 + }
87475 + }
87476 +#endif
87477 +
87478 /* Fix up syms, so that st_value is a pointer to location. */
87479 err = simplify_symbols(mod, info);
87480 if (err < 0)
87481 @@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87482
87483 flush_module_icache(mod);
87484
87485 - /* Now copy in args */
87486 - mod->args = strndup_user(uargs, ~0UL >> 1);
87487 - if (IS_ERR(mod->args)) {
87488 - err = PTR_ERR(mod->args);
87489 - goto free_arch_cleanup;
87490 - }
87491 -
87492 dynamic_debug_setup(info->debug, info->num_debug);
87493
87494 /* Finally it's fully formed, ready to start executing. */
87495 @@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87496 ddebug_cleanup:
87497 dynamic_debug_remove(info->debug);
87498 synchronize_sched();
87499 - kfree(mod->args);
87500 - free_arch_cleanup:
87501 module_arch_cleanup(mod);
87502 free_modinfo:
87503 free_modinfo(mod);
87504 + kfree(mod->args);
87505 free_unload:
87506 module_unload_free(mod);
87507 unlink_mod:
87508 @@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
87509 unsigned long nextval;
87510
87511 /* At worse, next value is at end of module */
87512 - if (within_module_init(addr, mod))
87513 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
87514 + if (within_module_init_rx(addr, mod))
87515 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87516 + else if (within_module_init_rw(addr, mod))
87517 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87518 + else if (within_module_core_rx(addr, mod))
87519 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87520 + else if (within_module_core_rw(addr, mod))
87521 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87522 else
87523 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
87524 + return NULL;
87525
87526 /* Scan for closest preceding symbol, and next symbol. (ELF
87527 starts real symbols at 1). */
87528 @@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
87529 return 0;
87530
87531 seq_printf(m, "%s %u",
87532 - mod->name, mod->init_size + mod->core_size);
87533 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87534 print_unload_info(m, mod);
87535
87536 /* Informative for users. */
87537 @@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
87538 mod->state == MODULE_STATE_COMING ? "Loading":
87539 "Live");
87540 /* Used by oprofile and other similar tools. */
87541 - seq_printf(m, " 0x%pK", mod->module_core);
87542 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87543
87544 /* Taints info */
87545 if (mod->taints)
87546 @@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
87547
87548 static int __init proc_modules_init(void)
87549 {
87550 +#ifndef CONFIG_GRKERNSEC_HIDESYM
87551 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87552 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87553 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87554 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87555 +#else
87556 proc_create("modules", 0, NULL, &proc_modules_operations);
87557 +#endif
87558 +#else
87559 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87560 +#endif
87561 return 0;
87562 }
87563 module_init(proc_modules_init);
87564 @@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
87565 {
87566 struct module *mod;
87567
87568 - if (addr < module_addr_min || addr > module_addr_max)
87569 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87570 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
87571 return NULL;
87572
87573 list_for_each_entry_rcu(mod, &modules, list) {
87574 if (mod->state == MODULE_STATE_UNFORMED)
87575 continue;
87576 - if (within_module_core(addr, mod)
87577 - || within_module_init(addr, mod))
87578 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
87579 return mod;
87580 }
87581 return NULL;
87582 @@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
87583 */
87584 struct module *__module_text_address(unsigned long addr)
87585 {
87586 - struct module *mod = __module_address(addr);
87587 + struct module *mod;
87588 +
87589 +#ifdef CONFIG_X86_32
87590 + addr = ktla_ktva(addr);
87591 +#endif
87592 +
87593 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87594 + return NULL;
87595 +
87596 + mod = __module_address(addr);
87597 +
87598 if (mod) {
87599 /* Make sure it's within the text section. */
87600 - if (!within(addr, mod->module_init, mod->init_text_size)
87601 - && !within(addr, mod->module_core, mod->core_text_size))
87602 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87603 mod = NULL;
87604 }
87605 return mod;
87606 diff --git a/kernel/notifier.c b/kernel/notifier.c
87607 index 2d5cc4c..d9ea600 100644
87608 --- a/kernel/notifier.c
87609 +++ b/kernel/notifier.c
87610 @@ -5,6 +5,7 @@
87611 #include <linux/rcupdate.h>
87612 #include <linux/vmalloc.h>
87613 #include <linux/reboot.h>
87614 +#include <linux/mm.h>
87615
87616 /*
87617 * Notifier list for kernel code which wants to be called
87618 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87619 while ((*nl) != NULL) {
87620 if (n->priority > (*nl)->priority)
87621 break;
87622 - nl = &((*nl)->next);
87623 + nl = (struct notifier_block **)&((*nl)->next);
87624 }
87625 - n->next = *nl;
87626 + pax_open_kernel();
87627 + *(const void **)&n->next = *nl;
87628 rcu_assign_pointer(*nl, n);
87629 + pax_close_kernel();
87630 return 0;
87631 }
87632
87633 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87634 return 0;
87635 if (n->priority > (*nl)->priority)
87636 break;
87637 - nl = &((*nl)->next);
87638 + nl = (struct notifier_block **)&((*nl)->next);
87639 }
87640 - n->next = *nl;
87641 + pax_open_kernel();
87642 + *(const void **)&n->next = *nl;
87643 rcu_assign_pointer(*nl, n);
87644 + pax_close_kernel();
87645 return 0;
87646 }
87647
87648 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87649 {
87650 while ((*nl) != NULL) {
87651 if ((*nl) == n) {
87652 + pax_open_kernel();
87653 rcu_assign_pointer(*nl, n->next);
87654 + pax_close_kernel();
87655 return 0;
87656 }
87657 - nl = &((*nl)->next);
87658 + nl = (struct notifier_block **)&((*nl)->next);
87659 }
87660 return -ENOENT;
87661 }
87662 diff --git a/kernel/padata.c b/kernel/padata.c
87663 index 161402f..598814c 100644
87664 --- a/kernel/padata.c
87665 +++ b/kernel/padata.c
87666 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87667 * seq_nr mod. number of cpus in use.
87668 */
87669
87670 - seq_nr = atomic_inc_return(&pd->seq_nr);
87671 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87672 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87673
87674 return padata_index_to_cpu(pd, cpu_index);
87675 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87676 padata_init_pqueues(pd);
87677 padata_init_squeues(pd);
87678 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87679 - atomic_set(&pd->seq_nr, -1);
87680 + atomic_set_unchecked(&pd->seq_nr, -1);
87681 atomic_set(&pd->reorder_objects, 0);
87682 atomic_set(&pd->refcnt, 0);
87683 pd->pinst = pinst;
87684 diff --git a/kernel/panic.c b/kernel/panic.c
87685 index 6d63003..486a109 100644
87686 --- a/kernel/panic.c
87687 +++ b/kernel/panic.c
87688 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87689 /*
87690 * Stop ourself in panic -- architecture code may override this
87691 */
87692 -void __weak panic_smp_self_stop(void)
87693 +void __weak __noreturn panic_smp_self_stop(void)
87694 {
87695 while (1)
87696 cpu_relax();
87697 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87698 disable_trace_on_warning();
87699
87700 pr_warn("------------[ cut here ]------------\n");
87701 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87702 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87703 raw_smp_processor_id(), current->pid, file, line, caller);
87704
87705 if (args)
87706 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87707 */
87708 void __stack_chk_fail(void)
87709 {
87710 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
87711 + dump_stack();
87712 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87713 __builtin_return_address(0));
87714 }
87715 EXPORT_SYMBOL(__stack_chk_fail);
87716 diff --git a/kernel/pid.c b/kernel/pid.c
87717 index 9b9a266..c20ef80 100644
87718 --- a/kernel/pid.c
87719 +++ b/kernel/pid.c
87720 @@ -33,6 +33,7 @@
87721 #include <linux/rculist.h>
87722 #include <linux/bootmem.h>
87723 #include <linux/hash.h>
87724 +#include <linux/security.h>
87725 #include <linux/pid_namespace.h>
87726 #include <linux/init_task.h>
87727 #include <linux/syscalls.h>
87728 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87729
87730 int pid_max = PID_MAX_DEFAULT;
87731
87732 -#define RESERVED_PIDS 300
87733 +#define RESERVED_PIDS 500
87734
87735 int pid_max_min = RESERVED_PIDS + 1;
87736 int pid_max_max = PID_MAX_LIMIT;
87737 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87738 */
87739 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87740 {
87741 + struct task_struct *task;
87742 +
87743 rcu_lockdep_assert(rcu_read_lock_held(),
87744 "find_task_by_pid_ns() needs rcu_read_lock()"
87745 " protection");
87746 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87747 +
87748 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87749 +
87750 + if (gr_pid_is_chrooted(task))
87751 + return NULL;
87752 +
87753 + return task;
87754 }
87755
87756 struct task_struct *find_task_by_vpid(pid_t vnr)
87757 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87758 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87759 }
87760
87761 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87762 +{
87763 + rcu_lockdep_assert(rcu_read_lock_held(),
87764 + "find_task_by_pid_ns() needs rcu_read_lock()"
87765 + " protection");
87766 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87767 +}
87768 +
87769 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87770 {
87771 struct pid *pid;
87772 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87773 index db95d8e..a0ca23f 100644
87774 --- a/kernel/pid_namespace.c
87775 +++ b/kernel/pid_namespace.c
87776 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87777 void __user *buffer, size_t *lenp, loff_t *ppos)
87778 {
87779 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87780 - struct ctl_table tmp = *table;
87781 + ctl_table_no_const tmp = *table;
87782
87783 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87784 return -EPERM;
87785 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87786 index 3b89464..5e38379 100644
87787 --- a/kernel/posix-cpu-timers.c
87788 +++ b/kernel/posix-cpu-timers.c
87789 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
87790
87791 static __init int init_posix_cpu_timers(void)
87792 {
87793 - struct k_clock process = {
87794 + static struct k_clock process = {
87795 .clock_getres = process_cpu_clock_getres,
87796 .clock_get = process_cpu_clock_get,
87797 .timer_create = process_cpu_timer_create,
87798 .nsleep = process_cpu_nsleep,
87799 .nsleep_restart = process_cpu_nsleep_restart,
87800 };
87801 - struct k_clock thread = {
87802 + static struct k_clock thread = {
87803 .clock_getres = thread_cpu_clock_getres,
87804 .clock_get = thread_cpu_clock_get,
87805 .timer_create = thread_cpu_timer_create,
87806 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87807 index 424c2d4..679242f 100644
87808 --- a/kernel/posix-timers.c
87809 +++ b/kernel/posix-timers.c
87810 @@ -43,6 +43,7 @@
87811 #include <linux/hash.h>
87812 #include <linux/posix-clock.h>
87813 #include <linux/posix-timers.h>
87814 +#include <linux/grsecurity.h>
87815 #include <linux/syscalls.h>
87816 #include <linux/wait.h>
87817 #include <linux/workqueue.h>
87818 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87819 * which we beg off on and pass to do_sys_settimeofday().
87820 */
87821
87822 -static struct k_clock posix_clocks[MAX_CLOCKS];
87823 +static struct k_clock *posix_clocks[MAX_CLOCKS];
87824
87825 /*
87826 * These ones are defined below.
87827 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87828 */
87829 static __init int init_posix_timers(void)
87830 {
87831 - struct k_clock clock_realtime = {
87832 + static struct k_clock clock_realtime = {
87833 .clock_getres = hrtimer_get_res,
87834 .clock_get = posix_clock_realtime_get,
87835 .clock_set = posix_clock_realtime_set,
87836 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87837 .timer_get = common_timer_get,
87838 .timer_del = common_timer_del,
87839 };
87840 - struct k_clock clock_monotonic = {
87841 + static struct k_clock clock_monotonic = {
87842 .clock_getres = hrtimer_get_res,
87843 .clock_get = posix_ktime_get_ts,
87844 .nsleep = common_nsleep,
87845 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87846 .timer_get = common_timer_get,
87847 .timer_del = common_timer_del,
87848 };
87849 - struct k_clock clock_monotonic_raw = {
87850 + static struct k_clock clock_monotonic_raw = {
87851 .clock_getres = hrtimer_get_res,
87852 .clock_get = posix_get_monotonic_raw,
87853 };
87854 - struct k_clock clock_realtime_coarse = {
87855 + static struct k_clock clock_realtime_coarse = {
87856 .clock_getres = posix_get_coarse_res,
87857 .clock_get = posix_get_realtime_coarse,
87858 };
87859 - struct k_clock clock_monotonic_coarse = {
87860 + static struct k_clock clock_monotonic_coarse = {
87861 .clock_getres = posix_get_coarse_res,
87862 .clock_get = posix_get_monotonic_coarse,
87863 };
87864 - struct k_clock clock_tai = {
87865 + static struct k_clock clock_tai = {
87866 .clock_getres = hrtimer_get_res,
87867 .clock_get = posix_get_tai,
87868 .nsleep = common_nsleep,
87869 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87870 .timer_get = common_timer_get,
87871 .timer_del = common_timer_del,
87872 };
87873 - struct k_clock clock_boottime = {
87874 + static struct k_clock clock_boottime = {
87875 .clock_getres = hrtimer_get_res,
87876 .clock_get = posix_get_boottime,
87877 .nsleep = common_nsleep,
87878 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87879 return;
87880 }
87881
87882 - posix_clocks[clock_id] = *new_clock;
87883 + posix_clocks[clock_id] = new_clock;
87884 }
87885 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87886
87887 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87888 return (id & CLOCKFD_MASK) == CLOCKFD ?
87889 &clock_posix_dynamic : &clock_posix_cpu;
87890
87891 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87892 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87893 return NULL;
87894 - return &posix_clocks[id];
87895 + return posix_clocks[id];
87896 }
87897
87898 static int common_timer_create(struct k_itimer *new_timer)
87899 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87900 struct k_clock *kc = clockid_to_kclock(which_clock);
87901 struct k_itimer *new_timer;
87902 int error, new_timer_id;
87903 - sigevent_t event;
87904 + sigevent_t event = { };
87905 int it_id_set = IT_ID_NOT_SET;
87906
87907 if (!kc)
87908 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87909 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87910 return -EFAULT;
87911
87912 + /* only the CLOCK_REALTIME clock can be set, all other clocks
87913 + have their clock_set fptr set to a nosettime dummy function
87914 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87915 + call common_clock_set, which calls do_sys_settimeofday, which
87916 + we hook
87917 + */
87918 +
87919 return kc->clock_set(which_clock, &new_tp);
87920 }
87921
87922 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87923 index 2fac9cc..56fef29 100644
87924 --- a/kernel/power/Kconfig
87925 +++ b/kernel/power/Kconfig
87926 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87927 config HIBERNATION
87928 bool "Hibernation (aka 'suspend to disk')"
87929 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87930 + depends on !GRKERNSEC_KMEM
87931 + depends on !PAX_MEMORY_SANITIZE
87932 select HIBERNATE_CALLBACKS
87933 select LZO_COMPRESS
87934 select LZO_DECOMPRESS
87935 diff --git a/kernel/power/process.c b/kernel/power/process.c
87936 index 06ec886..9dba35e 100644
87937 --- a/kernel/power/process.c
87938 +++ b/kernel/power/process.c
87939 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87940 unsigned int elapsed_msecs;
87941 bool wakeup = false;
87942 int sleep_usecs = USEC_PER_MSEC;
87943 + bool timedout = false;
87944
87945 do_gettimeofday(&start);
87946
87947 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87948
87949 while (true) {
87950 todo = 0;
87951 + if (time_after(jiffies, end_time))
87952 + timedout = true;
87953 read_lock(&tasklist_lock);
87954 do_each_thread(g, p) {
87955 if (p == current || !freeze_task(p))
87956 continue;
87957
87958 - if (!freezer_should_skip(p))
87959 + if (!freezer_should_skip(p)) {
87960 todo++;
87961 + if (timedout) {
87962 + printk(KERN_ERR "Task refusing to freeze:\n");
87963 + sched_show_task(p);
87964 + }
87965 + }
87966 } while_each_thread(g, p);
87967 read_unlock(&tasklist_lock);
87968
87969 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87970 todo += wq_busy;
87971 }
87972
87973 - if (!todo || time_after(jiffies, end_time))
87974 + if (!todo || timedout)
87975 break;
87976
87977 if (pm_wakeup_pending()) {
87978 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87979 index 4dae9cb..039ffbb 100644
87980 --- a/kernel/printk/printk.c
87981 +++ b/kernel/printk/printk.c
87982 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87983 if (from_file && type != SYSLOG_ACTION_OPEN)
87984 return 0;
87985
87986 +#ifdef CONFIG_GRKERNSEC_DMESG
87987 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87988 + return -EPERM;
87989 +#endif
87990 +
87991 if (syslog_action_restricted(type)) {
87992 if (capable(CAP_SYSLOG))
87993 return 0;
87994 diff --git a/kernel/profile.c b/kernel/profile.c
87995 index ebdd9c1..612ee05 100644
87996 --- a/kernel/profile.c
87997 +++ b/kernel/profile.c
87998 @@ -37,7 +37,7 @@ struct profile_hit {
87999 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88000 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88001
88002 -static atomic_t *prof_buffer;
88003 +static atomic_unchecked_t *prof_buffer;
88004 static unsigned long prof_len, prof_shift;
88005
88006 int prof_on __read_mostly;
88007 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88008 hits[i].pc = 0;
88009 continue;
88010 }
88011 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88012 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88013 hits[i].hits = hits[i].pc = 0;
88014 }
88015 }
88016 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88017 * Add the current hit(s) and flush the write-queue out
88018 * to the global buffer:
88019 */
88020 - atomic_add(nr_hits, &prof_buffer[pc]);
88021 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88022 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88023 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88024 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88025 hits[i].pc = hits[i].hits = 0;
88026 }
88027 out:
88028 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88029 {
88030 unsigned long pc;
88031 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88032 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88033 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88034 }
88035 #endif /* !CONFIG_SMP */
88036
88037 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88038 return -EFAULT;
88039 buf++; p++; count--; read++;
88040 }
88041 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88042 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88043 if (copy_to_user(buf, (void *)pnt, count))
88044 return -EFAULT;
88045 read += count;
88046 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88047 }
88048 #endif
88049 profile_discard_flip_buffers();
88050 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88051 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88052 return count;
88053 }
88054
88055 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88056 index 1f4bcb3..99cf7ab 100644
88057 --- a/kernel/ptrace.c
88058 +++ b/kernel/ptrace.c
88059 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88060 if (seize)
88061 flags |= PT_SEIZED;
88062 rcu_read_lock();
88063 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88064 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88065 flags |= PT_PTRACE_CAP;
88066 rcu_read_unlock();
88067 task->ptrace = flags;
88068 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88069 break;
88070 return -EIO;
88071 }
88072 - if (copy_to_user(dst, buf, retval))
88073 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88074 return -EFAULT;
88075 copied += retval;
88076 src += retval;
88077 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88078 bool seized = child->ptrace & PT_SEIZED;
88079 int ret = -EIO;
88080 siginfo_t siginfo, *si;
88081 - void __user *datavp = (void __user *) data;
88082 + void __user *datavp = (__force void __user *) data;
88083 unsigned long __user *datalp = datavp;
88084 unsigned long flags;
88085
88086 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88087 goto out;
88088 }
88089
88090 + if (gr_handle_ptrace(child, request)) {
88091 + ret = -EPERM;
88092 + goto out_put_task_struct;
88093 + }
88094 +
88095 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88096 ret = ptrace_attach(child, request, addr, data);
88097 /*
88098 * Some architectures need to do book-keeping after
88099 * a ptrace attach.
88100 */
88101 - if (!ret)
88102 + if (!ret) {
88103 arch_ptrace_attach(child);
88104 + gr_audit_ptrace(child);
88105 + }
88106 goto out_put_task_struct;
88107 }
88108
88109 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88110 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88111 if (copied != sizeof(tmp))
88112 return -EIO;
88113 - return put_user(tmp, (unsigned long __user *)data);
88114 + return put_user(tmp, (__force unsigned long __user *)data);
88115 }
88116
88117 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88118 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88119 }
88120
88121 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88122 - compat_long_t addr, compat_long_t data)
88123 + compat_ulong_t addr, compat_ulong_t data)
88124 {
88125 struct task_struct *child;
88126 long ret;
88127 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88128 goto out;
88129 }
88130
88131 + if (gr_handle_ptrace(child, request)) {
88132 + ret = -EPERM;
88133 + goto out_put_task_struct;
88134 + }
88135 +
88136 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88137 ret = ptrace_attach(child, request, addr, data);
88138 /*
88139 * Some architectures need to do book-keeping after
88140 * a ptrace attach.
88141 */
88142 - if (!ret)
88143 + if (!ret) {
88144 arch_ptrace_attach(child);
88145 + gr_audit_ptrace(child);
88146 + }
88147 goto out_put_task_struct;
88148 }
88149
88150 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88151 index 3318d82..1a5b2d1 100644
88152 --- a/kernel/rcu/srcu.c
88153 +++ b/kernel/rcu/srcu.c
88154 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88155
88156 idx = ACCESS_ONCE(sp->completed) & 0x1;
88157 preempt_disable();
88158 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88159 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88160 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88161 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88162 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88163 preempt_enable();
88164 return idx;
88165 }
88166 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88167 index 1254f31..16258dc 100644
88168 --- a/kernel/rcu/tiny.c
88169 +++ b/kernel/rcu/tiny.c
88170 @@ -46,7 +46,7 @@
88171 /* Forward declarations for tiny_plugin.h. */
88172 struct rcu_ctrlblk;
88173 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88174 -static void rcu_process_callbacks(struct softirq_action *unused);
88175 +static void rcu_process_callbacks(void);
88176 static void __call_rcu(struct rcu_head *head,
88177 void (*func)(struct rcu_head *rcu),
88178 struct rcu_ctrlblk *rcp);
88179 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88180 false));
88181 }
88182
88183 -static void rcu_process_callbacks(struct softirq_action *unused)
88184 +static __latent_entropy void rcu_process_callbacks(void)
88185 {
88186 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88187 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88188 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88189 index 732f8ae..9984c27 100644
88190 --- a/kernel/rcu/torture.c
88191 +++ b/kernel/rcu/torture.c
88192 @@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88193 { 0 };
88194 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88195 { 0 };
88196 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88197 -static atomic_t n_rcu_torture_alloc;
88198 -static atomic_t n_rcu_torture_alloc_fail;
88199 -static atomic_t n_rcu_torture_free;
88200 -static atomic_t n_rcu_torture_mberror;
88201 -static atomic_t n_rcu_torture_error;
88202 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88203 +static atomic_unchecked_t n_rcu_torture_alloc;
88204 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
88205 +static atomic_unchecked_t n_rcu_torture_free;
88206 +static atomic_unchecked_t n_rcu_torture_mberror;
88207 +static atomic_unchecked_t n_rcu_torture_error;
88208 static long n_rcu_torture_barrier_error;
88209 static long n_rcu_torture_boost_ktrerror;
88210 static long n_rcu_torture_boost_rterror;
88211 @@ -297,11 +297,11 @@ rcu_torture_alloc(void)
88212
88213 spin_lock_bh(&rcu_torture_lock);
88214 if (list_empty(&rcu_torture_freelist)) {
88215 - atomic_inc(&n_rcu_torture_alloc_fail);
88216 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88217 spin_unlock_bh(&rcu_torture_lock);
88218 return NULL;
88219 }
88220 - atomic_inc(&n_rcu_torture_alloc);
88221 + atomic_inc_unchecked(&n_rcu_torture_alloc);
88222 p = rcu_torture_freelist.next;
88223 list_del_init(p);
88224 spin_unlock_bh(&rcu_torture_lock);
88225 @@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88226 static void
88227 rcu_torture_free(struct rcu_torture *p)
88228 {
88229 - atomic_inc(&n_rcu_torture_free);
88230 + atomic_inc_unchecked(&n_rcu_torture_free);
88231 spin_lock_bh(&rcu_torture_lock);
88232 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88233 spin_unlock_bh(&rcu_torture_lock);
88234 @@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88235 i = rp->rtort_pipe_count;
88236 if (i > RCU_TORTURE_PIPE_LEN)
88237 i = RCU_TORTURE_PIPE_LEN;
88238 - atomic_inc(&rcu_torture_wcount[i]);
88239 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88240 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88241 rp->rtort_mbtest = 0;
88242 rcu_torture_free(rp);
88243 @@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
88244 i = old_rp->rtort_pipe_count;
88245 if (i > RCU_TORTURE_PIPE_LEN)
88246 i = RCU_TORTURE_PIPE_LEN;
88247 - atomic_inc(&rcu_torture_wcount[i]);
88248 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88249 old_rp->rtort_pipe_count++;
88250 if (gp_normal == gp_exp)
88251 exp = !!(rcu_random(&rand) & 0x80);
88252 @@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
88253 i = rp->rtort_pipe_count;
88254 if (i > RCU_TORTURE_PIPE_LEN)
88255 i = RCU_TORTURE_PIPE_LEN;
88256 - atomic_inc(&rcu_torture_wcount[i]);
88257 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88258 if (++rp->rtort_pipe_count >=
88259 RCU_TORTURE_PIPE_LEN) {
88260 rp->rtort_mbtest = 0;
88261 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
88262 return;
88263 }
88264 if (p->rtort_mbtest == 0)
88265 - atomic_inc(&n_rcu_torture_mberror);
88266 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88267 spin_lock(&rand_lock);
88268 cur_ops->read_delay(&rand);
88269 n_rcu_torture_timers++;
88270 @@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
88271 continue;
88272 }
88273 if (p->rtort_mbtest == 0)
88274 - atomic_inc(&n_rcu_torture_mberror);
88275 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88276 cur_ops->read_delay(&rand);
88277 preempt_disable();
88278 pipe_count = p->rtort_pipe_count;
88279 @@ -1072,11 +1072,11 @@ rcu_torture_printk(char *page)
88280 rcu_torture_current,
88281 rcu_torture_current_version,
88282 list_empty(&rcu_torture_freelist),
88283 - atomic_read(&n_rcu_torture_alloc),
88284 - atomic_read(&n_rcu_torture_alloc_fail),
88285 - atomic_read(&n_rcu_torture_free));
88286 + atomic_read_unchecked(&n_rcu_torture_alloc),
88287 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88288 + atomic_read_unchecked(&n_rcu_torture_free));
88289 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88290 - atomic_read(&n_rcu_torture_mberror),
88291 + atomic_read_unchecked(&n_rcu_torture_mberror),
88292 n_rcu_torture_boost_ktrerror,
88293 n_rcu_torture_boost_rterror);
88294 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88295 @@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
88296 n_barrier_attempts,
88297 n_rcu_torture_barrier_error);
88298 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88299 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88300 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88301 n_rcu_torture_barrier_error != 0 ||
88302 n_rcu_torture_boost_ktrerror != 0 ||
88303 n_rcu_torture_boost_rterror != 0 ||
88304 n_rcu_torture_boost_failure != 0 ||
88305 i > 1) {
88306 page += sprintf(page, "!!! ");
88307 - atomic_inc(&n_rcu_torture_error);
88308 + atomic_inc_unchecked(&n_rcu_torture_error);
88309 WARN_ON_ONCE(1);
88310 }
88311 page += sprintf(page, "Reader Pipe: ");
88312 @@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
88313 page += sprintf(page, "Free-Block Circulation: ");
88314 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88315 page += sprintf(page, " %d",
88316 - atomic_read(&rcu_torture_wcount[i]));
88317 + atomic_read_unchecked(&rcu_torture_wcount[i]));
88318 }
88319 page += sprintf(page, "\n");
88320 if (cur_ops->stats)
88321 @@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
88322
88323 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88324
88325 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88326 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88327 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88328 else if (n_online_successes != n_online_attempts ||
88329 n_offline_successes != n_offline_attempts)
88330 @@ -1961,18 +1961,18 @@ rcu_torture_init(void)
88331
88332 rcu_torture_current = NULL;
88333 rcu_torture_current_version = 0;
88334 - atomic_set(&n_rcu_torture_alloc, 0);
88335 - atomic_set(&n_rcu_torture_alloc_fail, 0);
88336 - atomic_set(&n_rcu_torture_free, 0);
88337 - atomic_set(&n_rcu_torture_mberror, 0);
88338 - atomic_set(&n_rcu_torture_error, 0);
88339 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88340 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88341 + atomic_set_unchecked(&n_rcu_torture_free, 0);
88342 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88343 + atomic_set_unchecked(&n_rcu_torture_error, 0);
88344 n_rcu_torture_barrier_error = 0;
88345 n_rcu_torture_boost_ktrerror = 0;
88346 n_rcu_torture_boost_rterror = 0;
88347 n_rcu_torture_boost_failure = 0;
88348 n_rcu_torture_boosts = 0;
88349 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88350 - atomic_set(&rcu_torture_wcount[i], 0);
88351 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88352 for_each_possible_cpu(cpu) {
88353 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88354 per_cpu(rcu_torture_count, cpu)[i] = 0;
88355 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88356 index b3d116c..ebf6598 100644
88357 --- a/kernel/rcu/tree.c
88358 +++ b/kernel/rcu/tree.c
88359 @@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88360 rcu_prepare_for_idle(smp_processor_id());
88361 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88362 smp_mb__before_atomic_inc(); /* See above. */
88363 - atomic_inc(&rdtp->dynticks);
88364 + atomic_inc_unchecked(&rdtp->dynticks);
88365 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88366 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88367 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88368
88369 /*
88370 * It is illegal to enter an extended quiescent state while
88371 @@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88372 int user)
88373 {
88374 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88375 - atomic_inc(&rdtp->dynticks);
88376 + atomic_inc_unchecked(&rdtp->dynticks);
88377 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88378 smp_mb__after_atomic_inc(); /* See above. */
88379 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88380 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88381 rcu_cleanup_after_idle(smp_processor_id());
88382 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88383 if (!user && !is_idle_task(current)) {
88384 @@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
88385 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88386
88387 if (rdtp->dynticks_nmi_nesting == 0 &&
88388 - (atomic_read(&rdtp->dynticks) & 0x1))
88389 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88390 return;
88391 rdtp->dynticks_nmi_nesting++;
88392 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88393 - atomic_inc(&rdtp->dynticks);
88394 + atomic_inc_unchecked(&rdtp->dynticks);
88395 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88396 smp_mb__after_atomic_inc(); /* See above. */
88397 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88398 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88399 }
88400
88401 /**
88402 @@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
88403 return;
88404 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88405 smp_mb__before_atomic_inc(); /* See above. */
88406 - atomic_inc(&rdtp->dynticks);
88407 + atomic_inc_unchecked(&rdtp->dynticks);
88408 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88409 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88410 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88411 }
88412
88413 /**
88414 @@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
88415 */
88416 bool notrace __rcu_is_watching(void)
88417 {
88418 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88419 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88420 }
88421
88422 /**
88423 @@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88424 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88425 bool *isidle, unsigned long *maxj)
88426 {
88427 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88428 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88429 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88430 return (rdp->dynticks_snap & 0x1) == 0;
88431 }
88432 @@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88433 unsigned int curr;
88434 unsigned int snap;
88435
88436 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88437 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88438 snap = (unsigned int)rdp->dynticks_snap;
88439
88440 /*
88441 @@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88442 rdp = this_cpu_ptr(rsp->rda);
88443 rcu_preempt_check_blocked_tasks(rnp);
88444 rnp->qsmask = rnp->qsmaskinit;
88445 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88446 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88447 WARN_ON_ONCE(rnp->completed != rsp->completed);
88448 - ACCESS_ONCE(rnp->completed) = rsp->completed;
88449 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88450 if (rnp == rdp->mynode)
88451 __note_gp_changes(rsp, rnp, rdp);
88452 rcu_preempt_boost_start_gp(rnp);
88453 @@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88454 rcu_for_each_node_breadth_first(rsp, rnp) {
88455 raw_spin_lock_irq(&rnp->lock);
88456 smp_mb__after_unlock_lock();
88457 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88458 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88459 rdp = this_cpu_ptr(rsp->rda);
88460 if (rnp == rdp->mynode)
88461 __note_gp_changes(rsp, rnp, rdp);
88462 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88463 rsp->qlen += rdp->qlen;
88464 rdp->n_cbs_orphaned += rdp->qlen;
88465 rdp->qlen_lazy = 0;
88466 - ACCESS_ONCE(rdp->qlen) = 0;
88467 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88468 }
88469
88470 /*
88471 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88472 }
88473 smp_mb(); /* List handling before counting for rcu_barrier(). */
88474 rdp->qlen_lazy -= count_lazy;
88475 - ACCESS_ONCE(rdp->qlen) -= count;
88476 + ACCESS_ONCE_RW(rdp->qlen) -= count;
88477 rdp->n_cbs_invoked += count;
88478
88479 /* Reinstate batch limit if we have worked down the excess. */
88480 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88481 /*
88482 * Do RCU core processing for the current CPU.
88483 */
88484 -static void rcu_process_callbacks(struct softirq_action *unused)
88485 +static void rcu_process_callbacks(void)
88486 {
88487 struct rcu_state *rsp;
88488
88489 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88490 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88491 if (debug_rcu_head_queue(head)) {
88492 /* Probable double call_rcu(), so leak the callback. */
88493 - ACCESS_ONCE(head->func) = rcu_leak_callback;
88494 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88495 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88496 return;
88497 }
88498 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88499 local_irq_restore(flags);
88500 return;
88501 }
88502 - ACCESS_ONCE(rdp->qlen)++;
88503 + ACCESS_ONCE_RW(rdp->qlen)++;
88504 if (lazy)
88505 rdp->qlen_lazy++;
88506 else
88507 @@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
88508 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88509 * course be required on a 64-bit system.
88510 */
88511 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88512 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88513 (ulong)atomic_long_read(&rsp->expedited_done) +
88514 ULONG_MAX / 8)) {
88515 synchronize_sched();
88516 - atomic_long_inc(&rsp->expedited_wrap);
88517 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
88518 return;
88519 }
88520
88521 @@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
88522 * Take a ticket. Note that atomic_inc_return() implies a
88523 * full memory barrier.
88524 */
88525 - snap = atomic_long_inc_return(&rsp->expedited_start);
88526 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88527 firstsnap = snap;
88528 get_online_cpus();
88529 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88530 @@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
88531 synchronize_sched_expedited_cpu_stop,
88532 NULL) == -EAGAIN) {
88533 put_online_cpus();
88534 - atomic_long_inc(&rsp->expedited_tryfail);
88535 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88536
88537 /* Check to see if someone else did our work for us. */
88538 s = atomic_long_read(&rsp->expedited_done);
88539 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88540 /* ensure test happens before caller kfree */
88541 smp_mb__before_atomic_inc(); /* ^^^ */
88542 - atomic_long_inc(&rsp->expedited_workdone1);
88543 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88544 return;
88545 }
88546
88547 @@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
88548 udelay(trycount * num_online_cpus());
88549 } else {
88550 wait_rcu_gp(call_rcu_sched);
88551 - atomic_long_inc(&rsp->expedited_normal);
88552 + atomic_long_inc_unchecked(&rsp->expedited_normal);
88553 return;
88554 }
88555
88556 @@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
88557 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88558 /* ensure test happens before caller kfree */
88559 smp_mb__before_atomic_inc(); /* ^^^ */
88560 - atomic_long_inc(&rsp->expedited_workdone2);
88561 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88562 return;
88563 }
88564
88565 @@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
88566 * period works for us.
88567 */
88568 get_online_cpus();
88569 - snap = atomic_long_read(&rsp->expedited_start);
88570 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
88571 smp_mb(); /* ensure read is before try_stop_cpus(). */
88572 }
88573 - atomic_long_inc(&rsp->expedited_stoppedcpus);
88574 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88575
88576 /*
88577 * Everyone up to our most recent fetch is covered by our grace
88578 @@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
88579 * than we did already did their update.
88580 */
88581 do {
88582 - atomic_long_inc(&rsp->expedited_done_tries);
88583 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88584 s = atomic_long_read(&rsp->expedited_done);
88585 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88586 /* ensure test happens before caller kfree */
88587 smp_mb__before_atomic_inc(); /* ^^^ */
88588 - atomic_long_inc(&rsp->expedited_done_lost);
88589 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88590 break;
88591 }
88592 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88593 - atomic_long_inc(&rsp->expedited_done_exit);
88594 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88595
88596 put_online_cpus();
88597 }
88598 @@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88599 * ACCESS_ONCE() to prevent the compiler from speculating
88600 * the increment to precede the early-exit check.
88601 */
88602 - ACCESS_ONCE(rsp->n_barrier_done)++;
88603 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88604 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88605 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88606 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88607 @@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88608
88609 /* Increment ->n_barrier_done to prevent duplicate work. */
88610 smp_mb(); /* Keep increment after above mechanism. */
88611 - ACCESS_ONCE(rsp->n_barrier_done)++;
88612 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88613 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88614 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88615 smp_mb(); /* Keep increment before caller's subsequent code. */
88616 @@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88617 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88618 init_callback_list(rdp);
88619 rdp->qlen_lazy = 0;
88620 - ACCESS_ONCE(rdp->qlen) = 0;
88621 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88622 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88623 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88624 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88625 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88626 rdp->cpu = cpu;
88627 rdp->rsp = rsp;
88628 rcu_boot_init_nocb_percpu_data(rdp);
88629 @@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88630 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88631 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88632 rcu_sysidle_init_percpu_data(rdp->dynticks);
88633 - atomic_set(&rdp->dynticks->dynticks,
88634 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88635 + atomic_set_unchecked(&rdp->dynticks->dynticks,
88636 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88637 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88638
88639 /* Add CPU to rcu_node bitmasks. */
88640 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88641 index 8c19873..bf83c57 100644
88642 --- a/kernel/rcu/tree.h
88643 +++ b/kernel/rcu/tree.h
88644 @@ -87,11 +87,11 @@ struct rcu_dynticks {
88645 long long dynticks_nesting; /* Track irq/process nesting level. */
88646 /* Process level is worth LLONG_MAX/2. */
88647 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88648 - atomic_t dynticks; /* Even value for idle, else odd. */
88649 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88650 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88651 long long dynticks_idle_nesting;
88652 /* irq/process nesting level from idle. */
88653 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
88654 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88655 /* "Idle" excludes userspace execution. */
88656 unsigned long dynticks_idle_jiffies;
88657 /* End of last non-NMI non-idle period. */
88658 @@ -431,17 +431,17 @@ struct rcu_state {
88659 /* _rcu_barrier(). */
88660 /* End of fields guarded by barrier_mutex. */
88661
88662 - atomic_long_t expedited_start; /* Starting ticket. */
88663 - atomic_long_t expedited_done; /* Done ticket. */
88664 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88665 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
88666 - atomic_long_t expedited_workdone1; /* # done by others #1. */
88667 - atomic_long_t expedited_workdone2; /* # done by others #2. */
88668 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
88669 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88670 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
88671 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88672 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88673 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88674 + atomic_long_t expedited_done; /* Done ticket. */
88675 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88676 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88677 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88678 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88679 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88680 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88681 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88682 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88683 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88684
88685 unsigned long jiffies_force_qs; /* Time at which to invoke */
88686 /* force_quiescent_state(). */
88687 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88688 index 6e2ef4b..c15df94 100644
88689 --- a/kernel/rcu/tree_plugin.h
88690 +++ b/kernel/rcu/tree_plugin.h
88691 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88692 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88693 {
88694 return !rcu_preempted_readers_exp(rnp) &&
88695 - ACCESS_ONCE(rnp->expmask) == 0;
88696 + ACCESS_ONCE_RW(rnp->expmask) == 0;
88697 }
88698
88699 /*
88700 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
88701
88702 /* Clean up and exit. */
88703 smp_mb(); /* ensure expedited GP seen before counter increment. */
88704 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88705 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88706 unlock_mb_ret:
88707 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88708 mb_ret:
88709 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88710 free_cpumask_var(cm);
88711 }
88712
88713 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88714 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88715 .store = &rcu_cpu_kthread_task,
88716 .thread_should_run = rcu_cpu_kthread_should_run,
88717 .thread_fn = rcu_cpu_kthread,
88718 @@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88719 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88720 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88721 cpu, ticks_value, ticks_title,
88722 - atomic_read(&rdtp->dynticks) & 0xfff,
88723 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88724 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88725 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88726 fast_no_hz);
88727 @@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88728
88729 /* Enqueue the callback on the nocb list and update counts. */
88730 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88731 - ACCESS_ONCE(*old_rhpp) = rhp;
88732 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
88733 atomic_long_add(rhcount, &rdp->nocb_q_count);
88734 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88735
88736 @@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
88737 * Extract queued callbacks, update counts, and wait
88738 * for a grace period to elapse.
88739 */
88740 - ACCESS_ONCE(rdp->nocb_head) = NULL;
88741 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88742 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88743 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88744 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88745 - ACCESS_ONCE(rdp->nocb_p_count) += c;
88746 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88747 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88748 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88749 rcu_nocb_wait_gp(rdp);
88750
88751 /* Each pass through the following loop invokes a callback. */
88752 @@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
88753 list = next;
88754 }
88755 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88756 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
88757 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88758 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88759 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88760 rdp->n_nocbs_invoked += c;
88761 }
88762 return 0;
88763 @@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
88764 {
88765 if (!rcu_nocb_need_deferred_wakeup(rdp))
88766 return;
88767 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
88768 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
88769 wake_up(&rdp->nocb_wq);
88770 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
88771 }
88772 @@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88773 t = kthread_run(rcu_nocb_kthread, rdp,
88774 "rcuo%c/%d", rsp->abbr, cpu);
88775 BUG_ON(IS_ERR(t));
88776 - ACCESS_ONCE(rdp->nocb_kthread) = t;
88777 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88778 }
88779 }
88780
88781 @@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88782
88783 /* Record start of fully idle period. */
88784 j = jiffies;
88785 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88786 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88787 smp_mb__before_atomic_inc();
88788 - atomic_inc(&rdtp->dynticks_idle);
88789 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88790 smp_mb__after_atomic_inc();
88791 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88792 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88793 }
88794
88795 /*
88796 @@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88797
88798 /* Record end of idle period. */
88799 smp_mb__before_atomic_inc();
88800 - atomic_inc(&rdtp->dynticks_idle);
88801 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88802 smp_mb__after_atomic_inc();
88803 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88804 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88805
88806 /*
88807 * If we are the timekeeping CPU, we are permitted to be non-idle
88808 @@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88809 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88810
88811 /* Pick up current idle and NMI-nesting counter and check. */
88812 - cur = atomic_read(&rdtp->dynticks_idle);
88813 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88814 if (cur & 0x1) {
88815 *isidle = false; /* We are not idle! */
88816 return;
88817 @@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
88818 case RCU_SYSIDLE_NOT:
88819
88820 /* First time all are idle, so note a short idle period. */
88821 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88822 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88823 break;
88824
88825 case RCU_SYSIDLE_SHORT:
88826 @@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
88827 static void rcu_sysidle_cancel(void)
88828 {
88829 smp_mb();
88830 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88831 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88832 }
88833
88834 /*
88835 @@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88836 smp_mb(); /* grace period precedes setting inuse. */
88837
88838 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88839 - ACCESS_ONCE(rshp->inuse) = 0;
88840 + ACCESS_ONCE_RW(rshp->inuse) = 0;
88841 }
88842
88843 /*
88844 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88845 index 4def475..8ffddde 100644
88846 --- a/kernel/rcu/tree_trace.c
88847 +++ b/kernel/rcu/tree_trace.c
88848 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88849 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88850 rdp->passed_quiesce, rdp->qs_pending);
88851 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88852 - atomic_read(&rdp->dynticks->dynticks),
88853 + atomic_read_unchecked(&rdp->dynticks->dynticks),
88854 rdp->dynticks->dynticks_nesting,
88855 rdp->dynticks->dynticks_nmi_nesting,
88856 rdp->dynticks_fqs);
88857 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88858 struct rcu_state *rsp = (struct rcu_state *)m->private;
88859
88860 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",
88861 - atomic_long_read(&rsp->expedited_start),
88862 + atomic_long_read_unchecked(&rsp->expedited_start),
88863 atomic_long_read(&rsp->expedited_done),
88864 - atomic_long_read(&rsp->expedited_wrap),
88865 - atomic_long_read(&rsp->expedited_tryfail),
88866 - atomic_long_read(&rsp->expedited_workdone1),
88867 - atomic_long_read(&rsp->expedited_workdone2),
88868 - atomic_long_read(&rsp->expedited_normal),
88869 - atomic_long_read(&rsp->expedited_stoppedcpus),
88870 - atomic_long_read(&rsp->expedited_done_tries),
88871 - atomic_long_read(&rsp->expedited_done_lost),
88872 - atomic_long_read(&rsp->expedited_done_exit));
88873 + atomic_long_read_unchecked(&rsp->expedited_wrap),
88874 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
88875 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
88876 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
88877 + atomic_long_read_unchecked(&rsp->expedited_normal),
88878 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88879 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
88880 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
88881 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
88882 return 0;
88883 }
88884
88885 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88886 index c54609f..2e8829c 100644
88887 --- a/kernel/rcu/update.c
88888 +++ b/kernel/rcu/update.c
88889 @@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
88890 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88891 */
88892 if (till_stall_check < 3) {
88893 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88894 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88895 till_stall_check = 3;
88896 } else if (till_stall_check > 300) {
88897 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88898 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88899 till_stall_check = 300;
88900 }
88901 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88902 diff --git a/kernel/resource.c b/kernel/resource.c
88903 index 3f285dc..5755f62 100644
88904 --- a/kernel/resource.c
88905 +++ b/kernel/resource.c
88906 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88907
88908 static int __init ioresources_init(void)
88909 {
88910 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88911 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88912 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88913 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88914 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88915 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88916 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88917 +#endif
88918 +#else
88919 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88920 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88921 +#endif
88922 return 0;
88923 }
88924 __initcall(ioresources_init);
88925 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88926 index 4a07353..66b5291 100644
88927 --- a/kernel/sched/auto_group.c
88928 +++ b/kernel/sched/auto_group.c
88929 @@ -11,7 +11,7 @@
88930
88931 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88932 static struct autogroup autogroup_default;
88933 -static atomic_t autogroup_seq_nr;
88934 +static atomic_unchecked_t autogroup_seq_nr;
88935
88936 void __init autogroup_init(struct task_struct *init_task)
88937 {
88938 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88939
88940 kref_init(&ag->kref);
88941 init_rwsem(&ag->lock);
88942 - ag->id = atomic_inc_return(&autogroup_seq_nr);
88943 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88944 ag->tg = tg;
88945 #ifdef CONFIG_RT_GROUP_SCHED
88946 /*
88947 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88948 index a63f4dc..349bbb0 100644
88949 --- a/kernel/sched/completion.c
88950 +++ b/kernel/sched/completion.c
88951 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88952 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88953 * or number of jiffies left till timeout) if completed.
88954 */
88955 -long __sched
88956 +long __sched __intentional_overflow(-1)
88957 wait_for_completion_interruptible_timeout(struct completion *x,
88958 unsigned long timeout)
88959 {
88960 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88961 *
88962 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88963 */
88964 -int __sched wait_for_completion_killable(struct completion *x)
88965 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88966 {
88967 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88968 if (t == -ERESTARTSYS)
88969 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88970 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88971 * or number of jiffies left till timeout) if completed.
88972 */
88973 -long __sched
88974 +long __sched __intentional_overflow(-1)
88975 wait_for_completion_killable_timeout(struct completion *x,
88976 unsigned long timeout)
88977 {
88978 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88979 index f5c6635..ab9f223 100644
88980 --- a/kernel/sched/core.c
88981 +++ b/kernel/sched/core.c
88982 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
88983 int sysctl_numa_balancing(struct ctl_table *table, int write,
88984 void __user *buffer, size_t *lenp, loff_t *ppos)
88985 {
88986 - struct ctl_table t;
88987 + ctl_table_no_const t;
88988 int err;
88989 int state = numabalancing_enabled;
88990
88991 @@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
88992 /* convert nice value [19,-20] to rlimit style value [1,40] */
88993 int nice_rlim = 20 - nice;
88994
88995 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88996 +
88997 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88998 capable(CAP_SYS_NICE));
88999 }
89000 @@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89001 if (nice > 19)
89002 nice = 19;
89003
89004 - if (increment < 0 && !can_nice(current, nice))
89005 + if (increment < 0 && (!can_nice(current, nice) ||
89006 + gr_handle_chroot_nice()))
89007 return -EPERM;
89008
89009 retval = security_task_setnice(current, nice);
89010 @@ -3332,6 +3335,7 @@ recheck:
89011 if (policy != p->policy && !rlim_rtprio)
89012 return -EPERM;
89013
89014 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89015 /* can't increase priority */
89016 if (attr->sched_priority > p->rt_priority &&
89017 attr->sched_priority > rlim_rtprio)
89018 @@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89019
89020 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89021
89022 -static struct ctl_table sd_ctl_dir[] = {
89023 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
89024 {
89025 .procname = "sched_domain",
89026 .mode = 0555,
89027 @@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89028 {}
89029 };
89030
89031 -static struct ctl_table *sd_alloc_ctl_entry(int n)
89032 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89033 {
89034 - struct ctl_table *entry =
89035 + ctl_table_no_const *entry =
89036 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89037
89038 return entry;
89039 }
89040
89041 -static void sd_free_ctl_entry(struct ctl_table **tablep)
89042 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89043 {
89044 - struct ctl_table *entry;
89045 + ctl_table_no_const *entry;
89046
89047 /*
89048 * In the intermediate directories, both the child directory and
89049 @@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89050 * will always be set. In the lowest directory the names are
89051 * static strings and all have proc handlers.
89052 */
89053 - for (entry = *tablep; entry->mode; entry++) {
89054 - if (entry->child)
89055 - sd_free_ctl_entry(&entry->child);
89056 + for (entry = tablep; entry->mode; entry++) {
89057 + if (entry->child) {
89058 + sd_free_ctl_entry(entry->child);
89059 + pax_open_kernel();
89060 + entry->child = NULL;
89061 + pax_close_kernel();
89062 + }
89063 if (entry->proc_handler == NULL)
89064 kfree(entry->procname);
89065 }
89066
89067 - kfree(*tablep);
89068 - *tablep = NULL;
89069 + kfree(tablep);
89070 }
89071
89072 static int min_load_idx = 0;
89073 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89074
89075 static void
89076 -set_table_entry(struct ctl_table *entry,
89077 +set_table_entry(ctl_table_no_const *entry,
89078 const char *procname, void *data, int maxlen,
89079 umode_t mode, proc_handler *proc_handler,
89080 bool load_idx)
89081 @@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89082 static struct ctl_table *
89083 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89084 {
89085 - struct ctl_table *table = sd_alloc_ctl_entry(13);
89086 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89087
89088 if (table == NULL)
89089 return NULL;
89090 @@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89091 return table;
89092 }
89093
89094 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89095 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89096 {
89097 - struct ctl_table *entry, *table;
89098 + ctl_table_no_const *entry, *table;
89099 struct sched_domain *sd;
89100 int domain_num = 0, i;
89101 char buf[32];
89102 @@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89103 static void register_sched_domain_sysctl(void)
89104 {
89105 int i, cpu_num = num_possible_cpus();
89106 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89107 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89108 char buf[32];
89109
89110 WARN_ON(sd_ctl_dir[0].child);
89111 + pax_open_kernel();
89112 sd_ctl_dir[0].child = entry;
89113 + pax_close_kernel();
89114
89115 if (entry == NULL)
89116 return;
89117 @@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89118 if (sd_sysctl_header)
89119 unregister_sysctl_table(sd_sysctl_header);
89120 sd_sysctl_header = NULL;
89121 - if (sd_ctl_dir[0].child)
89122 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
89123 + if (sd_ctl_dir[0].child) {
89124 + sd_free_ctl_entry(sd_ctl_dir[0].child);
89125 + pax_open_kernel();
89126 + sd_ctl_dir[0].child = NULL;
89127 + pax_close_kernel();
89128 + }
89129 }
89130 #else
89131 static void register_sched_domain_sysctl(void)
89132 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89133 index 9b4c4f3..665489b 100644
89134 --- a/kernel/sched/fair.c
89135 +++ b/kernel/sched/fair.c
89136 @@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89137
89138 static void reset_ptenuma_scan(struct task_struct *p)
89139 {
89140 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
89141 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89142 p->mm->numa_scan_offset = 0;
89143 }
89144
89145 @@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89146 * run_rebalance_domains is triggered when needed from the scheduler tick.
89147 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89148 */
89149 -static void run_rebalance_domains(struct softirq_action *h)
89150 +static __latent_entropy void run_rebalance_domains(void)
89151 {
89152 struct rq *this_rq = this_rq();
89153 enum cpu_idle_type idle = this_rq->idle_balance ?
89154 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89155 index f964add..dcd823d 100644
89156 --- a/kernel/sched/sched.h
89157 +++ b/kernel/sched/sched.h
89158 @@ -1157,7 +1157,7 @@ struct sched_class {
89159 #ifdef CONFIG_FAIR_GROUP_SCHED
89160 void (*task_move_group) (struct task_struct *p, int on_rq);
89161 #endif
89162 -};
89163 +} __do_const;
89164
89165 #define sched_class_highest (&stop_sched_class)
89166 #define for_each_class(class) \
89167 diff --git a/kernel/signal.c b/kernel/signal.c
89168 index 52f881d..1e9f941 100644
89169 --- a/kernel/signal.c
89170 +++ b/kernel/signal.c
89171 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89172
89173 int print_fatal_signals __read_mostly;
89174
89175 -static void __user *sig_handler(struct task_struct *t, int sig)
89176 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
89177 {
89178 return t->sighand->action[sig - 1].sa.sa_handler;
89179 }
89180
89181 -static int sig_handler_ignored(void __user *handler, int sig)
89182 +static int sig_handler_ignored(__sighandler_t handler, int sig)
89183 {
89184 /* Is it explicitly or implicitly ignored? */
89185 return handler == SIG_IGN ||
89186 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89187
89188 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89189 {
89190 - void __user *handler;
89191 + __sighandler_t handler;
89192
89193 handler = sig_handler(t, sig);
89194
89195 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89196 atomic_inc(&user->sigpending);
89197 rcu_read_unlock();
89198
89199 + if (!override_rlimit)
89200 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89201 +
89202 if (override_rlimit ||
89203 atomic_read(&user->sigpending) <=
89204 task_rlimit(t, RLIMIT_SIGPENDING)) {
89205 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89206
89207 int unhandled_signal(struct task_struct *tsk, int sig)
89208 {
89209 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89210 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89211 if (is_global_init(tsk))
89212 return 1;
89213 if (handler != SIG_IGN && handler != SIG_DFL)
89214 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89215 }
89216 }
89217
89218 + /* allow glibc communication via tgkill to other threads in our
89219 + thread group */
89220 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89221 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89222 + && gr_handle_signal(t, sig))
89223 + return -EPERM;
89224 +
89225 return security_task_kill(t, info, sig, 0);
89226 }
89227
89228 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89229 return send_signal(sig, info, p, 1);
89230 }
89231
89232 -static int
89233 +int
89234 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89235 {
89236 return send_signal(sig, info, t, 0);
89237 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89238 unsigned long int flags;
89239 int ret, blocked, ignored;
89240 struct k_sigaction *action;
89241 + int is_unhandled = 0;
89242
89243 spin_lock_irqsave(&t->sighand->siglock, flags);
89244 action = &t->sighand->action[sig-1];
89245 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89246 }
89247 if (action->sa.sa_handler == SIG_DFL)
89248 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89249 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89250 + is_unhandled = 1;
89251 ret = specific_send_sig_info(sig, info, t);
89252 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89253
89254 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
89255 + normal operation */
89256 + if (is_unhandled) {
89257 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89258 + gr_handle_crash(t, sig);
89259 + }
89260 +
89261 return ret;
89262 }
89263
89264 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89265 ret = check_kill_permission(sig, info, p);
89266 rcu_read_unlock();
89267
89268 - if (!ret && sig)
89269 + if (!ret && sig) {
89270 ret = do_send_sig_info(sig, info, p, true);
89271 + if (!ret)
89272 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89273 + }
89274
89275 return ret;
89276 }
89277 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89278 int error = -ESRCH;
89279
89280 rcu_read_lock();
89281 - p = find_task_by_vpid(pid);
89282 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89283 + /* allow glibc communication via tgkill to other threads in our
89284 + thread group */
89285 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89286 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
89287 + p = find_task_by_vpid_unrestricted(pid);
89288 + else
89289 +#endif
89290 + p = find_task_by_vpid(pid);
89291 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89292 error = check_kill_permission(sig, info, p);
89293 /*
89294 @@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89295 }
89296 seg = get_fs();
89297 set_fs(KERNEL_DS);
89298 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89299 - (stack_t __force __user *) &uoss,
89300 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89301 + (stack_t __force_user *) &uoss,
89302 compat_user_stack_pointer());
89303 set_fs(seg);
89304 if (ret >= 0 && uoss_ptr) {
89305 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89306 index eb89e18..a4e6792 100644
89307 --- a/kernel/smpboot.c
89308 +++ b/kernel/smpboot.c
89309 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89310 }
89311 smpboot_unpark_thread(plug_thread, cpu);
89312 }
89313 - list_add(&plug_thread->list, &hotplug_threads);
89314 + pax_list_add(&plug_thread->list, &hotplug_threads);
89315 out:
89316 mutex_unlock(&smpboot_threads_lock);
89317 return ret;
89318 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89319 {
89320 get_online_cpus();
89321 mutex_lock(&smpboot_threads_lock);
89322 - list_del(&plug_thread->list);
89323 + pax_list_del(&plug_thread->list);
89324 smpboot_destroy_threads(plug_thread);
89325 mutex_unlock(&smpboot_threads_lock);
89326 put_online_cpus();
89327 diff --git a/kernel/softirq.c b/kernel/softirq.c
89328 index 490fcbb..1e502c6 100644
89329 --- a/kernel/softirq.c
89330 +++ b/kernel/softirq.c
89331 @@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89332 EXPORT_SYMBOL(irq_stat);
89333 #endif
89334
89335 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89336 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89337
89338 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89339
89340 @@ -267,7 +267,7 @@ restart:
89341 kstat_incr_softirqs_this_cpu(vec_nr);
89342
89343 trace_softirq_entry(vec_nr);
89344 - h->action(h);
89345 + h->action();
89346 trace_softirq_exit(vec_nr);
89347 if (unlikely(prev_count != preempt_count())) {
89348 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
89349 @@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89350 or_softirq_pending(1UL << nr);
89351 }
89352
89353 -void open_softirq(int nr, void (*action)(struct softirq_action *))
89354 +void __init open_softirq(int nr, void (*action)(void))
89355 {
89356 softirq_vec[nr].action = action;
89357 }
89358 @@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89359 }
89360 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89361
89362 -static void tasklet_action(struct softirq_action *a)
89363 +static void tasklet_action(void)
89364 {
89365 struct tasklet_struct *list;
89366
89367 @@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
89368 }
89369 }
89370
89371 -static void tasklet_hi_action(struct softirq_action *a)
89372 +static __latent_entropy void tasklet_hi_action(void)
89373 {
89374 struct tasklet_struct *list;
89375
89376 @@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
89377 .notifier_call = cpu_callback
89378 };
89379
89380 -static struct smp_hotplug_thread softirq_threads = {
89381 +static struct smp_hotplug_thread softirq_threads __read_only = {
89382 .store = &ksoftirqd,
89383 .thread_should_run = ksoftirqd_should_run,
89384 .thread_fn = run_ksoftirqd,
89385 diff --git a/kernel/sys.c b/kernel/sys.c
89386 index c0a58be..784c618 100644
89387 --- a/kernel/sys.c
89388 +++ b/kernel/sys.c
89389 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89390 error = -EACCES;
89391 goto out;
89392 }
89393 +
89394 + if (gr_handle_chroot_setpriority(p, niceval)) {
89395 + error = -EACCES;
89396 + goto out;
89397 + }
89398 +
89399 no_nice = security_task_setnice(p, niceval);
89400 if (no_nice) {
89401 error = no_nice;
89402 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89403 goto error;
89404 }
89405
89406 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89407 + goto error;
89408 +
89409 if (rgid != (gid_t) -1 ||
89410 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89411 new->sgid = new->egid;
89412 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89413 old = current_cred();
89414
89415 retval = -EPERM;
89416 +
89417 + if (gr_check_group_change(kgid, kgid, kgid))
89418 + goto error;
89419 +
89420 if (ns_capable(old->user_ns, CAP_SETGID))
89421 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89422 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89423 @@ -403,7 +416,7 @@ error:
89424 /*
89425 * change the user struct in a credentials set to match the new UID
89426 */
89427 -static int set_user(struct cred *new)
89428 +int set_user(struct cred *new)
89429 {
89430 struct user_struct *new_user;
89431
89432 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89433 goto error;
89434 }
89435
89436 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89437 + goto error;
89438 +
89439 if (!uid_eq(new->uid, old->uid)) {
89440 retval = set_user(new);
89441 if (retval < 0)
89442 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89443 old = current_cred();
89444
89445 retval = -EPERM;
89446 +
89447 + if (gr_check_crash_uid(kuid))
89448 + goto error;
89449 + if (gr_check_user_change(kuid, kuid, kuid))
89450 + goto error;
89451 +
89452 if (ns_capable(old->user_ns, CAP_SETUID)) {
89453 new->suid = new->uid = kuid;
89454 if (!uid_eq(kuid, old->uid)) {
89455 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89456 goto error;
89457 }
89458
89459 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
89460 + goto error;
89461 +
89462 if (ruid != (uid_t) -1) {
89463 new->uid = kruid;
89464 if (!uid_eq(kruid, old->uid)) {
89465 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89466 goto error;
89467 }
89468
89469 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
89470 + goto error;
89471 +
89472 if (rgid != (gid_t) -1)
89473 new->gid = krgid;
89474 if (egid != (gid_t) -1)
89475 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89476 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89477 ns_capable(old->user_ns, CAP_SETUID)) {
89478 if (!uid_eq(kuid, old->fsuid)) {
89479 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89480 + goto error;
89481 +
89482 new->fsuid = kuid;
89483 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89484 goto change_okay;
89485 }
89486 }
89487
89488 +error:
89489 abort_creds(new);
89490 return old_fsuid;
89491
89492 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89493 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89494 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89495 ns_capable(old->user_ns, CAP_SETGID)) {
89496 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89497 + goto error;
89498 +
89499 if (!gid_eq(kgid, old->fsgid)) {
89500 new->fsgid = kgid;
89501 goto change_okay;
89502 }
89503 }
89504
89505 +error:
89506 abort_creds(new);
89507 return old_fsgid;
89508
89509 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89510 return -EFAULT;
89511
89512 down_read(&uts_sem);
89513 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
89514 + error = __copy_to_user(name->sysname, &utsname()->sysname,
89515 __OLD_UTS_LEN);
89516 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89517 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89518 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
89519 __OLD_UTS_LEN);
89520 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89521 - error |= __copy_to_user(&name->release, &utsname()->release,
89522 + error |= __copy_to_user(name->release, &utsname()->release,
89523 __OLD_UTS_LEN);
89524 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89525 - error |= __copy_to_user(&name->version, &utsname()->version,
89526 + error |= __copy_to_user(name->version, &utsname()->version,
89527 __OLD_UTS_LEN);
89528 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89529 - error |= __copy_to_user(&name->machine, &utsname()->machine,
89530 + error |= __copy_to_user(name->machine, &utsname()->machine,
89531 __OLD_UTS_LEN);
89532 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89533 up_read(&uts_sem);
89534 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89535 */
89536 new_rlim->rlim_cur = 1;
89537 }
89538 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89539 + is changed to a lower value. Since tasks can be created by the same
89540 + user in between this limit change and an execve by this task, force
89541 + a recheck only for this task by setting PF_NPROC_EXCEEDED
89542 + */
89543 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89544 + tsk->flags |= PF_NPROC_EXCEEDED;
89545 }
89546 if (!retval) {
89547 if (old_rlim)
89548 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89549 index 49e13e1..8dbc052 100644
89550 --- a/kernel/sysctl.c
89551 +++ b/kernel/sysctl.c
89552 @@ -94,7 +94,6 @@
89553
89554
89555 #if defined(CONFIG_SYSCTL)
89556 -
89557 /* External variables not in a header file. */
89558 extern int max_threads;
89559 extern int suid_dumpable;
89560 @@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
89561
89562 /* Constants used for minimum and maximum */
89563 #ifdef CONFIG_LOCKUP_DETECTOR
89564 -static int sixty = 60;
89565 +static int sixty __read_only = 60;
89566 #endif
89567
89568 -static int __maybe_unused neg_one = -1;
89569 -
89570 -static int zero;
89571 -static int __maybe_unused one = 1;
89572 -static int __maybe_unused two = 2;
89573 -static int __maybe_unused three = 3;
89574 -static unsigned long one_ul = 1;
89575 -static int one_hundred = 100;
89576 +static int __maybe_unused neg_one __read_only = -1;
89577 +static int zero __read_only = 0;
89578 +static int __maybe_unused one __read_only = 1;
89579 +static int __maybe_unused two __read_only = 2;
89580 +static int __maybe_unused three __read_only = 3;
89581 +static unsigned long one_ul __read_only = 1;
89582 +static int one_hundred __read_only = 100;
89583 #ifdef CONFIG_PRINTK
89584 -static int ten_thousand = 10000;
89585 +static int ten_thousand __read_only = 10000;
89586 #endif
89587
89588 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89589 @@ -177,10 +175,8 @@ static int proc_taint(struct ctl_table *table, int write,
89590 void __user *buffer, size_t *lenp, loff_t *ppos);
89591 #endif
89592
89593 -#ifdef CONFIG_PRINTK
89594 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89595 void __user *buffer, size_t *lenp, loff_t *ppos);
89596 -#endif
89597
89598 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89599 void __user *buffer, size_t *lenp, loff_t *ppos);
89600 @@ -211,6 +207,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89601
89602 #endif
89603
89604 +extern struct ctl_table grsecurity_table[];
89605 +
89606 static struct ctl_table kern_table[];
89607 static struct ctl_table vm_table[];
89608 static struct ctl_table fs_table[];
89609 @@ -225,6 +223,20 @@ extern struct ctl_table epoll_table[];
89610 int sysctl_legacy_va_layout;
89611 #endif
89612
89613 +#ifdef CONFIG_PAX_SOFTMODE
89614 +static ctl_table pax_table[] = {
89615 + {
89616 + .procname = "softmode",
89617 + .data = &pax_softmode,
89618 + .maxlen = sizeof(unsigned int),
89619 + .mode = 0600,
89620 + .proc_handler = &proc_dointvec,
89621 + },
89622 +
89623 + { }
89624 +};
89625 +#endif
89626 +
89627 /* The default sysctl tables: */
89628
89629 static struct ctl_table sysctl_base_table[] = {
89630 @@ -273,6 +285,22 @@ static int max_extfrag_threshold = 1000;
89631 #endif
89632
89633 static struct ctl_table kern_table[] = {
89634 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89635 + {
89636 + .procname = "grsecurity",
89637 + .mode = 0500,
89638 + .child = grsecurity_table,
89639 + },
89640 +#endif
89641 +
89642 +#ifdef CONFIG_PAX_SOFTMODE
89643 + {
89644 + .procname = "pax",
89645 + .mode = 0500,
89646 + .child = pax_table,
89647 + },
89648 +#endif
89649 +
89650 {
89651 .procname = "sched_child_runs_first",
89652 .data = &sysctl_sched_child_runs_first,
89653 @@ -635,7 +663,7 @@ static struct ctl_table kern_table[] = {
89654 .data = &modprobe_path,
89655 .maxlen = KMOD_PATH_LEN,
89656 .mode = 0644,
89657 - .proc_handler = proc_dostring,
89658 + .proc_handler = proc_dostring_modpriv,
89659 },
89660 {
89661 .procname = "modules_disabled",
89662 @@ -802,16 +830,20 @@ static struct ctl_table kern_table[] = {
89663 .extra1 = &zero,
89664 .extra2 = &one,
89665 },
89666 +#endif
89667 {
89668 .procname = "kptr_restrict",
89669 .data = &kptr_restrict,
89670 .maxlen = sizeof(int),
89671 .mode = 0644,
89672 .proc_handler = proc_dointvec_minmax_sysadmin,
89673 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89674 + .extra1 = &two,
89675 +#else
89676 .extra1 = &zero,
89677 +#endif
89678 .extra2 = &two,
89679 },
89680 -#endif
89681 {
89682 .procname = "ngroups_max",
89683 .data = &ngroups_max,
89684 @@ -1055,10 +1087,17 @@ static struct ctl_table kern_table[] = {
89685 */
89686 {
89687 .procname = "perf_event_paranoid",
89688 - .data = &sysctl_perf_event_paranoid,
89689 - .maxlen = sizeof(sysctl_perf_event_paranoid),
89690 + .data = &sysctl_perf_event_legitimately_concerned,
89691 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89692 .mode = 0644,
89693 - .proc_handler = proc_dointvec,
89694 + /* go ahead, be a hero */
89695 + .proc_handler = proc_dointvec_minmax_sysadmin,
89696 + .extra1 = &neg_one,
89697 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89698 + .extra2 = &three,
89699 +#else
89700 + .extra2 = &two,
89701 +#endif
89702 },
89703 {
89704 .procname = "perf_event_mlock_kb",
89705 @@ -1329,6 +1368,13 @@ static struct ctl_table vm_table[] = {
89706 .proc_handler = proc_dointvec_minmax,
89707 .extra1 = &zero,
89708 },
89709 + {
89710 + .procname = "heap_stack_gap",
89711 + .data = &sysctl_heap_stack_gap,
89712 + .maxlen = sizeof(sysctl_heap_stack_gap),
89713 + .mode = 0644,
89714 + .proc_handler = proc_doulongvec_minmax,
89715 + },
89716 #else
89717 {
89718 .procname = "nr_trim_pages",
89719 @@ -1793,6 +1839,16 @@ int proc_dostring(struct ctl_table *table, int write,
89720 buffer, lenp, ppos);
89721 }
89722
89723 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89724 + void __user *buffer, size_t *lenp, loff_t *ppos)
89725 +{
89726 + if (write && !capable(CAP_SYS_MODULE))
89727 + return -EPERM;
89728 +
89729 + return _proc_do_string(table->data, table->maxlen, write,
89730 + buffer, lenp, ppos);
89731 +}
89732 +
89733 static size_t proc_skip_spaces(char **buf)
89734 {
89735 size_t ret;
89736 @@ -1898,6 +1954,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89737 len = strlen(tmp);
89738 if (len > *size)
89739 len = *size;
89740 + if (len > sizeof(tmp))
89741 + len = sizeof(tmp);
89742 if (copy_to_user(*buf, tmp, len))
89743 return -EFAULT;
89744 *size -= len;
89745 @@ -2062,7 +2120,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89746 static int proc_taint(struct ctl_table *table, int write,
89747 void __user *buffer, size_t *lenp, loff_t *ppos)
89748 {
89749 - struct ctl_table t;
89750 + ctl_table_no_const t;
89751 unsigned long tmptaint = get_taint();
89752 int err;
89753
89754 @@ -2090,7 +2148,6 @@ static int proc_taint(struct ctl_table *table, int write,
89755 return err;
89756 }
89757
89758 -#ifdef CONFIG_PRINTK
89759 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89760 void __user *buffer, size_t *lenp, loff_t *ppos)
89761 {
89762 @@ -2099,7 +2156,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89763
89764 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89765 }
89766 -#endif
89767
89768 struct do_proc_dointvec_minmax_conv_param {
89769 int *min;
89770 @@ -2646,6 +2702,12 @@ int proc_dostring(struct ctl_table *table, int write,
89771 return -ENOSYS;
89772 }
89773
89774 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89775 + void __user *buffer, size_t *lenp, loff_t *ppos)
89776 +{
89777 + return -ENOSYS;
89778 +}
89779 +
89780 int proc_dointvec(struct ctl_table *table, int write,
89781 void __user *buffer, size_t *lenp, loff_t *ppos)
89782 {
89783 @@ -2702,5 +2764,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89784 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89785 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89786 EXPORT_SYMBOL(proc_dostring);
89787 +EXPORT_SYMBOL(proc_dostring_modpriv);
89788 EXPORT_SYMBOL(proc_doulongvec_minmax);
89789 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89790 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89791 index 13d2f7c..c93d0b0 100644
89792 --- a/kernel/taskstats.c
89793 +++ b/kernel/taskstats.c
89794 @@ -28,9 +28,12 @@
89795 #include <linux/fs.h>
89796 #include <linux/file.h>
89797 #include <linux/pid_namespace.h>
89798 +#include <linux/grsecurity.h>
89799 #include <net/genetlink.h>
89800 #include <linux/atomic.h>
89801
89802 +extern int gr_is_taskstats_denied(int pid);
89803 +
89804 /*
89805 * Maximum length of a cpumask that can be specified in
89806 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89807 @@ -576,6 +579,9 @@ err:
89808
89809 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89810 {
89811 + if (gr_is_taskstats_denied(current->pid))
89812 + return -EACCES;
89813 +
89814 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89815 return cmd_attr_register_cpumask(info);
89816 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89817 diff --git a/kernel/time.c b/kernel/time.c
89818 index 7c7964c..2a0d412 100644
89819 --- a/kernel/time.c
89820 +++ b/kernel/time.c
89821 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89822 return error;
89823
89824 if (tz) {
89825 + /* we log in do_settimeofday called below, so don't log twice
89826 + */
89827 + if (!tv)
89828 + gr_log_timechange();
89829 +
89830 sys_tz = *tz;
89831 update_vsyscall_tz();
89832 if (firsttime) {
89833 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89834 index 88c9c65..7497ebc 100644
89835 --- a/kernel/time/alarmtimer.c
89836 +++ b/kernel/time/alarmtimer.c
89837 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89838 struct platform_device *pdev;
89839 int error = 0;
89840 int i;
89841 - struct k_clock alarm_clock = {
89842 + static struct k_clock alarm_clock = {
89843 .clock_getres = alarm_clock_getres,
89844 .clock_get = alarm_clock_get,
89845 .timer_create = alarm_timer_create,
89846 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89847 index 5b40279..81e58db 100644
89848 --- a/kernel/time/timekeeping.c
89849 +++ b/kernel/time/timekeeping.c
89850 @@ -15,6 +15,7 @@
89851 #include <linux/init.h>
89852 #include <linux/mm.h>
89853 #include <linux/sched.h>
89854 +#include <linux/grsecurity.h>
89855 #include <linux/syscore_ops.h>
89856 #include <linux/clocksource.h>
89857 #include <linux/jiffies.h>
89858 @@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
89859 if (!timespec_valid_strict(tv))
89860 return -EINVAL;
89861
89862 + gr_log_timechange();
89863 +
89864 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89865 write_seqcount_begin(&timekeeper_seq);
89866
89867 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89868 index 61ed862..3b52c65 100644
89869 --- a/kernel/time/timer_list.c
89870 +++ b/kernel/time/timer_list.c
89871 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89872
89873 static void print_name_offset(struct seq_file *m, void *sym)
89874 {
89875 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89876 + SEQ_printf(m, "<%p>", NULL);
89877 +#else
89878 char symname[KSYM_NAME_LEN];
89879
89880 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89881 SEQ_printf(m, "<%pK>", sym);
89882 else
89883 SEQ_printf(m, "%s", symname);
89884 +#endif
89885 }
89886
89887 static void
89888 @@ -119,7 +123,11 @@ next_one:
89889 static void
89890 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89891 {
89892 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89893 + SEQ_printf(m, " .base: %p\n", NULL);
89894 +#else
89895 SEQ_printf(m, " .base: %pK\n", base);
89896 +#endif
89897 SEQ_printf(m, " .index: %d\n",
89898 base->index);
89899 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89900 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89901 {
89902 struct proc_dir_entry *pe;
89903
89904 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89905 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89906 +#else
89907 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89908 +#endif
89909 if (!pe)
89910 return -ENOMEM;
89911 return 0;
89912 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89913 index 1fb08f2..ca4bb1e 100644
89914 --- a/kernel/time/timer_stats.c
89915 +++ b/kernel/time/timer_stats.c
89916 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89917 static unsigned long nr_entries;
89918 static struct entry entries[MAX_ENTRIES];
89919
89920 -static atomic_t overflow_count;
89921 +static atomic_unchecked_t overflow_count;
89922
89923 /*
89924 * The entries are in a hash-table, for fast lookup:
89925 @@ -140,7 +140,7 @@ static void reset_entries(void)
89926 nr_entries = 0;
89927 memset(entries, 0, sizeof(entries));
89928 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89929 - atomic_set(&overflow_count, 0);
89930 + atomic_set_unchecked(&overflow_count, 0);
89931 }
89932
89933 static struct entry *alloc_entry(void)
89934 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89935 if (likely(entry))
89936 entry->count++;
89937 else
89938 - atomic_inc(&overflow_count);
89939 + atomic_inc_unchecked(&overflow_count);
89940
89941 out_unlock:
89942 raw_spin_unlock_irqrestore(lock, flags);
89943 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89944
89945 static void print_name_offset(struct seq_file *m, unsigned long addr)
89946 {
89947 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89948 + seq_printf(m, "<%p>", NULL);
89949 +#else
89950 char symname[KSYM_NAME_LEN];
89951
89952 if (lookup_symbol_name(addr, symname) < 0)
89953 - seq_printf(m, "<%p>", (void *)addr);
89954 + seq_printf(m, "<%pK>", (void *)addr);
89955 else
89956 seq_printf(m, "%s", symname);
89957 +#endif
89958 }
89959
89960 static int tstats_show(struct seq_file *m, void *v)
89961 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89962
89963 seq_puts(m, "Timer Stats Version: v0.3\n");
89964 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89965 - if (atomic_read(&overflow_count))
89966 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89967 + if (atomic_read_unchecked(&overflow_count))
89968 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89969 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89970
89971 for (i = 0; i < nr_entries; i++) {
89972 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89973 {
89974 struct proc_dir_entry *pe;
89975
89976 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89977 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89978 +#else
89979 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89980 +#endif
89981 if (!pe)
89982 return -ENOMEM;
89983 return 0;
89984 diff --git a/kernel/timer.c b/kernel/timer.c
89985 index accfd24..e00f0c0 100644
89986 --- a/kernel/timer.c
89987 +++ b/kernel/timer.c
89988 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89989 /*
89990 * This function runs timers and the timer-tq in bottom half context.
89991 */
89992 -static void run_timer_softirq(struct softirq_action *h)
89993 +static __latent_entropy void run_timer_softirq(void)
89994 {
89995 struct tvec_base *base = __this_cpu_read(tvec_bases);
89996
89997 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89998 *
89999 * In all cases the return value is guaranteed to be non-negative.
90000 */
90001 -signed long __sched schedule_timeout(signed long timeout)
90002 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90003 {
90004 struct timer_list timer;
90005 unsigned long expire;
90006 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90007 index b418cb0..f879a3d 100644
90008 --- a/kernel/trace/blktrace.c
90009 +++ b/kernel/trace/blktrace.c
90010 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90011 struct blk_trace *bt = filp->private_data;
90012 char buf[16];
90013
90014 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90015 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90016
90017 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90018 }
90019 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90020 return 1;
90021
90022 bt = buf->chan->private_data;
90023 - atomic_inc(&bt->dropped);
90024 + atomic_inc_unchecked(&bt->dropped);
90025 return 0;
90026 }
90027
90028 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90029
90030 bt->dir = dir;
90031 bt->dev = dev;
90032 - atomic_set(&bt->dropped, 0);
90033 + atomic_set_unchecked(&bt->dropped, 0);
90034 INIT_LIST_HEAD(&bt->running_list);
90035
90036 ret = -EIO;
90037 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90038 index cd7f76d..553c805 100644
90039 --- a/kernel/trace/ftrace.c
90040 +++ b/kernel/trace/ftrace.c
90041 @@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90042 if (unlikely(ftrace_disabled))
90043 return 0;
90044
90045 + ret = ftrace_arch_code_modify_prepare();
90046 + FTRACE_WARN_ON(ret);
90047 + if (ret)
90048 + return 0;
90049 +
90050 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90051 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90052 if (ret) {
90053 ftrace_bug(ret, ip);
90054 - return 0;
90055 }
90056 - return 1;
90057 + return ret ? 0 : 1;
90058 }
90059
90060 /*
90061 @@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90062 if (!count)
90063 return 0;
90064
90065 + pax_open_kernel();
90066 sort(start, count, sizeof(*start),
90067 ftrace_cmp_ips, ftrace_swap_ips);
90068 + pax_close_kernel();
90069
90070 start_pg = ftrace_allocate_pages(count);
90071 if (!start_pg)
90072 @@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90073 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90074
90075 static int ftrace_graph_active;
90076 -static struct notifier_block ftrace_suspend_notifier;
90077 -
90078 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90079 {
90080 return 0;
90081 @@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90082 ftrace_graph_entry = ftrace_graph_entry_test;
90083 }
90084
90085 +static struct notifier_block ftrace_suspend_notifier = {
90086 + .notifier_call = ftrace_suspend_notifier_call
90087 +};
90088 +
90089 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90090 trace_func_graph_ent_t entryfunc)
90091 {
90092 @@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90093 goto out;
90094 }
90095
90096 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90097 register_pm_notifier(&ftrace_suspend_notifier);
90098
90099 ftrace_graph_active++;
90100 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90101 index fc4da2d..f3e800b 100644
90102 --- a/kernel/trace/ring_buffer.c
90103 +++ b/kernel/trace/ring_buffer.c
90104 @@ -352,9 +352,9 @@ struct buffer_data_page {
90105 */
90106 struct buffer_page {
90107 struct list_head list; /* list of buffer pages */
90108 - local_t write; /* index for next write */
90109 + local_unchecked_t write; /* index for next write */
90110 unsigned read; /* index for next read */
90111 - local_t entries; /* entries on this page */
90112 + local_unchecked_t entries; /* entries on this page */
90113 unsigned long real_end; /* real end of data */
90114 struct buffer_data_page *page; /* Actual data page */
90115 };
90116 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90117 unsigned long last_overrun;
90118 local_t entries_bytes;
90119 local_t entries;
90120 - local_t overrun;
90121 - local_t commit_overrun;
90122 + local_unchecked_t overrun;
90123 + local_unchecked_t commit_overrun;
90124 local_t dropped_events;
90125 local_t committing;
90126 local_t commits;
90127 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90128 *
90129 * We add a counter to the write field to denote this.
90130 */
90131 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90132 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90133 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90134 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90135
90136 /*
90137 * Just make sure we have seen our old_write and synchronize
90138 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90139 * cmpxchg to only update if an interrupt did not already
90140 * do it for us. If the cmpxchg fails, we don't care.
90141 */
90142 - (void)local_cmpxchg(&next_page->write, old_write, val);
90143 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90144 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90145 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90146
90147 /*
90148 * No need to worry about races with clearing out the commit.
90149 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90150
90151 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90152 {
90153 - return local_read(&bpage->entries) & RB_WRITE_MASK;
90154 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90155 }
90156
90157 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90158 {
90159 - return local_read(&bpage->write) & RB_WRITE_MASK;
90160 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90161 }
90162
90163 static int
90164 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90165 * bytes consumed in ring buffer from here.
90166 * Increment overrun to account for the lost events.
90167 */
90168 - local_add(page_entries, &cpu_buffer->overrun);
90169 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
90170 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90171 }
90172
90173 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90174 * it is our responsibility to update
90175 * the counters.
90176 */
90177 - local_add(entries, &cpu_buffer->overrun);
90178 + local_add_unchecked(entries, &cpu_buffer->overrun);
90179 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90180
90181 /*
90182 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90183 if (tail == BUF_PAGE_SIZE)
90184 tail_page->real_end = 0;
90185
90186 - local_sub(length, &tail_page->write);
90187 + local_sub_unchecked(length, &tail_page->write);
90188 return;
90189 }
90190
90191 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90192 rb_event_set_padding(event);
90193
90194 /* Set the write back to the previous setting */
90195 - local_sub(length, &tail_page->write);
90196 + local_sub_unchecked(length, &tail_page->write);
90197 return;
90198 }
90199
90200 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90201
90202 /* Set write to end of buffer */
90203 length = (tail + length) - BUF_PAGE_SIZE;
90204 - local_sub(length, &tail_page->write);
90205 + local_sub_unchecked(length, &tail_page->write);
90206 }
90207
90208 /*
90209 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90210 * about it.
90211 */
90212 if (unlikely(next_page == commit_page)) {
90213 - local_inc(&cpu_buffer->commit_overrun);
90214 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90215 goto out_reset;
90216 }
90217
90218 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90219 cpu_buffer->tail_page) &&
90220 (cpu_buffer->commit_page ==
90221 cpu_buffer->reader_page))) {
90222 - local_inc(&cpu_buffer->commit_overrun);
90223 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90224 goto out_reset;
90225 }
90226 }
90227 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90228 length += RB_LEN_TIME_EXTEND;
90229
90230 tail_page = cpu_buffer->tail_page;
90231 - write = local_add_return(length, &tail_page->write);
90232 + write = local_add_return_unchecked(length, &tail_page->write);
90233
90234 /* set write to only the index of the write */
90235 write &= RB_WRITE_MASK;
90236 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90237 kmemcheck_annotate_bitfield(event, bitfield);
90238 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90239
90240 - local_inc(&tail_page->entries);
90241 + local_inc_unchecked(&tail_page->entries);
90242
90243 /*
90244 * If this is the first commit on the page, then update
90245 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90246
90247 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90248 unsigned long write_mask =
90249 - local_read(&bpage->write) & ~RB_WRITE_MASK;
90250 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90251 unsigned long event_length = rb_event_length(event);
90252 /*
90253 * This is on the tail page. It is possible that
90254 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90255 */
90256 old_index += write_mask;
90257 new_index += write_mask;
90258 - index = local_cmpxchg(&bpage->write, old_index, new_index);
90259 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90260 if (index == old_index) {
90261 /* update counters */
90262 local_sub(event_length, &cpu_buffer->entries_bytes);
90263 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90264
90265 /* Do the likely case first */
90266 if (likely(bpage->page == (void *)addr)) {
90267 - local_dec(&bpage->entries);
90268 + local_dec_unchecked(&bpage->entries);
90269 return;
90270 }
90271
90272 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90273 start = bpage;
90274 do {
90275 if (bpage->page == (void *)addr) {
90276 - local_dec(&bpage->entries);
90277 + local_dec_unchecked(&bpage->entries);
90278 return;
90279 }
90280 rb_inc_page(cpu_buffer, &bpage);
90281 @@ -3146,7 +3146,7 @@ static inline unsigned long
90282 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90283 {
90284 return local_read(&cpu_buffer->entries) -
90285 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90286 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90287 }
90288
90289 /**
90290 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90291 return 0;
90292
90293 cpu_buffer = buffer->buffers[cpu];
90294 - ret = local_read(&cpu_buffer->overrun);
90295 + ret = local_read_unchecked(&cpu_buffer->overrun);
90296
90297 return ret;
90298 }
90299 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90300 return 0;
90301
90302 cpu_buffer = buffer->buffers[cpu];
90303 - ret = local_read(&cpu_buffer->commit_overrun);
90304 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90305
90306 return ret;
90307 }
90308 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90309 /* if you care about this being correct, lock the buffer */
90310 for_each_buffer_cpu(buffer, cpu) {
90311 cpu_buffer = buffer->buffers[cpu];
90312 - overruns += local_read(&cpu_buffer->overrun);
90313 + overruns += local_read_unchecked(&cpu_buffer->overrun);
90314 }
90315
90316 return overruns;
90317 @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90318 /*
90319 * Reset the reader page to size zero.
90320 */
90321 - local_set(&cpu_buffer->reader_page->write, 0);
90322 - local_set(&cpu_buffer->reader_page->entries, 0);
90323 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90324 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90325 local_set(&cpu_buffer->reader_page->page->commit, 0);
90326 cpu_buffer->reader_page->real_end = 0;
90327
90328 @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90329 * want to compare with the last_overrun.
90330 */
90331 smp_mb();
90332 - overwrite = local_read(&(cpu_buffer->overrun));
90333 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90334
90335 /*
90336 * Here's the tricky part.
90337 @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90338
90339 cpu_buffer->head_page
90340 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90341 - local_set(&cpu_buffer->head_page->write, 0);
90342 - local_set(&cpu_buffer->head_page->entries, 0);
90343 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
90344 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90345 local_set(&cpu_buffer->head_page->page->commit, 0);
90346
90347 cpu_buffer->head_page->read = 0;
90348 @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90349
90350 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90351 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90352 - local_set(&cpu_buffer->reader_page->write, 0);
90353 - local_set(&cpu_buffer->reader_page->entries, 0);
90354 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90355 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90356 local_set(&cpu_buffer->reader_page->page->commit, 0);
90357 cpu_buffer->reader_page->read = 0;
90358
90359 local_set(&cpu_buffer->entries_bytes, 0);
90360 - local_set(&cpu_buffer->overrun, 0);
90361 - local_set(&cpu_buffer->commit_overrun, 0);
90362 + local_set_unchecked(&cpu_buffer->overrun, 0);
90363 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90364 local_set(&cpu_buffer->dropped_events, 0);
90365 local_set(&cpu_buffer->entries, 0);
90366 local_set(&cpu_buffer->committing, 0);
90367 @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90368 rb_init_page(bpage);
90369 bpage = reader->page;
90370 reader->page = *data_page;
90371 - local_set(&reader->write, 0);
90372 - local_set(&reader->entries, 0);
90373 + local_set_unchecked(&reader->write, 0);
90374 + local_set_unchecked(&reader->entries, 0);
90375 reader->read = 0;
90376 *data_page = bpage;
90377
90378 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90379 index 24c1f23..781fd73f 100644
90380 --- a/kernel/trace/trace.c
90381 +++ b/kernel/trace/trace.c
90382 @@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90383 return 0;
90384 }
90385
90386 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90387 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90388 {
90389 /* do nothing if flag is already set */
90390 if (!!(trace_flags & mask) == !!enabled)
90391 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90392 index 02b592f..f971546 100644
90393 --- a/kernel/trace/trace.h
90394 +++ b/kernel/trace/trace.h
90395 @@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
90396 void trace_printk_init_buffers(void);
90397 void trace_printk_start_comm(void);
90398 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90399 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90400 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90401
90402 /*
90403 * Normal trace_printk() and friends allocates special buffers
90404 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90405 index 26dc348..8708ca7 100644
90406 --- a/kernel/trace/trace_clock.c
90407 +++ b/kernel/trace/trace_clock.c
90408 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90409 return now;
90410 }
90411
90412 -static atomic64_t trace_counter;
90413 +static atomic64_unchecked_t trace_counter;
90414
90415 /*
90416 * trace_clock_counter(): simply an atomic counter.
90417 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90418 */
90419 u64 notrace trace_clock_counter(void)
90420 {
90421 - return atomic64_add_return(1, &trace_counter);
90422 + return atomic64_inc_return_unchecked(&trace_counter);
90423 }
90424 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90425 index 7b16d40..1b2875d 100644
90426 --- a/kernel/trace/trace_events.c
90427 +++ b/kernel/trace/trace_events.c
90428 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90429 return 0;
90430 }
90431
90432 -struct ftrace_module_file_ops;
90433 static void __add_event_to_tracers(struct ftrace_event_call *call);
90434
90435 /* Add an additional event_call dynamically */
90436 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90437 index 0abd9b8..6a663a2 100644
90438 --- a/kernel/trace/trace_mmiotrace.c
90439 +++ b/kernel/trace/trace_mmiotrace.c
90440 @@ -24,7 +24,7 @@ struct header_iter {
90441 static struct trace_array *mmio_trace_array;
90442 static bool overrun_detected;
90443 static unsigned long prev_overruns;
90444 -static atomic_t dropped_count;
90445 +static atomic_unchecked_t dropped_count;
90446
90447 static void mmio_reset_data(struct trace_array *tr)
90448 {
90449 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90450
90451 static unsigned long count_overruns(struct trace_iterator *iter)
90452 {
90453 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
90454 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90455 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90456
90457 if (over > prev_overruns)
90458 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90459 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90460 sizeof(*entry), 0, pc);
90461 if (!event) {
90462 - atomic_inc(&dropped_count);
90463 + atomic_inc_unchecked(&dropped_count);
90464 return;
90465 }
90466 entry = ring_buffer_event_data(event);
90467 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90468 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90469 sizeof(*entry), 0, pc);
90470 if (!event) {
90471 - atomic_inc(&dropped_count);
90472 + atomic_inc_unchecked(&dropped_count);
90473 return;
90474 }
90475 entry = ring_buffer_event_data(event);
90476 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90477 index ed32284..884d6c3 100644
90478 --- a/kernel/trace/trace_output.c
90479 +++ b/kernel/trace/trace_output.c
90480 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90481
90482 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90483 if (!IS_ERR(p)) {
90484 - p = mangle_path(s->buffer + s->len, p, "\n");
90485 + p = mangle_path(s->buffer + s->len, p, "\n\\");
90486 if (p) {
90487 s->len = p - s->buffer;
90488 return 1;
90489 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90490 goto out;
90491 }
90492
90493 + pax_open_kernel();
90494 if (event->funcs->trace == NULL)
90495 - event->funcs->trace = trace_nop_print;
90496 + *(void **)&event->funcs->trace = trace_nop_print;
90497 if (event->funcs->raw == NULL)
90498 - event->funcs->raw = trace_nop_print;
90499 + *(void **)&event->funcs->raw = trace_nop_print;
90500 if (event->funcs->hex == NULL)
90501 - event->funcs->hex = trace_nop_print;
90502 + *(void **)&event->funcs->hex = trace_nop_print;
90503 if (event->funcs->binary == NULL)
90504 - event->funcs->binary = trace_nop_print;
90505 + *(void **)&event->funcs->binary = trace_nop_print;
90506 + pax_close_kernel();
90507
90508 key = event->type & (EVENT_HASHSIZE - 1);
90509
90510 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90511 index e6be585..d73ae5e 100644
90512 --- a/kernel/trace/trace_stack.c
90513 +++ b/kernel/trace/trace_stack.c
90514 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90515 return;
90516
90517 /* we do not handle interrupt stacks yet */
90518 - if (!object_is_on_stack(stack))
90519 + if (!object_starts_on_stack(stack))
90520 return;
90521
90522 local_irq_save(flags);
90523 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90524 index 80a57af..7f5a7ff 100644
90525 --- a/kernel/user_namespace.c
90526 +++ b/kernel/user_namespace.c
90527 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90528 !kgid_has_mapping(parent_ns, group))
90529 return -EPERM;
90530
90531 +#ifdef CONFIG_GRKERNSEC
90532 + /*
90533 + * This doesn't really inspire confidence:
90534 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90535 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90536 + * Increases kernel attack surface in areas developers
90537 + * previously cared little about ("low importance due
90538 + * to requiring "root" capability")
90539 + * To be removed when this code receives *proper* review
90540 + */
90541 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90542 + !capable(CAP_SETGID))
90543 + return -EPERM;
90544 +#endif
90545 +
90546 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90547 if (!ns)
90548 return -ENOMEM;
90549 @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90550 if (atomic_read(&current->mm->mm_users) > 1)
90551 return -EINVAL;
90552
90553 - if (current->fs->users != 1)
90554 + if (atomic_read(&current->fs->users) != 1)
90555 return -EINVAL;
90556
90557 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90558 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90559 index 4f69f9a..7c6f8f8 100644
90560 --- a/kernel/utsname_sysctl.c
90561 +++ b/kernel/utsname_sysctl.c
90562 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90563 static int proc_do_uts_string(ctl_table *table, int write,
90564 void __user *buffer, size_t *lenp, loff_t *ppos)
90565 {
90566 - struct ctl_table uts_table;
90567 + ctl_table_no_const uts_table;
90568 int r;
90569 memcpy(&uts_table, table, sizeof(uts_table));
90570 uts_table.data = get_uts(table, write);
90571 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90572 index 4431610..4265616 100644
90573 --- a/kernel/watchdog.c
90574 +++ b/kernel/watchdog.c
90575 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90576 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90577 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90578
90579 -static struct smp_hotplug_thread watchdog_threads = {
90580 +static struct smp_hotplug_thread watchdog_threads __read_only = {
90581 .store = &softlockup_watchdog,
90582 .thread_should_run = watchdog_should_run,
90583 .thread_fn = watchdog,
90584 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90585 index 193e977..26dd63f 100644
90586 --- a/kernel/workqueue.c
90587 +++ b/kernel/workqueue.c
90588 @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90589 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90590 worker_flags |= WORKER_REBOUND;
90591 worker_flags &= ~WORKER_UNBOUND;
90592 - ACCESS_ONCE(worker->flags) = worker_flags;
90593 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
90594 }
90595
90596 spin_unlock_irq(&pool->lock);
90597 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90598 index a48abea..e108def 100644
90599 --- a/lib/Kconfig.debug
90600 +++ b/lib/Kconfig.debug
90601 @@ -854,7 +854,7 @@ config DEBUG_MUTEXES
90602
90603 config DEBUG_WW_MUTEX_SLOWPATH
90604 bool "Wait/wound mutex debugging: Slowpath testing"
90605 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90606 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90607 select DEBUG_LOCK_ALLOC
90608 select DEBUG_SPINLOCK
90609 select DEBUG_MUTEXES
90610 @@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90611
90612 config DEBUG_LOCK_ALLOC
90613 bool "Lock debugging: detect incorrect freeing of live locks"
90614 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90615 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90616 select DEBUG_SPINLOCK
90617 select DEBUG_MUTEXES
90618 select LOCKDEP
90619 @@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
90620
90621 config PROVE_LOCKING
90622 bool "Lock debugging: prove locking correctness"
90623 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90624 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90625 select LOCKDEP
90626 select DEBUG_SPINLOCK
90627 select DEBUG_MUTEXES
90628 @@ -932,7 +932,7 @@ config LOCKDEP
90629
90630 config LOCK_STAT
90631 bool "Lock usage statistics"
90632 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90633 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90634 select LOCKDEP
90635 select DEBUG_SPINLOCK
90636 select DEBUG_MUTEXES
90637 @@ -1394,6 +1394,7 @@ config LATENCYTOP
90638 depends on DEBUG_KERNEL
90639 depends on STACKTRACE_SUPPORT
90640 depends on PROC_FS
90641 + depends on !GRKERNSEC_HIDESYM
90642 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90643 select KALLSYMS
90644 select KALLSYMS_ALL
90645 @@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90646 config DEBUG_STRICT_USER_COPY_CHECKS
90647 bool "Strict user copy size checks"
90648 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90649 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90650 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90651 help
90652 Enabling this option turns a certain set of sanity checks for user
90653 copy operations into compile time failures.
90654 @@ -1529,7 +1530,7 @@ endmenu # runtime tests
90655
90656 config PROVIDE_OHCI1394_DMA_INIT
90657 bool "Remote debugging over FireWire early on boot"
90658 - depends on PCI && X86
90659 + depends on PCI && X86 && !GRKERNSEC
90660 help
90661 If you want to debug problems which hang or crash the kernel early
90662 on boot and the crashing machine has a FireWire port, you can use
90663 diff --git a/lib/Makefile b/lib/Makefile
90664 index 48140e3..de854e5 100644
90665 --- a/lib/Makefile
90666 +++ b/lib/Makefile
90667 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90668 obj-$(CONFIG_BTREE) += btree.o
90669 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90670 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90671 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90672 +obj-y += list_debug.o
90673 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90674
90675 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90676 diff --git a/lib/average.c b/lib/average.c
90677 index 114d1be..ab0350c 100644
90678 --- a/lib/average.c
90679 +++ b/lib/average.c
90680 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
90681 {
90682 unsigned long internal = ACCESS_ONCE(avg->internal);
90683
90684 - ACCESS_ONCE(avg->internal) = internal ?
90685 + ACCESS_ONCE_RW(avg->internal) = internal ?
90686 (((internal << avg->weight) - internal) +
90687 (val << avg->factor)) >> avg->weight :
90688 (val << avg->factor);
90689 diff --git a/lib/bitmap.c b/lib/bitmap.c
90690 index 06f7e4f..f3cf2b0 100644
90691 --- a/lib/bitmap.c
90692 +++ b/lib/bitmap.c
90693 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90694 {
90695 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90696 u32 chunk;
90697 - const char __user __force *ubuf = (const char __user __force *)buf;
90698 + const char __user *ubuf = (const char __force_user *)buf;
90699
90700 bitmap_zero(maskp, nmaskbits);
90701
90702 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90703 {
90704 if (!access_ok(VERIFY_READ, ubuf, ulen))
90705 return -EFAULT;
90706 - return __bitmap_parse((const char __force *)ubuf,
90707 + return __bitmap_parse((const char __force_kernel *)ubuf,
90708 ulen, 1, maskp, nmaskbits);
90709
90710 }
90711 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90712 {
90713 unsigned a, b;
90714 int c, old_c, totaldigits;
90715 - const char __user __force *ubuf = (const char __user __force *)buf;
90716 + const char __user *ubuf = (const char __force_user *)buf;
90717 int exp_digit, in_range;
90718
90719 totaldigits = c = 0;
90720 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90721 {
90722 if (!access_ok(VERIFY_READ, ubuf, ulen))
90723 return -EFAULT;
90724 - return __bitmap_parselist((const char __force *)ubuf,
90725 + return __bitmap_parselist((const char __force_kernel *)ubuf,
90726 ulen, 1, maskp, nmaskbits);
90727 }
90728 EXPORT_SYMBOL(bitmap_parselist_user);
90729 diff --git a/lib/bug.c b/lib/bug.c
90730 index 1686034..a9c00c8 100644
90731 --- a/lib/bug.c
90732 +++ b/lib/bug.c
90733 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90734 return BUG_TRAP_TYPE_NONE;
90735
90736 bug = find_bug(bugaddr);
90737 + if (!bug)
90738 + return BUG_TRAP_TYPE_NONE;
90739
90740 file = NULL;
90741 line = 0;
90742 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90743 index e0731c3..ad66444 100644
90744 --- a/lib/debugobjects.c
90745 +++ b/lib/debugobjects.c
90746 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90747 if (limit > 4)
90748 return;
90749
90750 - is_on_stack = object_is_on_stack(addr);
90751 + is_on_stack = object_starts_on_stack(addr);
90752 if (is_on_stack == onstack)
90753 return;
90754
90755 diff --git a/lib/devres.c b/lib/devres.c
90756 index 8235331..5881053 100644
90757 --- a/lib/devres.c
90758 +++ b/lib/devres.c
90759 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90760 void devm_iounmap(struct device *dev, void __iomem *addr)
90761 {
90762 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90763 - (void *)addr));
90764 + (void __force *)addr));
90765 iounmap(addr);
90766 }
90767 EXPORT_SYMBOL(devm_iounmap);
90768 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90769 {
90770 ioport_unmap(addr);
90771 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90772 - devm_ioport_map_match, (void *)addr));
90773 + devm_ioport_map_match, (void __force *)addr));
90774 }
90775 EXPORT_SYMBOL(devm_ioport_unmap);
90776 #endif /* CONFIG_HAS_IOPORT */
90777 diff --git a/lib/div64.c b/lib/div64.c
90778 index 4382ad7..08aa558 100644
90779 --- a/lib/div64.c
90780 +++ b/lib/div64.c
90781 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90782 EXPORT_SYMBOL(__div64_32);
90783
90784 #ifndef div_s64_rem
90785 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90786 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90787 {
90788 u64 quotient;
90789
90790 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90791 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90792 */
90793 #ifndef div64_u64
90794 -u64 div64_u64(u64 dividend, u64 divisor)
90795 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90796 {
90797 u32 high = divisor >> 32;
90798 u64 quot;
90799 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90800 index 98f2d7e..899da5c 100644
90801 --- a/lib/dma-debug.c
90802 +++ b/lib/dma-debug.c
90803 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90804
90805 void dma_debug_add_bus(struct bus_type *bus)
90806 {
90807 - struct notifier_block *nb;
90808 + notifier_block_no_const *nb;
90809
90810 if (global_disable)
90811 return;
90812 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90813
90814 static void check_for_stack(struct device *dev, void *addr)
90815 {
90816 - if (object_is_on_stack(addr))
90817 + if (object_starts_on_stack(addr))
90818 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90819 "stack [addr=%p]\n", addr);
90820 }
90821 diff --git a/lib/hash.c b/lib/hash.c
90822 index fea973f..386626f 100644
90823 --- a/lib/hash.c
90824 +++ b/lib/hash.c
90825 @@ -14,7 +14,7 @@
90826 #include <linux/hash.h>
90827 #include <linux/cache.h>
90828
90829 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
90830 +static struct fast_hash_ops arch_hash_ops __read_only = {
90831 .hash = jhash,
90832 .hash2 = jhash2,
90833 };
90834 diff --git a/lib/inflate.c b/lib/inflate.c
90835 index 013a761..c28f3fc 100644
90836 --- a/lib/inflate.c
90837 +++ b/lib/inflate.c
90838 @@ -269,7 +269,7 @@ static void free(void *where)
90839 malloc_ptr = free_mem_ptr;
90840 }
90841 #else
90842 -#define malloc(a) kmalloc(a, GFP_KERNEL)
90843 +#define malloc(a) kmalloc((a), GFP_KERNEL)
90844 #define free(a) kfree(a)
90845 #endif
90846
90847 diff --git a/lib/ioremap.c b/lib/ioremap.c
90848 index 0c9216c..863bd89 100644
90849 --- a/lib/ioremap.c
90850 +++ b/lib/ioremap.c
90851 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90852 unsigned long next;
90853
90854 phys_addr -= addr;
90855 - pmd = pmd_alloc(&init_mm, pud, addr);
90856 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90857 if (!pmd)
90858 return -ENOMEM;
90859 do {
90860 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90861 unsigned long next;
90862
90863 phys_addr -= addr;
90864 - pud = pud_alloc(&init_mm, pgd, addr);
90865 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
90866 if (!pud)
90867 return -ENOMEM;
90868 do {
90869 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90870 index bd2bea9..6b3c95e 100644
90871 --- a/lib/is_single_threaded.c
90872 +++ b/lib/is_single_threaded.c
90873 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90874 struct task_struct *p, *t;
90875 bool ret;
90876
90877 + if (!mm)
90878 + return true;
90879 +
90880 if (atomic_read(&task->signal->live) != 1)
90881 return false;
90882
90883 diff --git a/lib/kobject.c b/lib/kobject.c
90884 index cb14aea..8c53cdb 100644
90885 --- a/lib/kobject.c
90886 +++ b/lib/kobject.c
90887 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90888
90889
90890 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90891 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90892 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90893
90894 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90895 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90896 {
90897 enum kobj_ns_type type = ops->type;
90898 int error;
90899 diff --git a/lib/list_debug.c b/lib/list_debug.c
90900 index c24c2f7..f0296f4 100644
90901 --- a/lib/list_debug.c
90902 +++ b/lib/list_debug.c
90903 @@ -11,7 +11,9 @@
90904 #include <linux/bug.h>
90905 #include <linux/kernel.h>
90906 #include <linux/rculist.h>
90907 +#include <linux/mm.h>
90908
90909 +#ifdef CONFIG_DEBUG_LIST
90910 /*
90911 * Insert a new entry between two known consecutive entries.
90912 *
90913 @@ -19,21 +21,40 @@
90914 * the prev/next entries already!
90915 */
90916
90917 +static bool __list_add_debug(struct list_head *new,
90918 + struct list_head *prev,
90919 + struct list_head *next)
90920 +{
90921 + if (unlikely(next->prev != prev)) {
90922 + printk(KERN_ERR "list_add corruption. next->prev should be "
90923 + "prev (%p), but was %p. (next=%p).\n",
90924 + prev, next->prev, next);
90925 + BUG();
90926 + return false;
90927 + }
90928 + if (unlikely(prev->next != next)) {
90929 + printk(KERN_ERR "list_add corruption. prev->next should be "
90930 + "next (%p), but was %p. (prev=%p).\n",
90931 + next, prev->next, prev);
90932 + BUG();
90933 + return false;
90934 + }
90935 + if (unlikely(new == prev || new == next)) {
90936 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90937 + new, prev, next);
90938 + BUG();
90939 + return false;
90940 + }
90941 + return true;
90942 +}
90943 +
90944 void __list_add(struct list_head *new,
90945 - struct list_head *prev,
90946 - struct list_head *next)
90947 + struct list_head *prev,
90948 + struct list_head *next)
90949 {
90950 - WARN(next->prev != prev,
90951 - "list_add corruption. next->prev should be "
90952 - "prev (%p), but was %p. (next=%p).\n",
90953 - prev, next->prev, next);
90954 - WARN(prev->next != next,
90955 - "list_add corruption. prev->next should be "
90956 - "next (%p), but was %p. (prev=%p).\n",
90957 - next, prev->next, prev);
90958 - WARN(new == prev || new == next,
90959 - "list_add double add: new=%p, prev=%p, next=%p.\n",
90960 - new, prev, next);
90961 + if (!__list_add_debug(new, prev, next))
90962 + return;
90963 +
90964 next->prev = new;
90965 new->next = next;
90966 new->prev = prev;
90967 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90968 }
90969 EXPORT_SYMBOL(__list_add);
90970
90971 -void __list_del_entry(struct list_head *entry)
90972 +static bool __list_del_entry_debug(struct list_head *entry)
90973 {
90974 struct list_head *prev, *next;
90975
90976 prev = entry->prev;
90977 next = entry->next;
90978
90979 - if (WARN(next == LIST_POISON1,
90980 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90981 - entry, LIST_POISON1) ||
90982 - WARN(prev == LIST_POISON2,
90983 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90984 - entry, LIST_POISON2) ||
90985 - WARN(prev->next != entry,
90986 - "list_del corruption. prev->next should be %p, "
90987 - "but was %p\n", entry, prev->next) ||
90988 - WARN(next->prev != entry,
90989 - "list_del corruption. next->prev should be %p, "
90990 - "but was %p\n", entry, next->prev))
90991 + if (unlikely(next == LIST_POISON1)) {
90992 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90993 + entry, LIST_POISON1);
90994 + BUG();
90995 + return false;
90996 + }
90997 + if (unlikely(prev == LIST_POISON2)) {
90998 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90999 + entry, LIST_POISON2);
91000 + BUG();
91001 + return false;
91002 + }
91003 + if (unlikely(entry->prev->next != entry)) {
91004 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91005 + "but was %p\n", entry, prev->next);
91006 + BUG();
91007 + return false;
91008 + }
91009 + if (unlikely(entry->next->prev != entry)) {
91010 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91011 + "but was %p\n", entry, next->prev);
91012 + BUG();
91013 + return false;
91014 + }
91015 + return true;
91016 +}
91017 +
91018 +void __list_del_entry(struct list_head *entry)
91019 +{
91020 + if (!__list_del_entry_debug(entry))
91021 return;
91022
91023 - __list_del(prev, next);
91024 + __list_del(entry->prev, entry->next);
91025 }
91026 EXPORT_SYMBOL(__list_del_entry);
91027
91028 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91029 void __list_add_rcu(struct list_head *new,
91030 struct list_head *prev, struct list_head *next)
91031 {
91032 - WARN(next->prev != prev,
91033 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91034 - prev, next->prev, next);
91035 - WARN(prev->next != next,
91036 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91037 - next, prev->next, prev);
91038 + if (!__list_add_debug(new, prev, next))
91039 + return;
91040 +
91041 new->next = next;
91042 new->prev = prev;
91043 rcu_assign_pointer(list_next_rcu(prev), new);
91044 next->prev = new;
91045 }
91046 EXPORT_SYMBOL(__list_add_rcu);
91047 +#endif
91048 +
91049 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91050 +{
91051 +#ifdef CONFIG_DEBUG_LIST
91052 + if (!__list_add_debug(new, prev, next))
91053 + return;
91054 +#endif
91055 +
91056 + pax_open_kernel();
91057 + next->prev = new;
91058 + new->next = next;
91059 + new->prev = prev;
91060 + prev->next = new;
91061 + pax_close_kernel();
91062 +}
91063 +EXPORT_SYMBOL(__pax_list_add);
91064 +
91065 +void pax_list_del(struct list_head *entry)
91066 +{
91067 +#ifdef CONFIG_DEBUG_LIST
91068 + if (!__list_del_entry_debug(entry))
91069 + return;
91070 +#endif
91071 +
91072 + pax_open_kernel();
91073 + __list_del(entry->prev, entry->next);
91074 + entry->next = LIST_POISON1;
91075 + entry->prev = LIST_POISON2;
91076 + pax_close_kernel();
91077 +}
91078 +EXPORT_SYMBOL(pax_list_del);
91079 +
91080 +void pax_list_del_init(struct list_head *entry)
91081 +{
91082 + pax_open_kernel();
91083 + __list_del(entry->prev, entry->next);
91084 + INIT_LIST_HEAD(entry);
91085 + pax_close_kernel();
91086 +}
91087 +EXPORT_SYMBOL(pax_list_del_init);
91088 +
91089 +void __pax_list_add_rcu(struct list_head *new,
91090 + struct list_head *prev, struct list_head *next)
91091 +{
91092 +#ifdef CONFIG_DEBUG_LIST
91093 + if (!__list_add_debug(new, prev, next))
91094 + return;
91095 +#endif
91096 +
91097 + pax_open_kernel();
91098 + new->next = next;
91099 + new->prev = prev;
91100 + rcu_assign_pointer(list_next_rcu(prev), new);
91101 + next->prev = new;
91102 + pax_close_kernel();
91103 +}
91104 +EXPORT_SYMBOL(__pax_list_add_rcu);
91105 +
91106 +void pax_list_del_rcu(struct list_head *entry)
91107 +{
91108 +#ifdef CONFIG_DEBUG_LIST
91109 + if (!__list_del_entry_debug(entry))
91110 + return;
91111 +#endif
91112 +
91113 + pax_open_kernel();
91114 + __list_del(entry->prev, entry->next);
91115 + entry->next = LIST_POISON1;
91116 + entry->prev = LIST_POISON2;
91117 + pax_close_kernel();
91118 +}
91119 +EXPORT_SYMBOL(pax_list_del_rcu);
91120 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91121 index 963b703..438bc51 100644
91122 --- a/lib/percpu-refcount.c
91123 +++ b/lib/percpu-refcount.c
91124 @@ -29,7 +29,7 @@
91125 * can't hit 0 before we've added up all the percpu refs.
91126 */
91127
91128 -#define PCPU_COUNT_BIAS (1U << 31)
91129 +#define PCPU_COUNT_BIAS (1U << 30)
91130
91131 /**
91132 * percpu_ref_init - initialize a percpu refcount
91133 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91134 index bd4a8df..9e4804f 100644
91135 --- a/lib/radix-tree.c
91136 +++ b/lib/radix-tree.c
91137 @@ -93,7 +93,7 @@ struct radix_tree_preload {
91138 int nr;
91139 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91140 };
91141 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91142 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91143
91144 static inline void *ptr_to_indirect(void *ptr)
91145 {
91146 diff --git a/lib/random32.c b/lib/random32.c
91147 index 6148967..009bfe8 100644
91148 --- a/lib/random32.c
91149 +++ b/lib/random32.c
91150 @@ -44,7 +44,7 @@
91151 static void __init prandom_state_selftest(void);
91152 #endif
91153
91154 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91155 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91156
91157 /**
91158 * prandom_u32_state - seeded pseudo-random number generator.
91159 diff --git a/lib/rbtree.c b/lib/rbtree.c
91160 index 65f4eff..2cfa167 100644
91161 --- a/lib/rbtree.c
91162 +++ b/lib/rbtree.c
91163 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91164 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91165
91166 static const struct rb_augment_callbacks dummy_callbacks = {
91167 - dummy_propagate, dummy_copy, dummy_rotate
91168 + .propagate = dummy_propagate,
91169 + .copy = dummy_copy,
91170 + .rotate = dummy_rotate
91171 };
91172
91173 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91174 diff --git a/lib/show_mem.c b/lib/show_mem.c
91175 index 0922579..9d7adb9 100644
91176 --- a/lib/show_mem.c
91177 +++ b/lib/show_mem.c
91178 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91179 quicklist_total_size());
91180 #endif
91181 #ifdef CONFIG_MEMORY_FAILURE
91182 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91183 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91184 #endif
91185 }
91186 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91187 index bb2b201..46abaf9 100644
91188 --- a/lib/strncpy_from_user.c
91189 +++ b/lib/strncpy_from_user.c
91190 @@ -21,7 +21,7 @@
91191 */
91192 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91193 {
91194 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91195 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91196 long res = 0;
91197
91198 /*
91199 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91200 index a28df52..3d55877 100644
91201 --- a/lib/strnlen_user.c
91202 +++ b/lib/strnlen_user.c
91203 @@ -26,7 +26,7 @@
91204 */
91205 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91206 {
91207 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91208 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91209 long align, res = 0;
91210 unsigned long c;
91211
91212 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91213 index b604b83..c0547f6 100644
91214 --- a/lib/swiotlb.c
91215 +++ b/lib/swiotlb.c
91216 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91217
91218 void
91219 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91220 - dma_addr_t dev_addr)
91221 + dma_addr_t dev_addr, struct dma_attrs *attrs)
91222 {
91223 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91224
91225 diff --git a/lib/usercopy.c b/lib/usercopy.c
91226 index 4f5b1dd..7cab418 100644
91227 --- a/lib/usercopy.c
91228 +++ b/lib/usercopy.c
91229 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91230 WARN(1, "Buffer overflow detected!\n");
91231 }
91232 EXPORT_SYMBOL(copy_from_user_overflow);
91233 +
91234 +void copy_to_user_overflow(void)
91235 +{
91236 + WARN(1, "Buffer overflow detected!\n");
91237 +}
91238 +EXPORT_SYMBOL(copy_to_user_overflow);
91239 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91240 index 185b6d3..823c48c 100644
91241 --- a/lib/vsprintf.c
91242 +++ b/lib/vsprintf.c
91243 @@ -16,6 +16,9 @@
91244 * - scnprintf and vscnprintf
91245 */
91246
91247 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91248 +#define __INCLUDED_BY_HIDESYM 1
91249 +#endif
91250 #include <stdarg.h>
91251 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91252 #include <linux/types.h>
91253 @@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
91254 return number(buf, end, num, spec);
91255 }
91256
91257 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91258 +int kptr_restrict __read_mostly = 2;
91259 +#else
91260 int kptr_restrict __read_mostly;
91261 +#endif
91262
91263 /*
91264 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91265 @@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
91266 * - 'f' For simple symbolic function names without offset
91267 * - 'S' For symbolic direct pointers with offset
91268 * - 's' For symbolic direct pointers without offset
91269 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91270 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91271 * - 'B' For backtraced symbolic direct pointers with offset
91272 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91273 @@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91274
91275 if (!ptr && *fmt != 'K') {
91276 /*
91277 - * Print (null) with the same width as a pointer so it makes
91278 + * Print (nil) with the same width as a pointer so it makes
91279 * tabular output look nice.
91280 */
91281 if (spec.field_width == -1)
91282 spec.field_width = default_width;
91283 - return string(buf, end, "(null)", spec);
91284 + return string(buf, end, "(nil)", spec);
91285 }
91286
91287 switch (*fmt) {
91288 @@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91289 /* Fallthrough */
91290 case 'S':
91291 case 's':
91292 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91293 + break;
91294 +#else
91295 + return symbol_string(buf, end, ptr, spec, fmt);
91296 +#endif
91297 + case 'A':
91298 case 'B':
91299 return symbol_string(buf, end, ptr, spec, fmt);
91300 case 'R':
91301 @@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91302 va_end(va);
91303 return buf;
91304 }
91305 + case 'P':
91306 + break;
91307 case 'K':
91308 /*
91309 * %pK cannot be used in IRQ context because its test
91310 @@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91311 ((const struct file *)ptr)->f_path.dentry,
91312 spec, fmt);
91313 }
91314 +
91315 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91316 + /* 'P' = approved pointers to copy to userland,
91317 + as in the /proc/kallsyms case, as we make it display nothing
91318 + for non-root users, and the real contents for root users
91319 + Also ignore 'K' pointers, since we force their NULLing for non-root users
91320 + above
91321 + */
91322 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91323 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91324 + dump_stack();
91325 + ptr = NULL;
91326 + }
91327 +#endif
91328 +
91329 spec.flags |= SMALL;
91330 if (spec.field_width == -1) {
91331 spec.field_width = default_width;
91332 @@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91333 typeof(type) value; \
91334 if (sizeof(type) == 8) { \
91335 args = PTR_ALIGN(args, sizeof(u32)); \
91336 - *(u32 *)&value = *(u32 *)args; \
91337 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91338 + *(u32 *)&value = *(const u32 *)args; \
91339 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91340 } else { \
91341 args = PTR_ALIGN(args, sizeof(type)); \
91342 - value = *(typeof(type) *)args; \
91343 + value = *(const typeof(type) *)args; \
91344 } \
91345 args += sizeof(type); \
91346 value; \
91347 @@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91348 case FORMAT_TYPE_STR: {
91349 const char *str_arg = args;
91350 args += strlen(str_arg) + 1;
91351 - str = string(str, end, (char *)str_arg, spec);
91352 + str = string(str, end, str_arg, spec);
91353 break;
91354 }
91355
91356 diff --git a/localversion-grsec b/localversion-grsec
91357 new file mode 100644
91358 index 0000000..7cd6065
91359 --- /dev/null
91360 +++ b/localversion-grsec
91361 @@ -0,0 +1 @@
91362 +-grsec
91363 diff --git a/mm/Kconfig b/mm/Kconfig
91364 index 2888024..c15a810 100644
91365 --- a/mm/Kconfig
91366 +++ b/mm/Kconfig
91367 @@ -326,10 +326,11 @@ config KSM
91368 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91369
91370 config DEFAULT_MMAP_MIN_ADDR
91371 - int "Low address space to protect from user allocation"
91372 + int "Low address space to protect from user allocation"
91373 depends on MMU
91374 - default 4096
91375 - help
91376 + default 32768 if ALPHA || ARM || PARISC || SPARC32
91377 + default 65536
91378 + help
91379 This is the portion of low virtual memory which should be protected
91380 from userspace allocation. Keeping a user from writing to low pages
91381 can help reduce the impact of kernel NULL pointer bugs.
91382 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
91383
91384 config HWPOISON_INJECT
91385 tristate "HWPoison pages injector"
91386 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91387 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91388 select PROC_PAGE_MONITOR
91389
91390 config NOMMU_INITIAL_TRIM_EXCESS
91391 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91392 index 09d9591..165bb75 100644
91393 --- a/mm/backing-dev.c
91394 +++ b/mm/backing-dev.c
91395 @@ -12,7 +12,7 @@
91396 #include <linux/device.h>
91397 #include <trace/events/writeback.h>
91398
91399 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91400 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91401
91402 struct backing_dev_info default_backing_dev_info = {
91403 .name = "default",
91404 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91405 return err;
91406
91407 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91408 - atomic_long_inc_return(&bdi_seq));
91409 + atomic_long_inc_return_unchecked(&bdi_seq));
91410 if (err) {
91411 bdi_destroy(bdi);
91412 return err;
91413 diff --git a/mm/filemap.c b/mm/filemap.c
91414 index 7a13f6a..e52e841 100644
91415 --- a/mm/filemap.c
91416 +++ b/mm/filemap.c
91417 @@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91418 struct address_space *mapping = file->f_mapping;
91419
91420 if (!mapping->a_ops->readpage)
91421 - return -ENOEXEC;
91422 + return -ENODEV;
91423 file_accessed(file);
91424 vma->vm_ops = &generic_file_vm_ops;
91425 return 0;
91426 @@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91427
91428 while (bytes) {
91429 char __user *buf = iov->iov_base + base;
91430 - int copy = min(bytes, iov->iov_len - base);
91431 + size_t copy = min(bytes, iov->iov_len - base);
91432
91433 base = 0;
91434 left = __copy_from_user_inatomic(vaddr, buf, copy);
91435 @@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91436 BUG_ON(!in_atomic());
91437 kaddr = kmap_atomic(page);
91438 if (likely(i->nr_segs == 1)) {
91439 - int left;
91440 + size_t left;
91441 char __user *buf = i->iov->iov_base + i->iov_offset;
91442 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91443 copied = bytes - left;
91444 @@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91445
91446 kaddr = kmap(page);
91447 if (likely(i->nr_segs == 1)) {
91448 - int left;
91449 + size_t left;
91450 char __user *buf = i->iov->iov_base + i->iov_offset;
91451 left = __copy_from_user(kaddr + offset, buf, bytes);
91452 copied = bytes - left;
91453 @@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91454 * zero-length segments (without overruning the iovec).
91455 */
91456 while (bytes || unlikely(i->count && !iov->iov_len)) {
91457 - int copy;
91458 + size_t copy;
91459
91460 copy = min(bytes, iov->iov_len - base);
91461 BUG_ON(!i->count || i->count < copy);
91462 @@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91463 *pos = i_size_read(inode);
91464
91465 if (limit != RLIM_INFINITY) {
91466 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91467 if (*pos >= limit) {
91468 send_sig(SIGXFSZ, current, 0);
91469 return -EFBIG;
91470 diff --git a/mm/fremap.c b/mm/fremap.c
91471 index 34feba6..315fe78 100644
91472 --- a/mm/fremap.c
91473 +++ b/mm/fremap.c
91474 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91475 retry:
91476 vma = find_vma(mm, start);
91477
91478 +#ifdef CONFIG_PAX_SEGMEXEC
91479 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91480 + goto out;
91481 +#endif
91482 +
91483 /*
91484 * Make sure the vma is shared, that it supports prefaulting,
91485 * and that the remapped range is valid and fully within
91486 diff --git a/mm/highmem.c b/mm/highmem.c
91487 index b32b70c..e512eb0 100644
91488 --- a/mm/highmem.c
91489 +++ b/mm/highmem.c
91490 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91491 * So no dangers, even with speculative execution.
91492 */
91493 page = pte_page(pkmap_page_table[i]);
91494 + pax_open_kernel();
91495 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91496 -
91497 + pax_close_kernel();
91498 set_page_address(page, NULL);
91499 need_flush = 1;
91500 }
91501 @@ -198,9 +199,11 @@ start:
91502 }
91503 }
91504 vaddr = PKMAP_ADDR(last_pkmap_nr);
91505 +
91506 + pax_open_kernel();
91507 set_pte_at(&init_mm, vaddr,
91508 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91509 -
91510 + pax_close_kernel();
91511 pkmap_count[last_pkmap_nr] = 1;
91512 set_page_address(page, (void *)vaddr);
91513
91514 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91515 index c01cb9f..ac0f58e 100644
91516 --- a/mm/hugetlb.c
91517 +++ b/mm/hugetlb.c
91518 @@ -2068,15 +2068,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91519 struct hstate *h = &default_hstate;
91520 unsigned long tmp;
91521 int ret;
91522 + ctl_table_no_const hugetlb_table;
91523
91524 tmp = h->max_huge_pages;
91525
91526 if (write && h->order >= MAX_ORDER)
91527 return -EINVAL;
91528
91529 - table->data = &tmp;
91530 - table->maxlen = sizeof(unsigned long);
91531 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91532 + hugetlb_table = *table;
91533 + hugetlb_table.data = &tmp;
91534 + hugetlb_table.maxlen = sizeof(unsigned long);
91535 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91536 if (ret)
91537 goto out;
91538
91539 @@ -2121,15 +2123,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91540 struct hstate *h = &default_hstate;
91541 unsigned long tmp;
91542 int ret;
91543 + ctl_table_no_const hugetlb_table;
91544
91545 tmp = h->nr_overcommit_huge_pages;
91546
91547 if (write && h->order >= MAX_ORDER)
91548 return -EINVAL;
91549
91550 - table->data = &tmp;
91551 - table->maxlen = sizeof(unsigned long);
91552 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91553 + hugetlb_table = *table;
91554 + hugetlb_table.data = &tmp;
91555 + hugetlb_table.maxlen = sizeof(unsigned long);
91556 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91557 if (ret)
91558 goto out;
91559
91560 @@ -2598,6 +2602,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91561 return 1;
91562 }
91563
91564 +#ifdef CONFIG_PAX_SEGMEXEC
91565 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91566 +{
91567 + struct mm_struct *mm = vma->vm_mm;
91568 + struct vm_area_struct *vma_m;
91569 + unsigned long address_m;
91570 + pte_t *ptep_m;
91571 +
91572 + vma_m = pax_find_mirror_vma(vma);
91573 + if (!vma_m)
91574 + return;
91575 +
91576 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91577 + address_m = address + SEGMEXEC_TASK_SIZE;
91578 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91579 + get_page(page_m);
91580 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
91581 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91582 +}
91583 +#endif
91584 +
91585 /*
91586 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91587 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91588 @@ -2714,6 +2739,11 @@ retry_avoidcopy:
91589 make_huge_pte(vma, new_page, 1));
91590 page_remove_rmap(old_page);
91591 hugepage_add_new_anon_rmap(new_page, vma, address);
91592 +
91593 +#ifdef CONFIG_PAX_SEGMEXEC
91594 + pax_mirror_huge_pte(vma, address, new_page);
91595 +#endif
91596 +
91597 /* Make the old page be freed below */
91598 new_page = old_page;
91599 }
91600 @@ -2878,6 +2908,10 @@ retry:
91601 && (vma->vm_flags & VM_SHARED)));
91602 set_huge_pte_at(mm, address, ptep, new_pte);
91603
91604 +#ifdef CONFIG_PAX_SEGMEXEC
91605 + pax_mirror_huge_pte(vma, address, page);
91606 +#endif
91607 +
91608 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91609 /* Optimization, do the COW without a second fault */
91610 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91611 @@ -2908,6 +2942,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91612 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91613 struct hstate *h = hstate_vma(vma);
91614
91615 +#ifdef CONFIG_PAX_SEGMEXEC
91616 + struct vm_area_struct *vma_m;
91617 +#endif
91618 +
91619 address &= huge_page_mask(h);
91620
91621 ptep = huge_pte_offset(mm, address);
91622 @@ -2921,6 +2959,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91623 VM_FAULT_SET_HINDEX(hstate_index(h));
91624 }
91625
91626 +#ifdef CONFIG_PAX_SEGMEXEC
91627 + vma_m = pax_find_mirror_vma(vma);
91628 + if (vma_m) {
91629 + unsigned long address_m;
91630 +
91631 + if (vma->vm_start > vma_m->vm_start) {
91632 + address_m = address;
91633 + address -= SEGMEXEC_TASK_SIZE;
91634 + vma = vma_m;
91635 + h = hstate_vma(vma);
91636 + } else
91637 + address_m = address + SEGMEXEC_TASK_SIZE;
91638 +
91639 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91640 + return VM_FAULT_OOM;
91641 + address_m &= HPAGE_MASK;
91642 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91643 + }
91644 +#endif
91645 +
91646 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91647 if (!ptep)
91648 return VM_FAULT_OOM;
91649 diff --git a/mm/internal.h b/mm/internal.h
91650 index 29e1e76..fc3ff04 100644
91651 --- a/mm/internal.h
91652 +++ b/mm/internal.h
91653 @@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91654 * in mm/page_alloc.c
91655 */
91656 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91657 +extern void free_compound_page(struct page *page);
91658 extern void prep_compound_page(struct page *page, unsigned long order);
91659 #ifdef CONFIG_MEMORY_FAILURE
91660 extern bool is_free_buddy_page(struct page *page);
91661 @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
91662
91663 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91664 unsigned long, unsigned long,
91665 - unsigned long, unsigned long);
91666 + unsigned long, unsigned long) __intentional_overflow(-1);
91667
91668 extern void set_pageblock_order(void);
91669 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91670 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91671 index 31f01c5..7015178 100644
91672 --- a/mm/kmemleak.c
91673 +++ b/mm/kmemleak.c
91674 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91675
91676 for (i = 0; i < object->trace_len; i++) {
91677 void *ptr = (void *)object->trace[i];
91678 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91679 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91680 }
91681 }
91682
91683 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91684 return -ENOMEM;
91685 }
91686
91687 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91688 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91689 &kmemleak_fops);
91690 if (!dentry)
91691 pr_warning("Failed to create the debugfs kmemleak file\n");
91692 diff --git a/mm/maccess.c b/mm/maccess.c
91693 index d53adf9..03a24bf 100644
91694 --- a/mm/maccess.c
91695 +++ b/mm/maccess.c
91696 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91697 set_fs(KERNEL_DS);
91698 pagefault_disable();
91699 ret = __copy_from_user_inatomic(dst,
91700 - (__force const void __user *)src, size);
91701 + (const void __force_user *)src, size);
91702 pagefault_enable();
91703 set_fs(old_fs);
91704
91705 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91706
91707 set_fs(KERNEL_DS);
91708 pagefault_disable();
91709 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91710 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91711 pagefault_enable();
91712 set_fs(old_fs);
91713
91714 diff --git a/mm/madvise.c b/mm/madvise.c
91715 index 539eeb9..e24a987 100644
91716 --- a/mm/madvise.c
91717 +++ b/mm/madvise.c
91718 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91719 pgoff_t pgoff;
91720 unsigned long new_flags = vma->vm_flags;
91721
91722 +#ifdef CONFIG_PAX_SEGMEXEC
91723 + struct vm_area_struct *vma_m;
91724 +#endif
91725 +
91726 switch (behavior) {
91727 case MADV_NORMAL:
91728 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91729 @@ -126,6 +130,13 @@ success:
91730 /*
91731 * vm_flags is protected by the mmap_sem held in write mode.
91732 */
91733 +
91734 +#ifdef CONFIG_PAX_SEGMEXEC
91735 + vma_m = pax_find_mirror_vma(vma);
91736 + if (vma_m)
91737 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91738 +#endif
91739 +
91740 vma->vm_flags = new_flags;
91741
91742 out:
91743 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91744 struct vm_area_struct **prev,
91745 unsigned long start, unsigned long end)
91746 {
91747 +
91748 +#ifdef CONFIG_PAX_SEGMEXEC
91749 + struct vm_area_struct *vma_m;
91750 +#endif
91751 +
91752 *prev = vma;
91753 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91754 return -EINVAL;
91755 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91756 zap_page_range(vma, start, end - start, &details);
91757 } else
91758 zap_page_range(vma, start, end - start, NULL);
91759 +
91760 +#ifdef CONFIG_PAX_SEGMEXEC
91761 + vma_m = pax_find_mirror_vma(vma);
91762 + if (vma_m) {
91763 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91764 + struct zap_details details = {
91765 + .nonlinear_vma = vma_m,
91766 + .last_index = ULONG_MAX,
91767 + };
91768 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91769 + } else
91770 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91771 + }
91772 +#endif
91773 +
91774 return 0;
91775 }
91776
91777 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91778 if (end < start)
91779 return error;
91780
91781 +#ifdef CONFIG_PAX_SEGMEXEC
91782 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91783 + if (end > SEGMEXEC_TASK_SIZE)
91784 + return error;
91785 + } else
91786 +#endif
91787 +
91788 + if (end > TASK_SIZE)
91789 + return error;
91790 +
91791 error = 0;
91792 if (end == start)
91793 return error;
91794 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91795 index 90002ea..db1452d 100644
91796 --- a/mm/memory-failure.c
91797 +++ b/mm/memory-failure.c
91798 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91799
91800 int sysctl_memory_failure_recovery __read_mostly = 1;
91801
91802 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91803 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91804
91805 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91806
91807 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91808 pfn, t->comm, t->pid);
91809 si.si_signo = SIGBUS;
91810 si.si_errno = 0;
91811 - si.si_addr = (void *)addr;
91812 + si.si_addr = (void __user *)addr;
91813 #ifdef __ARCH_SI_TRAPNO
91814 si.si_trapno = trapno;
91815 #endif
91816 @@ -762,7 +762,7 @@ static struct page_state {
91817 unsigned long res;
91818 char *msg;
91819 int (*action)(struct page *p, unsigned long pfn);
91820 -} error_states[] = {
91821 +} __do_const error_states[] = {
91822 { reserved, reserved, "reserved kernel", me_kernel },
91823 /*
91824 * free pages are specially detected outside this table:
91825 @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91826 nr_pages = 1 << compound_order(hpage);
91827 else /* normal page or thp */
91828 nr_pages = 1;
91829 - atomic_long_add(nr_pages, &num_poisoned_pages);
91830 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91831
91832 /*
91833 * We need/can do nothing about count=0 pages.
91834 @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91835 if (!PageHWPoison(hpage)
91836 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91837 || (p != hpage && TestSetPageHWPoison(hpage))) {
91838 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91839 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91840 return 0;
91841 }
91842 set_page_hwpoison_huge_page(hpage);
91843 @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91844 }
91845 if (hwpoison_filter(p)) {
91846 if (TestClearPageHWPoison(p))
91847 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91848 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91849 unlock_page(hpage);
91850 put_page(hpage);
91851 return 0;
91852 @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91853 return 0;
91854 }
91855 if (TestClearPageHWPoison(p))
91856 - atomic_long_dec(&num_poisoned_pages);
91857 + atomic_long_dec_unchecked(&num_poisoned_pages);
91858 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91859 return 0;
91860 }
91861 @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91862 */
91863 if (TestClearPageHWPoison(page)) {
91864 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91865 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91866 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91867 freeit = 1;
91868 if (PageHuge(page))
91869 clear_page_hwpoison_huge_page(page);
91870 @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91871 if (PageHuge(page)) {
91872 set_page_hwpoison_huge_page(hpage);
91873 dequeue_hwpoisoned_huge_page(hpage);
91874 - atomic_long_add(1 << compound_order(hpage),
91875 + atomic_long_add_unchecked(1 << compound_order(hpage),
91876 &num_poisoned_pages);
91877 } else {
91878 SetPageHWPoison(page);
91879 - atomic_long_inc(&num_poisoned_pages);
91880 + atomic_long_inc_unchecked(&num_poisoned_pages);
91881 }
91882 }
91883 return ret;
91884 @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91885 put_page(page);
91886 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91887 SetPageHWPoison(page);
91888 - atomic_long_inc(&num_poisoned_pages);
91889 + atomic_long_inc_unchecked(&num_poisoned_pages);
91890 return 0;
91891 }
91892
91893 @@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
91894 if (!is_free_buddy_page(page))
91895 pr_info("soft offline: %#lx: page leaked\n",
91896 pfn);
91897 - atomic_long_inc(&num_poisoned_pages);
91898 + atomic_long_inc_unchecked(&num_poisoned_pages);
91899 }
91900 } else {
91901 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91902 @@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
91903 if (PageHuge(page)) {
91904 set_page_hwpoison_huge_page(hpage);
91905 dequeue_hwpoisoned_huge_page(hpage);
91906 - atomic_long_add(1 << compound_order(hpage),
91907 + atomic_long_add_unchecked(1 << compound_order(hpage),
91908 &num_poisoned_pages);
91909 } else {
91910 SetPageHWPoison(page);
91911 - atomic_long_inc(&num_poisoned_pages);
91912 + atomic_long_inc_unchecked(&num_poisoned_pages);
91913 }
91914 }
91915 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91916 diff --git a/mm/memory.c b/mm/memory.c
91917 index 22dfa61..90d7ec5 100644
91918 --- a/mm/memory.c
91919 +++ b/mm/memory.c
91920 @@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91921 free_pte_range(tlb, pmd, addr);
91922 } while (pmd++, addr = next, addr != end);
91923
91924 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91925 start &= PUD_MASK;
91926 if (start < floor)
91927 return;
91928 @@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91929 pmd = pmd_offset(pud, start);
91930 pud_clear(pud);
91931 pmd_free_tlb(tlb, pmd, start);
91932 +#endif
91933 +
91934 }
91935
91936 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91937 @@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91938 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91939 } while (pud++, addr = next, addr != end);
91940
91941 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91942 start &= PGDIR_MASK;
91943 if (start < floor)
91944 return;
91945 @@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91946 pud = pud_offset(pgd, start);
91947 pgd_clear(pgd);
91948 pud_free_tlb(tlb, pud, start);
91949 +#endif
91950 +
91951 }
91952
91953 /*
91954 @@ -1636,12 +1642,6 @@ no_page_table:
91955 return page;
91956 }
91957
91958 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91959 -{
91960 - return stack_guard_page_start(vma, addr) ||
91961 - stack_guard_page_end(vma, addr+PAGE_SIZE);
91962 -}
91963 -
91964 /**
91965 * __get_user_pages() - pin user pages in memory
91966 * @tsk: task_struct of target task
91967 @@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91968
91969 i = 0;
91970
91971 - do {
91972 + while (nr_pages) {
91973 struct vm_area_struct *vma;
91974
91975 - vma = find_extend_vma(mm, start);
91976 + vma = find_vma(mm, start);
91977 if (!vma && in_gate_area(mm, start)) {
91978 unsigned long pg = start & PAGE_MASK;
91979 pgd_t *pgd;
91980 @@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91981 goto next_page;
91982 }
91983
91984 - if (!vma ||
91985 + if (!vma || start < vma->vm_start ||
91986 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91987 !(vm_flags & vma->vm_flags))
91988 return i ? : -EFAULT;
91989 @@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91990 int ret;
91991 unsigned int fault_flags = 0;
91992
91993 - /* For mlock, just skip the stack guard page. */
91994 - if (foll_flags & FOLL_MLOCK) {
91995 - if (stack_guard_page(vma, start))
91996 - goto next_page;
91997 - }
91998 if (foll_flags & FOLL_WRITE)
91999 fault_flags |= FAULT_FLAG_WRITE;
92000 if (nonblocking)
92001 @@ -1893,7 +1888,7 @@ next_page:
92002 start += page_increm * PAGE_SIZE;
92003 nr_pages -= page_increm;
92004 } while (nr_pages && start < vma->vm_end);
92005 - } while (nr_pages);
92006 + }
92007 return i;
92008 }
92009 EXPORT_SYMBOL(__get_user_pages);
92010 @@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92011 unsigned long address, unsigned int fault_flags)
92012 {
92013 struct vm_area_struct *vma;
92014 + vm_flags_t vm_flags;
92015 int ret;
92016
92017 vma = find_extend_vma(mm, address);
92018 if (!vma || address < vma->vm_start)
92019 return -EFAULT;
92020
92021 + vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92022 + if (!(vm_flags & vma->vm_flags))
92023 + return -EFAULT;
92024 +
92025 ret = handle_mm_fault(mm, vma, address, fault_flags);
92026 if (ret & VM_FAULT_ERROR) {
92027 if (ret & VM_FAULT_OOM)
92028 @@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92029 page_add_file_rmap(page);
92030 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92031
92032 +#ifdef CONFIG_PAX_SEGMEXEC
92033 + pax_mirror_file_pte(vma, addr, page, ptl);
92034 +#endif
92035 +
92036 retval = 0;
92037 pte_unmap_unlock(pte, ptl);
92038 return retval;
92039 @@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92040 if (!page_count(page))
92041 return -EINVAL;
92042 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92043 +
92044 +#ifdef CONFIG_PAX_SEGMEXEC
92045 + struct vm_area_struct *vma_m;
92046 +#endif
92047 +
92048 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92049 BUG_ON(vma->vm_flags & VM_PFNMAP);
92050 vma->vm_flags |= VM_MIXEDMAP;
92051 +
92052 +#ifdef CONFIG_PAX_SEGMEXEC
92053 + vma_m = pax_find_mirror_vma(vma);
92054 + if (vma_m)
92055 + vma_m->vm_flags |= VM_MIXEDMAP;
92056 +#endif
92057 +
92058 }
92059 return insert_page(vma, addr, page, vma->vm_page_prot);
92060 }
92061 @@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92062 unsigned long pfn)
92063 {
92064 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92065 + BUG_ON(vma->vm_mirror);
92066
92067 if (addr < vma->vm_start || addr >= vma->vm_end)
92068 return -EFAULT;
92069 @@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92070
92071 BUG_ON(pud_huge(*pud));
92072
92073 - pmd = pmd_alloc(mm, pud, addr);
92074 + pmd = (mm == &init_mm) ?
92075 + pmd_alloc_kernel(mm, pud, addr) :
92076 + pmd_alloc(mm, pud, addr);
92077 if (!pmd)
92078 return -ENOMEM;
92079 do {
92080 @@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92081 unsigned long next;
92082 int err;
92083
92084 - pud = pud_alloc(mm, pgd, addr);
92085 + pud = (mm == &init_mm) ?
92086 + pud_alloc_kernel(mm, pgd, addr) :
92087 + pud_alloc(mm, pgd, addr);
92088 if (!pud)
92089 return -ENOMEM;
92090 do {
92091 @@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92092 copy_user_highpage(dst, src, va, vma);
92093 }
92094
92095 +#ifdef CONFIG_PAX_SEGMEXEC
92096 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92097 +{
92098 + struct mm_struct *mm = vma->vm_mm;
92099 + spinlock_t *ptl;
92100 + pte_t *pte, entry;
92101 +
92102 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92103 + entry = *pte;
92104 + if (!pte_present(entry)) {
92105 + if (!pte_none(entry)) {
92106 + BUG_ON(pte_file(entry));
92107 + free_swap_and_cache(pte_to_swp_entry(entry));
92108 + pte_clear_not_present_full(mm, address, pte, 0);
92109 + }
92110 + } else {
92111 + struct page *page;
92112 +
92113 + flush_cache_page(vma, address, pte_pfn(entry));
92114 + entry = ptep_clear_flush(vma, address, pte);
92115 + BUG_ON(pte_dirty(entry));
92116 + page = vm_normal_page(vma, address, entry);
92117 + if (page) {
92118 + update_hiwater_rss(mm);
92119 + if (PageAnon(page))
92120 + dec_mm_counter_fast(mm, MM_ANONPAGES);
92121 + else
92122 + dec_mm_counter_fast(mm, MM_FILEPAGES);
92123 + page_remove_rmap(page);
92124 + page_cache_release(page);
92125 + }
92126 + }
92127 + pte_unmap_unlock(pte, ptl);
92128 +}
92129 +
92130 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
92131 + *
92132 + * the ptl of the lower mapped page is held on entry and is not released on exit
92133 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92134 + */
92135 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92136 +{
92137 + struct mm_struct *mm = vma->vm_mm;
92138 + unsigned long address_m;
92139 + spinlock_t *ptl_m;
92140 + struct vm_area_struct *vma_m;
92141 + pmd_t *pmd_m;
92142 + pte_t *pte_m, entry_m;
92143 +
92144 + BUG_ON(!page_m || !PageAnon(page_m));
92145 +
92146 + vma_m = pax_find_mirror_vma(vma);
92147 + if (!vma_m)
92148 + return;
92149 +
92150 + BUG_ON(!PageLocked(page_m));
92151 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92152 + address_m = address + SEGMEXEC_TASK_SIZE;
92153 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92154 + pte_m = pte_offset_map(pmd_m, address_m);
92155 + ptl_m = pte_lockptr(mm, pmd_m);
92156 + if (ptl != ptl_m) {
92157 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92158 + if (!pte_none(*pte_m))
92159 + goto out;
92160 + }
92161 +
92162 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92163 + page_cache_get(page_m);
92164 + page_add_anon_rmap(page_m, vma_m, address_m);
92165 + inc_mm_counter_fast(mm, MM_ANONPAGES);
92166 + set_pte_at(mm, address_m, pte_m, entry_m);
92167 + update_mmu_cache(vma_m, address_m, pte_m);
92168 +out:
92169 + if (ptl != ptl_m)
92170 + spin_unlock(ptl_m);
92171 + pte_unmap(pte_m);
92172 + unlock_page(page_m);
92173 +}
92174 +
92175 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92176 +{
92177 + struct mm_struct *mm = vma->vm_mm;
92178 + unsigned long address_m;
92179 + spinlock_t *ptl_m;
92180 + struct vm_area_struct *vma_m;
92181 + pmd_t *pmd_m;
92182 + pte_t *pte_m, entry_m;
92183 +
92184 + BUG_ON(!page_m || PageAnon(page_m));
92185 +
92186 + vma_m = pax_find_mirror_vma(vma);
92187 + if (!vma_m)
92188 + return;
92189 +
92190 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92191 + address_m = address + SEGMEXEC_TASK_SIZE;
92192 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92193 + pte_m = pte_offset_map(pmd_m, address_m);
92194 + ptl_m = pte_lockptr(mm, pmd_m);
92195 + if (ptl != ptl_m) {
92196 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92197 + if (!pte_none(*pte_m))
92198 + goto out;
92199 + }
92200 +
92201 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92202 + page_cache_get(page_m);
92203 + page_add_file_rmap(page_m);
92204 + inc_mm_counter_fast(mm, MM_FILEPAGES);
92205 + set_pte_at(mm, address_m, pte_m, entry_m);
92206 + update_mmu_cache(vma_m, address_m, pte_m);
92207 +out:
92208 + if (ptl != ptl_m)
92209 + spin_unlock(ptl_m);
92210 + pte_unmap(pte_m);
92211 +}
92212 +
92213 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92214 +{
92215 + struct mm_struct *mm = vma->vm_mm;
92216 + unsigned long address_m;
92217 + spinlock_t *ptl_m;
92218 + struct vm_area_struct *vma_m;
92219 + pmd_t *pmd_m;
92220 + pte_t *pte_m, entry_m;
92221 +
92222 + vma_m = pax_find_mirror_vma(vma);
92223 + if (!vma_m)
92224 + return;
92225 +
92226 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92227 + address_m = address + SEGMEXEC_TASK_SIZE;
92228 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92229 + pte_m = pte_offset_map(pmd_m, address_m);
92230 + ptl_m = pte_lockptr(mm, pmd_m);
92231 + if (ptl != ptl_m) {
92232 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92233 + if (!pte_none(*pte_m))
92234 + goto out;
92235 + }
92236 +
92237 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92238 + set_pte_at(mm, address_m, pte_m, entry_m);
92239 +out:
92240 + if (ptl != ptl_m)
92241 + spin_unlock(ptl_m);
92242 + pte_unmap(pte_m);
92243 +}
92244 +
92245 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92246 +{
92247 + struct page *page_m;
92248 + pte_t entry;
92249 +
92250 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92251 + goto out;
92252 +
92253 + entry = *pte;
92254 + page_m = vm_normal_page(vma, address, entry);
92255 + if (!page_m)
92256 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92257 + else if (PageAnon(page_m)) {
92258 + if (pax_find_mirror_vma(vma)) {
92259 + pte_unmap_unlock(pte, ptl);
92260 + lock_page(page_m);
92261 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92262 + if (pte_same(entry, *pte))
92263 + pax_mirror_anon_pte(vma, address, page_m, ptl);
92264 + else
92265 + unlock_page(page_m);
92266 + }
92267 + } else
92268 + pax_mirror_file_pte(vma, address, page_m, ptl);
92269 +
92270 +out:
92271 + pte_unmap_unlock(pte, ptl);
92272 +}
92273 +#endif
92274 +
92275 /*
92276 * This routine handles present pages, when users try to write
92277 * to a shared page. It is done by copying the page to a new address
92278 @@ -2810,6 +3011,12 @@ gotten:
92279 */
92280 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92281 if (likely(pte_same(*page_table, orig_pte))) {
92282 +
92283 +#ifdef CONFIG_PAX_SEGMEXEC
92284 + if (pax_find_mirror_vma(vma))
92285 + BUG_ON(!trylock_page(new_page));
92286 +#endif
92287 +
92288 if (old_page) {
92289 if (!PageAnon(old_page)) {
92290 dec_mm_counter_fast(mm, MM_FILEPAGES);
92291 @@ -2861,6 +3068,10 @@ gotten:
92292 page_remove_rmap(old_page);
92293 }
92294
92295 +#ifdef CONFIG_PAX_SEGMEXEC
92296 + pax_mirror_anon_pte(vma, address, new_page, ptl);
92297 +#endif
92298 +
92299 /* Free the old page.. */
92300 new_page = old_page;
92301 ret |= VM_FAULT_WRITE;
92302 @@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92303 swap_free(entry);
92304 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92305 try_to_free_swap(page);
92306 +
92307 +#ifdef CONFIG_PAX_SEGMEXEC
92308 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92309 +#endif
92310 +
92311 unlock_page(page);
92312 if (page != swapcache) {
92313 /*
92314 @@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92315
92316 /* No need to invalidate - it was non-present before */
92317 update_mmu_cache(vma, address, page_table);
92318 +
92319 +#ifdef CONFIG_PAX_SEGMEXEC
92320 + pax_mirror_anon_pte(vma, address, page, ptl);
92321 +#endif
92322 +
92323 unlock:
92324 pte_unmap_unlock(page_table, ptl);
92325 out:
92326 @@ -3180,40 +3401,6 @@ out_release:
92327 }
92328
92329 /*
92330 - * This is like a special single-page "expand_{down|up}wards()",
92331 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
92332 - * doesn't hit another vma.
92333 - */
92334 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92335 -{
92336 - address &= PAGE_MASK;
92337 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92338 - struct vm_area_struct *prev = vma->vm_prev;
92339 -
92340 - /*
92341 - * Is there a mapping abutting this one below?
92342 - *
92343 - * That's only ok if it's the same stack mapping
92344 - * that has gotten split..
92345 - */
92346 - if (prev && prev->vm_end == address)
92347 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92348 -
92349 - expand_downwards(vma, address - PAGE_SIZE);
92350 - }
92351 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92352 - struct vm_area_struct *next = vma->vm_next;
92353 -
92354 - /* As VM_GROWSDOWN but s/below/above/ */
92355 - if (next && next->vm_start == address + PAGE_SIZE)
92356 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92357 -
92358 - expand_upwards(vma, address + PAGE_SIZE);
92359 - }
92360 - return 0;
92361 -}
92362 -
92363 -/*
92364 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92365 * but allow concurrent faults), and pte mapped but not yet locked.
92366 * We return with mmap_sem still held, but pte unmapped and unlocked.
92367 @@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92368 unsigned long address, pte_t *page_table, pmd_t *pmd,
92369 unsigned int flags)
92370 {
92371 - struct page *page;
92372 + struct page *page = NULL;
92373 spinlock_t *ptl;
92374 pte_t entry;
92375
92376 - pte_unmap(page_table);
92377 -
92378 - /* Check if we need to add a guard page to the stack */
92379 - if (check_stack_guard_page(vma, address) < 0)
92380 - return VM_FAULT_SIGBUS;
92381 -
92382 - /* Use the zero-page for reads */
92383 if (!(flags & FAULT_FLAG_WRITE)) {
92384 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92385 vma->vm_page_prot));
92386 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92387 + ptl = pte_lockptr(mm, pmd);
92388 + spin_lock(ptl);
92389 if (!pte_none(*page_table))
92390 goto unlock;
92391 goto setpte;
92392 }
92393
92394 /* Allocate our own private page. */
92395 + pte_unmap(page_table);
92396 +
92397 if (unlikely(anon_vma_prepare(vma)))
92398 goto oom;
92399 page = alloc_zeroed_user_highpage_movable(vma, address);
92400 @@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92401 if (!pte_none(*page_table))
92402 goto release;
92403
92404 +#ifdef CONFIG_PAX_SEGMEXEC
92405 + if (pax_find_mirror_vma(vma))
92406 + BUG_ON(!trylock_page(page));
92407 +#endif
92408 +
92409 inc_mm_counter_fast(mm, MM_ANONPAGES);
92410 page_add_new_anon_rmap(page, vma, address);
92411 setpte:
92412 @@ -3273,6 +3461,12 @@ setpte:
92413
92414 /* No need to invalidate - it was non-present before */
92415 update_mmu_cache(vma, address, page_table);
92416 +
92417 +#ifdef CONFIG_PAX_SEGMEXEC
92418 + if (page)
92419 + pax_mirror_anon_pte(vma, address, page, ptl);
92420 +#endif
92421 +
92422 unlock:
92423 pte_unmap_unlock(page_table, ptl);
92424 return 0;
92425 @@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92426 */
92427 /* Only go through if we didn't race with anybody else... */
92428 if (likely(pte_same(*page_table, orig_pte))) {
92429 +
92430 +#ifdef CONFIG_PAX_SEGMEXEC
92431 + if (anon && pax_find_mirror_vma(vma))
92432 + BUG_ON(!trylock_page(page));
92433 +#endif
92434 +
92435 flush_icache_page(vma, page);
92436 entry = mk_pte(page, vma->vm_page_prot);
92437 if (flags & FAULT_FLAG_WRITE)
92438 @@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92439
92440 /* no need to invalidate: a not-present page won't be cached */
92441 update_mmu_cache(vma, address, page_table);
92442 +
92443 +#ifdef CONFIG_PAX_SEGMEXEC
92444 + if (anon)
92445 + pax_mirror_anon_pte(vma, address, page, ptl);
92446 + else
92447 + pax_mirror_file_pte(vma, address, page, ptl);
92448 +#endif
92449 +
92450 } else {
92451 if (cow_page)
92452 mem_cgroup_uncharge_page(cow_page);
92453 @@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92454 if (flags & FAULT_FLAG_WRITE)
92455 flush_tlb_fix_spurious_fault(vma, address);
92456 }
92457 +
92458 +#ifdef CONFIG_PAX_SEGMEXEC
92459 + pax_mirror_pte(vma, address, pte, pmd, ptl);
92460 + return 0;
92461 +#endif
92462 +
92463 unlock:
92464 pte_unmap_unlock(pte, ptl);
92465 return 0;
92466 @@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92467 pmd_t *pmd;
92468 pte_t *pte;
92469
92470 +#ifdef CONFIG_PAX_SEGMEXEC
92471 + struct vm_area_struct *vma_m;
92472 +#endif
92473 +
92474 if (unlikely(is_vm_hugetlb_page(vma)))
92475 return hugetlb_fault(mm, vma, address, flags);
92476
92477 +#ifdef CONFIG_PAX_SEGMEXEC
92478 + vma_m = pax_find_mirror_vma(vma);
92479 + if (vma_m) {
92480 + unsigned long address_m;
92481 + pgd_t *pgd_m;
92482 + pud_t *pud_m;
92483 + pmd_t *pmd_m;
92484 +
92485 + if (vma->vm_start > vma_m->vm_start) {
92486 + address_m = address;
92487 + address -= SEGMEXEC_TASK_SIZE;
92488 + vma = vma_m;
92489 + } else
92490 + address_m = address + SEGMEXEC_TASK_SIZE;
92491 +
92492 + pgd_m = pgd_offset(mm, address_m);
92493 + pud_m = pud_alloc(mm, pgd_m, address_m);
92494 + if (!pud_m)
92495 + return VM_FAULT_OOM;
92496 + pmd_m = pmd_alloc(mm, pud_m, address_m);
92497 + if (!pmd_m)
92498 + return VM_FAULT_OOM;
92499 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92500 + return VM_FAULT_OOM;
92501 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92502 + }
92503 +#endif
92504 +
92505 pgd = pgd_offset(mm, address);
92506 pud = pud_alloc(mm, pgd, address);
92507 if (!pud)
92508 @@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92509 spin_unlock(&mm->page_table_lock);
92510 return 0;
92511 }
92512 +
92513 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92514 +{
92515 + pud_t *new = pud_alloc_one(mm, address);
92516 + if (!new)
92517 + return -ENOMEM;
92518 +
92519 + smp_wmb(); /* See comment in __pte_alloc */
92520 +
92521 + spin_lock(&mm->page_table_lock);
92522 + if (pgd_present(*pgd)) /* Another has populated it */
92523 + pud_free(mm, new);
92524 + else
92525 + pgd_populate_kernel(mm, pgd, new);
92526 + spin_unlock(&mm->page_table_lock);
92527 + return 0;
92528 +}
92529 #endif /* __PAGETABLE_PUD_FOLDED */
92530
92531 #ifndef __PAGETABLE_PMD_FOLDED
92532 @@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92533 spin_unlock(&mm->page_table_lock);
92534 return 0;
92535 }
92536 +
92537 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92538 +{
92539 + pmd_t *new = pmd_alloc_one(mm, address);
92540 + if (!new)
92541 + return -ENOMEM;
92542 +
92543 + smp_wmb(); /* See comment in __pte_alloc */
92544 +
92545 + spin_lock(&mm->page_table_lock);
92546 +#ifndef __ARCH_HAS_4LEVEL_HACK
92547 + if (pud_present(*pud)) /* Another has populated it */
92548 + pmd_free(mm, new);
92549 + else
92550 + pud_populate_kernel(mm, pud, new);
92551 +#else
92552 + if (pgd_present(*pud)) /* Another has populated it */
92553 + pmd_free(mm, new);
92554 + else
92555 + pgd_populate_kernel(mm, pud, new);
92556 +#endif /* __ARCH_HAS_4LEVEL_HACK */
92557 + spin_unlock(&mm->page_table_lock);
92558 + return 0;
92559 +}
92560 #endif /* __PAGETABLE_PMD_FOLDED */
92561
92562 #if !defined(__HAVE_ARCH_GATE_AREA)
92563 @@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
92564 gate_vma.vm_start = FIXADDR_USER_START;
92565 gate_vma.vm_end = FIXADDR_USER_END;
92566 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92567 - gate_vma.vm_page_prot = __P101;
92568 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92569
92570 return 0;
92571 }
92572 @@ -4011,8 +4298,8 @@ out:
92573 return ret;
92574 }
92575
92576 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92577 - void *buf, int len, int write)
92578 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92579 + void *buf, size_t len, int write)
92580 {
92581 resource_size_t phys_addr;
92582 unsigned long prot = 0;
92583 @@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92584 * Access another process' address space as given in mm. If non-NULL, use the
92585 * given task for page fault accounting.
92586 */
92587 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92588 - unsigned long addr, void *buf, int len, int write)
92589 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92590 + unsigned long addr, void *buf, size_t len, int write)
92591 {
92592 struct vm_area_struct *vma;
92593 void *old_buf = buf;
92594 @@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92595 down_read(&mm->mmap_sem);
92596 /* ignore errors, just check how much was successfully transferred */
92597 while (len) {
92598 - int bytes, ret, offset;
92599 + ssize_t bytes, ret, offset;
92600 void *maddr;
92601 struct page *page = NULL;
92602
92603 @@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92604 *
92605 * The caller must hold a reference on @mm.
92606 */
92607 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92608 - void *buf, int len, int write)
92609 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92610 + void *buf, size_t len, int write)
92611 {
92612 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92613 }
92614 @@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92615 * Source/target buffer must be kernel space,
92616 * Do not walk the page table directly, use get_user_pages
92617 */
92618 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
92619 - void *buf, int len, int write)
92620 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92621 + void *buf, size_t len, int write)
92622 {
92623 struct mm_struct *mm;
92624 - int ret;
92625 + ssize_t ret;
92626
92627 mm = get_task_mm(tsk);
92628 if (!mm)
92629 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92630 index ae3c8f3..fa4ee8e 100644
92631 --- a/mm/mempolicy.c
92632 +++ b/mm/mempolicy.c
92633 @@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92634 unsigned long vmstart;
92635 unsigned long vmend;
92636
92637 +#ifdef CONFIG_PAX_SEGMEXEC
92638 + struct vm_area_struct *vma_m;
92639 +#endif
92640 +
92641 vma = find_vma(mm, start);
92642 if (!vma || vma->vm_start > start)
92643 return -EFAULT;
92644 @@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92645 err = vma_replace_policy(vma, new_pol);
92646 if (err)
92647 goto out;
92648 +
92649 +#ifdef CONFIG_PAX_SEGMEXEC
92650 + vma_m = pax_find_mirror_vma(vma);
92651 + if (vma_m) {
92652 + err = vma_replace_policy(vma_m, new_pol);
92653 + if (err)
92654 + goto out;
92655 + }
92656 +#endif
92657 +
92658 }
92659
92660 out:
92661 @@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92662
92663 if (end < start)
92664 return -EINVAL;
92665 +
92666 +#ifdef CONFIG_PAX_SEGMEXEC
92667 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92668 + if (end > SEGMEXEC_TASK_SIZE)
92669 + return -EINVAL;
92670 + } else
92671 +#endif
92672 +
92673 + if (end > TASK_SIZE)
92674 + return -EINVAL;
92675 +
92676 if (end == start)
92677 return 0;
92678
92679 @@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92680 */
92681 tcred = __task_cred(task);
92682 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92683 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92684 - !capable(CAP_SYS_NICE)) {
92685 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92686 rcu_read_unlock();
92687 err = -EPERM;
92688 goto out_put;
92689 @@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92690 goto out;
92691 }
92692
92693 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92694 + if (mm != current->mm &&
92695 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92696 + mmput(mm);
92697 + err = -EPERM;
92698 + goto out;
92699 + }
92700 +#endif
92701 +
92702 err = do_migrate_pages(mm, old, new,
92703 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92704
92705 diff --git a/mm/migrate.c b/mm/migrate.c
92706 index bed4880..a493f67 100644
92707 --- a/mm/migrate.c
92708 +++ b/mm/migrate.c
92709 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92710 */
92711 tcred = __task_cred(task);
92712 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92713 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92714 - !capable(CAP_SYS_NICE)) {
92715 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92716 rcu_read_unlock();
92717 err = -EPERM;
92718 goto out;
92719 diff --git a/mm/mlock.c b/mm/mlock.c
92720 index 4e1a6816..9683079 100644
92721 --- a/mm/mlock.c
92722 +++ b/mm/mlock.c
92723 @@ -14,6 +14,7 @@
92724 #include <linux/pagevec.h>
92725 #include <linux/mempolicy.h>
92726 #include <linux/syscalls.h>
92727 +#include <linux/security.h>
92728 #include <linux/sched.h>
92729 #include <linux/export.h>
92730 #include <linux/rmap.h>
92731 @@ -604,7 +605,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92732 {
92733 unsigned long nstart, end, tmp;
92734 struct vm_area_struct * vma, * prev;
92735 - int error;
92736 + int error = 0;
92737
92738 VM_BUG_ON(start & ~PAGE_MASK);
92739 VM_BUG_ON(len != PAGE_ALIGN(len));
92740 @@ -613,6 +614,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92741 return -EINVAL;
92742 if (end == start)
92743 return 0;
92744 + if (end > TASK_SIZE)
92745 + return -EINVAL;
92746 +
92747 vma = find_vma(current->mm, start);
92748 if (!vma || vma->vm_start > start)
92749 return -ENOMEM;
92750 @@ -624,6 +628,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92751 for (nstart = start ; ; ) {
92752 vm_flags_t newflags;
92753
92754 +#ifdef CONFIG_PAX_SEGMEXEC
92755 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92756 + break;
92757 +#endif
92758 +
92759 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92760
92761 newflags = vma->vm_flags & ~VM_LOCKED;
92762 @@ -737,6 +746,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92763 locked += current->mm->locked_vm;
92764
92765 /* check against resource limits */
92766 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92767 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92768 error = do_mlock(start, len, 1);
92769
92770 @@ -774,6 +784,11 @@ static int do_mlockall(int flags)
92771 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92772 vm_flags_t newflags;
92773
92774 +#ifdef CONFIG_PAX_SEGMEXEC
92775 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92776 + break;
92777 +#endif
92778 +
92779 newflags = vma->vm_flags & ~VM_LOCKED;
92780 if (flags & MCL_CURRENT)
92781 newflags |= VM_LOCKED;
92782 @@ -805,8 +820,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92783 lock_limit >>= PAGE_SHIFT;
92784
92785 ret = -ENOMEM;
92786 +
92787 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92788 +
92789 down_write(&current->mm->mmap_sem);
92790 -
92791 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92792 capable(CAP_IPC_LOCK))
92793 ret = do_mlockall(flags);
92794 diff --git a/mm/mmap.c b/mm/mmap.c
92795 index 20ff0c3..a9eda98 100644
92796 --- a/mm/mmap.c
92797 +++ b/mm/mmap.c
92798 @@ -36,6 +36,7 @@
92799 #include <linux/sched/sysctl.h>
92800 #include <linux/notifier.h>
92801 #include <linux/memory.h>
92802 +#include <linux/random.h>
92803
92804 #include <asm/uaccess.h>
92805 #include <asm/cacheflush.h>
92806 @@ -52,6 +53,16 @@
92807 #define arch_rebalance_pgtables(addr, len) (addr)
92808 #endif
92809
92810 +static inline void verify_mm_writelocked(struct mm_struct *mm)
92811 +{
92812 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92813 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92814 + up_read(&mm->mmap_sem);
92815 + BUG();
92816 + }
92817 +#endif
92818 +}
92819 +
92820 static void unmap_region(struct mm_struct *mm,
92821 struct vm_area_struct *vma, struct vm_area_struct *prev,
92822 unsigned long start, unsigned long end);
92823 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92824 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92825 *
92826 */
92827 -pgprot_t protection_map[16] = {
92828 +pgprot_t protection_map[16] __read_only = {
92829 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92830 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92831 };
92832
92833 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
92834 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92835 {
92836 - return __pgprot(pgprot_val(protection_map[vm_flags &
92837 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92838 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92839 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92840 +
92841 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92842 + if (!(__supported_pte_mask & _PAGE_NX) &&
92843 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92844 + (vm_flags & (VM_READ | VM_WRITE)))
92845 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92846 +#endif
92847 +
92848 + return prot;
92849 }
92850 EXPORT_SYMBOL(vm_get_page_prot);
92851
92852 @@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
92853 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92854 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92855 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92856 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92857 /*
92858 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92859 * other variables. It can be updated by several CPUs frequently.
92860 @@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92861 struct vm_area_struct *next = vma->vm_next;
92862
92863 might_sleep();
92864 + BUG_ON(vma->vm_mirror);
92865 if (vma->vm_ops && vma->vm_ops->close)
92866 vma->vm_ops->close(vma);
92867 if (vma->vm_file)
92868 @@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92869 * not page aligned -Ram Gupta
92870 */
92871 rlim = rlimit(RLIMIT_DATA);
92872 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92873 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92874 (mm->end_data - mm->start_data) > rlim)
92875 goto out;
92876 @@ -940,6 +963,12 @@ static int
92877 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92878 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92879 {
92880 +
92881 +#ifdef CONFIG_PAX_SEGMEXEC
92882 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92883 + return 0;
92884 +#endif
92885 +
92886 if (is_mergeable_vma(vma, file, vm_flags) &&
92887 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92888 if (vma->vm_pgoff == vm_pgoff)
92889 @@ -959,6 +988,12 @@ static int
92890 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92891 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92892 {
92893 +
92894 +#ifdef CONFIG_PAX_SEGMEXEC
92895 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92896 + return 0;
92897 +#endif
92898 +
92899 if (is_mergeable_vma(vma, file, vm_flags) &&
92900 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92901 pgoff_t vm_pglen;
92902 @@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92903 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92904 struct vm_area_struct *prev, unsigned long addr,
92905 unsigned long end, unsigned long vm_flags,
92906 - struct anon_vma *anon_vma, struct file *file,
92907 + struct anon_vma *anon_vma, struct file *file,
92908 pgoff_t pgoff, struct mempolicy *policy)
92909 {
92910 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92911 struct vm_area_struct *area, *next;
92912 int err;
92913
92914 +#ifdef CONFIG_PAX_SEGMEXEC
92915 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92916 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92917 +
92918 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92919 +#endif
92920 +
92921 /*
92922 * We later require that vma->vm_flags == vm_flags,
92923 * so this tests vma->vm_flags & VM_SPECIAL, too.
92924 @@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92925 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92926 next = next->vm_next;
92927
92928 +#ifdef CONFIG_PAX_SEGMEXEC
92929 + if (prev)
92930 + prev_m = pax_find_mirror_vma(prev);
92931 + if (area)
92932 + area_m = pax_find_mirror_vma(area);
92933 + if (next)
92934 + next_m = pax_find_mirror_vma(next);
92935 +#endif
92936 +
92937 /*
92938 * Can it merge with the predecessor?
92939 */
92940 @@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92941 /* cases 1, 6 */
92942 err = vma_adjust(prev, prev->vm_start,
92943 next->vm_end, prev->vm_pgoff, NULL);
92944 - } else /* cases 2, 5, 7 */
92945 +
92946 +#ifdef CONFIG_PAX_SEGMEXEC
92947 + if (!err && prev_m)
92948 + err = vma_adjust(prev_m, prev_m->vm_start,
92949 + next_m->vm_end, prev_m->vm_pgoff, NULL);
92950 +#endif
92951 +
92952 + } else { /* cases 2, 5, 7 */
92953 err = vma_adjust(prev, prev->vm_start,
92954 end, prev->vm_pgoff, NULL);
92955 +
92956 +#ifdef CONFIG_PAX_SEGMEXEC
92957 + if (!err && prev_m)
92958 + err = vma_adjust(prev_m, prev_m->vm_start,
92959 + end_m, prev_m->vm_pgoff, NULL);
92960 +#endif
92961 +
92962 + }
92963 if (err)
92964 return NULL;
92965 khugepaged_enter_vma_merge(prev);
92966 @@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92967 mpol_equal(policy, vma_policy(next)) &&
92968 can_vma_merge_before(next, vm_flags,
92969 anon_vma, file, pgoff+pglen)) {
92970 - if (prev && addr < prev->vm_end) /* case 4 */
92971 + if (prev && addr < prev->vm_end) { /* case 4 */
92972 err = vma_adjust(prev, prev->vm_start,
92973 addr, prev->vm_pgoff, NULL);
92974 - else /* cases 3, 8 */
92975 +
92976 +#ifdef CONFIG_PAX_SEGMEXEC
92977 + if (!err && prev_m)
92978 + err = vma_adjust(prev_m, prev_m->vm_start,
92979 + addr_m, prev_m->vm_pgoff, NULL);
92980 +#endif
92981 +
92982 + } else { /* cases 3, 8 */
92983 err = vma_adjust(area, addr, next->vm_end,
92984 next->vm_pgoff - pglen, NULL);
92985 +
92986 +#ifdef CONFIG_PAX_SEGMEXEC
92987 + if (!err && area_m)
92988 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
92989 + next_m->vm_pgoff - pglen, NULL);
92990 +#endif
92991 +
92992 + }
92993 if (err)
92994 return NULL;
92995 khugepaged_enter_vma_merge(area);
92996 @@ -1172,8 +1253,10 @@ none:
92997 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92998 struct file *file, long pages)
92999 {
93000 - const unsigned long stack_flags
93001 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93002 +
93003 +#ifdef CONFIG_PAX_RANDMMAP
93004 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93005 +#endif
93006
93007 mm->total_vm += pages;
93008
93009 @@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93010 mm->shared_vm += pages;
93011 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93012 mm->exec_vm += pages;
93013 - } else if (flags & stack_flags)
93014 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93015 mm->stack_vm += pages;
93016 }
93017 #endif /* CONFIG_PROC_FS */
93018 @@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93019 locked += mm->locked_vm;
93020 lock_limit = rlimit(RLIMIT_MEMLOCK);
93021 lock_limit >>= PAGE_SHIFT;
93022 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93023 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93024 return -EAGAIN;
93025 }
93026 @@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93027 * (the exception is when the underlying filesystem is noexec
93028 * mounted, in which case we dont add PROT_EXEC.)
93029 */
93030 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93031 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93032 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93033 prot |= PROT_EXEC;
93034
93035 @@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93036 /* Obtain the address to map to. we verify (or select) it and ensure
93037 * that it represents a valid section of the address space.
93038 */
93039 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
93040 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93041 if (addr & ~PAGE_MASK)
93042 return addr;
93043
93044 @@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93045 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93046 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93047
93048 +#ifdef CONFIG_PAX_MPROTECT
93049 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93050 +
93051 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93052 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93053 + mm->binfmt->handle_mmap)
93054 + mm->binfmt->handle_mmap(file);
93055 +#endif
93056 +
93057 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93058 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93059 + gr_log_rwxmmap(file);
93060 +
93061 +#ifdef CONFIG_PAX_EMUPLT
93062 + vm_flags &= ~VM_EXEC;
93063 +#else
93064 + return -EPERM;
93065 +#endif
93066 +
93067 + }
93068 +
93069 + if (!(vm_flags & VM_EXEC))
93070 + vm_flags &= ~VM_MAYEXEC;
93071 +#else
93072 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93073 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93074 +#endif
93075 + else
93076 + vm_flags &= ~VM_MAYWRITE;
93077 + }
93078 +#endif
93079 +
93080 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93081 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93082 + vm_flags &= ~VM_PAGEEXEC;
93083 +#endif
93084 +
93085 if (flags & MAP_LOCKED)
93086 if (!can_do_mlock())
93087 return -EPERM;
93088 @@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93089 vm_flags |= VM_NORESERVE;
93090 }
93091
93092 + if (!gr_acl_handle_mmap(file, prot))
93093 + return -EACCES;
93094 +
93095 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93096 if (!IS_ERR_VALUE(addr) &&
93097 ((vm_flags & VM_LOCKED) ||
93098 @@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93099 vm_flags_t vm_flags = vma->vm_flags;
93100
93101 /* If it was private or non-writable, the write bit is already clear */
93102 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93103 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93104 return 0;
93105
93106 /* The backer wishes to know when pages are first written to? */
93107 @@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93108 struct rb_node **rb_link, *rb_parent;
93109 unsigned long charged = 0;
93110
93111 +#ifdef CONFIG_PAX_SEGMEXEC
93112 + struct vm_area_struct *vma_m = NULL;
93113 +#endif
93114 +
93115 + /*
93116 + * mm->mmap_sem is required to protect against another thread
93117 + * changing the mappings in case we sleep.
93118 + */
93119 + verify_mm_writelocked(mm);
93120 +
93121 /* Check against address space limit. */
93122 +
93123 +#ifdef CONFIG_PAX_RANDMMAP
93124 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93125 +#endif
93126 +
93127 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93128 unsigned long nr_pages;
93129
93130 @@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93131
93132 /* Clear old maps */
93133 error = -ENOMEM;
93134 -munmap_back:
93135 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93136 if (do_munmap(mm, addr, len))
93137 return -ENOMEM;
93138 - goto munmap_back;
93139 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93140 }
93141
93142 /*
93143 @@ -1554,6 +1692,16 @@ munmap_back:
93144 goto unacct_error;
93145 }
93146
93147 +#ifdef CONFIG_PAX_SEGMEXEC
93148 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93149 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93150 + if (!vma_m) {
93151 + error = -ENOMEM;
93152 + goto free_vma;
93153 + }
93154 + }
93155 +#endif
93156 +
93157 vma->vm_mm = mm;
93158 vma->vm_start = addr;
93159 vma->vm_end = addr + len;
93160 @@ -1573,6 +1721,13 @@ munmap_back:
93161 if (error)
93162 goto unmap_and_free_vma;
93163
93164 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93165 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93166 + vma->vm_flags |= VM_PAGEEXEC;
93167 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93168 + }
93169 +#endif
93170 +
93171 /* Can addr have changed??
93172 *
93173 * Answer: Yes, several device drivers can do it in their
93174 @@ -1606,6 +1761,12 @@ munmap_back:
93175 }
93176
93177 vma_link(mm, vma, prev, rb_link, rb_parent);
93178 +
93179 +#ifdef CONFIG_PAX_SEGMEXEC
93180 + if (vma_m)
93181 + BUG_ON(pax_mirror_vma(vma_m, vma));
93182 +#endif
93183 +
93184 /* Once vma denies write, undo our temporary denial count */
93185 if (vm_flags & VM_DENYWRITE)
93186 allow_write_access(file);
93187 @@ -1614,6 +1775,7 @@ out:
93188 perf_event_mmap(vma);
93189
93190 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93191 + track_exec_limit(mm, addr, addr + len, vm_flags);
93192 if (vm_flags & VM_LOCKED) {
93193 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93194 vma == get_gate_vma(current->mm)))
93195 @@ -1646,6 +1808,12 @@ unmap_and_free_vma:
93196 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93197 charged = 0;
93198 free_vma:
93199 +
93200 +#ifdef CONFIG_PAX_SEGMEXEC
93201 + if (vma_m)
93202 + kmem_cache_free(vm_area_cachep, vma_m);
93203 +#endif
93204 +
93205 kmem_cache_free(vm_area_cachep, vma);
93206 unacct_error:
93207 if (charged)
93208 @@ -1653,7 +1821,63 @@ unacct_error:
93209 return error;
93210 }
93211
93212 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93213 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93214 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93215 +{
93216 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93217 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93218 +
93219 + return 0;
93220 +}
93221 +#endif
93222 +
93223 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93224 +{
93225 + if (!vma) {
93226 +#ifdef CONFIG_STACK_GROWSUP
93227 + if (addr > sysctl_heap_stack_gap)
93228 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93229 + else
93230 + vma = find_vma(current->mm, 0);
93231 + if (vma && (vma->vm_flags & VM_GROWSUP))
93232 + return false;
93233 +#endif
93234 + return true;
93235 + }
93236 +
93237 + if (addr + len > vma->vm_start)
93238 + return false;
93239 +
93240 + if (vma->vm_flags & VM_GROWSDOWN)
93241 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93242 +#ifdef CONFIG_STACK_GROWSUP
93243 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93244 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93245 +#endif
93246 + else if (offset)
93247 + return offset <= vma->vm_start - addr - len;
93248 +
93249 + return true;
93250 +}
93251 +
93252 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93253 +{
93254 + if (vma->vm_start < len)
93255 + return -ENOMEM;
93256 +
93257 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
93258 + if (offset <= vma->vm_start - len)
93259 + return vma->vm_start - len - offset;
93260 + else
93261 + return -ENOMEM;
93262 + }
93263 +
93264 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
93265 + return vma->vm_start - len - sysctl_heap_stack_gap;
93266 + return -ENOMEM;
93267 +}
93268 +
93269 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93270 {
93271 /*
93272 * We implement the search by looking for an rbtree node that
93273 @@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93274 }
93275 }
93276
93277 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93278 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93279 check_current:
93280 /* Check if current node has a suitable gap */
93281 if (gap_start > high_limit)
93282 return -ENOMEM;
93283 +
93284 + if (gap_end - gap_start > info->threadstack_offset)
93285 + gap_start += info->threadstack_offset;
93286 + else
93287 + gap_start = gap_end;
93288 +
93289 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93290 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93291 + gap_start += sysctl_heap_stack_gap;
93292 + else
93293 + gap_start = gap_end;
93294 + }
93295 + if (vma->vm_flags & VM_GROWSDOWN) {
93296 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93297 + gap_end -= sysctl_heap_stack_gap;
93298 + else
93299 + gap_end = gap_start;
93300 + }
93301 if (gap_end >= low_limit && gap_end - gap_start >= length)
93302 goto found;
93303
93304 @@ -1755,7 +1997,7 @@ found:
93305 return gap_start;
93306 }
93307
93308 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93309 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93310 {
93311 struct mm_struct *mm = current->mm;
93312 struct vm_area_struct *vma;
93313 @@ -1809,6 +2051,24 @@ check_current:
93314 gap_end = vma->vm_start;
93315 if (gap_end < low_limit)
93316 return -ENOMEM;
93317 +
93318 + if (gap_end - gap_start > info->threadstack_offset)
93319 + gap_end -= info->threadstack_offset;
93320 + else
93321 + gap_end = gap_start;
93322 +
93323 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93324 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93325 + gap_start += sysctl_heap_stack_gap;
93326 + else
93327 + gap_start = gap_end;
93328 + }
93329 + if (vma->vm_flags & VM_GROWSDOWN) {
93330 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93331 + gap_end -= sysctl_heap_stack_gap;
93332 + else
93333 + gap_end = gap_start;
93334 + }
93335 if (gap_start <= high_limit && gap_end - gap_start >= length)
93336 goto found;
93337
93338 @@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93339 struct mm_struct *mm = current->mm;
93340 struct vm_area_struct *vma;
93341 struct vm_unmapped_area_info info;
93342 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93343
93344 if (len > TASK_SIZE - mmap_min_addr)
93345 return -ENOMEM;
93346 @@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93347 if (flags & MAP_FIXED)
93348 return addr;
93349
93350 +#ifdef CONFIG_PAX_RANDMMAP
93351 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93352 +#endif
93353 +
93354 if (addr) {
93355 addr = PAGE_ALIGN(addr);
93356 vma = find_vma(mm, addr);
93357 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93358 - (!vma || addr + len <= vma->vm_start))
93359 + check_heap_stack_gap(vma, addr, len, offset))
93360 return addr;
93361 }
93362
93363 @@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93364 info.low_limit = mm->mmap_base;
93365 info.high_limit = TASK_SIZE;
93366 info.align_mask = 0;
93367 + info.threadstack_offset = offset;
93368 return vm_unmapped_area(&info);
93369 }
93370 #endif
93371 @@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93372 struct mm_struct *mm = current->mm;
93373 unsigned long addr = addr0;
93374 struct vm_unmapped_area_info info;
93375 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93376
93377 /* requested length too big for entire address space */
93378 if (len > TASK_SIZE - mmap_min_addr)
93379 @@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93380 if (flags & MAP_FIXED)
93381 return addr;
93382
93383 +#ifdef CONFIG_PAX_RANDMMAP
93384 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93385 +#endif
93386 +
93387 /* requesting a specific address */
93388 if (addr) {
93389 addr = PAGE_ALIGN(addr);
93390 vma = find_vma(mm, addr);
93391 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93392 - (!vma || addr + len <= vma->vm_start))
93393 + check_heap_stack_gap(vma, addr, len, offset))
93394 return addr;
93395 }
93396
93397 @@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93398 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93399 info.high_limit = mm->mmap_base;
93400 info.align_mask = 0;
93401 + info.threadstack_offset = offset;
93402 addr = vm_unmapped_area(&info);
93403
93404 /*
93405 @@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93406 VM_BUG_ON(addr != -ENOMEM);
93407 info.flags = 0;
93408 info.low_limit = TASK_UNMAPPED_BASE;
93409 +
93410 +#ifdef CONFIG_PAX_RANDMMAP
93411 + if (mm->pax_flags & MF_PAX_RANDMMAP)
93412 + info.low_limit += mm->delta_mmap;
93413 +#endif
93414 +
93415 info.high_limit = TASK_SIZE;
93416 addr = vm_unmapped_area(&info);
93417 }
93418 @@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93419 return vma;
93420 }
93421
93422 +#ifdef CONFIG_PAX_SEGMEXEC
93423 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93424 +{
93425 + struct vm_area_struct *vma_m;
93426 +
93427 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93428 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93429 + BUG_ON(vma->vm_mirror);
93430 + return NULL;
93431 + }
93432 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93433 + vma_m = vma->vm_mirror;
93434 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93435 + BUG_ON(vma->vm_file != vma_m->vm_file);
93436 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93437 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93438 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93439 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93440 + return vma_m;
93441 +}
93442 +#endif
93443 +
93444 /*
93445 * Verify that the stack growth is acceptable and
93446 * update accounting. This is shared with both the
93447 @@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93448 return -ENOMEM;
93449
93450 /* Stack limit test */
93451 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
93452 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93453 return -ENOMEM;
93454
93455 @@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93456 locked = mm->locked_vm + grow;
93457 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93458 limit >>= PAGE_SHIFT;
93459 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93460 if (locked > limit && !capable(CAP_IPC_LOCK))
93461 return -ENOMEM;
93462 }
93463 @@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93464 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93465 * vma is the last one with address > vma->vm_end. Have to extend vma.
93466 */
93467 +#ifndef CONFIG_IA64
93468 +static
93469 +#endif
93470 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93471 {
93472 int error;
93473 + bool locknext;
93474
93475 if (!(vma->vm_flags & VM_GROWSUP))
93476 return -EFAULT;
93477
93478 + /* Also guard against wrapping around to address 0. */
93479 + if (address < PAGE_ALIGN(address+1))
93480 + address = PAGE_ALIGN(address+1);
93481 + else
93482 + return -ENOMEM;
93483 +
93484 /*
93485 * We must make sure the anon_vma is allocated
93486 * so that the anon_vma locking is not a noop.
93487 */
93488 if (unlikely(anon_vma_prepare(vma)))
93489 return -ENOMEM;
93490 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93491 + if (locknext && anon_vma_prepare(vma->vm_next))
93492 + return -ENOMEM;
93493 vma_lock_anon_vma(vma);
93494 + if (locknext)
93495 + vma_lock_anon_vma(vma->vm_next);
93496
93497 /*
93498 * vma->vm_start/vm_end cannot change under us because the caller
93499 * is required to hold the mmap_sem in read mode. We need the
93500 - * anon_vma lock to serialize against concurrent expand_stacks.
93501 - * Also guard against wrapping around to address 0.
93502 + * anon_vma locks to serialize against concurrent expand_stacks
93503 + * and expand_upwards.
93504 */
93505 - if (address < PAGE_ALIGN(address+4))
93506 - address = PAGE_ALIGN(address+4);
93507 - else {
93508 - vma_unlock_anon_vma(vma);
93509 - return -ENOMEM;
93510 - }
93511 error = 0;
93512
93513 /* Somebody else might have raced and expanded it already */
93514 - if (address > vma->vm_end) {
93515 + 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)
93516 + error = -ENOMEM;
93517 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93518 unsigned long size, grow;
93519
93520 size = address - vma->vm_start;
93521 @@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93522 }
93523 }
93524 }
93525 + if (locknext)
93526 + vma_unlock_anon_vma(vma->vm_next);
93527 vma_unlock_anon_vma(vma);
93528 khugepaged_enter_vma_merge(vma);
93529 validate_mm(vma->vm_mm);
93530 @@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
93531 unsigned long address)
93532 {
93533 int error;
93534 + bool lockprev = false;
93535 + struct vm_area_struct *prev;
93536
93537 /*
93538 * We must make sure the anon_vma is allocated
93539 @@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
93540 if (error)
93541 return error;
93542
93543 + prev = vma->vm_prev;
93544 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93545 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93546 +#endif
93547 + if (lockprev && anon_vma_prepare(prev))
93548 + return -ENOMEM;
93549 + if (lockprev)
93550 + vma_lock_anon_vma(prev);
93551 +
93552 vma_lock_anon_vma(vma);
93553
93554 /*
93555 @@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
93556 */
93557
93558 /* Somebody else might have raced and expanded it already */
93559 - if (address < vma->vm_start) {
93560 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93561 + error = -ENOMEM;
93562 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93563 unsigned long size, grow;
93564
93565 +#ifdef CONFIG_PAX_SEGMEXEC
93566 + struct vm_area_struct *vma_m;
93567 +
93568 + vma_m = pax_find_mirror_vma(vma);
93569 +#endif
93570 +
93571 size = vma->vm_end - address;
93572 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93573
93574 @@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
93575 vma->vm_pgoff -= grow;
93576 anon_vma_interval_tree_post_update_vma(vma);
93577 vma_gap_update(vma);
93578 +
93579 +#ifdef CONFIG_PAX_SEGMEXEC
93580 + if (vma_m) {
93581 + anon_vma_interval_tree_pre_update_vma(vma_m);
93582 + vma_m->vm_start -= grow << PAGE_SHIFT;
93583 + vma_m->vm_pgoff -= grow;
93584 + anon_vma_interval_tree_post_update_vma(vma_m);
93585 + vma_gap_update(vma_m);
93586 + }
93587 +#endif
93588 +
93589 spin_unlock(&vma->vm_mm->page_table_lock);
93590
93591 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93592 perf_event_mmap(vma);
93593 }
93594 }
93595 }
93596 vma_unlock_anon_vma(vma);
93597 + if (lockprev)
93598 + vma_unlock_anon_vma(prev);
93599 khugepaged_enter_vma_merge(vma);
93600 validate_mm(vma->vm_mm);
93601 return error;
93602 @@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93603 do {
93604 long nrpages = vma_pages(vma);
93605
93606 +#ifdef CONFIG_PAX_SEGMEXEC
93607 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93608 + vma = remove_vma(vma);
93609 + continue;
93610 + }
93611 +#endif
93612 +
93613 if (vma->vm_flags & VM_ACCOUNT)
93614 nr_accounted += nrpages;
93615 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93616 @@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93617 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93618 vma->vm_prev = NULL;
93619 do {
93620 +
93621 +#ifdef CONFIG_PAX_SEGMEXEC
93622 + if (vma->vm_mirror) {
93623 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93624 + vma->vm_mirror->vm_mirror = NULL;
93625 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
93626 + vma->vm_mirror = NULL;
93627 + }
93628 +#endif
93629 +
93630 vma_rb_erase(vma, &mm->mm_rb);
93631 mm->map_count--;
93632 tail_vma = vma;
93633 @@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93634 struct vm_area_struct *new;
93635 int err = -ENOMEM;
93636
93637 +#ifdef CONFIG_PAX_SEGMEXEC
93638 + struct vm_area_struct *vma_m, *new_m = NULL;
93639 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93640 +#endif
93641 +
93642 if (is_vm_hugetlb_page(vma) && (addr &
93643 ~(huge_page_mask(hstate_vma(vma)))))
93644 return -EINVAL;
93645
93646 +#ifdef CONFIG_PAX_SEGMEXEC
93647 + vma_m = pax_find_mirror_vma(vma);
93648 +#endif
93649 +
93650 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93651 if (!new)
93652 goto out_err;
93653
93654 +#ifdef CONFIG_PAX_SEGMEXEC
93655 + if (vma_m) {
93656 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93657 + if (!new_m) {
93658 + kmem_cache_free(vm_area_cachep, new);
93659 + goto out_err;
93660 + }
93661 + }
93662 +#endif
93663 +
93664 /* most fields are the same, copy all, and then fixup */
93665 *new = *vma;
93666
93667 @@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93668 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93669 }
93670
93671 +#ifdef CONFIG_PAX_SEGMEXEC
93672 + if (vma_m) {
93673 + *new_m = *vma_m;
93674 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
93675 + new_m->vm_mirror = new;
93676 + new->vm_mirror = new_m;
93677 +
93678 + if (new_below)
93679 + new_m->vm_end = addr_m;
93680 + else {
93681 + new_m->vm_start = addr_m;
93682 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93683 + }
93684 + }
93685 +#endif
93686 +
93687 err = vma_dup_policy(vma, new);
93688 if (err)
93689 goto out_free_vma;
93690 @@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93691 else
93692 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93693
93694 +#ifdef CONFIG_PAX_SEGMEXEC
93695 + if (!err && vma_m) {
93696 + struct mempolicy *pol = vma_policy(new);
93697 +
93698 + if (anon_vma_clone(new_m, vma_m))
93699 + goto out_free_mpol;
93700 +
93701 + mpol_get(pol);
93702 + set_vma_policy(new_m, pol);
93703 +
93704 + if (new_m->vm_file)
93705 + get_file(new_m->vm_file);
93706 +
93707 + if (new_m->vm_ops && new_m->vm_ops->open)
93708 + new_m->vm_ops->open(new_m);
93709 +
93710 + if (new_below)
93711 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93712 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93713 + else
93714 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93715 +
93716 + if (err) {
93717 + if (new_m->vm_ops && new_m->vm_ops->close)
93718 + new_m->vm_ops->close(new_m);
93719 + if (new_m->vm_file)
93720 + fput(new_m->vm_file);
93721 + mpol_put(pol);
93722 + }
93723 + }
93724 +#endif
93725 +
93726 /* Success. */
93727 if (!err)
93728 return 0;
93729 @@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93730 new->vm_ops->close(new);
93731 if (new->vm_file)
93732 fput(new->vm_file);
93733 - unlink_anon_vmas(new);
93734 out_free_mpol:
93735 mpol_put(vma_policy(new));
93736 out_free_vma:
93737 +
93738 +#ifdef CONFIG_PAX_SEGMEXEC
93739 + if (new_m) {
93740 + unlink_anon_vmas(new_m);
93741 + kmem_cache_free(vm_area_cachep, new_m);
93742 + }
93743 +#endif
93744 +
93745 + unlink_anon_vmas(new);
93746 kmem_cache_free(vm_area_cachep, new);
93747 out_err:
93748 return err;
93749 @@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93750 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93751 unsigned long addr, int new_below)
93752 {
93753 +
93754 +#ifdef CONFIG_PAX_SEGMEXEC
93755 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93756 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93757 + if (mm->map_count >= sysctl_max_map_count-1)
93758 + return -ENOMEM;
93759 + } else
93760 +#endif
93761 +
93762 if (mm->map_count >= sysctl_max_map_count)
93763 return -ENOMEM;
93764
93765 @@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93766 * work. This now handles partial unmappings.
93767 * Jeremy Fitzhardinge <jeremy@goop.org>
93768 */
93769 +#ifdef CONFIG_PAX_SEGMEXEC
93770 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93771 {
93772 + int ret = __do_munmap(mm, start, len);
93773 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93774 + return ret;
93775 +
93776 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93777 +}
93778 +
93779 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93780 +#else
93781 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93782 +#endif
93783 +{
93784 unsigned long end;
93785 struct vm_area_struct *vma, *prev, *last;
93786
93787 + /*
93788 + * mm->mmap_sem is required to protect against another thread
93789 + * changing the mappings in case we sleep.
93790 + */
93791 + verify_mm_writelocked(mm);
93792 +
93793 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93794 return -EINVAL;
93795
93796 @@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93797 /* Fix up all other VM information */
93798 remove_vma_list(mm, vma);
93799
93800 + track_exec_limit(mm, start, end, 0UL);
93801 +
93802 return 0;
93803 }
93804
93805 @@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
93806 int ret;
93807 struct mm_struct *mm = current->mm;
93808
93809 +
93810 +#ifdef CONFIG_PAX_SEGMEXEC
93811 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93812 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93813 + return -EINVAL;
93814 +#endif
93815 +
93816 down_write(&mm->mmap_sem);
93817 ret = do_munmap(mm, start, len);
93818 up_write(&mm->mmap_sem);
93819 @@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93820 return vm_munmap(addr, len);
93821 }
93822
93823 -static inline void verify_mm_writelocked(struct mm_struct *mm)
93824 -{
93825 -#ifdef CONFIG_DEBUG_VM
93826 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93827 - WARN_ON(1);
93828 - up_read(&mm->mmap_sem);
93829 - }
93830 -#endif
93831 -}
93832 -
93833 /*
93834 * this is really a simplified "do_mmap". it only handles
93835 * anonymous maps. eventually we may be able to do some
93836 @@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93837 struct rb_node ** rb_link, * rb_parent;
93838 pgoff_t pgoff = addr >> PAGE_SHIFT;
93839 int error;
93840 + unsigned long charged;
93841
93842 len = PAGE_ALIGN(len);
93843 if (!len)
93844 @@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93845
93846 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93847
93848 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93849 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93850 + flags &= ~VM_EXEC;
93851 +
93852 +#ifdef CONFIG_PAX_MPROTECT
93853 + if (mm->pax_flags & MF_PAX_MPROTECT)
93854 + flags &= ~VM_MAYEXEC;
93855 +#endif
93856 +
93857 + }
93858 +#endif
93859 +
93860 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93861 if (error & ~PAGE_MASK)
93862 return error;
93863
93864 + charged = len >> PAGE_SHIFT;
93865 +
93866 error = mlock_future_check(mm, mm->def_flags, len);
93867 if (error)
93868 return error;
93869 @@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93870 /*
93871 * Clear old maps. this also does some error checking for us
93872 */
93873 - munmap_back:
93874 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93875 if (do_munmap(mm, addr, len))
93876 return -ENOMEM;
93877 - goto munmap_back;
93878 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93879 }
93880
93881 /* Check against address space limits *after* clearing old maps... */
93882 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93883 + if (!may_expand_vm(mm, charged))
93884 return -ENOMEM;
93885
93886 if (mm->map_count > sysctl_max_map_count)
93887 return -ENOMEM;
93888
93889 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93890 + if (security_vm_enough_memory_mm(mm, charged))
93891 return -ENOMEM;
93892
93893 /* Can we just expand an old private anonymous mapping? */
93894 @@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93895 */
93896 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93897 if (!vma) {
93898 - vm_unacct_memory(len >> PAGE_SHIFT);
93899 + vm_unacct_memory(charged);
93900 return -ENOMEM;
93901 }
93902
93903 @@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93904 vma_link(mm, vma, prev, rb_link, rb_parent);
93905 out:
93906 perf_event_mmap(vma);
93907 - mm->total_vm += len >> PAGE_SHIFT;
93908 + mm->total_vm += charged;
93909 if (flags & VM_LOCKED)
93910 - mm->locked_vm += (len >> PAGE_SHIFT);
93911 + mm->locked_vm += charged;
93912 vma->vm_flags |= VM_SOFTDIRTY;
93913 + track_exec_limit(mm, addr, addr + len, flags);
93914 return addr;
93915 }
93916
93917 @@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
93918 while (vma) {
93919 if (vma->vm_flags & VM_ACCOUNT)
93920 nr_accounted += vma_pages(vma);
93921 + vma->vm_mirror = NULL;
93922 vma = remove_vma(vma);
93923 }
93924 vm_unacct_memory(nr_accounted);
93925 @@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93926 struct vm_area_struct *prev;
93927 struct rb_node **rb_link, *rb_parent;
93928
93929 +#ifdef CONFIG_PAX_SEGMEXEC
93930 + struct vm_area_struct *vma_m = NULL;
93931 +#endif
93932 +
93933 + if (security_mmap_addr(vma->vm_start))
93934 + return -EPERM;
93935 +
93936 /*
93937 * The vm_pgoff of a purely anonymous vma should be irrelevant
93938 * until its first write fault, when page's anon_vma and index
93939 @@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93940 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93941 return -ENOMEM;
93942
93943 +#ifdef CONFIG_PAX_SEGMEXEC
93944 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93945 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93946 + if (!vma_m)
93947 + return -ENOMEM;
93948 + }
93949 +#endif
93950 +
93951 vma_link(mm, vma, prev, rb_link, rb_parent);
93952 +
93953 +#ifdef CONFIG_PAX_SEGMEXEC
93954 + if (vma_m)
93955 + BUG_ON(pax_mirror_vma(vma_m, vma));
93956 +#endif
93957 +
93958 return 0;
93959 }
93960
93961 @@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93962 struct rb_node **rb_link, *rb_parent;
93963 bool faulted_in_anon_vma = true;
93964
93965 + BUG_ON(vma->vm_mirror);
93966 +
93967 /*
93968 * If anonymous vma has not yet been faulted, update new pgoff
93969 * to match new location, to increase its chance of merging.
93970 @@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93971 return NULL;
93972 }
93973
93974 +#ifdef CONFIG_PAX_SEGMEXEC
93975 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93976 +{
93977 + struct vm_area_struct *prev_m;
93978 + struct rb_node **rb_link_m, *rb_parent_m;
93979 + struct mempolicy *pol_m;
93980 +
93981 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93982 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93983 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93984 + *vma_m = *vma;
93985 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93986 + if (anon_vma_clone(vma_m, vma))
93987 + return -ENOMEM;
93988 + pol_m = vma_policy(vma_m);
93989 + mpol_get(pol_m);
93990 + set_vma_policy(vma_m, pol_m);
93991 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93992 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93993 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93994 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93995 + if (vma_m->vm_file)
93996 + get_file(vma_m->vm_file);
93997 + if (vma_m->vm_ops && vma_m->vm_ops->open)
93998 + vma_m->vm_ops->open(vma_m);
93999 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94000 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94001 + vma_m->vm_mirror = vma;
94002 + vma->vm_mirror = vma_m;
94003 + return 0;
94004 +}
94005 +#endif
94006 +
94007 /*
94008 * Return true if the calling process may expand its vm space by the passed
94009 * number of pages
94010 @@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94011
94012 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94013
94014 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94015 if (cur + npages > lim)
94016 return 0;
94017 return 1;
94018 @@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94019 vma->vm_start = addr;
94020 vma->vm_end = addr + len;
94021
94022 +#ifdef CONFIG_PAX_MPROTECT
94023 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94024 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94025 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94026 + return -EPERM;
94027 + if (!(vm_flags & VM_EXEC))
94028 + vm_flags &= ~VM_MAYEXEC;
94029 +#else
94030 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94031 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94032 +#endif
94033 + else
94034 + vm_flags &= ~VM_MAYWRITE;
94035 + }
94036 +#endif
94037 +
94038 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94039 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94040
94041 diff --git a/mm/mprotect.c b/mm/mprotect.c
94042 index 769a67a..414d24f 100644
94043 --- a/mm/mprotect.c
94044 +++ b/mm/mprotect.c
94045 @@ -24,10 +24,18 @@
94046 #include <linux/migrate.h>
94047 #include <linux/perf_event.h>
94048 #include <linux/ksm.h>
94049 +#include <linux/sched/sysctl.h>
94050 +
94051 +#ifdef CONFIG_PAX_MPROTECT
94052 +#include <linux/elf.h>
94053 +#include <linux/binfmts.h>
94054 +#endif
94055 +
94056 #include <asm/uaccess.h>
94057 #include <asm/pgtable.h>
94058 #include <asm/cacheflush.h>
94059 #include <asm/tlbflush.h>
94060 +#include <asm/mmu_context.h>
94061
94062 #ifndef pgprot_modify
94063 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94064 @@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94065 return pages;
94066 }
94067
94068 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94069 +/* called while holding the mmap semaphor for writing except stack expansion */
94070 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94071 +{
94072 + unsigned long oldlimit, newlimit = 0UL;
94073 +
94074 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94075 + return;
94076 +
94077 + spin_lock(&mm->page_table_lock);
94078 + oldlimit = mm->context.user_cs_limit;
94079 + if ((prot & VM_EXEC) && oldlimit < end)
94080 + /* USER_CS limit moved up */
94081 + newlimit = end;
94082 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94083 + /* USER_CS limit moved down */
94084 + newlimit = start;
94085 +
94086 + if (newlimit) {
94087 + mm->context.user_cs_limit = newlimit;
94088 +
94089 +#ifdef CONFIG_SMP
94090 + wmb();
94091 + cpus_clear(mm->context.cpu_user_cs_mask);
94092 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94093 +#endif
94094 +
94095 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94096 + }
94097 + spin_unlock(&mm->page_table_lock);
94098 + if (newlimit == end) {
94099 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
94100 +
94101 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
94102 + if (is_vm_hugetlb_page(vma))
94103 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94104 + else
94105 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94106 + }
94107 +}
94108 +#endif
94109 +
94110 int
94111 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94112 unsigned long start, unsigned long end, unsigned long newflags)
94113 @@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94114 int error;
94115 int dirty_accountable = 0;
94116
94117 +#ifdef CONFIG_PAX_SEGMEXEC
94118 + struct vm_area_struct *vma_m = NULL;
94119 + unsigned long start_m, end_m;
94120 +
94121 + start_m = start + SEGMEXEC_TASK_SIZE;
94122 + end_m = end + SEGMEXEC_TASK_SIZE;
94123 +#endif
94124 +
94125 if (newflags == oldflags) {
94126 *pprev = vma;
94127 return 0;
94128 }
94129
94130 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94131 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94132 +
94133 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94134 + return -ENOMEM;
94135 +
94136 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94137 + return -ENOMEM;
94138 + }
94139 +
94140 /*
94141 * If we make a private mapping writable we increase our commit;
94142 * but (without finer accounting) cannot reduce our commit if we
94143 @@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94144 }
94145 }
94146
94147 +#ifdef CONFIG_PAX_SEGMEXEC
94148 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94149 + if (start != vma->vm_start) {
94150 + error = split_vma(mm, vma, start, 1);
94151 + if (error)
94152 + goto fail;
94153 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94154 + *pprev = (*pprev)->vm_next;
94155 + }
94156 +
94157 + if (end != vma->vm_end) {
94158 + error = split_vma(mm, vma, end, 0);
94159 + if (error)
94160 + goto fail;
94161 + }
94162 +
94163 + if (pax_find_mirror_vma(vma)) {
94164 + error = __do_munmap(mm, start_m, end_m - start_m);
94165 + if (error)
94166 + goto fail;
94167 + } else {
94168 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94169 + if (!vma_m) {
94170 + error = -ENOMEM;
94171 + goto fail;
94172 + }
94173 + vma->vm_flags = newflags;
94174 + error = pax_mirror_vma(vma_m, vma);
94175 + if (error) {
94176 + vma->vm_flags = oldflags;
94177 + goto fail;
94178 + }
94179 + }
94180 + }
94181 +#endif
94182 +
94183 /*
94184 * First try to merge with previous and/or next vma.
94185 */
94186 @@ -277,9 +381,21 @@ success:
94187 * vm_flags and vm_page_prot are protected by the mmap_sem
94188 * held in write mode.
94189 */
94190 +
94191 +#ifdef CONFIG_PAX_SEGMEXEC
94192 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94193 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94194 +#endif
94195 +
94196 vma->vm_flags = newflags;
94197 +
94198 +#ifdef CONFIG_PAX_MPROTECT
94199 + if (mm->binfmt && mm->binfmt->handle_mprotect)
94200 + mm->binfmt->handle_mprotect(vma, newflags);
94201 +#endif
94202 +
94203 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94204 - vm_get_page_prot(newflags));
94205 + vm_get_page_prot(vma->vm_flags));
94206
94207 if (vma_wants_writenotify(vma)) {
94208 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94209 @@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94210 end = start + len;
94211 if (end <= start)
94212 return -ENOMEM;
94213 +
94214 +#ifdef CONFIG_PAX_SEGMEXEC
94215 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94216 + if (end > SEGMEXEC_TASK_SIZE)
94217 + return -EINVAL;
94218 + } else
94219 +#endif
94220 +
94221 + if (end > TASK_SIZE)
94222 + return -EINVAL;
94223 +
94224 if (!arch_validate_prot(prot))
94225 return -EINVAL;
94226
94227 @@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94228 /*
94229 * Does the application expect PROT_READ to imply PROT_EXEC:
94230 */
94231 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94232 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94233 prot |= PROT_EXEC;
94234
94235 vm_flags = calc_vm_prot_bits(prot);
94236 @@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94237 if (start > vma->vm_start)
94238 prev = vma;
94239
94240 +#ifdef CONFIG_PAX_MPROTECT
94241 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94242 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
94243 +#endif
94244 +
94245 for (nstart = start ; ; ) {
94246 unsigned long newflags;
94247
94248 @@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94249
94250 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94251 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94252 + if (prot & (PROT_WRITE | PROT_EXEC))
94253 + gr_log_rwxmprotect(vma);
94254 +
94255 + error = -EACCES;
94256 + goto out;
94257 + }
94258 +
94259 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94260 error = -EACCES;
94261 goto out;
94262 }
94263 @@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94264 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94265 if (error)
94266 goto out;
94267 +
94268 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
94269 +
94270 nstart = tmp;
94271
94272 if (nstart < prev->vm_end)
94273 diff --git a/mm/mremap.c b/mm/mremap.c
94274 index 0843feb..4f5b2e6 100644
94275 --- a/mm/mremap.c
94276 +++ b/mm/mremap.c
94277 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94278 continue;
94279 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94280 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94281 +
94282 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94283 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94284 + pte = pte_exprotect(pte);
94285 +#endif
94286 +
94287 pte = move_soft_dirty_pte(pte);
94288 set_pte_at(mm, new_addr, new_pte, pte);
94289 }
94290 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94291 if (is_vm_hugetlb_page(vma))
94292 goto Einval;
94293
94294 +#ifdef CONFIG_PAX_SEGMEXEC
94295 + if (pax_find_mirror_vma(vma))
94296 + goto Einval;
94297 +#endif
94298 +
94299 /* We can't remap across vm area boundaries */
94300 if (old_len > vma->vm_end - addr)
94301 goto Efault;
94302 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94303 unsigned long ret = -EINVAL;
94304 unsigned long charged = 0;
94305 unsigned long map_flags;
94306 + unsigned long pax_task_size = TASK_SIZE;
94307
94308 if (new_addr & ~PAGE_MASK)
94309 goto out;
94310
94311 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94312 +#ifdef CONFIG_PAX_SEGMEXEC
94313 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94314 + pax_task_size = SEGMEXEC_TASK_SIZE;
94315 +#endif
94316 +
94317 + pax_task_size -= PAGE_SIZE;
94318 +
94319 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94320 goto out;
94321
94322 /* Check if the location we're moving into overlaps the
94323 * old location at all, and fail if it does.
94324 */
94325 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
94326 - goto out;
94327 -
94328 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
94329 + if (addr + old_len > new_addr && new_addr + new_len > addr)
94330 goto out;
94331
94332 ret = do_munmap(mm, new_addr, new_len);
94333 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94334 unsigned long ret = -EINVAL;
94335 unsigned long charged = 0;
94336 bool locked = false;
94337 + unsigned long pax_task_size = TASK_SIZE;
94338
94339 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94340 return ret;
94341 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94342 if (!new_len)
94343 return ret;
94344
94345 +#ifdef CONFIG_PAX_SEGMEXEC
94346 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94347 + pax_task_size = SEGMEXEC_TASK_SIZE;
94348 +#endif
94349 +
94350 + pax_task_size -= PAGE_SIZE;
94351 +
94352 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94353 + old_len > pax_task_size || addr > pax_task_size-old_len)
94354 + return ret;
94355 +
94356 down_write(&current->mm->mmap_sem);
94357
94358 if (flags & MREMAP_FIXED) {
94359 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94360 new_addr = addr;
94361 }
94362 ret = addr;
94363 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94364 goto out;
94365 }
94366 }
94367 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94368 goto out;
94369 }
94370
94371 + map_flags = vma->vm_flags;
94372 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94373 + if (!(ret & ~PAGE_MASK)) {
94374 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94375 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94376 + }
94377 }
94378 out:
94379 if (ret & ~PAGE_MASK)
94380 diff --git a/mm/nommu.c b/mm/nommu.c
94381 index 8740213..f87e25b 100644
94382 --- a/mm/nommu.c
94383 +++ b/mm/nommu.c
94384 @@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94385 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94386 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94387 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94388 -int heap_stack_gap = 0;
94389
94390 atomic_long_t mmap_pages_allocated;
94391
94392 @@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94393 EXPORT_SYMBOL(find_vma);
94394
94395 /*
94396 - * find a VMA
94397 - * - we don't extend stack VMAs under NOMMU conditions
94398 - */
94399 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94400 -{
94401 - return find_vma(mm, addr);
94402 -}
94403 -
94404 -/*
94405 * expand a stack to a given address
94406 * - not supported under NOMMU conditions
94407 */
94408 @@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94409
94410 /* most fields are the same, copy all, and then fixup */
94411 *new = *vma;
94412 + INIT_LIST_HEAD(&new->anon_vma_chain);
94413 *region = *vma->vm_region;
94414 new->vm_region = region;
94415
94416 @@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94417 }
94418 EXPORT_SYMBOL(generic_file_remap_pages);
94419
94420 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94421 - unsigned long addr, void *buf, int len, int write)
94422 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94423 + unsigned long addr, void *buf, size_t len, int write)
94424 {
94425 struct vm_area_struct *vma;
94426
94427 @@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94428 *
94429 * The caller must hold a reference on @mm.
94430 */
94431 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94432 - void *buf, int len, int write)
94433 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94434 + void *buf, size_t len, int write)
94435 {
94436 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94437 }
94438 @@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94439 * Access another process' address space.
94440 * - source/target buffer must be kernel space
94441 */
94442 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94443 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94444 {
94445 struct mm_struct *mm;
94446
94447 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94448 index 7106cb1..0805f48 100644
94449 --- a/mm/page-writeback.c
94450 +++ b/mm/page-writeback.c
94451 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94452 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94453 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94454 */
94455 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94456 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94457 unsigned long thresh,
94458 unsigned long bg_thresh,
94459 unsigned long dirty,
94460 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94461 index 3bac76a..bf9f9ae 100644
94462 --- a/mm/page_alloc.c
94463 +++ b/mm/page_alloc.c
94464 @@ -61,6 +61,7 @@
94465 #include <linux/page-debug-flags.h>
94466 #include <linux/hugetlb.h>
94467 #include <linux/sched/rt.h>
94468 +#include <linux/random.h>
94469
94470 #include <asm/sections.h>
94471 #include <asm/tlbflush.h>
94472 @@ -354,7 +355,7 @@ out:
94473 * This usage means that zero-order pages may not be compound.
94474 */
94475
94476 -static void free_compound_page(struct page *page)
94477 +void free_compound_page(struct page *page)
94478 {
94479 __free_pages_ok(page, compound_order(page));
94480 }
94481 @@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94482 int i;
94483 int bad = 0;
94484
94485 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94486 + unsigned long index = 1UL << order;
94487 +#endif
94488 +
94489 trace_mm_page_free(page, order);
94490 kmemcheck_free_shadow(page, order);
94491
94492 @@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94493 debug_check_no_obj_freed(page_address(page),
94494 PAGE_SIZE << order);
94495 }
94496 +
94497 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94498 + for (; index; --index)
94499 + sanitize_highpage(page + index - 1);
94500 +#endif
94501 +
94502 arch_free_page(page, order);
94503 kernel_map_pages(page, 1 << order, 0);
94504
94505 @@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94506 local_irq_restore(flags);
94507 }
94508
94509 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94510 +bool __meminitdata extra_latent_entropy;
94511 +
94512 +static int __init setup_pax_extra_latent_entropy(char *str)
94513 +{
94514 + extra_latent_entropy = true;
94515 + return 0;
94516 +}
94517 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94518 +
94519 +volatile u64 latent_entropy __latent_entropy;
94520 +EXPORT_SYMBOL(latent_entropy);
94521 +#endif
94522 +
94523 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94524 {
94525 unsigned int nr_pages = 1 << order;
94526 @@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94527 __ClearPageReserved(p);
94528 set_page_count(p, 0);
94529
94530 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94531 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94532 + u64 hash = 0;
94533 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94534 + const u64 *data = lowmem_page_address(page);
94535 +
94536 + for (index = 0; index < end; index++)
94537 + hash ^= hash + data[index];
94538 + latent_entropy ^= hash;
94539 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94540 + }
94541 +#endif
94542 +
94543 page_zone(page)->managed_pages += nr_pages;
94544 set_page_refcounted(page);
94545 __free_pages(page, order);
94546 @@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94547 arch_alloc_page(page, order);
94548 kernel_map_pages(page, 1 << order, 1);
94549
94550 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
94551 if (gfp_flags & __GFP_ZERO)
94552 prep_zero_page(page, order, gfp_flags);
94553 +#endif
94554
94555 if (order && (gfp_flags & __GFP_COMP))
94556 prep_compound_page(page, order);
94557 diff --git a/mm/page_io.c b/mm/page_io.c
94558 index 7c59ef6..1358905 100644
94559 --- a/mm/page_io.c
94560 +++ b/mm/page_io.c
94561 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94562 struct file *swap_file = sis->swap_file;
94563 struct address_space *mapping = swap_file->f_mapping;
94564 struct iovec iov = {
94565 - .iov_base = kmap(page),
94566 + .iov_base = (void __force_user *)kmap(page),
94567 .iov_len = PAGE_SIZE,
94568 };
94569
94570 diff --git a/mm/percpu.c b/mm/percpu.c
94571 index 036cfe0..980d0fa 100644
94572 --- a/mm/percpu.c
94573 +++ b/mm/percpu.c
94574 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94575 static unsigned int pcpu_high_unit_cpu __read_mostly;
94576
94577 /* the address of the first chunk which starts with the kernel static area */
94578 -void *pcpu_base_addr __read_mostly;
94579 +void *pcpu_base_addr __read_only;
94580 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94581
94582 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94583 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94584 index fd26d04..0cea1b0 100644
94585 --- a/mm/process_vm_access.c
94586 +++ b/mm/process_vm_access.c
94587 @@ -13,6 +13,7 @@
94588 #include <linux/uio.h>
94589 #include <linux/sched.h>
94590 #include <linux/highmem.h>
94591 +#include <linux/security.h>
94592 #include <linux/ptrace.h>
94593 #include <linux/slab.h>
94594 #include <linux/syscalls.h>
94595 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94596 size_t iov_l_curr_offset = 0;
94597 ssize_t iov_len;
94598
94599 + return -ENOSYS; // PaX: until properly audited
94600 +
94601 /*
94602 * Work out how many pages of struct pages we're going to need
94603 * when eventually calling get_user_pages
94604 */
94605 for (i = 0; i < riovcnt; i++) {
94606 iov_len = rvec[i].iov_len;
94607 - if (iov_len > 0) {
94608 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
94609 - + iov_len)
94610 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94611 - / PAGE_SIZE + 1;
94612 - nr_pages = max(nr_pages, nr_pages_iov);
94613 - }
94614 + if (iov_len <= 0)
94615 + continue;
94616 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94617 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94618 + nr_pages = max(nr_pages, nr_pages_iov);
94619 }
94620
94621 if (nr_pages == 0)
94622 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94623 goto free_proc_pages;
94624 }
94625
94626 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94627 + rc = -EPERM;
94628 + goto put_task_struct;
94629 + }
94630 +
94631 mm = mm_access(task, PTRACE_MODE_ATTACH);
94632 if (!mm || IS_ERR(mm)) {
94633 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94634 diff --git a/mm/rmap.c b/mm/rmap.c
94635 index 8fc049f..1b21e12 100644
94636 --- a/mm/rmap.c
94637 +++ b/mm/rmap.c
94638 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94639 struct anon_vma *anon_vma = vma->anon_vma;
94640 struct anon_vma_chain *avc;
94641
94642 +#ifdef CONFIG_PAX_SEGMEXEC
94643 + struct anon_vma_chain *avc_m = NULL;
94644 +#endif
94645 +
94646 might_sleep();
94647 if (unlikely(!anon_vma)) {
94648 struct mm_struct *mm = vma->vm_mm;
94649 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94650 if (!avc)
94651 goto out_enomem;
94652
94653 +#ifdef CONFIG_PAX_SEGMEXEC
94654 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94655 + if (!avc_m)
94656 + goto out_enomem_free_avc;
94657 +#endif
94658 +
94659 anon_vma = find_mergeable_anon_vma(vma);
94660 allocated = NULL;
94661 if (!anon_vma) {
94662 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94663 /* page_table_lock to protect against threads */
94664 spin_lock(&mm->page_table_lock);
94665 if (likely(!vma->anon_vma)) {
94666 +
94667 +#ifdef CONFIG_PAX_SEGMEXEC
94668 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94669 +
94670 + if (vma_m) {
94671 + BUG_ON(vma_m->anon_vma);
94672 + vma_m->anon_vma = anon_vma;
94673 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
94674 + avc_m = NULL;
94675 + }
94676 +#endif
94677 +
94678 vma->anon_vma = anon_vma;
94679 anon_vma_chain_link(vma, avc, anon_vma);
94680 allocated = NULL;
94681 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94682
94683 if (unlikely(allocated))
94684 put_anon_vma(allocated);
94685 +
94686 +#ifdef CONFIG_PAX_SEGMEXEC
94687 + if (unlikely(avc_m))
94688 + anon_vma_chain_free(avc_m);
94689 +#endif
94690 +
94691 if (unlikely(avc))
94692 anon_vma_chain_free(avc);
94693 }
94694 return 0;
94695
94696 out_enomem_free_avc:
94697 +
94698 +#ifdef CONFIG_PAX_SEGMEXEC
94699 + if (avc_m)
94700 + anon_vma_chain_free(avc_m);
94701 +#endif
94702 +
94703 anon_vma_chain_free(avc);
94704 out_enomem:
94705 return -ENOMEM;
94706 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94707 * Attach the anon_vmas from src to dst.
94708 * Returns 0 on success, -ENOMEM on failure.
94709 */
94710 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94711 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94712 {
94713 struct anon_vma_chain *avc, *pavc;
94714 struct anon_vma *root = NULL;
94715 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94716 * the corresponding VMA in the parent process is attached to.
94717 * Returns 0 on success, non-zero on failure.
94718 */
94719 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94720 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94721 {
94722 struct anon_vma_chain *avc;
94723 struct anon_vma *anon_vma;
94724 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94725 void __init anon_vma_init(void)
94726 {
94727 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94728 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94729 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94730 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94731 + anon_vma_ctor);
94732 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94733 + SLAB_PANIC|SLAB_NO_SANITIZE);
94734 }
94735
94736 /*
94737 diff --git a/mm/shmem.c b/mm/shmem.c
94738 index 1f18c9d..3e03d33 100644
94739 --- a/mm/shmem.c
94740 +++ b/mm/shmem.c
94741 @@ -33,7 +33,7 @@
94742 #include <linux/swap.h>
94743 #include <linux/aio.h>
94744
94745 -static struct vfsmount *shm_mnt;
94746 +struct vfsmount *shm_mnt;
94747
94748 #ifdef CONFIG_SHMEM
94749 /*
94750 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94751 #define BOGO_DIRENT_SIZE 20
94752
94753 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94754 -#define SHORT_SYMLINK_LEN 128
94755 +#define SHORT_SYMLINK_LEN 64
94756
94757 /*
94758 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94759 @@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94760 static int shmem_xattr_validate(const char *name)
94761 {
94762 struct { const char *prefix; size_t len; } arr[] = {
94763 +
94764 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94765 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94766 +#endif
94767 +
94768 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94769 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94770 };
94771 @@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94772 if (err)
94773 return err;
94774
94775 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94776 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94777 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94778 + return -EOPNOTSUPP;
94779 + if (size > 8)
94780 + return -EINVAL;
94781 + }
94782 +#endif
94783 +
94784 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94785 }
94786
94787 @@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94788 int err = -ENOMEM;
94789
94790 /* Round up to L1_CACHE_BYTES to resist false sharing */
94791 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94792 - L1_CACHE_BYTES), GFP_KERNEL);
94793 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94794 if (!sbinfo)
94795 return -ENOMEM;
94796
94797 diff --git a/mm/slab.c b/mm/slab.c
94798 index b264214..83872cd 100644
94799 --- a/mm/slab.c
94800 +++ b/mm/slab.c
94801 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94802 if ((x)->max_freeable < i) \
94803 (x)->max_freeable = i; \
94804 } while (0)
94805 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94806 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94807 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94808 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94809 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94810 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94811 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94812 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94813 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94814 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94815 #else
94816 #define STATS_INC_ACTIVE(x) do { } while (0)
94817 #define STATS_DEC_ACTIVE(x) do { } while (0)
94818 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94819 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94820 #define STATS_INC_FREEHIT(x) do { } while (0)
94821 #define STATS_INC_FREEMISS(x) do { } while (0)
94822 +#define STATS_INC_SANITIZED(x) do { } while (0)
94823 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94824 #endif
94825
94826 #if DEBUG
94827 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94828 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94829 */
94830 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94831 - const struct page *page, void *obj)
94832 + const struct page *page, const void *obj)
94833 {
94834 u32 offset = (obj - page->s_mem);
94835 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94836 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94837 */
94838
94839 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94840 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94841 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94842
94843 if (INDEX_AC != INDEX_NODE)
94844 kmalloc_caches[INDEX_NODE] =
94845 create_kmalloc_cache("kmalloc-node",
94846 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94847 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94848
94849 slab_early_init = 0;
94850
94851 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94852 struct array_cache *ac = cpu_cache_get(cachep);
94853
94854 check_irq_off();
94855 +
94856 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94857 + if (pax_sanitize_slab) {
94858 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94859 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94860 +
94861 + if (cachep->ctor)
94862 + cachep->ctor(objp);
94863 +
94864 + STATS_INC_SANITIZED(cachep);
94865 + } else
94866 + STATS_INC_NOT_SANITIZED(cachep);
94867 + }
94868 +#endif
94869 +
94870 kmemleak_free_recursive(objp, cachep->flags);
94871 objp = cache_free_debugcheck(cachep, objp, caller);
94872
94873 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94874
94875 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94876 return;
94877 + VM_BUG_ON(!virt_addr_valid(objp));
94878 local_irq_save(flags);
94879 kfree_debugcheck(objp);
94880 c = virt_to_cache(objp);
94881 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94882 }
94883 /* cpu stats */
94884 {
94885 - unsigned long allochit = atomic_read(&cachep->allochit);
94886 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94887 - unsigned long freehit = atomic_read(&cachep->freehit);
94888 - unsigned long freemiss = atomic_read(&cachep->freemiss);
94889 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94890 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94891 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94892 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94893
94894 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94895 allochit, allocmiss, freehit, freemiss);
94896 }
94897 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94898 + {
94899 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94900 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94901 +
94902 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94903 + }
94904 +#endif
94905 #endif
94906 }
94907
94908 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94909 static int __init slab_proc_init(void)
94910 {
94911 #ifdef CONFIG_DEBUG_SLAB_LEAK
94912 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94913 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94914 #endif
94915 return 0;
94916 }
94917 module_init(slab_proc_init);
94918 #endif
94919
94920 +bool is_usercopy_object(const void *ptr)
94921 +{
94922 + struct page *page;
94923 + struct kmem_cache *cachep;
94924 +
94925 + if (ZERO_OR_NULL_PTR(ptr))
94926 + return false;
94927 +
94928 + if (!slab_is_available())
94929 + return false;
94930 +
94931 + if (!virt_addr_valid(ptr))
94932 + return false;
94933 +
94934 + page = virt_to_head_page(ptr);
94935 +
94936 + if (!PageSlab(page))
94937 + return false;
94938 +
94939 + cachep = page->slab_cache;
94940 + return cachep->flags & SLAB_USERCOPY;
94941 +}
94942 +
94943 +#ifdef CONFIG_PAX_USERCOPY
94944 +const char *check_heap_object(const void *ptr, unsigned long n)
94945 +{
94946 + struct page *page;
94947 + struct kmem_cache *cachep;
94948 + unsigned int objnr;
94949 + unsigned long offset;
94950 +
94951 + if (ZERO_OR_NULL_PTR(ptr))
94952 + return "<null>";
94953 +
94954 + if (!virt_addr_valid(ptr))
94955 + return NULL;
94956 +
94957 + page = virt_to_head_page(ptr);
94958 +
94959 + if (!PageSlab(page))
94960 + return NULL;
94961 +
94962 + cachep = page->slab_cache;
94963 + if (!(cachep->flags & SLAB_USERCOPY))
94964 + return cachep->name;
94965 +
94966 + objnr = obj_to_index(cachep, page, ptr);
94967 + BUG_ON(objnr >= cachep->num);
94968 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94969 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94970 + return NULL;
94971 +
94972 + return cachep->name;
94973 +}
94974 +#endif
94975 +
94976 /**
94977 * ksize - get the actual amount of memory allocated for a given object
94978 * @objp: Pointer to the object
94979 diff --git a/mm/slab.h b/mm/slab.h
94980 index 8184a7c..ab27737 100644
94981 --- a/mm/slab.h
94982 +++ b/mm/slab.h
94983 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94984 /* The slab cache that manages slab cache information */
94985 extern struct kmem_cache *kmem_cache;
94986
94987 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94988 +#ifdef CONFIG_X86_64
94989 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94990 +#else
94991 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94992 +#endif
94993 +extern bool pax_sanitize_slab;
94994 +#endif
94995 +
94996 unsigned long calculate_alignment(unsigned long flags,
94997 unsigned long align, unsigned long size);
94998
94999 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95000
95001 /* Legal flag mask for kmem_cache_create(), for various configurations */
95002 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95003 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95004 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95005 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
95006
95007 #if defined(CONFIG_DEBUG_SLAB)
95008 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95009 @@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95010 return s;
95011
95012 page = virt_to_head_page(x);
95013 +
95014 + BUG_ON(!PageSlab(page));
95015 +
95016 cachep = page->slab_cache;
95017 if (slab_equal_or_root(cachep, s))
95018 return cachep;
95019 diff --git a/mm/slab_common.c b/mm/slab_common.c
95020 index 1ec3c61..2067c11 100644
95021 --- a/mm/slab_common.c
95022 +++ b/mm/slab_common.c
95023 @@ -23,11 +23,22 @@
95024
95025 #include "slab.h"
95026
95027 -enum slab_state slab_state;
95028 +enum slab_state slab_state __read_only;
95029 LIST_HEAD(slab_caches);
95030 DEFINE_MUTEX(slab_mutex);
95031 struct kmem_cache *kmem_cache;
95032
95033 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95034 +bool pax_sanitize_slab __read_only = true;
95035 +static int __init pax_sanitize_slab_setup(char *str)
95036 +{
95037 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95038 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95039 + return 1;
95040 +}
95041 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95042 +#endif
95043 +
95044 #ifdef CONFIG_DEBUG_VM
95045 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95046 size_t size)
95047 @@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95048 if (err)
95049 goto out_free_cache;
95050
95051 - s->refcount = 1;
95052 + atomic_set(&s->refcount, 1);
95053 list_add(&s->list, &slab_caches);
95054 memcg_register_cache(s);
95055
95056 @@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95057
95058 get_online_cpus();
95059 mutex_lock(&slab_mutex);
95060 - s->refcount--;
95061 - if (!s->refcount) {
95062 + if (atomic_dec_and_test(&s->refcount)) {
95063 list_del(&s->list);
95064
95065 if (!__kmem_cache_shutdown(s)) {
95066 @@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95067 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95068 name, size, err);
95069
95070 - s->refcount = -1; /* Exempt from merging for now */
95071 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95072 }
95073
95074 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95075 @@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95076
95077 create_boot_cache(s, name, size, flags);
95078 list_add(&s->list, &slab_caches);
95079 - s->refcount = 1;
95080 + atomic_set(&s->refcount, 1);
95081 return s;
95082 }
95083
95084 @@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95085 EXPORT_SYMBOL(kmalloc_dma_caches);
95086 #endif
95087
95088 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95089 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95090 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
95091 +#endif
95092 +
95093 /*
95094 * Conversion table for small slabs sizes / 8 to the index in the
95095 * kmalloc array. This is necessary for slabs < 192 since we have non power
95096 @@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95097 return kmalloc_dma_caches[index];
95098
95099 #endif
95100 +
95101 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95102 + if (unlikely((flags & GFP_USERCOPY)))
95103 + return kmalloc_usercopy_caches[index];
95104 +
95105 +#endif
95106 +
95107 return kmalloc_caches[index];
95108 }
95109
95110 @@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95111 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95112 if (!kmalloc_caches[i]) {
95113 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95114 - 1 << i, flags);
95115 + 1 << i, SLAB_USERCOPY | flags);
95116 }
95117
95118 /*
95119 @@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95120 * earlier power of two caches
95121 */
95122 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95123 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95124 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95125
95126 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95127 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95128 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95129 }
95130
95131 /* Kmalloc array is now usable */
95132 @@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95133 }
95134 }
95135 #endif
95136 +
95137 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95138 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95139 + struct kmem_cache *s = kmalloc_caches[i];
95140 +
95141 + if (s) {
95142 + int size = kmalloc_size(i);
95143 + char *n = kasprintf(GFP_NOWAIT,
95144 + "usercopy-kmalloc-%d", size);
95145 +
95146 + BUG_ON(!n);
95147 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95148 + size, SLAB_USERCOPY | flags);
95149 + }
95150 + }
95151 +#endif
95152 +
95153 }
95154 #endif /* !CONFIG_SLOB */
95155
95156 @@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
95157 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95158 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95159 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95160 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95161 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
95162 +#endif
95163 #endif
95164 seq_putc(m, '\n');
95165 }
95166 diff --git a/mm/slob.c b/mm/slob.c
95167 index 4bf8809..98a6914 100644
95168 --- a/mm/slob.c
95169 +++ b/mm/slob.c
95170 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95171 /*
95172 * Return the size of a slob block.
95173 */
95174 -static slobidx_t slob_units(slob_t *s)
95175 +static slobidx_t slob_units(const slob_t *s)
95176 {
95177 if (s->units > 0)
95178 return s->units;
95179 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95180 /*
95181 * Return the next free slob block pointer after this one.
95182 */
95183 -static slob_t *slob_next(slob_t *s)
95184 +static slob_t *slob_next(const slob_t *s)
95185 {
95186 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95187 slobidx_t next;
95188 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95189 /*
95190 * Returns true if s is the last free block in its page.
95191 */
95192 -static int slob_last(slob_t *s)
95193 +static int slob_last(const slob_t *s)
95194 {
95195 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95196 }
95197
95198 -static void *slob_new_pages(gfp_t gfp, int order, int node)
95199 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95200 {
95201 - void *page;
95202 + struct page *page;
95203
95204 #ifdef CONFIG_NUMA
95205 if (node != NUMA_NO_NODE)
95206 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95207 if (!page)
95208 return NULL;
95209
95210 - return page_address(page);
95211 + __SetPageSlab(page);
95212 + return page;
95213 }
95214
95215 -static void slob_free_pages(void *b, int order)
95216 +static void slob_free_pages(struct page *sp, int order)
95217 {
95218 if (current->reclaim_state)
95219 current->reclaim_state->reclaimed_slab += 1 << order;
95220 - free_pages((unsigned long)b, order);
95221 + __ClearPageSlab(sp);
95222 + page_mapcount_reset(sp);
95223 + sp->private = 0;
95224 + __free_pages(sp, order);
95225 }
95226
95227 /*
95228 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95229
95230 /* Not enough space: must allocate a new page */
95231 if (!b) {
95232 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95233 - if (!b)
95234 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95235 + if (!sp)
95236 return NULL;
95237 - sp = virt_to_page(b);
95238 - __SetPageSlab(sp);
95239 + b = page_address(sp);
95240
95241 spin_lock_irqsave(&slob_lock, flags);
95242 sp->units = SLOB_UNITS(PAGE_SIZE);
95243 sp->freelist = b;
95244 + sp->private = 0;
95245 INIT_LIST_HEAD(&sp->list);
95246 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95247 set_slob_page_free(sp, slob_list);
95248 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95249 if (slob_page_free(sp))
95250 clear_slob_page_free(sp);
95251 spin_unlock_irqrestore(&slob_lock, flags);
95252 - __ClearPageSlab(sp);
95253 - page_mapcount_reset(sp);
95254 - slob_free_pages(b, 0);
95255 + slob_free_pages(sp, 0);
95256 return;
95257 }
95258
95259 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95260 + if (pax_sanitize_slab)
95261 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95262 +#endif
95263 +
95264 if (!slob_page_free(sp)) {
95265 /* This slob page is about to become partially free. Easy! */
95266 sp->units = units;
95267 @@ -424,11 +431,10 @@ out:
95268 */
95269
95270 static __always_inline void *
95271 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95272 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95273 {
95274 - unsigned int *m;
95275 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95276 - void *ret;
95277 + slob_t *m;
95278 + void *ret = NULL;
95279
95280 gfp &= gfp_allowed_mask;
95281
95282 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95283
95284 if (!m)
95285 return NULL;
95286 - *m = size;
95287 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95288 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95289 + m[0].units = size;
95290 + m[1].units = align;
95291 ret = (void *)m + align;
95292
95293 trace_kmalloc_node(caller, ret,
95294 size, size + align, gfp, node);
95295 } else {
95296 unsigned int order = get_order(size);
95297 + struct page *page;
95298
95299 if (likely(order))
95300 gfp |= __GFP_COMP;
95301 - ret = slob_new_pages(gfp, order, node);
95302 + page = slob_new_pages(gfp, order, node);
95303 + if (page) {
95304 + ret = page_address(page);
95305 + page->private = size;
95306 + }
95307
95308 trace_kmalloc_node(caller, ret,
95309 size, PAGE_SIZE << order, gfp, node);
95310 }
95311
95312 - kmemleak_alloc(ret, size, 1, gfp);
95313 + return ret;
95314 +}
95315 +
95316 +static __always_inline void *
95317 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95318 +{
95319 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95320 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95321 +
95322 + if (!ZERO_OR_NULL_PTR(ret))
95323 + kmemleak_alloc(ret, size, 1, gfp);
95324 return ret;
95325 }
95326
95327 @@ -493,34 +517,112 @@ void kfree(const void *block)
95328 return;
95329 kmemleak_free(block);
95330
95331 + VM_BUG_ON(!virt_addr_valid(block));
95332 sp = virt_to_page(block);
95333 - if (PageSlab(sp)) {
95334 + VM_BUG_ON(!PageSlab(sp));
95335 + if (!sp->private) {
95336 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95337 - unsigned int *m = (unsigned int *)(block - align);
95338 - slob_free(m, *m + align);
95339 - } else
95340 + slob_t *m = (slob_t *)(block - align);
95341 + slob_free(m, m[0].units + align);
95342 + } else {
95343 + __ClearPageSlab(sp);
95344 + page_mapcount_reset(sp);
95345 + sp->private = 0;
95346 __free_pages(sp, compound_order(sp));
95347 + }
95348 }
95349 EXPORT_SYMBOL(kfree);
95350
95351 +bool is_usercopy_object(const void *ptr)
95352 +{
95353 + if (!slab_is_available())
95354 + return false;
95355 +
95356 + // PAX: TODO
95357 +
95358 + return false;
95359 +}
95360 +
95361 +#ifdef CONFIG_PAX_USERCOPY
95362 +const char *check_heap_object(const void *ptr, unsigned long n)
95363 +{
95364 + struct page *page;
95365 + const slob_t *free;
95366 + const void *base;
95367 + unsigned long flags;
95368 +
95369 + if (ZERO_OR_NULL_PTR(ptr))
95370 + return "<null>";
95371 +
95372 + if (!virt_addr_valid(ptr))
95373 + return NULL;
95374 +
95375 + page = virt_to_head_page(ptr);
95376 + if (!PageSlab(page))
95377 + return NULL;
95378 +
95379 + if (page->private) {
95380 + base = page;
95381 + if (base <= ptr && n <= page->private - (ptr - base))
95382 + return NULL;
95383 + return "<slob>";
95384 + }
95385 +
95386 + /* some tricky double walking to find the chunk */
95387 + spin_lock_irqsave(&slob_lock, flags);
95388 + base = (void *)((unsigned long)ptr & PAGE_MASK);
95389 + free = page->freelist;
95390 +
95391 + while (!slob_last(free) && (void *)free <= ptr) {
95392 + base = free + slob_units(free);
95393 + free = slob_next(free);
95394 + }
95395 +
95396 + while (base < (void *)free) {
95397 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95398 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
95399 + int offset;
95400 +
95401 + if (ptr < base + align)
95402 + break;
95403 +
95404 + offset = ptr - base - align;
95405 + if (offset >= m) {
95406 + base += size;
95407 + continue;
95408 + }
95409 +
95410 + if (n > m - offset)
95411 + break;
95412 +
95413 + spin_unlock_irqrestore(&slob_lock, flags);
95414 + return NULL;
95415 + }
95416 +
95417 + spin_unlock_irqrestore(&slob_lock, flags);
95418 + return "<slob>";
95419 +}
95420 +#endif
95421 +
95422 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95423 size_t ksize(const void *block)
95424 {
95425 struct page *sp;
95426 int align;
95427 - unsigned int *m;
95428 + slob_t *m;
95429
95430 BUG_ON(!block);
95431 if (unlikely(block == ZERO_SIZE_PTR))
95432 return 0;
95433
95434 sp = virt_to_page(block);
95435 - if (unlikely(!PageSlab(sp)))
95436 - return PAGE_SIZE << compound_order(sp);
95437 + VM_BUG_ON(!PageSlab(sp));
95438 + if (sp->private)
95439 + return sp->private;
95440
95441 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95442 - m = (unsigned int *)(block - align);
95443 - return SLOB_UNITS(*m) * SLOB_UNIT;
95444 + m = (slob_t *)(block - align);
95445 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95446 }
95447 EXPORT_SYMBOL(ksize);
95448
95449 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95450
95451 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95452 {
95453 - void *b;
95454 + void *b = NULL;
95455
95456 flags &= gfp_allowed_mask;
95457
95458 lockdep_trace_alloc(flags);
95459
95460 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95461 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95462 +#else
95463 if (c->size < PAGE_SIZE) {
95464 b = slob_alloc(c->size, flags, c->align, node);
95465 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95466 SLOB_UNITS(c->size) * SLOB_UNIT,
95467 flags, node);
95468 } else {
95469 - b = slob_new_pages(flags, get_order(c->size), node);
95470 + struct page *sp;
95471 +
95472 + sp = slob_new_pages(flags, get_order(c->size), node);
95473 + if (sp) {
95474 + b = page_address(sp);
95475 + sp->private = c->size;
95476 + }
95477 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95478 PAGE_SIZE << get_order(c->size),
95479 flags, node);
95480 }
95481 +#endif
95482
95483 if (b && c->ctor)
95484 c->ctor(b);
95485 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95486
95487 static void __kmem_cache_free(void *b, int size)
95488 {
95489 - if (size < PAGE_SIZE)
95490 + struct page *sp;
95491 +
95492 + sp = virt_to_page(b);
95493 + BUG_ON(!PageSlab(sp));
95494 + if (!sp->private)
95495 slob_free(b, size);
95496 else
95497 - slob_free_pages(b, get_order(size));
95498 + slob_free_pages(sp, get_order(size));
95499 }
95500
95501 static void kmem_rcu_free(struct rcu_head *head)
95502 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95503
95504 void kmem_cache_free(struct kmem_cache *c, void *b)
95505 {
95506 + int size = c->size;
95507 +
95508 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95509 + if (size + c->align < PAGE_SIZE) {
95510 + size += c->align;
95511 + b -= c->align;
95512 + }
95513 +#endif
95514 +
95515 kmemleak_free_recursive(b, c->flags);
95516 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95517 struct slob_rcu *slob_rcu;
95518 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95519 - slob_rcu->size = c->size;
95520 + slob_rcu = b + (size - sizeof(struct slob_rcu));
95521 + slob_rcu->size = size;
95522 call_rcu(&slob_rcu->head, kmem_rcu_free);
95523 } else {
95524 - __kmem_cache_free(b, c->size);
95525 + __kmem_cache_free(b, size);
95526 }
95527
95528 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95529 + trace_kfree(_RET_IP_, b);
95530 +#else
95531 trace_kmem_cache_free(_RET_IP_, b);
95532 +#endif
95533 +
95534 }
95535 EXPORT_SYMBOL(kmem_cache_free);
95536
95537 diff --git a/mm/slub.c b/mm/slub.c
95538 index 25f14ad..ff4d0b7 100644
95539 --- a/mm/slub.c
95540 +++ b/mm/slub.c
95541 @@ -207,7 +207,7 @@ struct track {
95542
95543 enum track_item { TRACK_ALLOC, TRACK_FREE };
95544
95545 -#ifdef CONFIG_SYSFS
95546 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95547 static int sysfs_slab_add(struct kmem_cache *);
95548 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95549 static void sysfs_slab_remove(struct kmem_cache *);
95550 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
95551 if (!t->addr)
95552 return;
95553
95554 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95555 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95556 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95557 #ifdef CONFIG_STACKTRACE
95558 {
95559 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95560
95561 slab_free_hook(s, x);
95562
95563 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95564 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95565 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95566 + if (s->ctor)
95567 + s->ctor(x);
95568 + }
95569 +#endif
95570 +
95571 redo:
95572 /*
95573 * Determine the currently cpus per cpu slab.
95574 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
95575 * Merge control. If this is set then no merging of slab caches will occur.
95576 * (Could be removed. This was introduced to pacify the merge skeptics.)
95577 */
95578 -static int slub_nomerge;
95579 +static int slub_nomerge = 1;
95580
95581 /*
95582 * Calculate the order of allocation given an slab object size.
95583 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95584 s->inuse = size;
95585
95586 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95587 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95588 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95589 +#endif
95590 s->ctor)) {
95591 /*
95592 * Relocate free pointer after the object if it is not
95593 @@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95594 EXPORT_SYMBOL(__kmalloc_node);
95595 #endif
95596
95597 +bool is_usercopy_object(const void *ptr)
95598 +{
95599 + struct page *page;
95600 + struct kmem_cache *s;
95601 +
95602 + if (ZERO_OR_NULL_PTR(ptr))
95603 + return false;
95604 +
95605 + if (!slab_is_available())
95606 + return false;
95607 +
95608 + if (!virt_addr_valid(ptr))
95609 + return false;
95610 +
95611 + page = virt_to_head_page(ptr);
95612 +
95613 + if (!PageSlab(page))
95614 + return false;
95615 +
95616 + s = page->slab_cache;
95617 + return s->flags & SLAB_USERCOPY;
95618 +}
95619 +
95620 +#ifdef CONFIG_PAX_USERCOPY
95621 +const char *check_heap_object(const void *ptr, unsigned long n)
95622 +{
95623 + struct page *page;
95624 + struct kmem_cache *s;
95625 + unsigned long offset;
95626 +
95627 + if (ZERO_OR_NULL_PTR(ptr))
95628 + return "<null>";
95629 +
95630 + if (!virt_addr_valid(ptr))
95631 + return NULL;
95632 +
95633 + page = virt_to_head_page(ptr);
95634 +
95635 + if (!PageSlab(page))
95636 + return NULL;
95637 +
95638 + s = page->slab_cache;
95639 + if (!(s->flags & SLAB_USERCOPY))
95640 + return s->name;
95641 +
95642 + offset = (ptr - page_address(page)) % s->size;
95643 + if (offset <= s->object_size && n <= s->object_size - offset)
95644 + return NULL;
95645 +
95646 + return s->name;
95647 +}
95648 +#endif
95649 +
95650 size_t ksize(const void *object)
95651 {
95652 struct page *page;
95653 @@ -3387,6 +3451,7 @@ void kfree(const void *x)
95654 if (unlikely(ZERO_OR_NULL_PTR(x)))
95655 return;
95656
95657 + VM_BUG_ON(!virt_addr_valid(x));
95658 page = virt_to_head_page(x);
95659 if (unlikely(!PageSlab(page))) {
95660 BUG_ON(!PageCompound(page));
95661 @@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95662 /*
95663 * We may have set a slab to be unmergeable during bootstrap.
95664 */
95665 - if (s->refcount < 0)
95666 + if (atomic_read(&s->refcount) < 0)
95667 return 1;
95668
95669 return 0;
95670 @@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95671
95672 s = find_mergeable(memcg, size, align, flags, name, ctor);
95673 if (s) {
95674 - s->refcount++;
95675 + atomic_inc(&s->refcount);
95676 /*
95677 * Adjust the object sizes so that we clear
95678 * the complete object on kzalloc.
95679 @@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95680 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95681
95682 if (sysfs_slab_alias(s, name)) {
95683 - s->refcount--;
95684 + atomic_dec(&s->refcount);
95685 s = NULL;
95686 }
95687 }
95688 @@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95689 }
95690 #endif
95691
95692 -#ifdef CONFIG_SYSFS
95693 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95694 static int count_inuse(struct page *page)
95695 {
95696 return page->inuse;
95697 @@ -4268,12 +4333,12 @@ static void resiliency_test(void)
95698 validate_slab_cache(kmalloc_caches[9]);
95699 }
95700 #else
95701 -#ifdef CONFIG_SYSFS
95702 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95703 static void resiliency_test(void) {};
95704 #endif
95705 #endif
95706
95707 -#ifdef CONFIG_SYSFS
95708 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95709 enum slab_stat_type {
95710 SL_ALL, /* All slabs */
95711 SL_PARTIAL, /* Only partially allocated slabs */
95712 @@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
95713
95714 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95715 {
95716 - return sprintf(buf, "%d\n", s->refcount - 1);
95717 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95718 }
95719 SLAB_ATTR_RO(aliases);
95720
95721 @@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95722 SLAB_ATTR_RO(cache_dma);
95723 #endif
95724
95725 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95726 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95727 +{
95728 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95729 +}
95730 +SLAB_ATTR_RO(usercopy);
95731 +#endif
95732 +
95733 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95734 {
95735 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95736 @@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
95737 #ifdef CONFIG_ZONE_DMA
95738 &cache_dma_attr.attr,
95739 #endif
95740 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95741 + &usercopy_attr.attr,
95742 +#endif
95743 #ifdef CONFIG_NUMA
95744 &remote_node_defrag_ratio_attr.attr,
95745 #endif
95746 @@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
95747 return name;
95748 }
95749
95750 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95751 static int sysfs_slab_add(struct kmem_cache *s)
95752 {
95753 int err;
95754 @@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95755 kobject_del(&s->kobj);
95756 kobject_put(&s->kobj);
95757 }
95758 +#endif
95759
95760 /*
95761 * Need to buffer aliases during bootup until sysfs becomes
95762 @@ -5243,6 +5321,7 @@ struct saved_alias {
95763
95764 static struct saved_alias *alias_list;
95765
95766 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95767 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95768 {
95769 struct saved_alias *al;
95770 @@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95771 alias_list = al;
95772 return 0;
95773 }
95774 +#endif
95775
95776 static int __init slab_sysfs_init(void)
95777 {
95778 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95779 index 4cba9c2..b4f9fcc 100644
95780 --- a/mm/sparse-vmemmap.c
95781 +++ b/mm/sparse-vmemmap.c
95782 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95783 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95784 if (!p)
95785 return NULL;
95786 - pud_populate(&init_mm, pud, p);
95787 + pud_populate_kernel(&init_mm, pud, p);
95788 }
95789 return pud;
95790 }
95791 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95792 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95793 if (!p)
95794 return NULL;
95795 - pgd_populate(&init_mm, pgd, p);
95796 + pgd_populate_kernel(&init_mm, pgd, p);
95797 }
95798 return pgd;
95799 }
95800 diff --git a/mm/sparse.c b/mm/sparse.c
95801 index 63c3ea5..95c0858 100644
95802 --- a/mm/sparse.c
95803 +++ b/mm/sparse.c
95804 @@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95805
95806 for (i = 0; i < PAGES_PER_SECTION; i++) {
95807 if (PageHWPoison(&memmap[i])) {
95808 - atomic_long_sub(1, &num_poisoned_pages);
95809 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
95810 ClearPageHWPoison(&memmap[i]);
95811 }
95812 }
95813 diff --git a/mm/swap.c b/mm/swap.c
95814 index 0092097..33361ff 100644
95815 --- a/mm/swap.c
95816 +++ b/mm/swap.c
95817 @@ -31,6 +31,7 @@
95818 #include <linux/memcontrol.h>
95819 #include <linux/gfp.h>
95820 #include <linux/uio.h>
95821 +#include <linux/hugetlb.h>
95822
95823 #include "internal.h"
95824
95825 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
95826
95827 __page_cache_release(page);
95828 dtor = get_compound_page_dtor(page);
95829 + if (!PageHuge(page))
95830 + BUG_ON(dtor != free_compound_page);
95831 (*dtor)(page);
95832 }
95833
95834 diff --git a/mm/swapfile.c b/mm/swapfile.c
95835 index 4a7f7e6..22cddf5 100644
95836 --- a/mm/swapfile.c
95837 +++ b/mm/swapfile.c
95838 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95839
95840 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95841 /* Activity counter to indicate that a swapon or swapoff has occurred */
95842 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
95843 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95844
95845 static inline unsigned char swap_count(unsigned char ent)
95846 {
95847 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95848 spin_unlock(&swap_lock);
95849
95850 err = 0;
95851 - atomic_inc(&proc_poll_event);
95852 + atomic_inc_unchecked(&proc_poll_event);
95853 wake_up_interruptible(&proc_poll_wait);
95854
95855 out_dput:
95856 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95857
95858 poll_wait(file, &proc_poll_wait, wait);
95859
95860 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
95861 - seq->poll_event = atomic_read(&proc_poll_event);
95862 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95863 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95864 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95865 }
95866
95867 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95868 return ret;
95869
95870 seq = file->private_data;
95871 - seq->poll_event = atomic_read(&proc_poll_event);
95872 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95873 return 0;
95874 }
95875
95876 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95877 (frontswap_map) ? "FS" : "");
95878
95879 mutex_unlock(&swapon_mutex);
95880 - atomic_inc(&proc_poll_event);
95881 + atomic_inc_unchecked(&proc_poll_event);
95882 wake_up_interruptible(&proc_poll_wait);
95883
95884 if (S_ISREG(inode->i_mode))
95885 diff --git a/mm/util.c b/mm/util.c
95886 index a24aa22..a0d41ae 100644
95887 --- a/mm/util.c
95888 +++ b/mm/util.c
95889 @@ -297,6 +297,12 @@ done:
95890 void arch_pick_mmap_layout(struct mm_struct *mm)
95891 {
95892 mm->mmap_base = TASK_UNMAPPED_BASE;
95893 +
95894 +#ifdef CONFIG_PAX_RANDMMAP
95895 + if (mm->pax_flags & MF_PAX_RANDMMAP)
95896 + mm->mmap_base += mm->delta_mmap;
95897 +#endif
95898 +
95899 mm->get_unmapped_area = arch_get_unmapped_area;
95900 }
95901 #endif
95902 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95903 index 0fdf968..d6686e8 100644
95904 --- a/mm/vmalloc.c
95905 +++ b/mm/vmalloc.c
95906 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95907
95908 pte = pte_offset_kernel(pmd, addr);
95909 do {
95910 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95911 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95912 +
95913 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95914 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95915 + BUG_ON(!pte_exec(*pte));
95916 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95917 + continue;
95918 + }
95919 +#endif
95920 +
95921 + {
95922 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95923 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95924 + }
95925 } while (pte++, addr += PAGE_SIZE, addr != end);
95926 }
95927
95928 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95929 pte = pte_alloc_kernel(pmd, addr);
95930 if (!pte)
95931 return -ENOMEM;
95932 +
95933 + pax_open_kernel();
95934 do {
95935 struct page *page = pages[*nr];
95936
95937 - if (WARN_ON(!pte_none(*pte)))
95938 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95939 + if (pgprot_val(prot) & _PAGE_NX)
95940 +#endif
95941 +
95942 + if (!pte_none(*pte)) {
95943 + pax_close_kernel();
95944 + WARN_ON(1);
95945 return -EBUSY;
95946 - if (WARN_ON(!page))
95947 + }
95948 + if (!page) {
95949 + pax_close_kernel();
95950 + WARN_ON(1);
95951 return -ENOMEM;
95952 + }
95953 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95954 (*nr)++;
95955 } while (pte++, addr += PAGE_SIZE, addr != end);
95956 + pax_close_kernel();
95957 return 0;
95958 }
95959
95960 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95961 pmd_t *pmd;
95962 unsigned long next;
95963
95964 - pmd = pmd_alloc(&init_mm, pud, addr);
95965 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95966 if (!pmd)
95967 return -ENOMEM;
95968 do {
95969 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95970 pud_t *pud;
95971 unsigned long next;
95972
95973 - pud = pud_alloc(&init_mm, pgd, addr);
95974 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95975 if (!pud)
95976 return -ENOMEM;
95977 do {
95978 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95979 if (addr >= MODULES_VADDR && addr < MODULES_END)
95980 return 1;
95981 #endif
95982 +
95983 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95984 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95985 + return 1;
95986 +#endif
95987 +
95988 return is_vmalloc_addr(x);
95989 }
95990
95991 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95992
95993 if (!pgd_none(*pgd)) {
95994 pud_t *pud = pud_offset(pgd, addr);
95995 +#ifdef CONFIG_X86
95996 + if (!pud_large(*pud))
95997 +#endif
95998 if (!pud_none(*pud)) {
95999 pmd_t *pmd = pmd_offset(pud, addr);
96000 +#ifdef CONFIG_X86
96001 + if (!pmd_large(*pmd))
96002 +#endif
96003 if (!pmd_none(*pmd)) {
96004 pte_t *ptep, pte;
96005
96006 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96007 struct vm_struct *area;
96008
96009 BUG_ON(in_interrupt());
96010 +
96011 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96012 + if (flags & VM_KERNEXEC) {
96013 + if (start != VMALLOC_START || end != VMALLOC_END)
96014 + return NULL;
96015 + start = (unsigned long)MODULES_EXEC_VADDR;
96016 + end = (unsigned long)MODULES_EXEC_END;
96017 + }
96018 +#endif
96019 +
96020 if (flags & VM_IOREMAP)
96021 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96022
96023 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96024 if (count > totalram_pages)
96025 return NULL;
96026
96027 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96028 + if (!(pgprot_val(prot) & _PAGE_NX))
96029 + flags |= VM_KERNEXEC;
96030 +#endif
96031 +
96032 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96033 __builtin_return_address(0));
96034 if (!area)
96035 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96036 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96037 goto fail;
96038
96039 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96040 + if (!(pgprot_val(prot) & _PAGE_NX))
96041 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96042 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96043 + else
96044 +#endif
96045 +
96046 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96047 start, end, node, gfp_mask, caller);
96048 if (!area)
96049 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96050 * For tight control over page level allocator and protection flags
96051 * use __vmalloc() instead.
96052 */
96053 -
96054 void *vmalloc_exec(unsigned long size)
96055 {
96056 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96057 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96058 NUMA_NO_NODE, __builtin_return_address(0));
96059 }
96060
96061 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96062 {
96063 struct vm_struct *area;
96064
96065 + BUG_ON(vma->vm_mirror);
96066 +
96067 size = PAGE_ALIGN(size);
96068
96069 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96070 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96071 v->addr, v->addr + v->size, v->size);
96072
96073 if (v->caller)
96074 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96075 + seq_printf(m, " %pK", v->caller);
96076 +#else
96077 seq_printf(m, " %pS", v->caller);
96078 +#endif
96079
96080 if (v->nr_pages)
96081 seq_printf(m, " pages=%d", v->nr_pages);
96082 diff --git a/mm/vmstat.c b/mm/vmstat.c
96083 index def5dd2..4ce55cec 100644
96084 --- a/mm/vmstat.c
96085 +++ b/mm/vmstat.c
96086 @@ -20,6 +20,7 @@
96087 #include <linux/writeback.h>
96088 #include <linux/compaction.h>
96089 #include <linux/mm_inline.h>
96090 +#include <linux/grsecurity.h>
96091
96092 #include "internal.h"
96093
96094 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96095 *
96096 * vm_stat contains the global counters
96097 */
96098 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96099 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96100 EXPORT_SYMBOL(vm_stat);
96101
96102 #ifdef CONFIG_SMP
96103 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96104
96105 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96106 if (diff[i])
96107 - atomic_long_add(diff[i], &vm_stat[i]);
96108 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96109 }
96110
96111 /*
96112 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96113 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96114 if (v) {
96115
96116 - atomic_long_add(v, &zone->vm_stat[i]);
96117 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96118 global_diff[i] += v;
96119 #ifdef CONFIG_NUMA
96120 /* 3 seconds idle till flush */
96121 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96122
96123 v = p->vm_stat_diff[i];
96124 p->vm_stat_diff[i] = 0;
96125 - atomic_long_add(v, &zone->vm_stat[i]);
96126 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96127 global_diff[i] += v;
96128 }
96129 }
96130 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96131 if (pset->vm_stat_diff[i]) {
96132 int v = pset->vm_stat_diff[i];
96133 pset->vm_stat_diff[i] = 0;
96134 - atomic_long_add(v, &zone->vm_stat[i]);
96135 - atomic_long_add(v, &vm_stat[i]);
96136 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96137 + atomic_long_add_unchecked(v, &vm_stat[i]);
96138 }
96139 }
96140 #endif
96141 @@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96142 stat_items_size += sizeof(struct vm_event_state);
96143 #endif
96144
96145 - v = kmalloc(stat_items_size, GFP_KERNEL);
96146 + v = kzalloc(stat_items_size, GFP_KERNEL);
96147 m->private = v;
96148 if (!v)
96149 return ERR_PTR(-ENOMEM);
96150 +
96151 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
96152 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96153 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96154 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96155 + && !in_group_p(grsec_proc_gid)
96156 +#endif
96157 + )
96158 + return (unsigned long *)m->private + *pos;
96159 +#endif
96160 +#endif
96161 +
96162 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96163 v[i] = global_page_state(i);
96164 v += NR_VM_ZONE_STAT_ITEMS;
96165 @@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
96166 put_online_cpus();
96167 #endif
96168 #ifdef CONFIG_PROC_FS
96169 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96170 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96171 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96172 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96173 + {
96174 + mode_t gr_mode = S_IRUGO;
96175 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
96176 + gr_mode = S_IRUSR;
96177 +#endif
96178 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96179 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96180 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96181 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96182 + }
96183 #endif
96184 return 0;
96185 }
96186 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96187 index 175273f..1c63e05 100644
96188 --- a/net/8021q/vlan.c
96189 +++ b/net/8021q/vlan.c
96190 @@ -474,7 +474,7 @@ out:
96191 return NOTIFY_DONE;
96192 }
96193
96194 -static struct notifier_block vlan_notifier_block __read_mostly = {
96195 +static struct notifier_block vlan_notifier_block = {
96196 .notifier_call = vlan_device_event,
96197 };
96198
96199 @@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96200 err = -EPERM;
96201 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96202 break;
96203 - if ((args.u.name_type >= 0) &&
96204 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96205 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96206 struct vlan_net *vn;
96207
96208 vn = net_generic(net, vlan_net_id);
96209 diff --git a/net/9p/client.c b/net/9p/client.c
96210 index 9186550..e604a2f 100644
96211 --- a/net/9p/client.c
96212 +++ b/net/9p/client.c
96213 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96214 len - inline_len);
96215 } else {
96216 err = copy_from_user(ename + inline_len,
96217 - uidata, len - inline_len);
96218 + (char __force_user *)uidata, len - inline_len);
96219 if (err) {
96220 err = -EFAULT;
96221 goto out_err;
96222 @@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96223 kernel_buf = 1;
96224 indata = data;
96225 } else
96226 - indata = (__force char *)udata;
96227 + indata = (__force_kernel char *)udata;
96228 /*
96229 * response header len is 11
96230 * PDU Header(7) + IO Size (4)
96231 @@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96232 kernel_buf = 1;
96233 odata = data;
96234 } else
96235 - odata = (char *)udata;
96236 + odata = (char __force_kernel *)udata;
96237 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96238 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96239 fid->fid, offset, rsize);
96240 diff --git a/net/9p/mod.c b/net/9p/mod.c
96241 index 6ab36ae..6f1841b 100644
96242 --- a/net/9p/mod.c
96243 +++ b/net/9p/mod.c
96244 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96245 void v9fs_register_trans(struct p9_trans_module *m)
96246 {
96247 spin_lock(&v9fs_trans_lock);
96248 - list_add_tail(&m->list, &v9fs_trans_list);
96249 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96250 spin_unlock(&v9fs_trans_lock);
96251 }
96252 EXPORT_SYMBOL(v9fs_register_trans);
96253 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96254 void v9fs_unregister_trans(struct p9_trans_module *m)
96255 {
96256 spin_lock(&v9fs_trans_lock);
96257 - list_del_init(&m->list);
96258 + pax_list_del_init((struct list_head *)&m->list);
96259 spin_unlock(&v9fs_trans_lock);
96260 }
96261 EXPORT_SYMBOL(v9fs_unregister_trans);
96262 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96263 index b7bd7f2..2498bf7 100644
96264 --- a/net/9p/trans_fd.c
96265 +++ b/net/9p/trans_fd.c
96266 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96267 oldfs = get_fs();
96268 set_fs(get_ds());
96269 /* The cast to a user pointer is valid due to the set_fs() */
96270 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96271 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96272 set_fs(oldfs);
96273
96274 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96275 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96276 index 876fbe8..8bbea9f 100644
96277 --- a/net/atm/atm_misc.c
96278 +++ b/net/atm/atm_misc.c
96279 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96280 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96281 return 1;
96282 atm_return(vcc, truesize);
96283 - atomic_inc(&vcc->stats->rx_drop);
96284 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96285 return 0;
96286 }
96287 EXPORT_SYMBOL(atm_charge);
96288 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96289 }
96290 }
96291 atm_return(vcc, guess);
96292 - atomic_inc(&vcc->stats->rx_drop);
96293 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96294 return NULL;
96295 }
96296 EXPORT_SYMBOL(atm_alloc_charge);
96297 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96298
96299 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96300 {
96301 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96302 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96303 __SONET_ITEMS
96304 #undef __HANDLE_ITEM
96305 }
96306 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96307
96308 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96309 {
96310 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96311 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96312 __SONET_ITEMS
96313 #undef __HANDLE_ITEM
96314 }
96315 diff --git a/net/atm/lec.c b/net/atm/lec.c
96316 index 5a2f602..9396143 100644
96317 --- a/net/atm/lec.c
96318 +++ b/net/atm/lec.c
96319 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96320 }
96321
96322 static struct lane2_ops lane2_ops = {
96323 - lane2_resolve, /* resolve, spec 3.1.3 */
96324 - lane2_associate_req, /* associate_req, spec 3.1.4 */
96325 - NULL /* associate indicator, spec 3.1.5 */
96326 + .resolve = lane2_resolve,
96327 + .associate_req = lane2_associate_req,
96328 + .associate_indicator = NULL
96329 };
96330
96331 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96332 diff --git a/net/atm/lec.h b/net/atm/lec.h
96333 index 4149db1..f2ab682 100644
96334 --- a/net/atm/lec.h
96335 +++ b/net/atm/lec.h
96336 @@ -48,7 +48,7 @@ struct lane2_ops {
96337 const u8 *tlvs, u32 sizeoftlvs);
96338 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96339 const u8 *tlvs, u32 sizeoftlvs);
96340 -};
96341 +} __no_const;
96342
96343 /*
96344 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96345 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96346 index d1b2d9a..d549f7f 100644
96347 --- a/net/atm/mpoa_caches.c
96348 +++ b/net/atm/mpoa_caches.c
96349 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96350
96351
96352 static struct in_cache_ops ingress_ops = {
96353 - in_cache_add_entry, /* add_entry */
96354 - in_cache_get, /* get */
96355 - in_cache_get_with_mask, /* get_with_mask */
96356 - in_cache_get_by_vcc, /* get_by_vcc */
96357 - in_cache_put, /* put */
96358 - in_cache_remove_entry, /* remove_entry */
96359 - cache_hit, /* cache_hit */
96360 - clear_count_and_expired, /* clear_count */
96361 - check_resolving_entries, /* check_resolving */
96362 - refresh_entries, /* refresh */
96363 - in_destroy_cache /* destroy_cache */
96364 + .add_entry = in_cache_add_entry,
96365 + .get = in_cache_get,
96366 + .get_with_mask = in_cache_get_with_mask,
96367 + .get_by_vcc = in_cache_get_by_vcc,
96368 + .put = in_cache_put,
96369 + .remove_entry = in_cache_remove_entry,
96370 + .cache_hit = cache_hit,
96371 + .clear_count = clear_count_and_expired,
96372 + .check_resolving = check_resolving_entries,
96373 + .refresh = refresh_entries,
96374 + .destroy_cache = in_destroy_cache
96375 };
96376
96377 static struct eg_cache_ops egress_ops = {
96378 - eg_cache_add_entry, /* add_entry */
96379 - eg_cache_get_by_cache_id, /* get_by_cache_id */
96380 - eg_cache_get_by_tag, /* get_by_tag */
96381 - eg_cache_get_by_vcc, /* get_by_vcc */
96382 - eg_cache_get_by_src_ip, /* get_by_src_ip */
96383 - eg_cache_put, /* put */
96384 - eg_cache_remove_entry, /* remove_entry */
96385 - update_eg_cache_entry, /* update */
96386 - clear_expired, /* clear_expired */
96387 - eg_destroy_cache /* destroy_cache */
96388 + .add_entry = eg_cache_add_entry,
96389 + .get_by_cache_id = eg_cache_get_by_cache_id,
96390 + .get_by_tag = eg_cache_get_by_tag,
96391 + .get_by_vcc = eg_cache_get_by_vcc,
96392 + .get_by_src_ip = eg_cache_get_by_src_ip,
96393 + .put = eg_cache_put,
96394 + .remove_entry = eg_cache_remove_entry,
96395 + .update = update_eg_cache_entry,
96396 + .clear_expired = clear_expired,
96397 + .destroy_cache = eg_destroy_cache
96398 };
96399
96400
96401 diff --git a/net/atm/proc.c b/net/atm/proc.c
96402 index bbb6461..cf04016 100644
96403 --- a/net/atm/proc.c
96404 +++ b/net/atm/proc.c
96405 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96406 const struct k_atm_aal_stats *stats)
96407 {
96408 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96409 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96410 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96411 - atomic_read(&stats->rx_drop));
96412 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96413 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96414 + atomic_read_unchecked(&stats->rx_drop));
96415 }
96416
96417 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96418 diff --git a/net/atm/resources.c b/net/atm/resources.c
96419 index 0447d5d..3cf4728 100644
96420 --- a/net/atm/resources.c
96421 +++ b/net/atm/resources.c
96422 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96423 static void copy_aal_stats(struct k_atm_aal_stats *from,
96424 struct atm_aal_stats *to)
96425 {
96426 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96427 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96428 __AAL_STAT_ITEMS
96429 #undef __HANDLE_ITEM
96430 }
96431 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96432 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96433 struct atm_aal_stats *to)
96434 {
96435 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96436 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96437 __AAL_STAT_ITEMS
96438 #undef __HANDLE_ITEM
96439 }
96440 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96441 index 919a5ce..cc6b444 100644
96442 --- a/net/ax25/sysctl_net_ax25.c
96443 +++ b/net/ax25/sysctl_net_ax25.c
96444 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96445 {
96446 char path[sizeof("net/ax25/") + IFNAMSIZ];
96447 int k;
96448 - struct ctl_table *table;
96449 + ctl_table_no_const *table;
96450
96451 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96452 if (!table)
96453 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96454 index 8323bce..a03130d 100644
96455 --- a/net/batman-adv/bat_iv_ogm.c
96456 +++ b/net/batman-adv/bat_iv_ogm.c
96457 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96458
96459 /* randomize initial seqno to avoid collision */
96460 get_random_bytes(&random_seqno, sizeof(random_seqno));
96461 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96462 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96463
96464 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96465 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96466 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96467 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96468
96469 /* change sequence number to network order */
96470 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96471 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96472 batadv_ogm_packet->seqno = htonl(seqno);
96473 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96474 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96475
96476 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96477
96478 @@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
96479 return;
96480
96481 /* could be changed by schedule_own_packet() */
96482 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96483 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96484
96485 if (ogm_packet->flags & BATADV_DIRECTLINK)
96486 has_directlink_flag = true;
96487 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96488 index 88df9b1..69cf7c0 100644
96489 --- a/net/batman-adv/fragmentation.c
96490 +++ b/net/batman-adv/fragmentation.c
96491 @@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96492 frag_header.packet_type = BATADV_UNICAST_FRAG;
96493 frag_header.version = BATADV_COMPAT_VERSION;
96494 frag_header.ttl = BATADV_TTL;
96495 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96496 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96497 frag_header.reserved = 0;
96498 frag_header.no = 0;
96499 frag_header.total_size = htons(skb->len);
96500 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96501 index f82c267..0e56d32 100644
96502 --- a/net/batman-adv/soft-interface.c
96503 +++ b/net/batman-adv/soft-interface.c
96504 @@ -283,7 +283,7 @@ send:
96505 primary_if->net_dev->dev_addr, ETH_ALEN);
96506
96507 /* set broadcast sequence number */
96508 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96509 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96510 bcast_packet->seqno = htonl(seqno);
96511
96512 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96513 @@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96514 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96515
96516 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96517 - atomic_set(&bat_priv->bcast_seqno, 1);
96518 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96519 atomic_set(&bat_priv->tt.vn, 0);
96520 atomic_set(&bat_priv->tt.local_changes, 0);
96521 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96522 @@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96523
96524 /* randomize initial seqno to avoid collision */
96525 get_random_bytes(&random_seqno, sizeof(random_seqno));
96526 - atomic_set(&bat_priv->frag_seqno, random_seqno);
96527 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96528
96529 bat_priv->primary_if = NULL;
96530 bat_priv->num_ifaces = 0;
96531 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96532 index 78370ab..1cb3614 100644
96533 --- a/net/batman-adv/types.h
96534 +++ b/net/batman-adv/types.h
96535 @@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
96536 struct batadv_hard_iface_bat_iv {
96537 unsigned char *ogm_buff;
96538 int ogm_buff_len;
96539 - atomic_t ogm_seqno;
96540 + atomic_unchecked_t ogm_seqno;
96541 };
96542
96543 /**
96544 @@ -714,7 +714,7 @@ struct batadv_priv {
96545 atomic_t bonding;
96546 atomic_t fragmentation;
96547 atomic_t packet_size_max;
96548 - atomic_t frag_seqno;
96549 + atomic_unchecked_t frag_seqno;
96550 #ifdef CONFIG_BATMAN_ADV_BLA
96551 atomic_t bridge_loop_avoidance;
96552 #endif
96553 @@ -730,7 +730,7 @@ struct batadv_priv {
96554 #endif
96555 uint32_t isolation_mark;
96556 uint32_t isolation_mark_mask;
96557 - atomic_t bcast_seqno;
96558 + atomic_unchecked_t bcast_seqno;
96559 atomic_t bcast_queue_left;
96560 atomic_t batman_queue_left;
96561 char num_ifaces;
96562 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96563 index 7552f9e..074ce29 100644
96564 --- a/net/bluetooth/hci_sock.c
96565 +++ b/net/bluetooth/hci_sock.c
96566 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96567 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96568 }
96569
96570 - len = min_t(unsigned int, len, sizeof(uf));
96571 + len = min((size_t)len, sizeof(uf));
96572 if (copy_from_user(&uf, optval, len)) {
96573 err = -EFAULT;
96574 break;
96575 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96576 index b0ad2c7..96f6a5e 100644
96577 --- a/net/bluetooth/l2cap_core.c
96578 +++ b/net/bluetooth/l2cap_core.c
96579 @@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96580 break;
96581
96582 case L2CAP_CONF_RFC:
96583 - if (olen == sizeof(rfc))
96584 - memcpy(&rfc, (void *)val, olen);
96585 + if (olen != sizeof(rfc))
96586 + break;
96587 +
96588 + memcpy(&rfc, (void *)val, olen);
96589
96590 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96591 rfc.mode != chan->mode)
96592 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96593 index d58f76b..b69600a 100644
96594 --- a/net/bluetooth/l2cap_sock.c
96595 +++ b/net/bluetooth/l2cap_sock.c
96596 @@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96597 struct sock *sk = sock->sk;
96598 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96599 struct l2cap_options opts;
96600 - int len, err = 0;
96601 + int err = 0;
96602 + size_t len = optlen;
96603 u32 opt;
96604
96605 BT_DBG("sk %p", sk);
96606 @@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96607 opts.max_tx = chan->max_tx;
96608 opts.txwin_size = chan->tx_win;
96609
96610 - len = min_t(unsigned int, sizeof(opts), optlen);
96611 + len = min(sizeof(opts), len);
96612 if (copy_from_user((char *) &opts, optval, len)) {
96613 err = -EFAULT;
96614 break;
96615 @@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96616 struct bt_security sec;
96617 struct bt_power pwr;
96618 struct l2cap_conn *conn;
96619 - int len, err = 0;
96620 + int err = 0;
96621 + size_t len = optlen;
96622 u32 opt;
96623
96624 BT_DBG("sk %p", sk);
96625 @@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96626
96627 sec.level = BT_SECURITY_LOW;
96628
96629 - len = min_t(unsigned int, sizeof(sec), optlen);
96630 + len = min(sizeof(sec), len);
96631 if (copy_from_user((char *) &sec, optval, len)) {
96632 err = -EFAULT;
96633 break;
96634 @@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96635
96636 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96637
96638 - len = min_t(unsigned int, sizeof(pwr), optlen);
96639 + len = min(sizeof(pwr), len);
96640 if (copy_from_user((char *) &pwr, optval, len)) {
96641 err = -EFAULT;
96642 break;
96643 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96644 index 3c2d3e4..884855a 100644
96645 --- a/net/bluetooth/rfcomm/sock.c
96646 +++ b/net/bluetooth/rfcomm/sock.c
96647 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96648 struct sock *sk = sock->sk;
96649 struct bt_security sec;
96650 int err = 0;
96651 - size_t len;
96652 + size_t len = optlen;
96653 u32 opt;
96654
96655 BT_DBG("sk %p", sk);
96656 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96657
96658 sec.level = BT_SECURITY_LOW;
96659
96660 - len = min_t(unsigned int, sizeof(sec), optlen);
96661 + len = min(sizeof(sec), len);
96662 if (copy_from_user((char *) &sec, optval, len)) {
96663 err = -EFAULT;
96664 break;
96665 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96666 index f9c0980a..fcbbfeb 100644
96667 --- a/net/bluetooth/rfcomm/tty.c
96668 +++ b/net/bluetooth/rfcomm/tty.c
96669 @@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96670 BT_DBG("tty %p id %d", tty, tty->index);
96671
96672 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96673 - dev->channel, dev->port.count);
96674 + dev->channel, atomic_read(&dev->port.count));
96675
96676 err = tty_port_open(&dev->port, tty, filp);
96677 if (err)
96678 @@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96679 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96680
96681 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96682 - dev->port.count);
96683 + atomic_read(&dev->port.count));
96684
96685 tty_port_close(&dev->port, tty, filp);
96686 }
96687 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96688 index 0e474b1..fb7109c 100644
96689 --- a/net/bridge/netfilter/ebtables.c
96690 +++ b/net/bridge/netfilter/ebtables.c
96691 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96692 tmp.valid_hooks = t->table->valid_hooks;
96693 }
96694 mutex_unlock(&ebt_mutex);
96695 - if (copy_to_user(user, &tmp, *len) != 0) {
96696 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96697 BUGPRINT("c2u Didn't work\n");
96698 ret = -EFAULT;
96699 break;
96700 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96701 goto out;
96702 tmp.valid_hooks = t->valid_hooks;
96703
96704 - if (copy_to_user(user, &tmp, *len) != 0) {
96705 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96706 ret = -EFAULT;
96707 break;
96708 }
96709 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96710 tmp.entries_size = t->table->entries_size;
96711 tmp.valid_hooks = t->table->valid_hooks;
96712
96713 - if (copy_to_user(user, &tmp, *len) != 0) {
96714 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96715 ret = -EFAULT;
96716 break;
96717 }
96718 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96719 index 0f45522..dab651f 100644
96720 --- a/net/caif/cfctrl.c
96721 +++ b/net/caif/cfctrl.c
96722 @@ -10,6 +10,7 @@
96723 #include <linux/spinlock.h>
96724 #include <linux/slab.h>
96725 #include <linux/pkt_sched.h>
96726 +#include <linux/sched.h>
96727 #include <net/caif/caif_layer.h>
96728 #include <net/caif/cfpkt.h>
96729 #include <net/caif/cfctrl.h>
96730 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96731 memset(&dev_info, 0, sizeof(dev_info));
96732 dev_info.id = 0xff;
96733 cfsrvl_init(&this->serv, 0, &dev_info, false);
96734 - atomic_set(&this->req_seq_no, 1);
96735 - atomic_set(&this->rsp_seq_no, 1);
96736 + atomic_set_unchecked(&this->req_seq_no, 1);
96737 + atomic_set_unchecked(&this->rsp_seq_no, 1);
96738 this->serv.layer.receive = cfctrl_recv;
96739 sprintf(this->serv.layer.name, "ctrl");
96740 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96741 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96742 struct cfctrl_request_info *req)
96743 {
96744 spin_lock_bh(&ctrl->info_list_lock);
96745 - atomic_inc(&ctrl->req_seq_no);
96746 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
96747 + atomic_inc_unchecked(&ctrl->req_seq_no);
96748 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96749 list_add_tail(&req->list, &ctrl->list);
96750 spin_unlock_bh(&ctrl->info_list_lock);
96751 }
96752 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96753 if (p != first)
96754 pr_warn("Requests are not received in order\n");
96755
96756 - atomic_set(&ctrl->rsp_seq_no,
96757 + atomic_set_unchecked(&ctrl->rsp_seq_no,
96758 p->sequence_no);
96759 list_del(&p->list);
96760 goto out;
96761 diff --git a/net/can/af_can.c b/net/can/af_can.c
96762 index a27f8aa..67174a3 100644
96763 --- a/net/can/af_can.c
96764 +++ b/net/can/af_can.c
96765 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96766 };
96767
96768 /* notifier block for netdevice event */
96769 -static struct notifier_block can_netdev_notifier __read_mostly = {
96770 +static struct notifier_block can_netdev_notifier = {
96771 .notifier_call = can_notifier,
96772 };
96773
96774 diff --git a/net/can/gw.c b/net/can/gw.c
96775 index ac31891..4799c17 100644
96776 --- a/net/can/gw.c
96777 +++ b/net/can/gw.c
96778 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96779 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96780
96781 static HLIST_HEAD(cgw_list);
96782 -static struct notifier_block notifier;
96783
96784 static struct kmem_cache *cgw_cache __read_mostly;
96785
96786 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96787 return err;
96788 }
96789
96790 +static struct notifier_block notifier = {
96791 + .notifier_call = cgw_notifier
96792 +};
96793 +
96794 static __init int cgw_module_init(void)
96795 {
96796 /* sanitize given module parameter */
96797 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
96798 return -ENOMEM;
96799
96800 /* set notifier */
96801 - notifier.notifier_call = cgw_notifier;
96802 register_netdevice_notifier(&notifier);
96803
96804 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96805 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96806 index 30efc5c..cfa1bbc 100644
96807 --- a/net/ceph/messenger.c
96808 +++ b/net/ceph/messenger.c
96809 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
96810 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96811
96812 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96813 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
96814 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96815
96816 static struct page *zero_page; /* used in certain error cases */
96817
96818 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96819 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96820 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96821
96822 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96823 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96824 s = addr_str[i];
96825
96826 switch (ss->ss_family) {
96827 diff --git a/net/compat.c b/net/compat.c
96828 index f50161f..94fa415 100644
96829 --- a/net/compat.c
96830 +++ b/net/compat.c
96831 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96832 return -EFAULT;
96833 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96834 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96835 - kmsg->msg_name = compat_ptr(tmp1);
96836 - kmsg->msg_iov = compat_ptr(tmp2);
96837 - kmsg->msg_control = compat_ptr(tmp3);
96838 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96839 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96840 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96841 return 0;
96842 }
96843
96844 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96845
96846 if (kern_msg->msg_namelen) {
96847 if (mode == VERIFY_READ) {
96848 - int err = move_addr_to_kernel(kern_msg->msg_name,
96849 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96850 kern_msg->msg_namelen,
96851 kern_address);
96852 if (err < 0)
96853 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96854 kern_msg->msg_name = NULL;
96855
96856 tot_len = iov_from_user_compat_to_kern(kern_iov,
96857 - (struct compat_iovec __user *)kern_msg->msg_iov,
96858 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
96859 kern_msg->msg_iovlen);
96860 if (tot_len >= 0)
96861 kern_msg->msg_iov = kern_iov;
96862 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96863
96864 #define CMSG_COMPAT_FIRSTHDR(msg) \
96865 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96866 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96867 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96868 (struct compat_cmsghdr __user *)NULL)
96869
96870 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96871 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96872 (ucmlen) <= (unsigned long) \
96873 ((mhdr)->msg_controllen - \
96874 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96875 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96876
96877 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96878 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96879 {
96880 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96881 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96882 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96883 msg->msg_controllen)
96884 return NULL;
96885 return (struct compat_cmsghdr __user *)ptr;
96886 @@ -222,7 +222,7 @@ Efault:
96887
96888 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96889 {
96890 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96891 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96892 struct compat_cmsghdr cmhdr;
96893 struct compat_timeval ctv;
96894 struct compat_timespec cts[3];
96895 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96896
96897 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96898 {
96899 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96900 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96901 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96902 int fdnum = scm->fp->count;
96903 struct file **fp = scm->fp->fp;
96904 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96905 return -EFAULT;
96906 old_fs = get_fs();
96907 set_fs(KERNEL_DS);
96908 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96909 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96910 set_fs(old_fs);
96911
96912 return err;
96913 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96914 len = sizeof(ktime);
96915 old_fs = get_fs();
96916 set_fs(KERNEL_DS);
96917 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96918 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96919 set_fs(old_fs);
96920
96921 if (!err) {
96922 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96923 case MCAST_JOIN_GROUP:
96924 case MCAST_LEAVE_GROUP:
96925 {
96926 - struct compat_group_req __user *gr32 = (void *)optval;
96927 + struct compat_group_req __user *gr32 = (void __user *)optval;
96928 struct group_req __user *kgr =
96929 compat_alloc_user_space(sizeof(struct group_req));
96930 u32 interface;
96931 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96932 case MCAST_BLOCK_SOURCE:
96933 case MCAST_UNBLOCK_SOURCE:
96934 {
96935 - struct compat_group_source_req __user *gsr32 = (void *)optval;
96936 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96937 struct group_source_req __user *kgsr = compat_alloc_user_space(
96938 sizeof(struct group_source_req));
96939 u32 interface;
96940 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96941 }
96942 case MCAST_MSFILTER:
96943 {
96944 - struct compat_group_filter __user *gf32 = (void *)optval;
96945 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96946 struct group_filter __user *kgf;
96947 u32 interface, fmode, numsrc;
96948
96949 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96950 char __user *optval, int __user *optlen,
96951 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96952 {
96953 - struct compat_group_filter __user *gf32 = (void *)optval;
96954 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96955 struct group_filter __user *kgf;
96956 int __user *koptlen;
96957 u32 interface, fmode, numsrc;
96958 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96959
96960 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96961 return -EINVAL;
96962 - if (copy_from_user(a, args, nas[call]))
96963 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96964 return -EFAULT;
96965 a0 = a[0];
96966 a1 = a[1];
96967 diff --git a/net/core/datagram.c b/net/core/datagram.c
96968 index a16ed7b..eb44d17 100644
96969 --- a/net/core/datagram.c
96970 +++ b/net/core/datagram.c
96971 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96972 }
96973
96974 kfree_skb(skb);
96975 - atomic_inc(&sk->sk_drops);
96976 + atomic_inc_unchecked(&sk->sk_drops);
96977 sk_mem_reclaim_partial(sk);
96978
96979 return err;
96980 diff --git a/net/core/dev.c b/net/core/dev.c
96981 index 45fa2f1..f3e28ec 100644
96982 --- a/net/core/dev.c
96983 +++ b/net/core/dev.c
96984 @@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96985 {
96986 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96987 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96988 - atomic_long_inc(&dev->rx_dropped);
96989 + atomic_long_inc_unchecked(&dev->rx_dropped);
96990 kfree_skb(skb);
96991 return NET_RX_DROP;
96992 }
96993 }
96994
96995 if (unlikely(!is_skb_forwardable(dev, skb))) {
96996 - atomic_long_inc(&dev->rx_dropped);
96997 + atomic_long_inc_unchecked(&dev->rx_dropped);
96998 kfree_skb(skb);
96999 return NET_RX_DROP;
97000 }
97001 @@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97002
97003 struct dev_gso_cb {
97004 void (*destructor)(struct sk_buff *skb);
97005 -};
97006 +} __no_const;
97007
97008 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97009
97010 @@ -3227,7 +3227,7 @@ enqueue:
97011
97012 local_irq_restore(flags);
97013
97014 - atomic_long_inc(&skb->dev->rx_dropped);
97015 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97016 kfree_skb(skb);
97017 return NET_RX_DROP;
97018 }
97019 @@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97020 }
97021 EXPORT_SYMBOL(netif_rx_ni);
97022
97023 -static void net_tx_action(struct softirq_action *h)
97024 +static __latent_entropy void net_tx_action(void)
97025 {
97026 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97027
97028 @@ -3645,7 +3645,7 @@ ncls:
97029 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97030 } else {
97031 drop:
97032 - atomic_long_inc(&skb->dev->rx_dropped);
97033 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97034 kfree_skb(skb);
97035 /* Jamal, now you will not able to escape explaining
97036 * me how you were going to use this. :-)
97037 @@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97038 }
97039 EXPORT_SYMBOL(netif_napi_del);
97040
97041 -static void net_rx_action(struct softirq_action *h)
97042 +static __latent_entropy void net_rx_action(void)
97043 {
97044 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97045 unsigned long time_limit = jiffies + 2;
97046 @@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97047 } else {
97048 netdev_stats_to_stats64(storage, &dev->stats);
97049 }
97050 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97051 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97052 return storage;
97053 }
97054 EXPORT_SYMBOL(dev_get_stats);
97055 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97056 index cf999e0..c59a975 100644
97057 --- a/net/core/dev_ioctl.c
97058 +++ b/net/core/dev_ioctl.c
97059 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97060 if (no_module && capable(CAP_NET_ADMIN))
97061 no_module = request_module("netdev-%s", name);
97062 if (no_module && capable(CAP_SYS_MODULE)) {
97063 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
97064 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
97065 +#else
97066 if (!request_module("%s", name))
97067 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97068 name);
97069 +#endif
97070 }
97071 }
97072 EXPORT_SYMBOL(dev_load);
97073 diff --git a/net/core/filter.c b/net/core/filter.c
97074 index ad30d62..21c0743 100644
97075 --- a/net/core/filter.c
97076 +++ b/net/core/filter.c
97077 @@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97078 void *ptr;
97079 u32 A = 0; /* Accumulator */
97080 u32 X = 0; /* Index Register */
97081 - u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97082 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97083 u32 tmp;
97084 int k;
97085
97086 @@ -292,10 +292,10 @@ load_b:
97087 X = K;
97088 continue;
97089 case BPF_S_LD_MEM:
97090 - A = mem[K];
97091 + A = mem[K&15];
97092 continue;
97093 case BPF_S_LDX_MEM:
97094 - X = mem[K];
97095 + X = mem[K&15];
97096 continue;
97097 case BPF_S_MISC_TAX:
97098 X = A;
97099 @@ -308,10 +308,10 @@ load_b:
97100 case BPF_S_RET_A:
97101 return A;
97102 case BPF_S_ST:
97103 - mem[K] = A;
97104 + mem[K&15] = A;
97105 continue;
97106 case BPF_S_STX:
97107 - mem[K] = X;
97108 + mem[K&15] = X;
97109 continue;
97110 case BPF_S_ANC_PROTOCOL:
97111 A = ntohs(skb->protocol);
97112 @@ -355,6 +355,10 @@ load_b:
97113
97114 if (skb_is_nonlinear(skb))
97115 return 0;
97116 +
97117 + if (skb->len < sizeof(struct nlattr))
97118 + return 0;
97119 +
97120 if (A > skb->len - sizeof(struct nlattr))
97121 return 0;
97122
97123 @@ -371,11 +375,15 @@ load_b:
97124
97125 if (skb_is_nonlinear(skb))
97126 return 0;
97127 +
97128 + if (skb->len < sizeof(struct nlattr))
97129 + return 0;
97130 +
97131 if (A > skb->len - sizeof(struct nlattr))
97132 return 0;
97133
97134 nla = (struct nlattr *)&skb->data[A];
97135 - if (nla->nla_len > A - skb->len)
97136 + if (nla->nla_len > skb->len - A)
97137 return 0;
97138
97139 nla = nla_find_nested(nla, X);
97140 @@ -391,9 +399,10 @@ load_b:
97141 continue;
97142 #endif
97143 default:
97144 - WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97145 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97146 fentry->code, fentry->jt,
97147 fentry->jf, fentry->k);
97148 + BUG();
97149 return 0;
97150 }
97151 }
97152 @@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97153 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97154 int pc, ret = 0;
97155
97156 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
97157 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
97158 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97159 if (!masks)
97160 return -ENOMEM;
97161 @@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97162 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97163 if (!fp)
97164 return -ENOMEM;
97165 - memcpy(fp->insns, fprog->filter, fsize);
97166 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97167
97168 atomic_set(&fp->refcnt, 1);
97169 fp->len = fprog->len;
97170 diff --git a/net/core/flow.c b/net/core/flow.c
97171 index dfa602c..3103d88 100644
97172 --- a/net/core/flow.c
97173 +++ b/net/core/flow.c
97174 @@ -61,7 +61,7 @@ struct flow_cache {
97175 struct timer_list rnd_timer;
97176 };
97177
97178 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
97179 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97180 EXPORT_SYMBOL(flow_cache_genid);
97181 static struct flow_cache flow_cache_global;
97182 static struct kmem_cache *flow_cachep __read_mostly;
97183 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97184
97185 static int flow_entry_valid(struct flow_cache_entry *fle)
97186 {
97187 - if (atomic_read(&flow_cache_genid) != fle->genid)
97188 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97189 return 0;
97190 if (fle->object && !fle->object->ops->check(fle->object))
97191 return 0;
97192 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97193 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97194 fcp->hash_count++;
97195 }
97196 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97197 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97198 flo = fle->object;
97199 if (!flo)
97200 goto ret_object;
97201 @@ -279,7 +279,7 @@ nocache:
97202 }
97203 flo = resolver(net, key, family, dir, flo, ctx);
97204 if (fle) {
97205 - fle->genid = atomic_read(&flow_cache_genid);
97206 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
97207 if (!IS_ERR(flo))
97208 fle->object = flo;
97209 else
97210 diff --git a/net/core/iovec.c b/net/core/iovec.c
97211 index b618694..192bbba 100644
97212 --- a/net/core/iovec.c
97213 +++ b/net/core/iovec.c
97214 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97215 if (m->msg_namelen) {
97216 if (mode == VERIFY_READ) {
97217 void __user *namep;
97218 - namep = (void __user __force *) m->msg_name;
97219 + namep = (void __force_user *) m->msg_name;
97220 err = move_addr_to_kernel(namep, m->msg_namelen,
97221 address);
97222 if (err < 0)
97223 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97224 }
97225
97226 size = m->msg_iovlen * sizeof(struct iovec);
97227 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97228 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97229 return -EFAULT;
97230
97231 m->msg_iov = iov;
97232 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97233 index e161290..8149aea 100644
97234 --- a/net/core/neighbour.c
97235 +++ b/net/core/neighbour.c
97236 @@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97237 void __user *buffer, size_t *lenp, loff_t *ppos)
97238 {
97239 int size, ret;
97240 - struct ctl_table tmp = *ctl;
97241 + ctl_table_no_const tmp = *ctl;
97242
97243 tmp.extra1 = &zero;
97244 tmp.extra2 = &unres_qlen_max;
97245 @@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
97246 void __user *buffer,
97247 size_t *lenp, loff_t *ppos)
97248 {
97249 - struct ctl_table tmp = *ctl;
97250 + ctl_table_no_const tmp = *ctl;
97251 int ret;
97252
97253 tmp.extra1 = &zero;
97254 @@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97255 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97256 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97257 } else {
97258 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97259 dev_name_source = "default";
97260 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97261 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97262 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97263 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97264 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97265 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97266 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97267 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97268 }
97269
97270 if (handler) {
97271 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97272 index 2bf8329..7960607 100644
97273 --- a/net/core/net-procfs.c
97274 +++ b/net/core/net-procfs.c
97275 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97276 else
97277 seq_printf(seq, "%04x", ntohs(pt->type));
97278
97279 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97280 + seq_printf(seq, " %-8s %pf\n",
97281 + pt->dev ? pt->dev->name : "", NULL);
97282 +#else
97283 seq_printf(seq, " %-8s %pf\n",
97284 pt->dev ? pt->dev->name : "", pt->func);
97285 +#endif
97286 }
97287
97288 return 0;
97289 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97290 index 81d3a9a..a0bd7a8 100644
97291 --- a/net/core/net_namespace.c
97292 +++ b/net/core/net_namespace.c
97293 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97294 int error;
97295 LIST_HEAD(net_exit_list);
97296
97297 - list_add_tail(&ops->list, list);
97298 + pax_list_add_tail((struct list_head *)&ops->list, list);
97299 if (ops->init || (ops->id && ops->size)) {
97300 for_each_net(net) {
97301 error = ops_init(ops, net);
97302 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97303
97304 out_undo:
97305 /* If I have an error cleanup all namespaces I initialized */
97306 - list_del(&ops->list);
97307 + pax_list_del((struct list_head *)&ops->list);
97308 ops_exit_list(ops, &net_exit_list);
97309 ops_free_list(ops, &net_exit_list);
97310 return error;
97311 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97312 struct net *net;
97313 LIST_HEAD(net_exit_list);
97314
97315 - list_del(&ops->list);
97316 + pax_list_del((struct list_head *)&ops->list);
97317 for_each_net(net)
97318 list_add_tail(&net->exit_list, &net_exit_list);
97319 ops_exit_list(ops, &net_exit_list);
97320 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97321 mutex_lock(&net_mutex);
97322 error = register_pernet_operations(&pernet_list, ops);
97323 if (!error && (first_device == &pernet_list))
97324 - first_device = &ops->list;
97325 + first_device = (struct list_head *)&ops->list;
97326 mutex_unlock(&net_mutex);
97327 return error;
97328 }
97329 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97330 index df9e6b1..6e68e4e 100644
97331 --- a/net/core/netpoll.c
97332 +++ b/net/core/netpoll.c
97333 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97334 struct udphdr *udph;
97335 struct iphdr *iph;
97336 struct ethhdr *eth;
97337 - static atomic_t ip_ident;
97338 + static atomic_unchecked_t ip_ident;
97339 struct ipv6hdr *ip6h;
97340
97341 udp_len = len + sizeof(*udph);
97342 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97343 put_unaligned(0x45, (unsigned char *)iph);
97344 iph->tos = 0;
97345 put_unaligned(htons(ip_len), &(iph->tot_len));
97346 - iph->id = htons(atomic_inc_return(&ip_ident));
97347 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97348 iph->frag_off = 0;
97349 iph->ttl = 64;
97350 iph->protocol = IPPROTO_UDP;
97351 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97352 index 120eecc..cd1ec44 100644
97353 --- a/net/core/rtnetlink.c
97354 +++ b/net/core/rtnetlink.c
97355 @@ -58,7 +58,7 @@ struct rtnl_link {
97356 rtnl_doit_func doit;
97357 rtnl_dumpit_func dumpit;
97358 rtnl_calcit_func calcit;
97359 -};
97360 +} __no_const;
97361
97362 static DEFINE_MUTEX(rtnl_mutex);
97363
97364 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97365 if (rtnl_link_ops_get(ops->kind))
97366 return -EEXIST;
97367
97368 - if (!ops->dellink)
97369 - ops->dellink = unregister_netdevice_queue;
97370 + if (!ops->dellink) {
97371 + pax_open_kernel();
97372 + *(void **)&ops->dellink = unregister_netdevice_queue;
97373 + pax_close_kernel();
97374 + }
97375
97376 - list_add_tail(&ops->list, &link_ops);
97377 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97378 return 0;
97379 }
97380 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97381 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97382 for_each_net(net) {
97383 __rtnl_kill_links(net, ops);
97384 }
97385 - list_del(&ops->list);
97386 + pax_list_del((struct list_head *)&ops->list);
97387 }
97388 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97389
97390 diff --git a/net/core/scm.c b/net/core/scm.c
97391 index b442e7e..6f5b5a2 100644
97392 --- a/net/core/scm.c
97393 +++ b/net/core/scm.c
97394 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97395 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97396 {
97397 struct cmsghdr __user *cm
97398 - = (__force struct cmsghdr __user *)msg->msg_control;
97399 + = (struct cmsghdr __force_user *)msg->msg_control;
97400 struct cmsghdr cmhdr;
97401 int cmlen = CMSG_LEN(len);
97402 int err;
97403 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97404 err = -EFAULT;
97405 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97406 goto out;
97407 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97408 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97409 goto out;
97410 cmlen = CMSG_SPACE(len);
97411 if (msg->msg_controllen < cmlen)
97412 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97413 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97414 {
97415 struct cmsghdr __user *cm
97416 - = (__force struct cmsghdr __user*)msg->msg_control;
97417 + = (struct cmsghdr __force_user *)msg->msg_control;
97418
97419 int fdmax = 0;
97420 int fdnum = scm->fp->count;
97421 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97422 if (fdnum < fdmax)
97423 fdmax = fdnum;
97424
97425 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97426 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97427 i++, cmfptr++)
97428 {
97429 struct socket *sock;
97430 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97431 index 90b96a1..cd18f16 100644
97432 --- a/net/core/skbuff.c
97433 +++ b/net/core/skbuff.c
97434 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
97435 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97436 int len, __wsum csum)
97437 {
97438 - const struct skb_checksum_ops ops = {
97439 + static const struct skb_checksum_ops ops = {
97440 .update = csum_partial_ext,
97441 .combine = csum_block_add_ext,
97442 };
97443 @@ -3220,13 +3220,15 @@ void __init skb_init(void)
97444 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97445 sizeof(struct sk_buff),
97446 0,
97447 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97448 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97449 + SLAB_NO_SANITIZE,
97450 NULL);
97451 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97452 (2*sizeof(struct sk_buff)) +
97453 sizeof(atomic_t),
97454 0,
97455 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97456 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97457 + SLAB_NO_SANITIZE,
97458 NULL);
97459 }
97460
97461 diff --git a/net/core/sock.c b/net/core/sock.c
97462 index c0fc6bd..51d8326 100644
97463 --- a/net/core/sock.c
97464 +++ b/net/core/sock.c
97465 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97466 struct sk_buff_head *list = &sk->sk_receive_queue;
97467
97468 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97469 - atomic_inc(&sk->sk_drops);
97470 + atomic_inc_unchecked(&sk->sk_drops);
97471 trace_sock_rcvqueue_full(sk, skb);
97472 return -ENOMEM;
97473 }
97474 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97475 return err;
97476
97477 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97478 - atomic_inc(&sk->sk_drops);
97479 + atomic_inc_unchecked(&sk->sk_drops);
97480 return -ENOBUFS;
97481 }
97482
97483 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97484 skb_dst_force(skb);
97485
97486 spin_lock_irqsave(&list->lock, flags);
97487 - skb->dropcount = atomic_read(&sk->sk_drops);
97488 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97489 __skb_queue_tail(list, skb);
97490 spin_unlock_irqrestore(&list->lock, flags);
97491
97492 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97493 skb->dev = NULL;
97494
97495 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97496 - atomic_inc(&sk->sk_drops);
97497 + atomic_inc_unchecked(&sk->sk_drops);
97498 goto discard_and_relse;
97499 }
97500 if (nested)
97501 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97502 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97503 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97504 bh_unlock_sock(sk);
97505 - atomic_inc(&sk->sk_drops);
97506 + atomic_inc_unchecked(&sk->sk_drops);
97507 goto discard_and_relse;
97508 }
97509
97510 @@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97511 struct timeval tm;
97512 } v;
97513
97514 - int lv = sizeof(int);
97515 - int len;
97516 + unsigned int lv = sizeof(int);
97517 + unsigned int len;
97518
97519 if (get_user(len, optlen))
97520 return -EFAULT;
97521 - if (len < 0)
97522 + if (len > INT_MAX)
97523 return -EINVAL;
97524
97525 memset(&v, 0, sizeof(v));
97526 @@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97527
97528 case SO_PEERNAME:
97529 {
97530 - char address[128];
97531 + char address[_K_SS_MAXSIZE];
97532
97533 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97534 return -ENOTCONN;
97535 - if (lv < len)
97536 + if (lv < len || sizeof address < len)
97537 return -EINVAL;
97538 if (copy_to_user(optval, address, len))
97539 return -EFAULT;
97540 @@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97541
97542 if (len > lv)
97543 len = lv;
97544 - if (copy_to_user(optval, &v, len))
97545 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
97546 return -EFAULT;
97547 lenout:
97548 if (put_user(len, optlen))
97549 @@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97550 */
97551 smp_wmb();
97552 atomic_set(&sk->sk_refcnt, 1);
97553 - atomic_set(&sk->sk_drops, 0);
97554 + atomic_set_unchecked(&sk->sk_drops, 0);
97555 }
97556 EXPORT_SYMBOL(sock_init_data);
97557
97558 @@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97559 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97560 int level, int type)
97561 {
97562 + struct sock_extended_err ee;
97563 struct sock_exterr_skb *serr;
97564 struct sk_buff *skb, *skb2;
97565 int copied, err;
97566 @@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97567 sock_recv_timestamp(msg, sk, skb);
97568
97569 serr = SKB_EXT_ERR(skb);
97570 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97571 + ee = serr->ee;
97572 + put_cmsg(msg, level, type, sizeof ee, &ee);
97573
97574 msg->msg_flags |= MSG_ERRQUEUE;
97575 err = copied;
97576 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97577 index a0e9cf6..ef7f9ed 100644
97578 --- a/net/core/sock_diag.c
97579 +++ b/net/core/sock_diag.c
97580 @@ -9,26 +9,33 @@
97581 #include <linux/inet_diag.h>
97582 #include <linux/sock_diag.h>
97583
97584 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97585 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97586 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97587 static DEFINE_MUTEX(sock_diag_table_mutex);
97588
97589 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97590 {
97591 +#ifndef CONFIG_GRKERNSEC_HIDESYM
97592 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97593 cookie[1] != INET_DIAG_NOCOOKIE) &&
97594 ((u32)(unsigned long)sk != cookie[0] ||
97595 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97596 return -ESTALE;
97597 else
97598 +#endif
97599 return 0;
97600 }
97601 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97602
97603 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97604 {
97605 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97606 + cookie[0] = 0;
97607 + cookie[1] = 0;
97608 +#else
97609 cookie[0] = (u32)(unsigned long)sk;
97610 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97611 +#endif
97612 }
97613 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97614
97615 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97616 mutex_lock(&sock_diag_table_mutex);
97617 if (sock_diag_handlers[hndl->family])
97618 err = -EBUSY;
97619 - else
97620 + else {
97621 + pax_open_kernel();
97622 sock_diag_handlers[hndl->family] = hndl;
97623 + pax_close_kernel();
97624 + }
97625 mutex_unlock(&sock_diag_table_mutex);
97626
97627 return err;
97628 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97629
97630 mutex_lock(&sock_diag_table_mutex);
97631 BUG_ON(sock_diag_handlers[family] != hnld);
97632 + pax_open_kernel();
97633 sock_diag_handlers[family] = NULL;
97634 + pax_close_kernel();
97635 mutex_unlock(&sock_diag_table_mutex);
97636 }
97637 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97638 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97639 index cf9cd13..8b56af3 100644
97640 --- a/net/core/sysctl_net_core.c
97641 +++ b/net/core/sysctl_net_core.c
97642 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97643 {
97644 unsigned int orig_size, size;
97645 int ret, i;
97646 - struct ctl_table tmp = {
97647 + ctl_table_no_const tmp = {
97648 .data = &size,
97649 .maxlen = sizeof(size),
97650 .mode = table->mode
97651 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97652 void __user *buffer, size_t *lenp, loff_t *ppos)
97653 {
97654 char id[IFNAMSIZ];
97655 - struct ctl_table tbl = {
97656 + ctl_table_no_const tbl = {
97657 .data = id,
97658 .maxlen = IFNAMSIZ,
97659 };
97660 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
97661
97662 static __net_init int sysctl_core_net_init(struct net *net)
97663 {
97664 - struct ctl_table *tbl;
97665 + ctl_table_no_const *tbl = NULL;
97666
97667 net->core.sysctl_somaxconn = SOMAXCONN;
97668
97669 - tbl = netns_core_table;
97670 if (!net_eq(net, &init_net)) {
97671 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97672 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97673 if (tbl == NULL)
97674 goto err_dup;
97675
97676 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97677 if (net->user_ns != &init_user_ns) {
97678 tbl[0].procname = NULL;
97679 }
97680 - }
97681 -
97682 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97683 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97684 + } else
97685 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97686 if (net->core.sysctl_hdr == NULL)
97687 goto err_reg;
97688
97689 return 0;
97690
97691 err_reg:
97692 - if (tbl != netns_core_table)
97693 - kfree(tbl);
97694 + kfree(tbl);
97695 err_dup:
97696 return -ENOMEM;
97697 }
97698 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97699 kfree(tbl);
97700 }
97701
97702 -static __net_initdata struct pernet_operations sysctl_core_ops = {
97703 +static __net_initconst struct pernet_operations sysctl_core_ops = {
97704 .init = sysctl_core_net_init,
97705 .exit = sysctl_core_net_exit,
97706 };
97707 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97708 index 4c04848..f575934 100644
97709 --- a/net/decnet/af_decnet.c
97710 +++ b/net/decnet/af_decnet.c
97711 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
97712 .sysctl_rmem = sysctl_decnet_rmem,
97713 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97714 .obj_size = sizeof(struct dn_sock),
97715 + .slab_flags = SLAB_USERCOPY,
97716 };
97717
97718 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97719 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97720 index a603823..a36ee0b 100644
97721 --- a/net/decnet/dn_dev.c
97722 +++ b/net/decnet/dn_dev.c
97723 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97724 .extra1 = &min_t3,
97725 .extra2 = &max_t3
97726 },
97727 - {0}
97728 + { }
97729 },
97730 };
97731
97732 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97733 index 5325b54..a0d4d69 100644
97734 --- a/net/decnet/sysctl_net_decnet.c
97735 +++ b/net/decnet/sysctl_net_decnet.c
97736 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97737
97738 if (len > *lenp) len = *lenp;
97739
97740 - if (copy_to_user(buffer, addr, len))
97741 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
97742 return -EFAULT;
97743
97744 *lenp = len;
97745 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97746
97747 if (len > *lenp) len = *lenp;
97748
97749 - if (copy_to_user(buffer, devname, len))
97750 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
97751 return -EFAULT;
97752
97753 *lenp = len;
97754 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97755 index 1846c1f..96d4a9f 100644
97756 --- a/net/ieee802154/dgram.c
97757 +++ b/net/ieee802154/dgram.c
97758 @@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97759 if (saddr) {
97760 saddr->family = AF_IEEE802154;
97761 saddr->addr = mac_cb(skb)->sa;
97762 + }
97763 + if (addr_len)
97764 *addr_len = sizeof(*saddr);
97765 - }
97766
97767 if (flags & MSG_TRUNC)
97768 copied = skb->len;
97769 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97770 index 19ab78a..bf575c9 100644
97771 --- a/net/ipv4/af_inet.c
97772 +++ b/net/ipv4/af_inet.c
97773 @@ -1703,13 +1703,9 @@ static int __init inet_init(void)
97774
97775 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97776
97777 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97778 - if (!sysctl_local_reserved_ports)
97779 - goto out;
97780 -
97781 rc = proto_register(&tcp_prot, 1);
97782 if (rc)
97783 - goto out_free_reserved_ports;
97784 + goto out;
97785
97786 rc = proto_register(&udp_prot, 1);
97787 if (rc)
97788 @@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
97789 proto_unregister(&udp_prot);
97790 out_unregister_tcp_proto:
97791 proto_unregister(&tcp_prot);
97792 -out_free_reserved_ports:
97793 - kfree(sysctl_local_reserved_ports);
97794 goto out;
97795 }
97796
97797 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97798 index bdbf68b..deb4759 100644
97799 --- a/net/ipv4/devinet.c
97800 +++ b/net/ipv4/devinet.c
97801 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97802 idx = 0;
97803 head = &net->dev_index_head[h];
97804 rcu_read_lock();
97805 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97806 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97807 net->dev_base_seq;
97808 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97809 if (idx < s_idx)
97810 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97811 idx = 0;
97812 head = &net->dev_index_head[h];
97813 rcu_read_lock();
97814 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97815 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97816 net->dev_base_seq;
97817 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97818 if (idx < s_idx)
97819 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97820 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97821 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97822
97823 -static struct devinet_sysctl_table {
97824 +static const struct devinet_sysctl_table {
97825 struct ctl_table_header *sysctl_header;
97826 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97827 } devinet_sysctl = {
97828 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
97829 int err;
97830 struct ipv4_devconf *all, *dflt;
97831 #ifdef CONFIG_SYSCTL
97832 - struct ctl_table *tbl = ctl_forward_entry;
97833 + ctl_table_no_const *tbl = NULL;
97834 struct ctl_table_header *forw_hdr;
97835 #endif
97836
97837 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
97838 goto err_alloc_dflt;
97839
97840 #ifdef CONFIG_SYSCTL
97841 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97842 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97843 if (tbl == NULL)
97844 goto err_alloc_ctl;
97845
97846 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
97847 goto err_reg_dflt;
97848
97849 err = -ENOMEM;
97850 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97851 + if (!net_eq(net, &init_net))
97852 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97853 + else
97854 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97855 if (forw_hdr == NULL)
97856 goto err_reg_ctl;
97857 net->ipv4.forw_hdr = forw_hdr;
97858 @@ -2272,8 +2275,7 @@ err_reg_ctl:
97859 err_reg_dflt:
97860 __devinet_sysctl_unregister(all);
97861 err_reg_all:
97862 - if (tbl != ctl_forward_entry)
97863 - kfree(tbl);
97864 + kfree(tbl);
97865 err_alloc_ctl:
97866 #endif
97867 if (dflt != &ipv4_devconf_dflt)
97868 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97869 index c7539e2..b455e51 100644
97870 --- a/net/ipv4/fib_frontend.c
97871 +++ b/net/ipv4/fib_frontend.c
97872 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97873 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97874 fib_sync_up(dev);
97875 #endif
97876 - atomic_inc(&net->ipv4.dev_addr_genid);
97877 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97878 rt_cache_flush(dev_net(dev));
97879 break;
97880 case NETDEV_DOWN:
97881 fib_del_ifaddr(ifa, NULL);
97882 - atomic_inc(&net->ipv4.dev_addr_genid);
97883 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97884 if (ifa->ifa_dev->ifa_list == NULL) {
97885 /* Last address was deleted from this interface.
97886 * Disable IP.
97887 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97888 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97889 fib_sync_up(dev);
97890 #endif
97891 - atomic_inc(&net->ipv4.dev_addr_genid);
97892 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97893 rt_cache_flush(net);
97894 break;
97895 case NETDEV_DOWN:
97896 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97897 index b53f0bf..3585b33 100644
97898 --- a/net/ipv4/fib_semantics.c
97899 +++ b/net/ipv4/fib_semantics.c
97900 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97901 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97902 nh->nh_gw,
97903 nh->nh_parent->fib_scope);
97904 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97905 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97906
97907 return nh->nh_saddr;
97908 }
97909 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97910 index 0d1e2cb..4501a2c 100644
97911 --- a/net/ipv4/inet_connection_sock.c
97912 +++ b/net/ipv4/inet_connection_sock.c
97913 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97914 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97915 #endif
97916
97917 -unsigned long *sysctl_local_reserved_ports;
97918 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97919 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97920
97921 void inet_get_local_port_range(struct net *net, int *low, int *high)
97922 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97923 index 8b9cf27..0d8d592 100644
97924 --- a/net/ipv4/inet_hashtables.c
97925 +++ b/net/ipv4/inet_hashtables.c
97926 @@ -18,6 +18,7 @@
97927 #include <linux/sched.h>
97928 #include <linux/slab.h>
97929 #include <linux/wait.h>
97930 +#include <linux/security.h>
97931
97932 #include <net/inet_connection_sock.h>
97933 #include <net/inet_hashtables.h>
97934 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97935 return inet_ehashfn(net, laddr, lport, faddr, fport);
97936 }
97937
97938 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97939 +
97940 /*
97941 * Allocate and initialize a new local port bind bucket.
97942 * The bindhash mutex for snum's hash chain must be held here.
97943 @@ -554,6 +557,8 @@ ok:
97944 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97945 spin_unlock(&head->lock);
97946
97947 + gr_update_task_in_ip_table(current, inet_sk(sk));
97948 +
97949 if (tw) {
97950 inet_twsk_deschedule(tw, death_row);
97951 while (twrefcnt) {
97952 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97953 index 48f4244..f56d83a 100644
97954 --- a/net/ipv4/inetpeer.c
97955 +++ b/net/ipv4/inetpeer.c
97956 @@ -496,8 +496,8 @@ relookup:
97957 if (p) {
97958 p->daddr = *daddr;
97959 atomic_set(&p->refcnt, 1);
97960 - atomic_set(&p->rid, 0);
97961 - atomic_set(&p->ip_id_count,
97962 + atomic_set_unchecked(&p->rid, 0);
97963 + atomic_set_unchecked(&p->ip_id_count,
97964 (daddr->family == AF_INET) ?
97965 secure_ip_id(daddr->addr.a4) :
97966 secure_ipv6_id(daddr->addr.a6));
97967 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97968 index c10a3ce..dd71f84 100644
97969 --- a/net/ipv4/ip_fragment.c
97970 +++ b/net/ipv4/ip_fragment.c
97971 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97972 return 0;
97973
97974 start = qp->rid;
97975 - end = atomic_inc_return(&peer->rid);
97976 + end = atomic_inc_return_unchecked(&peer->rid);
97977 qp->rid = end;
97978
97979 rc = qp->q.fragments && (end - start) > max;
97980 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97981
97982 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97983 {
97984 - struct ctl_table *table;
97985 + ctl_table_no_const *table = NULL;
97986 struct ctl_table_header *hdr;
97987
97988 - table = ip4_frags_ns_ctl_table;
97989 if (!net_eq(net, &init_net)) {
97990 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97991 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97992 if (table == NULL)
97993 goto err_alloc;
97994
97995 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97996 /* Don't export sysctls to unprivileged users */
97997 if (net->user_ns != &init_user_ns)
97998 table[0].procname = NULL;
97999 - }
98000 + hdr = register_net_sysctl(net, "net/ipv4", table);
98001 + } else
98002 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98003
98004 - hdr = register_net_sysctl(net, "net/ipv4", table);
98005 if (hdr == NULL)
98006 goto err_reg;
98007
98008 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98009 return 0;
98010
98011 err_reg:
98012 - if (!net_eq(net, &init_net))
98013 - kfree(table);
98014 + kfree(table);
98015 err_alloc:
98016 return -ENOMEM;
98017 }
98018 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98019 index ec4f762..4ce3645 100644
98020 --- a/net/ipv4/ip_gre.c
98021 +++ b/net/ipv4/ip_gre.c
98022 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98023 module_param(log_ecn_error, bool, 0644);
98024 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98025
98026 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98027 +static struct rtnl_link_ops ipgre_link_ops;
98028 static int ipgre_tunnel_init(struct net_device *dev);
98029
98030 static int ipgre_net_id __read_mostly;
98031 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98032 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98033 };
98034
98035 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98036 +static struct rtnl_link_ops ipgre_link_ops = {
98037 .kind = "gre",
98038 .maxtype = IFLA_GRE_MAX,
98039 .policy = ipgre_policy,
98040 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98041 .fill_info = ipgre_fill_info,
98042 };
98043
98044 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98045 +static struct rtnl_link_ops ipgre_tap_ops = {
98046 .kind = "gretap",
98047 .maxtype = IFLA_GRE_MAX,
98048 .policy = ipgre_policy,
98049 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98050 index 580dd96..9fcef7e 100644
98051 --- a/net/ipv4/ip_sockglue.c
98052 +++ b/net/ipv4/ip_sockglue.c
98053 @@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98054 len = min_t(unsigned int, len, opt->optlen);
98055 if (put_user(len, optlen))
98056 return -EFAULT;
98057 - if (copy_to_user(optval, opt->__data, len))
98058 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
98059 + copy_to_user(optval, opt->__data, len))
98060 return -EFAULT;
98061 return 0;
98062 }
98063 @@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98064 if (sk->sk_type != SOCK_STREAM)
98065 return -ENOPROTOOPT;
98066
98067 - msg.msg_control = optval;
98068 + msg.msg_control = (void __force_kernel *)optval;
98069 msg.msg_controllen = len;
98070 msg.msg_flags = flags;
98071
98072 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98073 index 48eafae..defff53 100644
98074 --- a/net/ipv4/ip_vti.c
98075 +++ b/net/ipv4/ip_vti.c
98076 @@ -44,7 +44,7 @@
98077 #include <net/net_namespace.h>
98078 #include <net/netns/generic.h>
98079
98080 -static struct rtnl_link_ops vti_link_ops __read_mostly;
98081 +static struct rtnl_link_ops vti_link_ops;
98082
98083 static int vti_net_id __read_mostly;
98084 static int vti_tunnel_init(struct net_device *dev);
98085 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98086 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98087 };
98088
98089 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
98090 +static struct rtnl_link_ops vti_link_ops = {
98091 .kind = "vti",
98092 .maxtype = IFLA_VTI_MAX,
98093 .policy = vti_policy,
98094 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98095 index b3e86ea..18ce98c 100644
98096 --- a/net/ipv4/ipconfig.c
98097 +++ b/net/ipv4/ipconfig.c
98098 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98099
98100 mm_segment_t oldfs = get_fs();
98101 set_fs(get_ds());
98102 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98103 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98104 set_fs(oldfs);
98105 return res;
98106 }
98107 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98108
98109 mm_segment_t oldfs = get_fs();
98110 set_fs(get_ds());
98111 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98112 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98113 set_fs(oldfs);
98114 return res;
98115 }
98116 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
98117
98118 mm_segment_t oldfs = get_fs();
98119 set_fs(get_ds());
98120 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
98121 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
98122 set_fs(oldfs);
98123 return res;
98124 }
98125 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
98126 index 812b183..56cbe9c 100644
98127 --- a/net/ipv4/ipip.c
98128 +++ b/net/ipv4/ipip.c
98129 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98130 static int ipip_net_id __read_mostly;
98131
98132 static int ipip_tunnel_init(struct net_device *dev);
98133 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
98134 +static struct rtnl_link_ops ipip_link_ops;
98135
98136 static int ipip_err(struct sk_buff *skb, u32 info)
98137 {
98138 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
98139 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
98140 };
98141
98142 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
98143 +static struct rtnl_link_ops ipip_link_ops = {
98144 .kind = "ipip",
98145 .maxtype = IFLA_IPTUN_MAX,
98146 .policy = ipip_policy,
98147 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
98148 index 59da7cd..e318de1 100644
98149 --- a/net/ipv4/netfilter/arp_tables.c
98150 +++ b/net/ipv4/netfilter/arp_tables.c
98151 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
98152 #endif
98153
98154 static int get_info(struct net *net, void __user *user,
98155 - const int *len, int compat)
98156 + int len, int compat)
98157 {
98158 char name[XT_TABLE_MAXNAMELEN];
98159 struct xt_table *t;
98160 int ret;
98161
98162 - if (*len != sizeof(struct arpt_getinfo)) {
98163 - duprintf("length %u != %Zu\n", *len,
98164 + if (len != sizeof(struct arpt_getinfo)) {
98165 + duprintf("length %u != %Zu\n", len,
98166 sizeof(struct arpt_getinfo));
98167 return -EINVAL;
98168 }
98169 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98170 info.size = private->size;
98171 strcpy(info.name, name);
98172
98173 - if (copy_to_user(user, &info, *len) != 0)
98174 + if (copy_to_user(user, &info, len) != 0)
98175 ret = -EFAULT;
98176 else
98177 ret = 0;
98178 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98179
98180 switch (cmd) {
98181 case ARPT_SO_GET_INFO:
98182 - ret = get_info(sock_net(sk), user, len, 1);
98183 + ret = get_info(sock_net(sk), user, *len, 1);
98184 break;
98185 case ARPT_SO_GET_ENTRIES:
98186 ret = compat_get_entries(sock_net(sk), user, len);
98187 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98188
98189 switch (cmd) {
98190 case ARPT_SO_GET_INFO:
98191 - ret = get_info(sock_net(sk), user, len, 0);
98192 + ret = get_info(sock_net(sk), user, *len, 0);
98193 break;
98194
98195 case ARPT_SO_GET_ENTRIES:
98196 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98197 index 718dfbd..cef4152 100644
98198 --- a/net/ipv4/netfilter/ip_tables.c
98199 +++ b/net/ipv4/netfilter/ip_tables.c
98200 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98201 #endif
98202
98203 static int get_info(struct net *net, void __user *user,
98204 - const int *len, int compat)
98205 + int len, int compat)
98206 {
98207 char name[XT_TABLE_MAXNAMELEN];
98208 struct xt_table *t;
98209 int ret;
98210
98211 - if (*len != sizeof(struct ipt_getinfo)) {
98212 - duprintf("length %u != %zu\n", *len,
98213 + if (len != sizeof(struct ipt_getinfo)) {
98214 + duprintf("length %u != %zu\n", len,
98215 sizeof(struct ipt_getinfo));
98216 return -EINVAL;
98217 }
98218 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98219 info.size = private->size;
98220 strcpy(info.name, name);
98221
98222 - if (copy_to_user(user, &info, *len) != 0)
98223 + if (copy_to_user(user, &info, len) != 0)
98224 ret = -EFAULT;
98225 else
98226 ret = 0;
98227 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98228
98229 switch (cmd) {
98230 case IPT_SO_GET_INFO:
98231 - ret = get_info(sock_net(sk), user, len, 1);
98232 + ret = get_info(sock_net(sk), user, *len, 1);
98233 break;
98234 case IPT_SO_GET_ENTRIES:
98235 ret = compat_get_entries(sock_net(sk), user, len);
98236 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98237
98238 switch (cmd) {
98239 case IPT_SO_GET_INFO:
98240 - ret = get_info(sock_net(sk), user, len, 0);
98241 + ret = get_info(sock_net(sk), user, *len, 0);
98242 break;
98243
98244 case IPT_SO_GET_ENTRIES:
98245 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98246 index 2d11c09..3f153f8 100644
98247 --- a/net/ipv4/ping.c
98248 +++ b/net/ipv4/ping.c
98249 @@ -59,7 +59,7 @@ struct ping_table {
98250 };
98251
98252 static struct ping_table ping_table;
98253 -struct pingv6_ops pingv6_ops;
98254 +struct pingv6_ops *pingv6_ops;
98255 EXPORT_SYMBOL_GPL(pingv6_ops);
98256
98257 static u16 ping_port_rover;
98258 @@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
98259 struct group_info *group_info = get_current_groups();
98260 int i, j, count = group_info->ngroups;
98261 kgid_t low, high;
98262 + int ret = 0;
98263
98264 inet_get_ping_group_range_net(net, &low, &high);
98265 if (gid_lte(low, group) && gid_lte(group, high))
98266 - return 0;
98267 + goto out_release_group;
98268
98269 for (i = 0; i < group_info->nblocks; i++) {
98270 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98271 for (j = 0; j < cp_count; j++) {
98272 kgid_t gid = group_info->blocks[i][j];
98273 if (gid_lte(low, gid) && gid_lte(gid, high))
98274 - return 0;
98275 + goto out_release_group;
98276 }
98277
98278 count -= cp_count;
98279 }
98280
98281 - return -EACCES;
98282 + ret = -EACCES;
98283 +
98284 +out_release_group:
98285 + put_group_info(group_info);
98286 + return ret;
98287 }
98288 EXPORT_SYMBOL_GPL(ping_init_sock);
98289
98290 @@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98291 return -ENODEV;
98292 }
98293 }
98294 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98295 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98296 scoped);
98297 rcu_read_unlock();
98298
98299 @@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98300 }
98301 #if IS_ENABLED(CONFIG_IPV6)
98302 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98303 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98304 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98305 #endif
98306 }
98307
98308 @@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98309 info, (u8 *)icmph);
98310 #if IS_ENABLED(CONFIG_IPV6)
98311 } else if (family == AF_INET6) {
98312 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98313 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98314 info, (u8 *)icmph);
98315 #endif
98316 }
98317 @@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98318 {
98319 struct inet_sock *isk = inet_sk(sk);
98320 int family = sk->sk_family;
98321 + struct sockaddr_in *sin;
98322 + struct sockaddr_in6 *sin6;
98323 struct sk_buff *skb;
98324 int copied, err;
98325
98326 @@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98327 if (flags & MSG_OOB)
98328 goto out;
98329
98330 + if (addr_len) {
98331 + if (family == AF_INET)
98332 + *addr_len = sizeof(*sin);
98333 + else if (family == AF_INET6 && addr_len)
98334 + *addr_len = sizeof(*sin6);
98335 + }
98336 +
98337 if (flags & MSG_ERRQUEUE) {
98338 if (family == AF_INET) {
98339 return ip_recv_error(sk, msg, len, addr_len);
98340 #if IS_ENABLED(CONFIG_IPV6)
98341 } else if (family == AF_INET6) {
98342 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
98343 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
98344 addr_len);
98345 #endif
98346 }
98347 @@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98348 sin->sin_port = 0 /* skb->h.uh->source */;
98349 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98350 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98351 - *addr_len = sizeof(*sin);
98352 }
98353
98354 if (isk->cmsg_flags)
98355 @@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98356 sin6->sin6_scope_id =
98357 ipv6_iface_scope_id(&sin6->sin6_addr,
98358 IP6CB(skb)->iif);
98359 - *addr_len = sizeof(*sin6);
98360 }
98361
98362 if (inet6_sk(sk)->rxopt.all)
98363 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
98364 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
98365 if (skb->protocol == htons(ETH_P_IPV6) &&
98366 inet6_sk(sk)->rxopt.all)
98367 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
98368 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
98369 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
98370 ip_cmsg_recv(msg, skb);
98371 #endif
98372 @@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98373 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98374 0, sock_i_ino(sp),
98375 atomic_read(&sp->sk_refcnt), sp,
98376 - atomic_read(&sp->sk_drops));
98377 + atomic_read_unchecked(&sp->sk_drops));
98378 }
98379
98380 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98381 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98382 index c04518f..824ebe5 100644
98383 --- a/net/ipv4/raw.c
98384 +++ b/net/ipv4/raw.c
98385 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98386 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98387 {
98388 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98389 - atomic_inc(&sk->sk_drops);
98390 + atomic_inc_unchecked(&sk->sk_drops);
98391 kfree_skb(skb);
98392 return NET_RX_DROP;
98393 }
98394 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98395 if (flags & MSG_OOB)
98396 goto out;
98397
98398 + if (addr_len)
98399 + *addr_len = sizeof(*sin);
98400 +
98401 if (flags & MSG_ERRQUEUE) {
98402 err = ip_recv_error(sk, msg, len, addr_len);
98403 goto out;
98404 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98405 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98406 sin->sin_port = 0;
98407 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98408 - *addr_len = sizeof(*sin);
98409 }
98410 if (inet->cmsg_flags)
98411 ip_cmsg_recv(msg, skb);
98412 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98413
98414 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98415 {
98416 + struct icmp_filter filter;
98417 +
98418 if (optlen > sizeof(struct icmp_filter))
98419 optlen = sizeof(struct icmp_filter);
98420 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98421 + if (copy_from_user(&filter, optval, optlen))
98422 return -EFAULT;
98423 + raw_sk(sk)->filter = filter;
98424 return 0;
98425 }
98426
98427 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98428 {
98429 int len, ret = -EFAULT;
98430 + struct icmp_filter filter;
98431
98432 if (get_user(len, optlen))
98433 goto out;
98434 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98435 if (len > sizeof(struct icmp_filter))
98436 len = sizeof(struct icmp_filter);
98437 ret = -EFAULT;
98438 - if (put_user(len, optlen) ||
98439 - copy_to_user(optval, &raw_sk(sk)->filter, len))
98440 + filter = raw_sk(sk)->filter;
98441 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98442 goto out;
98443 ret = 0;
98444 out: return ret;
98445 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98446 0, 0L, 0,
98447 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98448 0, sock_i_ino(sp),
98449 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98450 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98451 }
98452
98453 static int raw_seq_show(struct seq_file *seq, void *v)
98454 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98455 index 4c011ec..5cdfedb 100644
98456 --- a/net/ipv4/route.c
98457 +++ b/net/ipv4/route.c
98458 @@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98459 .maxlen = sizeof(int),
98460 .mode = 0200,
98461 .proc_handler = ipv4_sysctl_rtcache_flush,
98462 + .extra1 = &init_net,
98463 },
98464 { },
98465 };
98466
98467 static __net_init int sysctl_route_net_init(struct net *net)
98468 {
98469 - struct ctl_table *tbl;
98470 + ctl_table_no_const *tbl = NULL;
98471
98472 - tbl = ipv4_route_flush_table;
98473 if (!net_eq(net, &init_net)) {
98474 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98475 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98476 if (tbl == NULL)
98477 goto err_dup;
98478
98479 /* Don't export sysctls to unprivileged users */
98480 if (net->user_ns != &init_user_ns)
98481 tbl[0].procname = NULL;
98482 - }
98483 - tbl[0].extra1 = net;
98484 + tbl[0].extra1 = net;
98485 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98486 + } else
98487 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98488
98489 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98490 if (net->ipv4.route_hdr == NULL)
98491 goto err_reg;
98492 return 0;
98493
98494 err_reg:
98495 - if (tbl != ipv4_route_flush_table)
98496 - kfree(tbl);
98497 + kfree(tbl);
98498 err_dup:
98499 return -ENOMEM;
98500 }
98501 @@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98502
98503 static __net_init int rt_genid_init(struct net *net)
98504 {
98505 - atomic_set(&net->ipv4.rt_genid, 0);
98506 - atomic_set(&net->fnhe_genid, 0);
98507 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98508 + atomic_set_unchecked(&net->fnhe_genid, 0);
98509 get_random_bytes(&net->ipv4.dev_addr_genid,
98510 sizeof(net->ipv4.dev_addr_genid));
98511 return 0;
98512 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98513 index 44eba05..b36864b 100644
98514 --- a/net/ipv4/sysctl_net_ipv4.c
98515 +++ b/net/ipv4/sysctl_net_ipv4.c
98516 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98517 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98518 int ret;
98519 int range[2];
98520 - struct ctl_table tmp = {
98521 + ctl_table_no_const tmp = {
98522 .data = &range,
98523 .maxlen = sizeof(range),
98524 .mode = table->mode,
98525 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98526 int ret;
98527 gid_t urange[2];
98528 kgid_t low, high;
98529 - struct ctl_table tmp = {
98530 + ctl_table_no_const tmp = {
98531 .data = &urange,
98532 .maxlen = sizeof(urange),
98533 .mode = table->mode,
98534 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98535 void __user *buffer, size_t *lenp, loff_t *ppos)
98536 {
98537 char val[TCP_CA_NAME_MAX];
98538 - struct ctl_table tbl = {
98539 + ctl_table_no_const tbl = {
98540 .data = val,
98541 .maxlen = TCP_CA_NAME_MAX,
98542 };
98543 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98544 void __user *buffer, size_t *lenp,
98545 loff_t *ppos)
98546 {
98547 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98548 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98549 int ret;
98550
98551 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98552 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98553 void __user *buffer, size_t *lenp,
98554 loff_t *ppos)
98555 {
98556 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98557 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98558 int ret;
98559
98560 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98561 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98562 void __user *buffer, size_t *lenp,
98563 loff_t *ppos)
98564 {
98565 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98566 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98567 struct tcp_fastopen_context *ctxt;
98568 int ret;
98569 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98570 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
98571 },
98572 {
98573 .procname = "ip_local_reserved_ports",
98574 - .data = NULL, /* initialized in sysctl_ipv4_init */
98575 + .data = sysctl_local_reserved_ports,
98576 .maxlen = 65536,
98577 .mode = 0644,
98578 .proc_handler = proc_do_large_bitmap,
98579 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
98580
98581 static __net_init int ipv4_sysctl_init_net(struct net *net)
98582 {
98583 - struct ctl_table *table;
98584 + ctl_table_no_const *table = NULL;
98585
98586 - table = ipv4_net_table;
98587 if (!net_eq(net, &init_net)) {
98588 int i;
98589
98590 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98591 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98592 if (table == NULL)
98593 goto err_alloc;
98594
98595 @@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98596 net->ipv4.sysctl_local_ports.range[0] = 32768;
98597 net->ipv4.sysctl_local_ports.range[1] = 61000;
98598
98599 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98600 + if (!net_eq(net, &init_net))
98601 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98602 + else
98603 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98604 if (net->ipv4.ipv4_hdr == NULL)
98605 goto err_reg;
98606
98607 return 0;
98608
98609 err_reg:
98610 - if (!net_eq(net, &init_net))
98611 - kfree(table);
98612 + kfree(table);
98613 err_alloc:
98614 return -ENOMEM;
98615 }
98616 @@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98617 static __init int sysctl_ipv4_init(void)
98618 {
98619 struct ctl_table_header *hdr;
98620 - struct ctl_table *i;
98621 -
98622 - for (i = ipv4_table; i->procname; i++) {
98623 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98624 - i->data = sysctl_local_reserved_ports;
98625 - break;
98626 - }
98627 - }
98628 - if (!i->procname)
98629 - return -EINVAL;
98630
98631 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98632 if (hdr == NULL)
98633 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98634 index eeaac39..dc29942 100644
98635 --- a/net/ipv4/tcp_input.c
98636 +++ b/net/ipv4/tcp_input.c
98637 @@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98638 * without any lock. We want to make sure compiler wont store
98639 * intermediate values in this location.
98640 */
98641 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98642 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98643 sk->sk_max_pacing_rate);
98644 }
98645
98646 @@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98647 * simplifies code)
98648 */
98649 static void
98650 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98651 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98652 struct sk_buff *head, struct sk_buff *tail,
98653 u32 start, u32 end)
98654 {
98655 @@ -5562,6 +5562,7 @@ discard:
98656 tcp_paws_reject(&tp->rx_opt, 0))
98657 goto discard_and_undo;
98658
98659 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98660 if (th->syn) {
98661 /* We see SYN without ACK. It is attempt of
98662 * simultaneous connect with crossed SYNs.
98663 @@ -5612,6 +5613,7 @@ discard:
98664 goto discard;
98665 #endif
98666 }
98667 +#endif
98668 /* "fifth, if neither of the SYN or RST bits is set then
98669 * drop the segment and return."
98670 */
98671 @@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98672 goto discard;
98673
98674 if (th->syn) {
98675 - if (th->fin)
98676 + if (th->fin || th->urg || th->psh)
98677 goto discard;
98678 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98679 return 1;
98680 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98681 index 1e4eac7..a66fa4a 100644
98682 --- a/net/ipv4/tcp_ipv4.c
98683 +++ b/net/ipv4/tcp_ipv4.c
98684 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98685 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98686
98687
98688 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98689 +extern int grsec_enable_blackhole;
98690 +#endif
98691 +
98692 #ifdef CONFIG_TCP_MD5SIG
98693 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98694 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98695 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98696 return 0;
98697
98698 reset:
98699 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98700 + if (!grsec_enable_blackhole)
98701 +#endif
98702 tcp_v4_send_reset(rsk, skb);
98703 discard:
98704 kfree_skb(skb);
98705 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98706 TCP_SKB_CB(skb)->sacked = 0;
98707
98708 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98709 - if (!sk)
98710 + if (!sk) {
98711 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98712 + ret = 1;
98713 +#endif
98714 goto no_tcp_socket;
98715 -
98716 + }
98717 process:
98718 - if (sk->sk_state == TCP_TIME_WAIT)
98719 + if (sk->sk_state == TCP_TIME_WAIT) {
98720 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98721 + ret = 2;
98722 +#endif
98723 goto do_time_wait;
98724 + }
98725
98726 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98727 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98728 @@ -2033,6 +2047,10 @@ csum_error:
98729 bad_packet:
98730 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98731 } else {
98732 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98733 + if (!grsec_enable_blackhole || (ret == 1 &&
98734 + (skb->dev->flags & IFF_LOOPBACK)))
98735 +#endif
98736 tcp_v4_send_reset(NULL, skb);
98737 }
98738
98739 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98740 index 7a436c5..1b05c59 100644
98741 --- a/net/ipv4/tcp_minisocks.c
98742 +++ b/net/ipv4/tcp_minisocks.c
98743 @@ -27,6 +27,10 @@
98744 #include <net/inet_common.h>
98745 #include <net/xfrm.h>
98746
98747 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98748 +extern int grsec_enable_blackhole;
98749 +#endif
98750 +
98751 int sysctl_tcp_syncookies __read_mostly = 1;
98752 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98753
98754 @@ -709,7 +713,10 @@ embryonic_reset:
98755 * avoid becoming vulnerable to outside attack aiming at
98756 * resetting legit local connections.
98757 */
98758 - req->rsk_ops->send_reset(sk, skb);
98759 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98760 + if (!grsec_enable_blackhole)
98761 +#endif
98762 + req->rsk_ops->send_reset(sk, skb);
98763 } else if (fastopen) { /* received a valid RST pkt */
98764 reqsk_fastopen_remove(sk, req, true);
98765 tcp_reset(sk);
98766 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98767 index 1f2d376..01d18c4 100644
98768 --- a/net/ipv4/tcp_probe.c
98769 +++ b/net/ipv4/tcp_probe.c
98770 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98771 if (cnt + width >= len)
98772 break;
98773
98774 - if (copy_to_user(buf + cnt, tbuf, width))
98775 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98776 return -EFAULT;
98777 cnt += width;
98778 }
98779 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98780 index 64f0354..a81b39d 100644
98781 --- a/net/ipv4/tcp_timer.c
98782 +++ b/net/ipv4/tcp_timer.c
98783 @@ -22,6 +22,10 @@
98784 #include <linux/gfp.h>
98785 #include <net/tcp.h>
98786
98787 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98788 +extern int grsec_lastack_retries;
98789 +#endif
98790 +
98791 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98792 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98793 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98794 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98795 }
98796 }
98797
98798 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98799 + if ((sk->sk_state == TCP_LAST_ACK) &&
98800 + (grsec_lastack_retries > 0) &&
98801 + (grsec_lastack_retries < retry_until))
98802 + retry_until = grsec_lastack_retries;
98803 +#endif
98804 +
98805 if (retransmits_timed_out(sk, retry_until,
98806 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98807 /* Has it gone just too far? */
98808 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98809 index 77bd16f..5f7174a 100644
98810 --- a/net/ipv4/udp.c
98811 +++ b/net/ipv4/udp.c
98812 @@ -87,6 +87,7 @@
98813 #include <linux/types.h>
98814 #include <linux/fcntl.h>
98815 #include <linux/module.h>
98816 +#include <linux/security.h>
98817 #include <linux/socket.h>
98818 #include <linux/sockios.h>
98819 #include <linux/igmp.h>
98820 @@ -113,6 +114,10 @@
98821 #include <net/busy_poll.h>
98822 #include "udp_impl.h"
98823
98824 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98825 +extern int grsec_enable_blackhole;
98826 +#endif
98827 +
98828 struct udp_table udp_table __read_mostly;
98829 EXPORT_SYMBOL(udp_table);
98830
98831 @@ -615,6 +620,9 @@ found:
98832 return s;
98833 }
98834
98835 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98836 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98837 +
98838 /*
98839 * This routine is called by the ICMP module when it gets some
98840 * sort of error condition. If err < 0 then the socket should
98841 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98842 dport = usin->sin_port;
98843 if (dport == 0)
98844 return -EINVAL;
98845 +
98846 + err = gr_search_udp_sendmsg(sk, usin);
98847 + if (err)
98848 + return err;
98849 } else {
98850 if (sk->sk_state != TCP_ESTABLISHED)
98851 return -EDESTADDRREQ;
98852 +
98853 + err = gr_search_udp_sendmsg(sk, NULL);
98854 + if (err)
98855 + return err;
98856 +
98857 daddr = inet->inet_daddr;
98858 dport = inet->inet_dport;
98859 /* Open fast path for connected socket.
98860 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98861 IS_UDPLITE(sk));
98862 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98863 IS_UDPLITE(sk));
98864 - atomic_inc(&sk->sk_drops);
98865 + atomic_inc_unchecked(&sk->sk_drops);
98866 __skb_unlink(skb, rcvq);
98867 __skb_queue_tail(&list_kill, skb);
98868 }
98869 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98870 int is_udplite = IS_UDPLITE(sk);
98871 bool slow;
98872
98873 + /*
98874 + * Check any passed addresses
98875 + */
98876 + if (addr_len)
98877 + *addr_len = sizeof(*sin);
98878 +
98879 if (flags & MSG_ERRQUEUE)
98880 return ip_recv_error(sk, msg, len, addr_len);
98881
98882 @@ -1243,6 +1266,10 @@ try_again:
98883 if (!skb)
98884 goto out;
98885
98886 + err = gr_search_udp_recvmsg(sk, skb);
98887 + if (err)
98888 + goto out_free;
98889 +
98890 ulen = skb->len - sizeof(struct udphdr);
98891 copied = len;
98892 if (copied > ulen)
98893 @@ -1276,7 +1303,7 @@ try_again:
98894 if (unlikely(err)) {
98895 trace_kfree_skb(skb, udp_recvmsg);
98896 if (!peeked) {
98897 - atomic_inc(&sk->sk_drops);
98898 + atomic_inc_unchecked(&sk->sk_drops);
98899 UDP_INC_STATS_USER(sock_net(sk),
98900 UDP_MIB_INERRORS, is_udplite);
98901 }
98902 @@ -1295,7 +1322,6 @@ try_again:
98903 sin->sin_port = udp_hdr(skb)->source;
98904 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98905 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98906 - *addr_len = sizeof(*sin);
98907 }
98908 if (inet->cmsg_flags)
98909 ip_cmsg_recv(msg, skb);
98910 @@ -1566,7 +1592,7 @@ csum_error:
98911 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98912 drop:
98913 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98914 - atomic_inc(&sk->sk_drops);
98915 + atomic_inc_unchecked(&sk->sk_drops);
98916 kfree_skb(skb);
98917 return -1;
98918 }
98919 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98920 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98921
98922 if (!skb1) {
98923 - atomic_inc(&sk->sk_drops);
98924 + atomic_inc_unchecked(&sk->sk_drops);
98925 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98926 IS_UDPLITE(sk));
98927 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98928 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98929 goto csum_error;
98930
98931 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98932 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98933 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98934 +#endif
98935 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98936
98937 /*
98938 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98939 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98940 0, sock_i_ino(sp),
98941 atomic_read(&sp->sk_refcnt), sp,
98942 - atomic_read(&sp->sk_drops));
98943 + atomic_read_unchecked(&sp->sk_drops));
98944 }
98945
98946 int udp4_seq_show(struct seq_file *seq, void *v)
98947 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98948 index e1a6393..f634ce5 100644
98949 --- a/net/ipv4/xfrm4_policy.c
98950 +++ b/net/ipv4/xfrm4_policy.c
98951 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98952 fl4->flowi4_tos = iph->tos;
98953 }
98954
98955 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98956 +static int xfrm4_garbage_collect(struct dst_ops *ops)
98957 {
98958 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98959
98960 - xfrm4_policy_afinfo.garbage_collect(net);
98961 + xfrm_garbage_collect_deferred(net);
98962 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98963 }
98964
98965 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98966
98967 static int __net_init xfrm4_net_init(struct net *net)
98968 {
98969 - struct ctl_table *table;
98970 + ctl_table_no_const *table = NULL;
98971 struct ctl_table_header *hdr;
98972
98973 - table = xfrm4_policy_table;
98974 if (!net_eq(net, &init_net)) {
98975 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98976 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98977 if (!table)
98978 goto err_alloc;
98979
98980 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98981 - }
98982 -
98983 - hdr = register_net_sysctl(net, "net/ipv4", table);
98984 + hdr = register_net_sysctl(net, "net/ipv4", table);
98985 + } else
98986 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98987 if (!hdr)
98988 goto err_reg;
98989
98990 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98991 return 0;
98992
98993 err_reg:
98994 - if (!net_eq(net, &init_net))
98995 - kfree(table);
98996 + kfree(table);
98997 err_alloc:
98998 return -ENOMEM;
98999 }
99000 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99001 index 6c7fa08..285086c 100644
99002 --- a/net/ipv6/addrconf.c
99003 +++ b/net/ipv6/addrconf.c
99004 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99005 idx = 0;
99006 head = &net->dev_index_head[h];
99007 rcu_read_lock();
99008 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99009 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99010 net->dev_base_seq;
99011 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99012 if (idx < s_idx)
99013 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
99014 p.iph.ihl = 5;
99015 p.iph.protocol = IPPROTO_IPV6;
99016 p.iph.ttl = 64;
99017 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
99018 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
99019
99020 if (ops->ndo_do_ioctl) {
99021 mm_segment_t oldfs = get_fs();
99022 @@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
99023 s_ip_idx = ip_idx = cb->args[2];
99024
99025 rcu_read_lock();
99026 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99027 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99028 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
99029 idx = 0;
99030 head = &net->dev_index_head[h];
99031 @@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
99032 dst_free(&ifp->rt->dst);
99033 break;
99034 }
99035 - atomic_inc(&net->ipv6.dev_addr_genid);
99036 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
99037 rt_genid_bump_ipv6(net);
99038 }
99039
99040 @@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
99041 int *valp = ctl->data;
99042 int val = *valp;
99043 loff_t pos = *ppos;
99044 - struct ctl_table lctl;
99045 + ctl_table_no_const lctl;
99046 int ret;
99047
99048 /*
99049 @@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
99050 int *valp = ctl->data;
99051 int val = *valp;
99052 loff_t pos = *ppos;
99053 - struct ctl_table lctl;
99054 + ctl_table_no_const lctl;
99055 int ret;
99056
99057 /*
99058 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
99059 index d935889..2f64330 100644
99060 --- a/net/ipv6/af_inet6.c
99061 +++ b/net/ipv6/af_inet6.c
99062 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
99063 net->ipv6.sysctl.bindv6only = 0;
99064 net->ipv6.sysctl.icmpv6_time = 1*HZ;
99065 net->ipv6.sysctl.flowlabel_consistency = 1;
99066 - atomic_set(&net->ipv6.rt_genid, 0);
99067 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
99068
99069 err = ipv6_init_mibs(net);
99070 if (err)
99071 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
99072 index c3bf2d2..1f00573 100644
99073 --- a/net/ipv6/datagram.c
99074 +++ b/net/ipv6/datagram.c
99075 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
99076 0,
99077 sock_i_ino(sp),
99078 atomic_read(&sp->sk_refcnt), sp,
99079 - atomic_read(&sp->sk_drops));
99080 + atomic_read_unchecked(&sp->sk_drops));
99081 }
99082 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
99083 index 7b32652..0bc348b 100644
99084 --- a/net/ipv6/icmp.c
99085 +++ b/net/ipv6/icmp.c
99086 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
99087
99088 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
99089 {
99090 - struct ctl_table *table;
99091 + ctl_table_no_const *table;
99092
99093 table = kmemdup(ipv6_icmp_table_template,
99094 sizeof(ipv6_icmp_table_template),
99095 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
99096 index f3ffb43..1172ba7 100644
99097 --- a/net/ipv6/ip6_gre.c
99098 +++ b/net/ipv6/ip6_gre.c
99099 @@ -71,7 +71,7 @@ struct ip6gre_net {
99100 struct net_device *fb_tunnel_dev;
99101 };
99102
99103 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
99104 +static struct rtnl_link_ops ip6gre_link_ops;
99105 static int ip6gre_tunnel_init(struct net_device *dev);
99106 static void ip6gre_tunnel_setup(struct net_device *dev);
99107 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
99108 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
99109 }
99110
99111
99112 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
99113 +static struct inet6_protocol ip6gre_protocol = {
99114 .handler = ip6gre_rcv,
99115 .err_handler = ip6gre_err,
99116 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
99117 @@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
99118 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
99119 };
99120
99121 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99122 +static struct rtnl_link_ops ip6gre_link_ops = {
99123 .kind = "ip6gre",
99124 .maxtype = IFLA_GRE_MAX,
99125 .policy = ip6gre_policy,
99126 @@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
99127 .fill_info = ip6gre_fill_info,
99128 };
99129
99130 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
99131 +static struct rtnl_link_ops ip6gre_tap_ops = {
99132 .kind = "ip6gretap",
99133 .maxtype = IFLA_GRE_MAX,
99134 .policy = ip6gre_policy,
99135 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
99136 index 5db8d31..4a72c26 100644
99137 --- a/net/ipv6/ip6_tunnel.c
99138 +++ b/net/ipv6/ip6_tunnel.c
99139 @@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99140
99141 static int ip6_tnl_dev_init(struct net_device *dev);
99142 static void ip6_tnl_dev_setup(struct net_device *dev);
99143 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
99144 +static struct rtnl_link_ops ip6_link_ops;
99145
99146 static int ip6_tnl_net_id __read_mostly;
99147 struct ip6_tnl_net {
99148 @@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
99149 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
99150 };
99151
99152 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
99153 +static struct rtnl_link_ops ip6_link_ops = {
99154 .kind = "ip6tnl",
99155 .maxtype = IFLA_IPTUN_MAX,
99156 .policy = ip6_tnl_policy,
99157 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
99158 index 2d19272..3a46322 100644
99159 --- a/net/ipv6/ip6_vti.c
99160 +++ b/net/ipv6/ip6_vti.c
99161 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
99162
99163 static int vti6_dev_init(struct net_device *dev);
99164 static void vti6_dev_setup(struct net_device *dev);
99165 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
99166 +static struct rtnl_link_ops vti6_link_ops;
99167
99168 static int vti6_net_id __read_mostly;
99169 struct vti6_net {
99170 @@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
99171 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
99172 };
99173
99174 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
99175 +static struct rtnl_link_ops vti6_link_ops = {
99176 .kind = "vti6",
99177 .maxtype = IFLA_VTI_MAX,
99178 .policy = vti6_policy,
99179 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99180 index 0a00f44..bec42b2 100644
99181 --- a/net/ipv6/ipv6_sockglue.c
99182 +++ b/net/ipv6/ipv6_sockglue.c
99183 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99184 if (sk->sk_type != SOCK_STREAM)
99185 return -ENOPROTOOPT;
99186
99187 - msg.msg_control = optval;
99188 + msg.msg_control = (void __force_kernel *)optval;
99189 msg.msg_controllen = len;
99190 msg.msg_flags = flags;
99191
99192 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99193 index 710238f..0fd1816 100644
99194 --- a/net/ipv6/netfilter/ip6_tables.c
99195 +++ b/net/ipv6/netfilter/ip6_tables.c
99196 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99197 #endif
99198
99199 static int get_info(struct net *net, void __user *user,
99200 - const int *len, int compat)
99201 + int len, int compat)
99202 {
99203 char name[XT_TABLE_MAXNAMELEN];
99204 struct xt_table *t;
99205 int ret;
99206
99207 - if (*len != sizeof(struct ip6t_getinfo)) {
99208 - duprintf("length %u != %zu\n", *len,
99209 + if (len != sizeof(struct ip6t_getinfo)) {
99210 + duprintf("length %u != %zu\n", len,
99211 sizeof(struct ip6t_getinfo));
99212 return -EINVAL;
99213 }
99214 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99215 info.size = private->size;
99216 strcpy(info.name, name);
99217
99218 - if (copy_to_user(user, &info, *len) != 0)
99219 + if (copy_to_user(user, &info, len) != 0)
99220 ret = -EFAULT;
99221 else
99222 ret = 0;
99223 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99224
99225 switch (cmd) {
99226 case IP6T_SO_GET_INFO:
99227 - ret = get_info(sock_net(sk), user, len, 1);
99228 + ret = get_info(sock_net(sk), user, *len, 1);
99229 break;
99230 case IP6T_SO_GET_ENTRIES:
99231 ret = compat_get_entries(sock_net(sk), user, len);
99232 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99233
99234 switch (cmd) {
99235 case IP6T_SO_GET_INFO:
99236 - ret = get_info(sock_net(sk), user, len, 0);
99237 + ret = get_info(sock_net(sk), user, *len, 0);
99238 break;
99239
99240 case IP6T_SO_GET_ENTRIES:
99241 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99242 index 767ab8d..c5ec70a 100644
99243 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99244 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99245 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99246
99247 static int nf_ct_frag6_sysctl_register(struct net *net)
99248 {
99249 - struct ctl_table *table;
99250 + ctl_table_no_const *table = NULL;
99251 struct ctl_table_header *hdr;
99252
99253 - table = nf_ct_frag6_sysctl_table;
99254 if (!net_eq(net, &init_net)) {
99255 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99256 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99257 GFP_KERNEL);
99258 if (table == NULL)
99259 goto err_alloc;
99260 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99261 table[0].data = &net->nf_frag.frags.timeout;
99262 table[1].data = &net->nf_frag.frags.low_thresh;
99263 table[2].data = &net->nf_frag.frags.high_thresh;
99264 - }
99265 -
99266 - hdr = register_net_sysctl(net, "net/netfilter", table);
99267 + hdr = register_net_sysctl(net, "net/netfilter", table);
99268 + } else
99269 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99270 if (hdr == NULL)
99271 goto err_reg;
99272
99273 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99274 return 0;
99275
99276 err_reg:
99277 - if (!net_eq(net, &init_net))
99278 - kfree(table);
99279 + kfree(table);
99280 err_alloc:
99281 return -ENOMEM;
99282 }
99283 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99284 index 827f795..7e28e82 100644
99285 --- a/net/ipv6/output_core.c
99286 +++ b/net/ipv6/output_core.c
99287 @@ -9,8 +9,8 @@
99288
99289 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99290 {
99291 - static atomic_t ipv6_fragmentation_id;
99292 - int old, new;
99293 + static atomic_unchecked_t ipv6_fragmentation_id;
99294 + int id;
99295
99296 #if IS_ENABLED(CONFIG_IPV6)
99297 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99298 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99299 }
99300 }
99301 #endif
99302 - do {
99303 - old = atomic_read(&ipv6_fragmentation_id);
99304 - new = old + 1;
99305 - if (!new)
99306 - new = 1;
99307 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99308 - fhdr->identification = htonl(new);
99309 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99310 + if (!id)
99311 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99312 + fhdr->identification = htonl(id);
99313 }
99314 EXPORT_SYMBOL(ipv6_select_ident);
99315
99316 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99317 index bda7429..469b26b 100644
99318 --- a/net/ipv6/ping.c
99319 +++ b/net/ipv6/ping.c
99320 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
99321 };
99322 #endif
99323
99324 +static struct pingv6_ops real_pingv6_ops = {
99325 + .ipv6_recv_error = ipv6_recv_error,
99326 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
99327 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
99328 + .icmpv6_err_convert = icmpv6_err_convert,
99329 + .ipv6_icmp_error = ipv6_icmp_error,
99330 + .ipv6_chk_addr = ipv6_chk_addr,
99331 +};
99332 +
99333 +static struct pingv6_ops dummy_pingv6_ops = {
99334 + .ipv6_recv_error = dummy_ipv6_recv_error,
99335 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
99336 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
99337 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
99338 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
99339 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
99340 +};
99341 +
99342 int __init pingv6_init(void)
99343 {
99344 #ifdef CONFIG_PROC_FS
99345 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
99346 if (ret)
99347 return ret;
99348 #endif
99349 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99350 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
99351 - pingv6_ops.ip6_datagram_recv_specific_ctl =
99352 - ip6_datagram_recv_specific_ctl;
99353 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99354 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99355 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99356 + pingv6_ops = &real_pingv6_ops;
99357 return inet6_register_protosw(&pingv6_protosw);
99358 }
99359
99360 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
99361 */
99362 void pingv6_exit(void)
99363 {
99364 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99365 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
99366 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
99367 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99368 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99369 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99370 #ifdef CONFIG_PROC_FS
99371 unregister_pernet_subsys(&ping_v6_net_ops);
99372 #endif
99373 + pingv6_ops = &dummy_pingv6_ops;
99374 inet6_unregister_protosw(&pingv6_protosw);
99375 }
99376 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99377 index 1f29996..46fe0c7 100644
99378 --- a/net/ipv6/raw.c
99379 +++ b/net/ipv6/raw.c
99380 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99381 {
99382 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99383 skb_checksum_complete(skb)) {
99384 - atomic_inc(&sk->sk_drops);
99385 + atomic_inc_unchecked(&sk->sk_drops);
99386 kfree_skb(skb);
99387 return NET_RX_DROP;
99388 }
99389 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99390 struct raw6_sock *rp = raw6_sk(sk);
99391
99392 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99393 - atomic_inc(&sk->sk_drops);
99394 + atomic_inc_unchecked(&sk->sk_drops);
99395 kfree_skb(skb);
99396 return NET_RX_DROP;
99397 }
99398 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99399
99400 if (inet->hdrincl) {
99401 if (skb_checksum_complete(skb)) {
99402 - atomic_inc(&sk->sk_drops);
99403 + atomic_inc_unchecked(&sk->sk_drops);
99404 kfree_skb(skb);
99405 return NET_RX_DROP;
99406 }
99407 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99408 if (flags & MSG_OOB)
99409 return -EOPNOTSUPP;
99410
99411 + if (addr_len)
99412 + *addr_len=sizeof(*sin6);
99413 +
99414 if (flags & MSG_ERRQUEUE)
99415 return ipv6_recv_error(sk, msg, len, addr_len);
99416
99417 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99418 sin6->sin6_flowinfo = 0;
99419 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99420 IP6CB(skb)->iif);
99421 - *addr_len = sizeof(*sin6);
99422 }
99423
99424 sock_recv_ts_and_drops(msg, sk, skb);
99425 @@ -610,7 +612,7 @@ out:
99426 return err;
99427 }
99428
99429 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99430 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99431 struct flowi6 *fl6, struct dst_entry **dstp,
99432 unsigned int flags)
99433 {
99434 @@ -922,12 +924,15 @@ do_confirm:
99435 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99436 char __user *optval, int optlen)
99437 {
99438 + struct icmp6_filter filter;
99439 +
99440 switch (optname) {
99441 case ICMPV6_FILTER:
99442 if (optlen > sizeof(struct icmp6_filter))
99443 optlen = sizeof(struct icmp6_filter);
99444 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99445 + if (copy_from_user(&filter, optval, optlen))
99446 return -EFAULT;
99447 + raw6_sk(sk)->filter = filter;
99448 return 0;
99449 default:
99450 return -ENOPROTOOPT;
99451 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99452 char __user *optval, int __user *optlen)
99453 {
99454 int len;
99455 + struct icmp6_filter filter;
99456
99457 switch (optname) {
99458 case ICMPV6_FILTER:
99459 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99460 len = sizeof(struct icmp6_filter);
99461 if (put_user(len, optlen))
99462 return -EFAULT;
99463 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99464 + filter = raw6_sk(sk)->filter;
99465 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
99466 return -EFAULT;
99467 return 0;
99468 default:
99469 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99470 index cc85a9b..526a133 100644
99471 --- a/net/ipv6/reassembly.c
99472 +++ b/net/ipv6/reassembly.c
99473 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99474
99475 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99476 {
99477 - struct ctl_table *table;
99478 + ctl_table_no_const *table = NULL;
99479 struct ctl_table_header *hdr;
99480
99481 - table = ip6_frags_ns_ctl_table;
99482 if (!net_eq(net, &init_net)) {
99483 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99484 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99485 if (table == NULL)
99486 goto err_alloc;
99487
99488 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99489 /* Don't export sysctls to unprivileged users */
99490 if (net->user_ns != &init_user_ns)
99491 table[0].procname = NULL;
99492 - }
99493 + hdr = register_net_sysctl(net, "net/ipv6", table);
99494 + } else
99495 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99496
99497 - hdr = register_net_sysctl(net, "net/ipv6", table);
99498 if (hdr == NULL)
99499 goto err_reg;
99500
99501 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99502 return 0;
99503
99504 err_reg:
99505 - if (!net_eq(net, &init_net))
99506 - kfree(table);
99507 + kfree(table);
99508 err_alloc:
99509 return -ENOMEM;
99510 }
99511 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99512 index fba54a4..73e374e 100644
99513 --- a/net/ipv6/route.c
99514 +++ b/net/ipv6/route.c
99515 @@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
99516
99517 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99518 {
99519 - struct ctl_table *table;
99520 + ctl_table_no_const *table;
99521
99522 table = kmemdup(ipv6_route_table_template,
99523 sizeof(ipv6_route_table_template),
99524 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99525 index b4d74c8..b4f3fbe 100644
99526 --- a/net/ipv6/sit.c
99527 +++ b/net/ipv6/sit.c
99528 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99529 static void ipip6_dev_free(struct net_device *dev);
99530 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99531 __be32 *v4dst);
99532 -static struct rtnl_link_ops sit_link_ops __read_mostly;
99533 +static struct rtnl_link_ops sit_link_ops;
99534
99535 static int sit_net_id __read_mostly;
99536 struct sit_net {
99537 @@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99538 unregister_netdevice_queue(dev, head);
99539 }
99540
99541 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
99542 +static struct rtnl_link_ops sit_link_ops = {
99543 .kind = "sit",
99544 .maxtype = IFLA_IPTUN_MAX,
99545 .policy = ipip6_policy,
99546 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99547 index 7f405a1..eabef92 100644
99548 --- a/net/ipv6/sysctl_net_ipv6.c
99549 +++ b/net/ipv6/sysctl_net_ipv6.c
99550 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
99551
99552 static int __net_init ipv6_sysctl_net_init(struct net *net)
99553 {
99554 - struct ctl_table *ipv6_table;
99555 + ctl_table_no_const *ipv6_table;
99556 struct ctl_table *ipv6_route_table;
99557 struct ctl_table *ipv6_icmp_table;
99558 int err;
99559 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99560 index 889079b..a04512c 100644
99561 --- a/net/ipv6/tcp_ipv6.c
99562 +++ b/net/ipv6/tcp_ipv6.c
99563 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99564 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99565 }
99566
99567 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99568 +extern int grsec_enable_blackhole;
99569 +#endif
99570 +
99571 static void tcp_v6_hash(struct sock *sk)
99572 {
99573 if (sk->sk_state != TCP_CLOSE) {
99574 @@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99575 return 0;
99576
99577 reset:
99578 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99579 + if (!grsec_enable_blackhole)
99580 +#endif
99581 tcp_v6_send_reset(sk, skb);
99582 discard:
99583 if (opt_skb)
99584 @@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99585 TCP_SKB_CB(skb)->sacked = 0;
99586
99587 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99588 - if (!sk)
99589 + if (!sk) {
99590 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99591 + ret = 1;
99592 +#endif
99593 goto no_tcp_socket;
99594 + }
99595
99596 process:
99597 - if (sk->sk_state == TCP_TIME_WAIT)
99598 + if (sk->sk_state == TCP_TIME_WAIT) {
99599 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99600 + ret = 2;
99601 +#endif
99602 goto do_time_wait;
99603 + }
99604
99605 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99606 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99607 @@ -1553,6 +1568,10 @@ csum_error:
99608 bad_packet:
99609 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99610 } else {
99611 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99612 + if (!grsec_enable_blackhole || (ret == 1 &&
99613 + (skb->dev->flags & IFF_LOOPBACK)))
99614 +#endif
99615 tcp_v6_send_reset(NULL, skb);
99616 }
99617
99618 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99619 index 1e586d9..384a9c9 100644
99620 --- a/net/ipv6/udp.c
99621 +++ b/net/ipv6/udp.c
99622 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99623 udp_ipv6_hash_secret + net_hash_mix(net));
99624 }
99625
99626 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99627 +extern int grsec_enable_blackhole;
99628 +#endif
99629 +
99630 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99631 {
99632 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99633 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99634 int is_udp4;
99635 bool slow;
99636
99637 + if (addr_len)
99638 + *addr_len = sizeof(struct sockaddr_in6);
99639 +
99640 if (flags & MSG_ERRQUEUE)
99641 return ipv6_recv_error(sk, msg, len, addr_len);
99642
99643 @@ -435,7 +442,7 @@ try_again:
99644 if (unlikely(err)) {
99645 trace_kfree_skb(skb, udpv6_recvmsg);
99646 if (!peeked) {
99647 - atomic_inc(&sk->sk_drops);
99648 + atomic_inc_unchecked(&sk->sk_drops);
99649 if (is_udp4)
99650 UDP_INC_STATS_USER(sock_net(sk),
99651 UDP_MIB_INERRORS,
99652 @@ -475,7 +482,7 @@ try_again:
99653 ipv6_iface_scope_id(&sin6->sin6_addr,
99654 IP6CB(skb)->iif);
99655 }
99656 - *addr_len = sizeof(*sin6);
99657 +
99658 }
99659
99660 if (np->rxopt.all)
99661 @@ -690,7 +697,7 @@ csum_error:
99662 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99663 drop:
99664 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99665 - atomic_inc(&sk->sk_drops);
99666 + atomic_inc_unchecked(&sk->sk_drops);
99667 kfree_skb(skb);
99668 return -1;
99669 }
99670 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99671 if (likely(skb1 == NULL))
99672 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99673 if (!skb1) {
99674 - atomic_inc(&sk->sk_drops);
99675 + atomic_inc_unchecked(&sk->sk_drops);
99676 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99677 IS_UDPLITE(sk));
99678 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99679 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99680 goto csum_error;
99681
99682 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99683 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99684 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99685 +#endif
99686 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99687
99688 kfree_skb(skb);
99689 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99690 index 5f8e128..865d38e 100644
99691 --- a/net/ipv6/xfrm6_policy.c
99692 +++ b/net/ipv6/xfrm6_policy.c
99693 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99694 }
99695 }
99696
99697 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99698 +static int xfrm6_garbage_collect(struct dst_ops *ops)
99699 {
99700 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99701
99702 - xfrm6_policy_afinfo.garbage_collect(net);
99703 + xfrm_garbage_collect_deferred(net);
99704 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99705 }
99706
99707 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99708
99709 static int __net_init xfrm6_net_init(struct net *net)
99710 {
99711 - struct ctl_table *table;
99712 + ctl_table_no_const *table = NULL;
99713 struct ctl_table_header *hdr;
99714
99715 - table = xfrm6_policy_table;
99716 if (!net_eq(net, &init_net)) {
99717 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99718 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99719 if (!table)
99720 goto err_alloc;
99721
99722 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99723 - }
99724 + hdr = register_net_sysctl(net, "net/ipv6", table);
99725 + } else
99726 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99727
99728 - hdr = register_net_sysctl(net, "net/ipv6", table);
99729 if (!hdr)
99730 goto err_reg;
99731
99732 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99733 return 0;
99734
99735 err_reg:
99736 - if (!net_eq(net, &init_net))
99737 - kfree(table);
99738 + kfree(table);
99739 err_alloc:
99740 return -ENOMEM;
99741 }
99742 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99743 index 2ba8b97..6d33010 100644
99744 --- a/net/irda/ircomm/ircomm_tty.c
99745 +++ b/net/irda/ircomm/ircomm_tty.c
99746 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99747 add_wait_queue(&port->open_wait, &wait);
99748
99749 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99750 - __FILE__, __LINE__, tty->driver->name, port->count);
99751 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99752
99753 spin_lock_irqsave(&port->lock, flags);
99754 if (!tty_hung_up_p(filp))
99755 - port->count--;
99756 + atomic_dec(&port->count);
99757 port->blocked_open++;
99758 spin_unlock_irqrestore(&port->lock, flags);
99759
99760 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99761 }
99762
99763 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99764 - __FILE__, __LINE__, tty->driver->name, port->count);
99765 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99766
99767 schedule();
99768 }
99769 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99770
99771 spin_lock_irqsave(&port->lock, flags);
99772 if (!tty_hung_up_p(filp))
99773 - port->count++;
99774 + atomic_inc(&port->count);
99775 port->blocked_open--;
99776 spin_unlock_irqrestore(&port->lock, flags);
99777
99778 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99779 - __FILE__, __LINE__, tty->driver->name, port->count);
99780 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99781
99782 if (!retval)
99783 port->flags |= ASYNC_NORMAL_ACTIVE;
99784 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99785
99786 /* ++ is not atomic, so this should be protected - Jean II */
99787 spin_lock_irqsave(&self->port.lock, flags);
99788 - self->port.count++;
99789 + atomic_inc(&self->port.count);
99790 spin_unlock_irqrestore(&self->port.lock, flags);
99791 tty_port_tty_set(&self->port, tty);
99792
99793 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99794 - self->line, self->port.count);
99795 + self->line, atomic_read(&self->port.count));
99796
99797 /* Not really used by us, but lets do it anyway */
99798 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99799 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99800 tty_kref_put(port->tty);
99801 }
99802 port->tty = NULL;
99803 - port->count = 0;
99804 + atomic_set(&port->count, 0);
99805 spin_unlock_irqrestore(&port->lock, flags);
99806
99807 wake_up_interruptible(&port->open_wait);
99808 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99809 seq_putc(m, '\n');
99810
99811 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99812 - seq_printf(m, "Open count: %d\n", self->port.count);
99813 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99814 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99815 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99816
99817 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99818 index c4b7218..3e83259 100644
99819 --- a/net/iucv/af_iucv.c
99820 +++ b/net/iucv/af_iucv.c
99821 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99822
99823 write_lock_bh(&iucv_sk_list.lock);
99824
99825 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99826 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99827 while (__iucv_get_sock_by_name(name)) {
99828 sprintf(name, "%08x",
99829 - atomic_inc_return(&iucv_sk_list.autobind_name));
99830 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99831 }
99832
99833 write_unlock_bh(&iucv_sk_list.lock);
99834 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99835 index cd5b8ec..f205e6b 100644
99836 --- a/net/iucv/iucv.c
99837 +++ b/net/iucv/iucv.c
99838 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99839 return NOTIFY_OK;
99840 }
99841
99842 -static struct notifier_block __refdata iucv_cpu_notifier = {
99843 +static struct notifier_block iucv_cpu_notifier = {
99844 .notifier_call = iucv_cpu_notify,
99845 };
99846
99847 diff --git a/net/key/af_key.c b/net/key/af_key.c
99848 index 7932697..a13d158 100644
99849 --- a/net/key/af_key.c
99850 +++ b/net/key/af_key.c
99851 @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99852 static u32 get_acqseq(void)
99853 {
99854 u32 res;
99855 - static atomic_t acqseq;
99856 + static atomic_unchecked_t acqseq;
99857
99858 do {
99859 - res = atomic_inc_return(&acqseq);
99860 + res = atomic_inc_return_unchecked(&acqseq);
99861 } while (!res);
99862 return res;
99863 }
99864 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99865 index 0b44d85..1a7f88b 100644
99866 --- a/net/l2tp/l2tp_ip.c
99867 +++ b/net/l2tp/l2tp_ip.c
99868 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99869 if (flags & MSG_OOB)
99870 goto out;
99871
99872 + if (addr_len)
99873 + *addr_len = sizeof(*sin);
99874 +
99875 skb = skb_recv_datagram(sk, flags, noblock, &err);
99876 if (!skb)
99877 goto out;
99878 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99879 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99880 sin->sin_port = 0;
99881 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99882 - *addr_len = sizeof(*sin);
99883 }
99884 if (inet->cmsg_flags)
99885 ip_cmsg_recv(msg, skb);
99886 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99887 index 453e974..b3a43a5 100644
99888 --- a/net/mac80211/cfg.c
99889 +++ b/net/mac80211/cfg.c
99890 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99891 ret = ieee80211_vif_use_channel(sdata, chandef,
99892 IEEE80211_CHANCTX_EXCLUSIVE);
99893 }
99894 - } else if (local->open_count == local->monitors) {
99895 + } else if (local_read(&local->open_count) == local->monitors) {
99896 local->_oper_chandef = *chandef;
99897 ieee80211_hw_config(local, 0);
99898 }
99899 @@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99900 else
99901 local->probe_req_reg--;
99902
99903 - if (!local->open_count)
99904 + if (!local_read(&local->open_count))
99905 break;
99906
99907 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99908 @@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99909 if (chanctx_conf) {
99910 *chandef = chanctx_conf->def;
99911 ret = 0;
99912 - } else if (local->open_count > 0 &&
99913 - local->open_count == local->monitors &&
99914 + } else if (local_read(&local->open_count) > 0 &&
99915 + local_read(&local->open_count) == local->monitors &&
99916 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99917 if (local->use_chanctx)
99918 *chandef = local->monitor_chandef;
99919 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99920 index 5e44e317..3d404a6 100644
99921 --- a/net/mac80211/ieee80211_i.h
99922 +++ b/net/mac80211/ieee80211_i.h
99923 @@ -28,6 +28,7 @@
99924 #include <net/ieee80211_radiotap.h>
99925 #include <net/cfg80211.h>
99926 #include <net/mac80211.h>
99927 +#include <asm/local.h>
99928 #include "key.h"
99929 #include "sta_info.h"
99930 #include "debug.h"
99931 @@ -994,7 +995,7 @@ struct ieee80211_local {
99932 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99933 spinlock_t queue_stop_reason_lock;
99934
99935 - int open_count;
99936 + local_t open_count;
99937 int monitors, cooked_mntrs;
99938 /* number of interfaces with corresponding FIF_ flags */
99939 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99940 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99941 index ce1c443..6cd39e1 100644
99942 --- a/net/mac80211/iface.c
99943 +++ b/net/mac80211/iface.c
99944 @@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99945 break;
99946 }
99947
99948 - if (local->open_count == 0) {
99949 + if (local_read(&local->open_count) == 0) {
99950 res = drv_start(local);
99951 if (res)
99952 goto err_del_bss;
99953 @@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99954 res = drv_add_interface(local, sdata);
99955 if (res)
99956 goto err_stop;
99957 - } else if (local->monitors == 0 && local->open_count == 0) {
99958 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99959 res = ieee80211_add_virtual_monitor(local);
99960 if (res)
99961 goto err_stop;
99962 @@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99963 atomic_inc(&local->iff_promiscs);
99964
99965 if (coming_up)
99966 - local->open_count++;
99967 + local_inc(&local->open_count);
99968
99969 if (hw_reconf_flags)
99970 ieee80211_hw_config(local, hw_reconf_flags);
99971 @@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99972 err_del_interface:
99973 drv_remove_interface(local, sdata);
99974 err_stop:
99975 - if (!local->open_count)
99976 + if (!local_read(&local->open_count))
99977 drv_stop(local);
99978 err_del_bss:
99979 sdata->bss = NULL;
99980 @@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99981 }
99982
99983 if (going_down)
99984 - local->open_count--;
99985 + local_dec(&local->open_count);
99986
99987 switch (sdata->vif.type) {
99988 case NL80211_IFTYPE_AP_VLAN:
99989 @@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99990 }
99991 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99992
99993 - if (local->open_count == 0)
99994 + if (local_read(&local->open_count) == 0)
99995 ieee80211_clear_tx_pending(local);
99996
99997 /*
99998 @@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99999
100000 ieee80211_recalc_ps(local, -1);
100001
100002 - if (local->open_count == 0) {
100003 + if (local_read(&local->open_count) == 0) {
100004 ieee80211_stop_device(local);
100005
100006 /* no reconfiguring after stop! */
100007 @@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100008 ieee80211_configure_filter(local);
100009 ieee80211_hw_config(local, hw_reconf_flags);
100010
100011 - if (local->monitors == local->open_count)
100012 + if (local->monitors == local_read(&local->open_count))
100013 ieee80211_add_virtual_monitor(local);
100014 }
100015
100016 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
100017 index d767cfb..b4cd07d 100644
100018 --- a/net/mac80211/main.c
100019 +++ b/net/mac80211/main.c
100020 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
100021 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
100022 IEEE80211_CONF_CHANGE_POWER);
100023
100024 - if (changed && local->open_count) {
100025 + if (changed && local_read(&local->open_count)) {
100026 ret = drv_config(local, changed);
100027 /*
100028 * Goal:
100029 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
100030 index af64fb8..366e371 100644
100031 --- a/net/mac80211/pm.c
100032 +++ b/net/mac80211/pm.c
100033 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100034 struct ieee80211_sub_if_data *sdata;
100035 struct sta_info *sta;
100036
100037 - if (!local->open_count)
100038 + if (!local_read(&local->open_count))
100039 goto suspend;
100040
100041 ieee80211_scan_cancel(local);
100042 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100043 cancel_work_sync(&local->dynamic_ps_enable_work);
100044 del_timer_sync(&local->dynamic_ps_timer);
100045
100046 - local->wowlan = wowlan && local->open_count;
100047 + local->wowlan = wowlan && local_read(&local->open_count);
100048 if (local->wowlan) {
100049 int err = drv_suspend(local, wowlan);
100050 if (err < 0) {
100051 @@ -115,7 +115,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
100052 WARN_ON(!list_empty(&local->chanctx_list));
100053
100054 /* stop hardware - this must stop RX */
100055 - if (local->open_count)
100056 + if (local_read(&local->open_count))
100057 ieee80211_stop_device(local);
100058
100059 suspend:
100060 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
100061 index 22b223f..ab70070 100644
100062 --- a/net/mac80211/rate.c
100063 +++ b/net/mac80211/rate.c
100064 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
100065
100066 ASSERT_RTNL();
100067
100068 - if (local->open_count)
100069 + if (local_read(&local->open_count))
100070 return -EBUSY;
100071
100072 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
100073 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
100074 index 6ff1346..936ca9a 100644
100075 --- a/net/mac80211/rc80211_pid_debugfs.c
100076 +++ b/net/mac80211/rc80211_pid_debugfs.c
100077 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
100078
100079 spin_unlock_irqrestore(&events->lock, status);
100080
100081 - if (copy_to_user(buf, pb, p))
100082 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
100083 return -EFAULT;
100084
100085 return p;
100086 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
100087 index b8700d4..89086d5 100644
100088 --- a/net/mac80211/util.c
100089 +++ b/net/mac80211/util.c
100090 @@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100091 }
100092 #endif
100093 /* everything else happens only if HW was up & running */
100094 - if (!local->open_count)
100095 + if (!local_read(&local->open_count))
100096 goto wake_up;
100097
100098 /*
100099 @@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
100100 local->in_reconfig = false;
100101 barrier();
100102
100103 - if (local->monitors == local->open_count && local->monitors > 0)
100104 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
100105 ieee80211_add_virtual_monitor(local);
100106
100107 /*
100108 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
100109 index e9410d1..77b6378 100644
100110 --- a/net/netfilter/Kconfig
100111 +++ b/net/netfilter/Kconfig
100112 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
100113
100114 To compile it as a module, choose M here. If unsure, say N.
100115
100116 +config NETFILTER_XT_MATCH_GRADM
100117 + tristate '"gradm" match support'
100118 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
100119 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
100120 + ---help---
100121 + The gradm match allows to match on grsecurity RBAC being enabled.
100122 + It is useful when iptables rules are applied early on bootup to
100123 + prevent connections to the machine (except from a trusted host)
100124 + while the RBAC system is disabled.
100125 +
100126 config NETFILTER_XT_MATCH_HASHLIMIT
100127 tristate '"hashlimit" match support'
100128 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
100129 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
100130 index bffdad7..f9317d1 100644
100131 --- a/net/netfilter/Makefile
100132 +++ b/net/netfilter/Makefile
100133 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
100134 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
100135 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
100136 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
100137 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
100138 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
100139 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
100140 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
100141 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
100142 index de770ec..3fc49d2 100644
100143 --- a/net/netfilter/ipset/ip_set_core.c
100144 +++ b/net/netfilter/ipset/ip_set_core.c
100145 @@ -1922,7 +1922,7 @@ done:
100146 return ret;
100147 }
100148
100149 -static struct nf_sockopt_ops so_set __read_mostly = {
100150 +static struct nf_sockopt_ops so_set = {
100151 .pf = PF_INET,
100152 .get_optmin = SO_IP_SET,
100153 .get_optmax = SO_IP_SET + 1,
100154 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
100155 index a8eb0a8..86f2de4 100644
100156 --- a/net/netfilter/ipvs/ip_vs_conn.c
100157 +++ b/net/netfilter/ipvs/ip_vs_conn.c
100158 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
100159 /* Increase the refcnt counter of the dest */
100160 ip_vs_dest_hold(dest);
100161
100162 - conn_flags = atomic_read(&dest->conn_flags);
100163 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
100164 if (cp->protocol != IPPROTO_UDP)
100165 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
100166 flags = cp->flags;
100167 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
100168
100169 cp->control = NULL;
100170 atomic_set(&cp->n_control, 0);
100171 - atomic_set(&cp->in_pkts, 0);
100172 + atomic_set_unchecked(&cp->in_pkts, 0);
100173
100174 cp->packet_xmit = NULL;
100175 cp->app = NULL;
100176 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
100177
100178 /* Don't drop the entry if its number of incoming packets is not
100179 located in [0, 8] */
100180 - i = atomic_read(&cp->in_pkts);
100181 + i = atomic_read_unchecked(&cp->in_pkts);
100182 if (i > 8 || i < 0) return 0;
100183
100184 if (!todrop_rate[i]) return 0;
100185 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100186 index 4f26ee4..6a9d7c3 100644
100187 --- a/net/netfilter/ipvs/ip_vs_core.c
100188 +++ b/net/netfilter/ipvs/ip_vs_core.c
100189 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100190 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100191 /* do not touch skb anymore */
100192
100193 - atomic_inc(&cp->in_pkts);
100194 + atomic_inc_unchecked(&cp->in_pkts);
100195 ip_vs_conn_put(cp);
100196 return ret;
100197 }
100198 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100199 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100200 pkts = sysctl_sync_threshold(ipvs);
100201 else
100202 - pkts = atomic_add_return(1, &cp->in_pkts);
100203 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100204
100205 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100206 ip_vs_sync_conn(net, cp, pkts);
100207 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100208 index 35be035..50f8834 100644
100209 --- a/net/netfilter/ipvs/ip_vs_ctl.c
100210 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
100211 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100212 */
100213 ip_vs_rs_hash(ipvs, dest);
100214 }
100215 - atomic_set(&dest->conn_flags, conn_flags);
100216 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
100217
100218 /* bind the service */
100219 old_svc = rcu_dereference_protected(dest->svc, 1);
100220 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100221 * align with netns init in ip_vs_control_net_init()
100222 */
100223
100224 -static struct ctl_table vs_vars[] = {
100225 +static ctl_table_no_const vs_vars[] __read_only = {
100226 {
100227 .procname = "amemthresh",
100228 .maxlen = sizeof(int),
100229 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100230 " %-7s %-6d %-10d %-10d\n",
100231 &dest->addr.in6,
100232 ntohs(dest->port),
100233 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100234 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100235 atomic_read(&dest->weight),
100236 atomic_read(&dest->activeconns),
100237 atomic_read(&dest->inactconns));
100238 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100239 "%-7s %-6d %-10d %-10d\n",
100240 ntohl(dest->addr.ip),
100241 ntohs(dest->port),
100242 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100243 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100244 atomic_read(&dest->weight),
100245 atomic_read(&dest->activeconns),
100246 atomic_read(&dest->inactconns));
100247 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100248
100249 entry.addr = dest->addr.ip;
100250 entry.port = dest->port;
100251 - entry.conn_flags = atomic_read(&dest->conn_flags);
100252 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100253 entry.weight = atomic_read(&dest->weight);
100254 entry.u_threshold = dest->u_threshold;
100255 entry.l_threshold = dest->l_threshold;
100256 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100257 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100258 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100259 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100260 - (atomic_read(&dest->conn_flags) &
100261 + (atomic_read_unchecked(&dest->conn_flags) &
100262 IP_VS_CONN_F_FWD_MASK)) ||
100263 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100264 atomic_read(&dest->weight)) ||
100265 @@ -3580,7 +3580,7 @@ out:
100266 }
100267
100268
100269 -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100270 +static const struct genl_ops ip_vs_genl_ops[] = {
100271 {
100272 .cmd = IPVS_CMD_NEW_SERVICE,
100273 .flags = GENL_ADMIN_PERM,
100274 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100275 {
100276 int idx;
100277 struct netns_ipvs *ipvs = net_ipvs(net);
100278 - struct ctl_table *tbl;
100279 + ctl_table_no_const *tbl;
100280
100281 atomic_set(&ipvs->dropentry, 0);
100282 spin_lock_init(&ipvs->dropentry_lock);
100283 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100284 index ca056a3..9cf01ef 100644
100285 --- a/net/netfilter/ipvs/ip_vs_lblc.c
100286 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
100287 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100288 * IPVS LBLC sysctl table
100289 */
100290 #ifdef CONFIG_SYSCTL
100291 -static struct ctl_table vs_vars_table[] = {
100292 +static ctl_table_no_const vs_vars_table[] __read_only = {
100293 {
100294 .procname = "lblc_expiration",
100295 .data = NULL,
100296 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100297 index 3f21a2f..a112e85 100644
100298 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
100299 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100300 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100301 * IPVS LBLCR sysctl table
100302 */
100303
100304 -static struct ctl_table vs_vars_table[] = {
100305 +static ctl_table_no_const vs_vars_table[] __read_only = {
100306 {
100307 .procname = "lblcr_expiration",
100308 .data = NULL,
100309 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100310 index db80126..ef7110e 100644
100311 --- a/net/netfilter/ipvs/ip_vs_sync.c
100312 +++ b/net/netfilter/ipvs/ip_vs_sync.c
100313 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100314 cp = cp->control;
100315 if (cp) {
100316 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100317 - pkts = atomic_add_return(1, &cp->in_pkts);
100318 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100319 else
100320 pkts = sysctl_sync_threshold(ipvs);
100321 ip_vs_sync_conn(net, cp->control, pkts);
100322 @@ -771,7 +771,7 @@ control:
100323 if (!cp)
100324 return;
100325 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100326 - pkts = atomic_add_return(1, &cp->in_pkts);
100327 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100328 else
100329 pkts = sysctl_sync_threshold(ipvs);
100330 goto sloop;
100331 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100332
100333 if (opt)
100334 memcpy(&cp->in_seq, opt, sizeof(*opt));
100335 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100336 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100337 cp->state = state;
100338 cp->old_state = cp->state;
100339 /*
100340 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100341 index c47444e..b0961c6 100644
100342 --- a/net/netfilter/ipvs/ip_vs_xmit.c
100343 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
100344 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100345 else
100346 rc = NF_ACCEPT;
100347 /* do not touch skb anymore */
100348 - atomic_inc(&cp->in_pkts);
100349 + atomic_inc_unchecked(&cp->in_pkts);
100350 goto out;
100351 }
100352
100353 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100354 else
100355 rc = NF_ACCEPT;
100356 /* do not touch skb anymore */
100357 - atomic_inc(&cp->in_pkts);
100358 + atomic_inc_unchecked(&cp->in_pkts);
100359 goto out;
100360 }
100361
100362 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100363 index a4b5e2a..13b1de3 100644
100364 --- a/net/netfilter/nf_conntrack_acct.c
100365 +++ b/net/netfilter/nf_conntrack_acct.c
100366 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100367 #ifdef CONFIG_SYSCTL
100368 static int nf_conntrack_acct_init_sysctl(struct net *net)
100369 {
100370 - struct ctl_table *table;
100371 + ctl_table_no_const *table;
100372
100373 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100374 GFP_KERNEL);
100375 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100376 index 356bef5..99932cb 100644
100377 --- a/net/netfilter/nf_conntrack_core.c
100378 +++ b/net/netfilter/nf_conntrack_core.c
100379 @@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
100380 #define DYING_NULLS_VAL ((1<<30)+1)
100381 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100382
100383 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100384 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100385 +#endif
100386 +
100387 int nf_conntrack_init_net(struct net *net)
100388 {
100389 int ret;
100390 @@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
100391 goto err_stat;
100392 }
100393
100394 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100395 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100396 +#else
100397 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100398 +#endif
100399 if (!net->ct.slabname) {
100400 ret = -ENOMEM;
100401 goto err_slabname;
100402 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100403 index 1df1761..ce8b88a 100644
100404 --- a/net/netfilter/nf_conntrack_ecache.c
100405 +++ b/net/netfilter/nf_conntrack_ecache.c
100406 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100407 #ifdef CONFIG_SYSCTL
100408 static int nf_conntrack_event_init_sysctl(struct net *net)
100409 {
100410 - struct ctl_table *table;
100411 + ctl_table_no_const *table;
100412
100413 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100414 GFP_KERNEL);
100415 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100416 index 974a2a4..52cc6ff 100644
100417 --- a/net/netfilter/nf_conntrack_helper.c
100418 +++ b/net/netfilter/nf_conntrack_helper.c
100419 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100420
100421 static int nf_conntrack_helper_init_sysctl(struct net *net)
100422 {
100423 - struct ctl_table *table;
100424 + ctl_table_no_const *table;
100425
100426 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100427 GFP_KERNEL);
100428 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100429 index b65d586..beec902 100644
100430 --- a/net/netfilter/nf_conntrack_proto.c
100431 +++ b/net/netfilter/nf_conntrack_proto.c
100432 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100433
100434 static void
100435 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100436 - struct ctl_table **table,
100437 + ctl_table_no_const **table,
100438 unsigned int users)
100439 {
100440 if (users > 0)
100441 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100442 index f641751..d3c5b51 100644
100443 --- a/net/netfilter/nf_conntrack_standalone.c
100444 +++ b/net/netfilter/nf_conntrack_standalone.c
100445 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100446
100447 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100448 {
100449 - struct ctl_table *table;
100450 + ctl_table_no_const *table;
100451
100452 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100453 GFP_KERNEL);
100454 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100455 index 7a394df..bd91a8a 100644
100456 --- a/net/netfilter/nf_conntrack_timestamp.c
100457 +++ b/net/netfilter/nf_conntrack_timestamp.c
100458 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100459 #ifdef CONFIG_SYSCTL
100460 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100461 {
100462 - struct ctl_table *table;
100463 + ctl_table_no_const *table;
100464
100465 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100466 GFP_KERNEL);
100467 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100468 index 85296d4..8becdec 100644
100469 --- a/net/netfilter/nf_log.c
100470 +++ b/net/netfilter/nf_log.c
100471 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100472
100473 #ifdef CONFIG_SYSCTL
100474 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100475 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100476 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100477
100478 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100479 void __user *buffer, size_t *lenp, loff_t *ppos)
100480 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100481 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100482 mutex_unlock(&nf_log_mutex);
100483 } else {
100484 + ctl_table_no_const nf_log_table = *table;
100485 +
100486 mutex_lock(&nf_log_mutex);
100487 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100488 lockdep_is_held(&nf_log_mutex));
100489 if (!logger)
100490 - table->data = "NONE";
100491 + nf_log_table.data = "NONE";
100492 else
100493 - table->data = logger->name;
100494 - r = proc_dostring(table, write, buffer, lenp, ppos);
100495 + nf_log_table.data = logger->name;
100496 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100497 mutex_unlock(&nf_log_mutex);
100498 }
100499
100500 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100501 index f042ae5..30ea486 100644
100502 --- a/net/netfilter/nf_sockopt.c
100503 +++ b/net/netfilter/nf_sockopt.c
100504 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100505 }
100506 }
100507
100508 - list_add(&reg->list, &nf_sockopts);
100509 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100510 out:
100511 mutex_unlock(&nf_sockopt_mutex);
100512 return ret;
100513 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100514 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100515 {
100516 mutex_lock(&nf_sockopt_mutex);
100517 - list_del(&reg->list);
100518 + pax_list_del((struct list_head *)&reg->list);
100519 mutex_unlock(&nf_sockopt_mutex);
100520 }
100521 EXPORT_SYMBOL(nf_unregister_sockopt);
100522 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
100523 index adce01e..8d52d50 100644
100524 --- a/net/netfilter/nf_tables_api.c
100525 +++ b/net/netfilter/nf_tables_api.c
100526 @@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
100527 #ifdef CONFIG_MODULES
100528 if (autoload) {
100529 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
100530 - request_module("nft-chain-%u-%*.s", afi->family,
100531 - nla_len(nla)-1, (const char *)nla_data(nla));
100532 + request_module("nft-chain-%u-%.*s", afi->family,
100533 + nla_len(nla), (const char *)nla_data(nla));
100534 nfnl_lock(NFNL_SUBSYS_NFTABLES);
100535 type = __nf_tables_chain_type_lookup(afi->family, nla);
100536 if (type != NULL)
100537 @@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
100538
100539 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
100540 [NFTA_SET_TABLE] = { .type = NLA_STRING },
100541 - [NFTA_SET_NAME] = { .type = NLA_STRING },
100542 + [NFTA_SET_NAME] = { .type = NLA_STRING,
100543 + .len = IFNAMSIZ - 1 },
100544 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
100545 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
100546 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
100547 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100548 index a155d19..726b0f2 100644
100549 --- a/net/netfilter/nfnetlink_log.c
100550 +++ b/net/netfilter/nfnetlink_log.c
100551 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100552 struct nfnl_log_net {
100553 spinlock_t instances_lock;
100554 struct hlist_head instance_table[INSTANCE_BUCKETS];
100555 - atomic_t global_seq;
100556 + atomic_unchecked_t global_seq;
100557 };
100558
100559 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100560 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100561 /* global sequence number */
100562 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100563 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100564 - htonl(atomic_inc_return(&log->global_seq))))
100565 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
100566 goto nla_put_failure;
100567
100568 if (data_len) {
100569 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100570 index 82cb823..5685dd5 100644
100571 --- a/net/netfilter/nft_compat.c
100572 +++ b/net/netfilter/nft_compat.c
100573 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100574 /* We want to reuse existing compat_to_user */
100575 old_fs = get_fs();
100576 set_fs(KERNEL_DS);
100577 - t->compat_to_user(out, in);
100578 + t->compat_to_user((void __force_user *)out, in);
100579 set_fs(old_fs);
100580 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100581 kfree(out);
100582 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100583 /* We want to reuse existing compat_to_user */
100584 old_fs = get_fs();
100585 set_fs(KERNEL_DS);
100586 - m->compat_to_user(out, in);
100587 + m->compat_to_user((void __force_user *)out, in);
100588 set_fs(old_fs);
100589 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100590 kfree(out);
100591 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100592 new file mode 100644
100593 index 0000000..c566332
100594 --- /dev/null
100595 +++ b/net/netfilter/xt_gradm.c
100596 @@ -0,0 +1,51 @@
100597 +/*
100598 + * gradm match for netfilter
100599 + * Copyright © Zbigniew Krzystolik, 2010
100600 + *
100601 + * This program is free software; you can redistribute it and/or modify
100602 + * it under the terms of the GNU General Public License; either version
100603 + * 2 or 3 as published by the Free Software Foundation.
100604 + */
100605 +#include <linux/module.h>
100606 +#include <linux/moduleparam.h>
100607 +#include <linux/skbuff.h>
100608 +#include <linux/netfilter/x_tables.h>
100609 +#include <linux/grsecurity.h>
100610 +#include <linux/netfilter/xt_gradm.h>
100611 +
100612 +static bool
100613 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
100614 +{
100615 + const struct xt_gradm_mtinfo *info = par->matchinfo;
100616 + bool retval = false;
100617 + if (gr_acl_is_enabled())
100618 + retval = true;
100619 + return retval ^ info->invflags;
100620 +}
100621 +
100622 +static struct xt_match gradm_mt_reg __read_mostly = {
100623 + .name = "gradm",
100624 + .revision = 0,
100625 + .family = NFPROTO_UNSPEC,
100626 + .match = gradm_mt,
100627 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
100628 + .me = THIS_MODULE,
100629 +};
100630 +
100631 +static int __init gradm_mt_init(void)
100632 +{
100633 + return xt_register_match(&gradm_mt_reg);
100634 +}
100635 +
100636 +static void __exit gradm_mt_exit(void)
100637 +{
100638 + xt_unregister_match(&gradm_mt_reg);
100639 +}
100640 +
100641 +module_init(gradm_mt_init);
100642 +module_exit(gradm_mt_exit);
100643 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
100644 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
100645 +MODULE_LICENSE("GPL");
100646 +MODULE_ALIAS("ipt_gradm");
100647 +MODULE_ALIAS("ip6t_gradm");
100648 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
100649 index 11de55e..f25e448 100644
100650 --- a/net/netfilter/xt_statistic.c
100651 +++ b/net/netfilter/xt_statistic.c
100652 @@ -19,7 +19,7 @@
100653 #include <linux/module.h>
100654
100655 struct xt_statistic_priv {
100656 - atomic_t count;
100657 + atomic_unchecked_t count;
100658 } ____cacheline_aligned_in_smp;
100659
100660 MODULE_LICENSE("GPL");
100661 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
100662 break;
100663 case XT_STATISTIC_MODE_NTH:
100664 do {
100665 - oval = atomic_read(&info->master->count);
100666 + oval = atomic_read_unchecked(&info->master->count);
100667 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
100668 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
100669 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
100670 if (nval == 0)
100671 ret = !ret;
100672 break;
100673 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
100674 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
100675 if (info->master == NULL)
100676 return -ENOMEM;
100677 - atomic_set(&info->master->count, info->u.nth.count);
100678 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
100679
100680 return 0;
100681 }
100682 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
100683 index 04748ab6..ca8f86f 100644
100684 --- a/net/netlink/af_netlink.c
100685 +++ b/net/netlink/af_netlink.c
100686 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
100687 sk->sk_error_report(sk);
100688 }
100689 }
100690 - atomic_inc(&sk->sk_drops);
100691 + atomic_inc_unchecked(&sk->sk_drops);
100692 }
100693
100694 static void netlink_rcv_wake(struct sock *sk)
100695 @@ -2933,7 +2933,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
100696 sk_wmem_alloc_get(s),
100697 nlk->cb_running,
100698 atomic_read(&s->sk_refcnt),
100699 - atomic_read(&s->sk_drops),
100700 + atomic_read_unchecked(&s->sk_drops),
100701 sock_i_ino(s)
100702 );
100703
100704 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
100705 index b74aa07..d41926e 100644
100706 --- a/net/netrom/af_netrom.c
100707 +++ b/net/netrom/af_netrom.c
100708 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
100709 *uaddr_len = sizeof(struct full_sockaddr_ax25);
100710 } else {
100711 sax->fsa_ax25.sax25_family = AF_NETROM;
100712 - sax->fsa_ax25.sax25_ndigis = 0;
100713 sax->fsa_ax25.sax25_call = nr->source_addr;
100714 *uaddr_len = sizeof(struct sockaddr_ax25);
100715 }
100716 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
100717 index 48a6a93..0b0496e 100644
100718 --- a/net/packet/af_packet.c
100719 +++ b/net/packet/af_packet.c
100720 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100721
100722 spin_lock(&sk->sk_receive_queue.lock);
100723 po->stats.stats1.tp_packets++;
100724 - skb->dropcount = atomic_read(&sk->sk_drops);
100725 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
100726 __skb_queue_tail(&sk->sk_receive_queue, skb);
100727 spin_unlock(&sk->sk_receive_queue.lock);
100728 sk->sk_data_ready(sk, skb->len);
100729 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100730 drop_n_acct:
100731 spin_lock(&sk->sk_receive_queue.lock);
100732 po->stats.stats1.tp_drops++;
100733 - atomic_inc(&sk->sk_drops);
100734 + atomic_inc_unchecked(&sk->sk_drops);
100735 spin_unlock(&sk->sk_receive_queue.lock);
100736
100737 drop_n_restore:
100738 @@ -3449,7 +3449,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100739 case PACKET_HDRLEN:
100740 if (len > sizeof(int))
100741 len = sizeof(int);
100742 - if (copy_from_user(&val, optval, len))
100743 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
100744 return -EFAULT;
100745 switch (val) {
100746 case TPACKET_V1:
100747 @@ -3495,7 +3495,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100748 len = lv;
100749 if (put_user(len, optlen))
100750 return -EFAULT;
100751 - if (copy_to_user(optval, data, len))
100752 + if (len > sizeof(st) || copy_to_user(optval, data, len))
100753 return -EFAULT;
100754 return 0;
100755 }
100756 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
100757 index e774117..900b8b7 100644
100758 --- a/net/phonet/pep.c
100759 +++ b/net/phonet/pep.c
100760 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100761
100762 case PNS_PEP_CTRL_REQ:
100763 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
100764 - atomic_inc(&sk->sk_drops);
100765 + atomic_inc_unchecked(&sk->sk_drops);
100766 break;
100767 }
100768 __skb_pull(skb, 4);
100769 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100770 }
100771
100772 if (pn->rx_credits == 0) {
100773 - atomic_inc(&sk->sk_drops);
100774 + atomic_inc_unchecked(&sk->sk_drops);
100775 err = -ENOBUFS;
100776 break;
100777 }
100778 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
100779 }
100780
100781 if (pn->rx_credits == 0) {
100782 - atomic_inc(&sk->sk_drops);
100783 + atomic_inc_unchecked(&sk->sk_drops);
100784 err = NET_RX_DROP;
100785 break;
100786 }
100787 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
100788 index 008214a..bb68240 100644
100789 --- a/net/phonet/socket.c
100790 +++ b/net/phonet/socket.c
100791 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
100792 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
100793 sock_i_ino(sk),
100794 atomic_read(&sk->sk_refcnt), sk,
100795 - atomic_read(&sk->sk_drops));
100796 + atomic_read_unchecked(&sk->sk_drops));
100797 }
100798 seq_pad(seq, '\n');
100799 return 0;
100800 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
100801 index c02a8c4..3c5b600 100644
100802 --- a/net/phonet/sysctl.c
100803 +++ b/net/phonet/sysctl.c
100804 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
100805 {
100806 int ret;
100807 int range[2] = {local_port_range[0], local_port_range[1]};
100808 - struct ctl_table tmp = {
100809 + ctl_table_no_const tmp = {
100810 .data = &range,
100811 .maxlen = sizeof(range),
100812 .mode = table->mode,
100813 diff --git a/net/rds/cong.c b/net/rds/cong.c
100814 index e5b65ac..f3b6fb7 100644
100815 --- a/net/rds/cong.c
100816 +++ b/net/rds/cong.c
100817 @@ -78,7 +78,7 @@
100818 * finds that the saved generation number is smaller than the global generation
100819 * number, it wakes up the process.
100820 */
100821 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
100822 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
100823
100824 /*
100825 * Congestion monitoring
100826 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
100827 rdsdebug("waking map %p for %pI4\n",
100828 map, &map->m_addr);
100829 rds_stats_inc(s_cong_update_received);
100830 - atomic_inc(&rds_cong_generation);
100831 + atomic_inc_unchecked(&rds_cong_generation);
100832 if (waitqueue_active(&map->m_waitq))
100833 wake_up(&map->m_waitq);
100834 if (waitqueue_active(&rds_poll_waitq))
100835 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
100836
100837 int rds_cong_updated_since(unsigned long *recent)
100838 {
100839 - unsigned long gen = atomic_read(&rds_cong_generation);
100840 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
100841
100842 if (likely(*recent == gen))
100843 return 0;
100844 diff --git a/net/rds/ib.h b/net/rds/ib.h
100845 index 7280ab8..e04f4ea 100644
100846 --- a/net/rds/ib.h
100847 +++ b/net/rds/ib.h
100848 @@ -128,7 +128,7 @@ struct rds_ib_connection {
100849 /* sending acks */
100850 unsigned long i_ack_flags;
100851 #ifdef KERNEL_HAS_ATOMIC64
100852 - atomic64_t i_ack_next; /* next ACK to send */
100853 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100854 #else
100855 spinlock_t i_ack_lock; /* protect i_ack_next */
100856 u64 i_ack_next; /* next ACK to send */
100857 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
100858 index 31b74f5..dc1fbfa 100644
100859 --- a/net/rds/ib_cm.c
100860 +++ b/net/rds/ib_cm.c
100861 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
100862 /* Clear the ACK state */
100863 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100864 #ifdef KERNEL_HAS_ATOMIC64
100865 - atomic64_set(&ic->i_ack_next, 0);
100866 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100867 #else
100868 ic->i_ack_next = 0;
100869 #endif
100870 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
100871 index b7ebe23..b6352f6 100644
100872 --- a/net/rds/ib_recv.c
100873 +++ b/net/rds/ib_recv.c
100874 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100875 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
100876 int ack_required)
100877 {
100878 - atomic64_set(&ic->i_ack_next, seq);
100879 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100880 if (ack_required) {
100881 smp_mb__before_clear_bit();
100882 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100883 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100884 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100885 smp_mb__after_clear_bit();
100886
100887 - return atomic64_read(&ic->i_ack_next);
100888 + return atomic64_read_unchecked(&ic->i_ack_next);
100889 }
100890 #endif
100891
100892 diff --git a/net/rds/iw.h b/net/rds/iw.h
100893 index 04ce3b1..48119a6 100644
100894 --- a/net/rds/iw.h
100895 +++ b/net/rds/iw.h
100896 @@ -134,7 +134,7 @@ struct rds_iw_connection {
100897 /* sending acks */
100898 unsigned long i_ack_flags;
100899 #ifdef KERNEL_HAS_ATOMIC64
100900 - atomic64_t i_ack_next; /* next ACK to send */
100901 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100902 #else
100903 spinlock_t i_ack_lock; /* protect i_ack_next */
100904 u64 i_ack_next; /* next ACK to send */
100905 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
100906 index a91e1db..cf3053f 100644
100907 --- a/net/rds/iw_cm.c
100908 +++ b/net/rds/iw_cm.c
100909 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
100910 /* Clear the ACK state */
100911 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100912 #ifdef KERNEL_HAS_ATOMIC64
100913 - atomic64_set(&ic->i_ack_next, 0);
100914 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100915 #else
100916 ic->i_ack_next = 0;
100917 #endif
100918 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
100919 index 4503335..db566b4 100644
100920 --- a/net/rds/iw_recv.c
100921 +++ b/net/rds/iw_recv.c
100922 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100923 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
100924 int ack_required)
100925 {
100926 - atomic64_set(&ic->i_ack_next, seq);
100927 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100928 if (ack_required) {
100929 smp_mb__before_clear_bit();
100930 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100931 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100932 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100933 smp_mb__after_clear_bit();
100934
100935 - return atomic64_read(&ic->i_ack_next);
100936 + return atomic64_read_unchecked(&ic->i_ack_next);
100937 }
100938 #endif
100939
100940 diff --git a/net/rds/rds.h b/net/rds/rds.h
100941 index 48f8ffc..0ef3eec 100644
100942 --- a/net/rds/rds.h
100943 +++ b/net/rds/rds.h
100944 @@ -449,7 +449,7 @@ struct rds_transport {
100945 void (*sync_mr)(void *trans_private, int direction);
100946 void (*free_mr)(void *trans_private, int invalidate);
100947 void (*flush_mrs)(void);
100948 -};
100949 +} __do_const;
100950
100951 struct rds_sock {
100952 struct sock rs_sk;
100953 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
100954 index edac9ef..16bcb98 100644
100955 --- a/net/rds/tcp.c
100956 +++ b/net/rds/tcp.c
100957 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
100958 int val = 1;
100959
100960 set_fs(KERNEL_DS);
100961 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
100962 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
100963 sizeof(val));
100964 set_fs(oldfs);
100965 }
100966 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
100967 index 81cf5a4..b5826ff 100644
100968 --- a/net/rds/tcp_send.c
100969 +++ b/net/rds/tcp_send.c
100970 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
100971
100972 oldfs = get_fs();
100973 set_fs(KERNEL_DS);
100974 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
100975 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
100976 sizeof(val));
100977 set_fs(oldfs);
100978 }
100979 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
100980 index e61aa60..f07cc89 100644
100981 --- a/net/rxrpc/af_rxrpc.c
100982 +++ b/net/rxrpc/af_rxrpc.c
100983 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
100984 __be32 rxrpc_epoch;
100985
100986 /* current debugging ID */
100987 -atomic_t rxrpc_debug_id;
100988 +atomic_unchecked_t rxrpc_debug_id;
100989
100990 /* count of skbs currently in use */
100991 atomic_t rxrpc_n_skbs;
100992 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
100993 index cd97a0c..0041649 100644
100994 --- a/net/rxrpc/ar-ack.c
100995 +++ b/net/rxrpc/ar-ack.c
100996 @@ -182,7 +182,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100997
100998 _enter("{%d,%d,%d,%d},",
100999 call->acks_hard, call->acks_unacked,
101000 - atomic_read(&call->sequence),
101001 + atomic_read_unchecked(&call->sequence),
101002 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
101003
101004 stop = 0;
101005 @@ -206,7 +206,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
101006
101007 /* each Tx packet has a new serial number */
101008 sp->hdr.serial =
101009 - htonl(atomic_inc_return(&call->conn->serial));
101010 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
101011
101012 hdr = (struct rxrpc_header *) txb->head;
101013 hdr->serial = sp->hdr.serial;
101014 @@ -410,7 +410,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
101015 */
101016 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
101017 {
101018 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
101019 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
101020 }
101021
101022 /*
101023 @@ -636,7 +636,7 @@ process_further:
101024
101025 latest = ntohl(sp->hdr.serial);
101026 hard = ntohl(ack.firstPacket);
101027 - tx = atomic_read(&call->sequence);
101028 + tx = atomic_read_unchecked(&call->sequence);
101029
101030 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
101031 latest,
101032 @@ -1168,7 +1168,7 @@ void rxrpc_process_call(struct work_struct *work)
101033 goto maybe_reschedule;
101034
101035 send_ACK_with_skew:
101036 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
101037 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
101038 ntohl(ack.serial));
101039 send_ACK:
101040 mtu = call->conn->trans->peer->if_mtu;
101041 @@ -1180,7 +1180,7 @@ send_ACK:
101042 ackinfo.rxMTU = htonl(5692);
101043 ackinfo.jumbo_max = htonl(4);
101044
101045 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
101046 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
101047 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
101048 ntohl(hdr.serial),
101049 ntohs(ack.maxSkew),
101050 @@ -1198,7 +1198,7 @@ send_ACK:
101051 send_message:
101052 _debug("send message");
101053
101054 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
101055 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
101056 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
101057 send_message_2:
101058
101059 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
101060 index a3bbb36..3341fb9 100644
101061 --- a/net/rxrpc/ar-call.c
101062 +++ b/net/rxrpc/ar-call.c
101063 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
101064 spin_lock_init(&call->lock);
101065 rwlock_init(&call->state_lock);
101066 atomic_set(&call->usage, 1);
101067 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
101068 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101069 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
101070
101071 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
101072 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
101073 index 7bf5b5b..4a3bf2c 100644
101074 --- a/net/rxrpc/ar-connection.c
101075 +++ b/net/rxrpc/ar-connection.c
101076 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
101077 rwlock_init(&conn->lock);
101078 spin_lock_init(&conn->state_lock);
101079 atomic_set(&conn->usage, 1);
101080 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
101081 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101082 conn->avail_calls = RXRPC_MAXCALLS;
101083 conn->size_align = 4;
101084 conn->header_size = sizeof(struct rxrpc_header);
101085 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
101086 index e7ed43a..6afa140 100644
101087 --- a/net/rxrpc/ar-connevent.c
101088 +++ b/net/rxrpc/ar-connevent.c
101089 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
101090
101091 len = iov[0].iov_len + iov[1].iov_len;
101092
101093 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
101094 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101095 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
101096
101097 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
101098 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
101099 index 529572f..c758ca7 100644
101100 --- a/net/rxrpc/ar-input.c
101101 +++ b/net/rxrpc/ar-input.c
101102 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
101103 /* track the latest serial number on this connection for ACK packet
101104 * information */
101105 serial = ntohl(sp->hdr.serial);
101106 - hi_serial = atomic_read(&call->conn->hi_serial);
101107 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
101108 while (serial > hi_serial)
101109 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
101110 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
101111 serial);
101112
101113 /* request ACK generation for any ACK or DATA packet that requests
101114 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
101115 index 5f43675..ca07817 100644
101116 --- a/net/rxrpc/ar-internal.h
101117 +++ b/net/rxrpc/ar-internal.h
101118 @@ -272,8 +272,8 @@ struct rxrpc_connection {
101119 int error; /* error code for local abort */
101120 int debug_id; /* debug ID for printks */
101121 unsigned int call_counter; /* call ID counter */
101122 - atomic_t serial; /* packet serial number counter */
101123 - atomic_t hi_serial; /* highest serial number received */
101124 + atomic_unchecked_t serial; /* packet serial number counter */
101125 + atomic_unchecked_t hi_serial; /* highest serial number received */
101126 u8 avail_calls; /* number of calls available */
101127 u8 size_align; /* data size alignment (for security) */
101128 u8 header_size; /* rxrpc + security header size */
101129 @@ -346,7 +346,7 @@ struct rxrpc_call {
101130 spinlock_t lock;
101131 rwlock_t state_lock; /* lock for state transition */
101132 atomic_t usage;
101133 - atomic_t sequence; /* Tx data packet sequence counter */
101134 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
101135 u32 abort_code; /* local/remote abort code */
101136 enum { /* current state of call */
101137 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
101138 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
101139 */
101140 extern atomic_t rxrpc_n_skbs;
101141 extern __be32 rxrpc_epoch;
101142 -extern atomic_t rxrpc_debug_id;
101143 +extern atomic_unchecked_t rxrpc_debug_id;
101144 extern struct workqueue_struct *rxrpc_workqueue;
101145
101146 /*
101147 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
101148 index 87f7135..74d3703 100644
101149 --- a/net/rxrpc/ar-local.c
101150 +++ b/net/rxrpc/ar-local.c
101151 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
101152 spin_lock_init(&local->lock);
101153 rwlock_init(&local->services_lock);
101154 atomic_set(&local->usage, 1);
101155 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
101156 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101157 memcpy(&local->srx, srx, sizeof(*srx));
101158 }
101159
101160 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
101161 index d0e8f1c..a3a1686 100644
101162 --- a/net/rxrpc/ar-output.c
101163 +++ b/net/rxrpc/ar-output.c
101164 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
101165 sp->hdr.cid = call->cid;
101166 sp->hdr.callNumber = call->call_id;
101167 sp->hdr.seq =
101168 - htonl(atomic_inc_return(&call->sequence));
101169 + htonl(atomic_inc_return_unchecked(&call->sequence));
101170 sp->hdr.serial =
101171 - htonl(atomic_inc_return(&conn->serial));
101172 + htonl(atomic_inc_return_unchecked(&conn->serial));
101173 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
101174 sp->hdr.userStatus = 0;
101175 sp->hdr.securityIndex = conn->security_ix;
101176 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
101177 index bebaa43..2644591 100644
101178 --- a/net/rxrpc/ar-peer.c
101179 +++ b/net/rxrpc/ar-peer.c
101180 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
101181 INIT_LIST_HEAD(&peer->error_targets);
101182 spin_lock_init(&peer->lock);
101183 atomic_set(&peer->usage, 1);
101184 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
101185 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101186 memcpy(&peer->srx, srx, sizeof(*srx));
101187
101188 rxrpc_assess_MTU_size(peer);
101189 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
101190 index 38047f7..9f48511 100644
101191 --- a/net/rxrpc/ar-proc.c
101192 +++ b/net/rxrpc/ar-proc.c
101193 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
101194 atomic_read(&conn->usage),
101195 rxrpc_conn_states[conn->state],
101196 key_serial(conn->key),
101197 - atomic_read(&conn->serial),
101198 - atomic_read(&conn->hi_serial));
101199 + atomic_read_unchecked(&conn->serial),
101200 + atomic_read_unchecked(&conn->hi_serial));
101201
101202 return 0;
101203 }
101204 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
101205 index 92df566..87ec1bf 100644
101206 --- a/net/rxrpc/ar-transport.c
101207 +++ b/net/rxrpc/ar-transport.c
101208 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
101209 spin_lock_init(&trans->client_lock);
101210 rwlock_init(&trans->conn_lock);
101211 atomic_set(&trans->usage, 1);
101212 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
101213 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
101214
101215 if (peer->srx.transport.family == AF_INET) {
101216 switch (peer->srx.transport_type) {
101217 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
101218 index f226709..0e735a8 100644
101219 --- a/net/rxrpc/rxkad.c
101220 +++ b/net/rxrpc/rxkad.c
101221 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
101222
101223 len = iov[0].iov_len + iov[1].iov_len;
101224
101225 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
101226 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101227 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
101228
101229 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
101230 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
101231
101232 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
101233
101234 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
101235 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101236 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
101237
101238 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
101239 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
101240 index 2b1738e..a9d0fc9 100644
101241 --- a/net/sctp/ipv6.c
101242 +++ b/net/sctp/ipv6.c
101243 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
101244 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
101245 };
101246
101247 -static struct sctp_af sctp_af_inet6 = {
101248 +static struct sctp_af sctp_af_inet6 __read_only = {
101249 .sa_family = AF_INET6,
101250 .sctp_xmit = sctp_v6_xmit,
101251 .setsockopt = ipv6_setsockopt,
101252 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
101253 #endif
101254 };
101255
101256 -static struct sctp_pf sctp_pf_inet6 = {
101257 +static struct sctp_pf sctp_pf_inet6 __read_only = {
101258 .event_msgname = sctp_inet6_event_msgname,
101259 .skb_msgname = sctp_inet6_skb_msgname,
101260 .af_supported = sctp_inet6_af_supported,
101261 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
101262
101263 void sctp_v6_pf_exit(void)
101264 {
101265 - list_del(&sctp_af_inet6.list);
101266 + pax_list_del(&sctp_af_inet6.list);
101267 }
101268
101269 /* Initialize IPv6 support and register with socket layer. */
101270 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
101271 index 4e1d0fc..068fef7 100644
101272 --- a/net/sctp/protocol.c
101273 +++ b/net/sctp/protocol.c
101274 @@ -831,8 +831,10 @@ int sctp_register_af(struct sctp_af *af)
101275 return 0;
101276 }
101277
101278 + pax_open_kernel();
101279 INIT_LIST_HEAD(&af->list);
101280 - list_add_tail(&af->list, &sctp_address_families);
101281 + pax_close_kernel();
101282 + pax_list_add_tail(&af->list, &sctp_address_families);
101283 return 1;
101284 }
101285
101286 @@ -962,7 +964,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
101287
101288 static struct sctp_af sctp_af_inet;
101289
101290 -static struct sctp_pf sctp_pf_inet = {
101291 +static struct sctp_pf sctp_pf_inet __read_only = {
101292 .event_msgname = sctp_inet_event_msgname,
101293 .skb_msgname = sctp_inet_skb_msgname,
101294 .af_supported = sctp_inet_af_supported,
101295 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
101296 };
101297
101298 /* IPv4 address related functions. */
101299 -static struct sctp_af sctp_af_inet = {
101300 +static struct sctp_af sctp_af_inet __read_only = {
101301 .sa_family = AF_INET,
101302 .sctp_xmit = sctp_v4_xmit,
101303 .setsockopt = ip_setsockopt,
101304 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
101305
101306 static void sctp_v4_pf_exit(void)
101307 {
101308 - list_del(&sctp_af_inet.list);
101309 + pax_list_del(&sctp_af_inet.list);
101310 }
101311
101312 static int sctp_v4_protosw_init(void)
101313 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
101314 index 5d6883f..394a102 100644
101315 --- a/net/sctp/sm_sideeffect.c
101316 +++ b/net/sctp/sm_sideeffect.c
101317 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
101318 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
101319 }
101320
101321 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101322 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101323 NULL,
101324 sctp_generate_t1_cookie_event,
101325 sctp_generate_t1_init_event,
101326 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
101327 index 981aaf8..5bc016d 100644
101328 --- a/net/sctp/socket.c
101329 +++ b/net/sctp/socket.c
101330 @@ -2169,11 +2169,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
101331 {
101332 struct sctp_association *asoc;
101333 struct sctp_ulpevent *event;
101334 + struct sctp_event_subscribe subscribe;
101335
101336 if (optlen > sizeof(struct sctp_event_subscribe))
101337 return -EINVAL;
101338 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
101339 + if (copy_from_user(&subscribe, optval, optlen))
101340 return -EFAULT;
101341 + sctp_sk(sk)->subscribe = subscribe;
101342
101343 /*
101344 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
101345 @@ -4255,13 +4257,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
101346 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101347 int __user *optlen)
101348 {
101349 + struct sctp_event_subscribe subscribe;
101350 +
101351 if (len <= 0)
101352 return -EINVAL;
101353 if (len > sizeof(struct sctp_event_subscribe))
101354 len = sizeof(struct sctp_event_subscribe);
101355 if (put_user(len, optlen))
101356 return -EFAULT;
101357 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
101358 + subscribe = sctp_sk(sk)->subscribe;
101359 + if (copy_to_user(optval, &subscribe, len))
101360 return -EFAULT;
101361 return 0;
101362 }
101363 @@ -4279,6 +4284,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101364 */
101365 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
101366 {
101367 + __u32 autoclose;
101368 +
101369 /* Applicable to UDP-style socket only */
101370 if (sctp_style(sk, TCP))
101371 return -EOPNOTSUPP;
101372 @@ -4287,7 +4294,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
101373 len = sizeof(int);
101374 if (put_user(len, optlen))
101375 return -EFAULT;
101376 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
101377 + autoclose = sctp_sk(sk)->autoclose;
101378 + if (copy_to_user(optval, &autoclose, sizeof(int)))
101379 return -EFAULT;
101380 return 0;
101381 }
101382 @@ -4662,12 +4670,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
101383 */
101384 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
101385 {
101386 + struct sctp_initmsg initmsg;
101387 +
101388 if (len < sizeof(struct sctp_initmsg))
101389 return -EINVAL;
101390 len = sizeof(struct sctp_initmsg);
101391 if (put_user(len, optlen))
101392 return -EFAULT;
101393 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
101394 + initmsg = sctp_sk(sk)->initmsg;
101395 + if (copy_to_user(optval, &initmsg, len))
101396 return -EFAULT;
101397 return 0;
101398 }
101399 @@ -4708,6 +4719,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
101400 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
101401 if (space_left < addrlen)
101402 return -ENOMEM;
101403 + if (addrlen > sizeof(temp) || addrlen < 0)
101404 + return -EFAULT;
101405 if (copy_to_user(to, &temp, addrlen))
101406 return -EFAULT;
101407 to += addrlen;
101408 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
101409 index 35c8923..536614e 100644
101410 --- a/net/sctp/sysctl.c
101411 +++ b/net/sctp/sysctl.c
101412 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
101413 {
101414 struct net *net = current->nsproxy->net_ns;
101415 char tmp[8];
101416 - struct ctl_table tbl;
101417 + ctl_table_no_const tbl;
101418 int ret;
101419 int changed = 0;
101420 char *none = "none";
101421 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
101422 {
101423 struct net *net = current->nsproxy->net_ns;
101424 int new_value;
101425 - struct ctl_table tbl;
101426 + ctl_table_no_const tbl;
101427 unsigned int min = *(unsigned int *) ctl->extra1;
101428 unsigned int max = *(unsigned int *) ctl->extra2;
101429 int ret;
101430 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101431 {
101432 struct net *net = current->nsproxy->net_ns;
101433 int new_value;
101434 - struct ctl_table tbl;
101435 + ctl_table_no_const tbl;
101436 unsigned int min = *(unsigned int *) ctl->extra1;
101437 unsigned int max = *(unsigned int *) ctl->extra2;
101438 int ret;
101439 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101440
101441 int sctp_sysctl_net_register(struct net *net)
101442 {
101443 - struct ctl_table *table = sctp_net_table;
101444 + ctl_table_no_const *table = NULL;
101445
101446 if (!net_eq(net, &init_net)) {
101447 int i;
101448 @@ -415,7 +415,10 @@ int sctp_sysctl_net_register(struct net *net)
101449 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
101450 }
101451
101452 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
101453 + if (!net_eq(net, &init_net))
101454 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
101455 + else
101456 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
101457 return 0;
101458 }
101459
101460 diff --git a/net/socket.c b/net/socket.c
101461 index a19ae19..89554dc 100644
101462 --- a/net/socket.c
101463 +++ b/net/socket.c
101464 @@ -88,6 +88,7 @@
101465 #include <linux/magic.h>
101466 #include <linux/slab.h>
101467 #include <linux/xattr.h>
101468 +#include <linux/in.h>
101469
101470 #include <asm/uaccess.h>
101471 #include <asm/unistd.h>
101472 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
101473 unsigned int sysctl_net_busy_poll __read_mostly;
101474 #endif
101475
101476 +#include <linux/grsock.h>
101477 +
101478 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101479 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
101480 unsigned long nr_segs, loff_t pos);
101481 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
101482 */
101483
101484 static DEFINE_SPINLOCK(net_family_lock);
101485 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101486 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101487
101488 /*
101489 * Statistics counters of the socket lists
101490 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
101491 &sockfs_dentry_operations, SOCKFS_MAGIC);
101492 }
101493
101494 -static struct vfsmount *sock_mnt __read_mostly;
101495 +struct vfsmount *sock_mnt __read_mostly;
101496
101497 static struct file_system_type sock_fs_type = {
101498 .name = "sockfs",
101499 @@ -1256,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101500 return -EAFNOSUPPORT;
101501 if (type < 0 || type >= SOCK_MAX)
101502 return -EINVAL;
101503 + if (protocol < 0)
101504 + return -EINVAL;
101505
101506 /* Compatibility.
101507
101508 @@ -1276,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101509 if (err)
101510 return err;
101511
101512 + if(!kern && !gr_search_socket(family, type, protocol)) {
101513 + if (rcu_access_pointer(net_families[family]) == NULL)
101514 + return -EAFNOSUPPORT;
101515 + else
101516 + return -EACCES;
101517 + }
101518 +
101519 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
101520 + if (rcu_access_pointer(net_families[family]) == NULL)
101521 + return -EAFNOSUPPORT;
101522 + else
101523 + return -EACCES;
101524 + }
101525 +
101526 /*
101527 * Allocate the socket and allow the family to set things up. if
101528 * the protocol is 0, the family is instructed to select an appropriate
101529 @@ -1527,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101530 if (sock) {
101531 err = move_addr_to_kernel(umyaddr, addrlen, &address);
101532 if (err >= 0) {
101533 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
101534 + err = -EACCES;
101535 + goto error;
101536 + }
101537 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
101538 + if (err)
101539 + goto error;
101540 +
101541 err = security_socket_bind(sock,
101542 (struct sockaddr *)&address,
101543 addrlen);
101544 @@ -1535,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101545 (struct sockaddr *)
101546 &address, addrlen);
101547 }
101548 +error:
101549 fput_light(sock->file, fput_needed);
101550 }
101551 return err;
101552 @@ -1558,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
101553 if ((unsigned int)backlog > somaxconn)
101554 backlog = somaxconn;
101555
101556 + if (gr_handle_sock_server_other(sock->sk)) {
101557 + err = -EPERM;
101558 + goto error;
101559 + }
101560 +
101561 + err = gr_search_listen(sock);
101562 + if (err)
101563 + goto error;
101564 +
101565 err = security_socket_listen(sock, backlog);
101566 if (!err)
101567 err = sock->ops->listen(sock, backlog);
101568
101569 +error:
101570 fput_light(sock->file, fput_needed);
101571 }
101572 return err;
101573 @@ -1605,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101574 newsock->type = sock->type;
101575 newsock->ops = sock->ops;
101576
101577 + if (gr_handle_sock_server_other(sock->sk)) {
101578 + err = -EPERM;
101579 + sock_release(newsock);
101580 + goto out_put;
101581 + }
101582 +
101583 + err = gr_search_accept(sock);
101584 + if (err) {
101585 + sock_release(newsock);
101586 + goto out_put;
101587 + }
101588 +
101589 /*
101590 * We don't need try_module_get here, as the listening socket (sock)
101591 * has the protocol module (sock->ops->owner) held.
101592 @@ -1650,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101593 fd_install(newfd, newfile);
101594 err = newfd;
101595
101596 + gr_attach_curr_ip(newsock->sk);
101597 +
101598 out_put:
101599 fput_light(sock->file, fput_needed);
101600 out:
101601 @@ -1682,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101602 int, addrlen)
101603 {
101604 struct socket *sock;
101605 + struct sockaddr *sck;
101606 struct sockaddr_storage address;
101607 int err, fput_needed;
101608
101609 @@ -1692,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101610 if (err < 0)
101611 goto out_put;
101612
101613 + sck = (struct sockaddr *)&address;
101614 +
101615 + if (gr_handle_sock_client(sck)) {
101616 + err = -EACCES;
101617 + goto out_put;
101618 + }
101619 +
101620 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
101621 + if (err)
101622 + goto out_put;
101623 +
101624 err =
101625 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
101626 if (err)
101627 @@ -1773,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
101628 * the protocol.
101629 */
101630
101631 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
101632 +
101633 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
101634 unsigned int, flags, struct sockaddr __user *, addr,
101635 int, addr_len)
101636 @@ -1839,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
101637 struct socket *sock;
101638 struct iovec iov;
101639 struct msghdr msg;
101640 - struct sockaddr_storage address;
101641 + struct sockaddr_storage address = { };
101642 int err, err2;
101643 int fput_needed;
101644
101645 @@ -2065,7 +2131,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
101646 * checking falls down on this.
101647 */
101648 if (copy_from_user(ctl_buf,
101649 - (void __user __force *)msg_sys->msg_control,
101650 + (void __force_user *)msg_sys->msg_control,
101651 ctl_len))
101652 goto out_freectl;
101653 msg_sys->msg_control = ctl_buf;
101654 @@ -2216,7 +2282,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101655 int err, total_len, len;
101656
101657 /* kernel mode address */
101658 - struct sockaddr_storage addr;
101659 + struct sockaddr_storage addr = { };
101660
101661 /* user mode address pointers */
101662 struct sockaddr __user *uaddr;
101663 @@ -2245,7 +2311,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101664 /* Save the user-mode address (verify_iovec will change the
101665 * kernel msghdr to use the kernel address space)
101666 */
101667 - uaddr = (__force void __user *)msg_sys->msg_name;
101668 + uaddr = (void __force_user *)msg_sys->msg_name;
101669 uaddr_len = COMPAT_NAMELEN(msg);
101670 if (MSG_CMSG_COMPAT & flags)
101671 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
101672 @@ -2889,7 +2955,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
101673 ifr = compat_alloc_user_space(buf_size);
101674 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
101675
101676 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101677 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101678 return -EFAULT;
101679
101680 if (put_user(convert_in ? rxnfc : compat_ptr(data),
101681 @@ -3000,7 +3066,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
101682 old_fs = get_fs();
101683 set_fs(KERNEL_DS);
101684 err = dev_ioctl(net, cmd,
101685 - (struct ifreq __user __force *) &kifr);
101686 + (struct ifreq __force_user *) &kifr);
101687 set_fs(old_fs);
101688
101689 return err;
101690 @@ -3093,7 +3159,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
101691
101692 old_fs = get_fs();
101693 set_fs(KERNEL_DS);
101694 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
101695 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
101696 set_fs(old_fs);
101697
101698 if (cmd == SIOCGIFMAP && !err) {
101699 @@ -3177,7 +3243,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
101700 ret |= get_user(rtdev, &(ur4->rt_dev));
101701 if (rtdev) {
101702 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
101703 - r4.rt_dev = (char __user __force *)devname;
101704 + r4.rt_dev = (char __force_user *)devname;
101705 devname[15] = 0;
101706 } else
101707 r4.rt_dev = NULL;
101708 @@ -3404,8 +3470,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
101709 int __user *uoptlen;
101710 int err;
101711
101712 - uoptval = (char __user __force *) optval;
101713 - uoptlen = (int __user __force *) optlen;
101714 + uoptval = (char __force_user *) optval;
101715 + uoptlen = (int __force_user *) optlen;
101716
101717 set_fs(KERNEL_DS);
101718 if (level == SOL_SOCKET)
101719 @@ -3425,7 +3491,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
101720 char __user *uoptval;
101721 int err;
101722
101723 - uoptval = (char __user __force *) optval;
101724 + uoptval = (char __force_user *) optval;
101725
101726 set_fs(KERNEL_DS);
101727 if (level == SOL_SOCKET)
101728 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
101729 index 0f73f45..a96aa52 100644
101730 --- a/net/sunrpc/auth_gss/svcauth_gss.c
101731 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
101732 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101733 uint64_t *handle)
101734 {
101735 struct rsc rsci, *rscp = NULL;
101736 - static atomic64_t ctxhctr;
101737 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
101738 long long ctxh;
101739 struct gss_api_mech *gm = NULL;
101740 time_t expiry;
101741 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101742 status = -ENOMEM;
101743 /* the handle needs to be just a unique id,
101744 * use a static counter */
101745 - ctxh = atomic64_inc_return(&ctxhctr);
101746 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
101747
101748 /* make a copy for the caller */
101749 *handle = ctxh;
101750 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
101751 index 0edada9..9247ea0 100644
101752 --- a/net/sunrpc/clnt.c
101753 +++ b/net/sunrpc/clnt.c
101754 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
101755 (RPC_IS_ASYNC(task) ? "async" : "sync"));
101756
101757 /* Increment call count */
101758 - task->tk_msg.rpc_proc->p_count++;
101759 + pax_open_kernel();
101760 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
101761 + pax_close_kernel();
101762 clnt->cl_stats->rpccnt++;
101763 task->tk_action = call_reserve;
101764 }
101765 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
101766 index ff3cc4b..7612a9e 100644
101767 --- a/net/sunrpc/sched.c
101768 +++ b/net/sunrpc/sched.c
101769 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
101770 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
101771 static void rpc_task_set_debuginfo(struct rpc_task *task)
101772 {
101773 - static atomic_t rpc_pid;
101774 + static atomic_unchecked_t rpc_pid;
101775
101776 - task->tk_pid = atomic_inc_return(&rpc_pid);
101777 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
101778 }
101779 #else
101780 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
101781 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
101782 index 5de6801..b4e330d 100644
101783 --- a/net/sunrpc/svc.c
101784 +++ b/net/sunrpc/svc.c
101785 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
101786 svc_putnl(resv, RPC_SUCCESS);
101787
101788 /* Bump per-procedure stats counter */
101789 - procp->pc_count++;
101790 + pax_open_kernel();
101791 + (*(unsigned int *)&procp->pc_count)++;
101792 + pax_close_kernel();
101793
101794 /* Initialize storage for argp and resp */
101795 memset(rqstp->rq_argp, 0, procp->pc_argsize);
101796 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
101797 index 621ca7b..59421dd 100644
101798 --- a/net/sunrpc/svcauth_unix.c
101799 +++ b/net/sunrpc/svcauth_unix.c
101800 @@ -414,7 +414,7 @@ struct unix_gid {
101801 struct group_info *gi;
101802 };
101803
101804 -static int unix_gid_hash(kuid_t uid)
101805 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
101806 {
101807 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
101808 }
101809 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
101810 (*bpp)[-1] = '\n';
101811 }
101812
101813 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101814 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101815
101816 static int unix_gid_parse(struct cache_detail *cd,
101817 char *mesg, int mlen)
101818 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
101819 index c1b6270..05089c1 100644
101820 --- a/net/sunrpc/xprtrdma/svc_rdma.c
101821 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
101822 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
101823 static unsigned int min_max_inline = 4096;
101824 static unsigned int max_max_inline = 65536;
101825
101826 -atomic_t rdma_stat_recv;
101827 -atomic_t rdma_stat_read;
101828 -atomic_t rdma_stat_write;
101829 -atomic_t rdma_stat_sq_starve;
101830 -atomic_t rdma_stat_rq_starve;
101831 -atomic_t rdma_stat_rq_poll;
101832 -atomic_t rdma_stat_rq_prod;
101833 -atomic_t rdma_stat_sq_poll;
101834 -atomic_t rdma_stat_sq_prod;
101835 +atomic_unchecked_t rdma_stat_recv;
101836 +atomic_unchecked_t rdma_stat_read;
101837 +atomic_unchecked_t rdma_stat_write;
101838 +atomic_unchecked_t rdma_stat_sq_starve;
101839 +atomic_unchecked_t rdma_stat_rq_starve;
101840 +atomic_unchecked_t rdma_stat_rq_poll;
101841 +atomic_unchecked_t rdma_stat_rq_prod;
101842 +atomic_unchecked_t rdma_stat_sq_poll;
101843 +atomic_unchecked_t rdma_stat_sq_prod;
101844
101845 /* Temporary NFS request map and context caches */
101846 struct kmem_cache *svc_rdma_map_cachep;
101847 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
101848 len -= *ppos;
101849 if (len > *lenp)
101850 len = *lenp;
101851 - if (len && copy_to_user(buffer, str_buf, len))
101852 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
101853 return -EFAULT;
101854 *lenp = len;
101855 *ppos += len;
101856 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
101857 {
101858 .procname = "rdma_stat_read",
101859 .data = &rdma_stat_read,
101860 - .maxlen = sizeof(atomic_t),
101861 + .maxlen = sizeof(atomic_unchecked_t),
101862 .mode = 0644,
101863 .proc_handler = read_reset_stat,
101864 },
101865 {
101866 .procname = "rdma_stat_recv",
101867 .data = &rdma_stat_recv,
101868 - .maxlen = sizeof(atomic_t),
101869 + .maxlen = sizeof(atomic_unchecked_t),
101870 .mode = 0644,
101871 .proc_handler = read_reset_stat,
101872 },
101873 {
101874 .procname = "rdma_stat_write",
101875 .data = &rdma_stat_write,
101876 - .maxlen = sizeof(atomic_t),
101877 + .maxlen = sizeof(atomic_unchecked_t),
101878 .mode = 0644,
101879 .proc_handler = read_reset_stat,
101880 },
101881 {
101882 .procname = "rdma_stat_sq_starve",
101883 .data = &rdma_stat_sq_starve,
101884 - .maxlen = sizeof(atomic_t),
101885 + .maxlen = sizeof(atomic_unchecked_t),
101886 .mode = 0644,
101887 .proc_handler = read_reset_stat,
101888 },
101889 {
101890 .procname = "rdma_stat_rq_starve",
101891 .data = &rdma_stat_rq_starve,
101892 - .maxlen = sizeof(atomic_t),
101893 + .maxlen = sizeof(atomic_unchecked_t),
101894 .mode = 0644,
101895 .proc_handler = read_reset_stat,
101896 },
101897 {
101898 .procname = "rdma_stat_rq_poll",
101899 .data = &rdma_stat_rq_poll,
101900 - .maxlen = sizeof(atomic_t),
101901 + .maxlen = sizeof(atomic_unchecked_t),
101902 .mode = 0644,
101903 .proc_handler = read_reset_stat,
101904 },
101905 {
101906 .procname = "rdma_stat_rq_prod",
101907 .data = &rdma_stat_rq_prod,
101908 - .maxlen = sizeof(atomic_t),
101909 + .maxlen = sizeof(atomic_unchecked_t),
101910 .mode = 0644,
101911 .proc_handler = read_reset_stat,
101912 },
101913 {
101914 .procname = "rdma_stat_sq_poll",
101915 .data = &rdma_stat_sq_poll,
101916 - .maxlen = sizeof(atomic_t),
101917 + .maxlen = sizeof(atomic_unchecked_t),
101918 .mode = 0644,
101919 .proc_handler = read_reset_stat,
101920 },
101921 {
101922 .procname = "rdma_stat_sq_prod",
101923 .data = &rdma_stat_sq_prod,
101924 - .maxlen = sizeof(atomic_t),
101925 + .maxlen = sizeof(atomic_unchecked_t),
101926 .mode = 0644,
101927 .proc_handler = read_reset_stat,
101928 },
101929 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101930 index 0ce7552..d074459 100644
101931 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101932 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101933 @@ -501,7 +501,7 @@ next_sge:
101934 svc_rdma_put_context(ctxt, 0);
101935 goto out;
101936 }
101937 - atomic_inc(&rdma_stat_read);
101938 + atomic_inc_unchecked(&rdma_stat_read);
101939
101940 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
101941 chl_map->ch[ch_no].count -= read_wr.num_sge;
101942 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101943 dto_q);
101944 list_del_init(&ctxt->dto_q);
101945 } else {
101946 - atomic_inc(&rdma_stat_rq_starve);
101947 + atomic_inc_unchecked(&rdma_stat_rq_starve);
101948 clear_bit(XPT_DATA, &xprt->xpt_flags);
101949 ctxt = NULL;
101950 }
101951 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101952 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
101953 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
101954 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
101955 - atomic_inc(&rdma_stat_recv);
101956 + atomic_inc_unchecked(&rdma_stat_recv);
101957
101958 /* Build up the XDR from the receive buffers. */
101959 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
101960 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101961 index c1d124d..acfc59e 100644
101962 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101963 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101964 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
101965 write_wr.wr.rdma.remote_addr = to;
101966
101967 /* Post It */
101968 - atomic_inc(&rdma_stat_write);
101969 + atomic_inc_unchecked(&rdma_stat_write);
101970 if (svc_rdma_send(xprt, &write_wr))
101971 goto err;
101972 return 0;
101973 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101974 index 62e4f9b..dd3f2d7 100644
101975 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
101976 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101977 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101978 return;
101979
101980 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
101981 - atomic_inc(&rdma_stat_rq_poll);
101982 + atomic_inc_unchecked(&rdma_stat_rq_poll);
101983
101984 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
101985 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
101986 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101987 }
101988
101989 if (ctxt)
101990 - atomic_inc(&rdma_stat_rq_prod);
101991 + atomic_inc_unchecked(&rdma_stat_rq_prod);
101992
101993 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
101994 /*
101995 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101996 return;
101997
101998 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
101999 - atomic_inc(&rdma_stat_sq_poll);
102000 + atomic_inc_unchecked(&rdma_stat_sq_poll);
102001 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
102002 if (wc.status != IB_WC_SUCCESS)
102003 /* Close the transport */
102004 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
102005 }
102006
102007 if (ctxt)
102008 - atomic_inc(&rdma_stat_sq_prod);
102009 + atomic_inc_unchecked(&rdma_stat_sq_prod);
102010 }
102011
102012 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
102013 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
102014 spin_lock_bh(&xprt->sc_lock);
102015 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
102016 spin_unlock_bh(&xprt->sc_lock);
102017 - atomic_inc(&rdma_stat_sq_starve);
102018 + atomic_inc_unchecked(&rdma_stat_sq_starve);
102019
102020 /* See if we can opportunistically reap SQ WR to make room */
102021 sq_cq_reap(xprt);
102022 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
102023 index e7000be..e3b0ba7 100644
102024 --- a/net/sysctl_net.c
102025 +++ b/net/sysctl_net.c
102026 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
102027 kgid_t root_gid = make_kgid(net->user_ns, 0);
102028
102029 /* Allow network administrator to have same access as root. */
102030 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
102031 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
102032 uid_eq(root_uid, current_euid())) {
102033 int mode = (table->mode >> 6) & 7;
102034 return (mode << 6) | (mode << 3) | mode;
102035 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
102036 index 6424372..afd36e9 100644
102037 --- a/net/tipc/subscr.c
102038 +++ b/net/tipc/subscr.c
102039 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
102040 struct tipc_subscriber *subscriber = sub->subscriber;
102041 struct kvec msg_sect;
102042
102043 - msg_sect.iov_base = (void *)&sub->evt;
102044 + msg_sect.iov_base = &sub->evt;
102045 msg_sect.iov_len = sizeof(struct tipc_event);
102046 sub->evt.event = htohl(event, sub->swap);
102047 sub->evt.found_lower = htohl(found_lower, sub->swap);
102048 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
102049 index 94404f1..5782191 100644
102050 --- a/net/unix/af_unix.c
102051 +++ b/net/unix/af_unix.c
102052 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
102053 err = -ECONNREFUSED;
102054 if (!S_ISSOCK(inode->i_mode))
102055 goto put_fail;
102056 +
102057 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
102058 + err = -EACCES;
102059 + goto put_fail;
102060 + }
102061 +
102062 u = unix_find_socket_byinode(inode);
102063 if (!u)
102064 goto put_fail;
102065 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
102066 if (u) {
102067 struct dentry *dentry;
102068 dentry = unix_sk(u)->path.dentry;
102069 +
102070 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
102071 + err = -EPERM;
102072 + sock_put(u);
102073 + goto fail;
102074 + }
102075 +
102076 if (dentry)
102077 touch_atime(&unix_sk(u)->path);
102078 } else
102079 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
102080 */
102081 err = security_path_mknod(&path, dentry, mode, 0);
102082 if (!err) {
102083 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
102084 + err = -EACCES;
102085 + goto out;
102086 + }
102087 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
102088 if (!err) {
102089 res->mnt = mntget(path.mnt);
102090 res->dentry = dget(dentry);
102091 + gr_handle_create(dentry, path.mnt);
102092 }
102093 }
102094 +out:
102095 done_path_create(&path, dentry);
102096 return err;
102097 }
102098 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
102099 seq_puts(seq, "Num RefCount Protocol Flags Type St "
102100 "Inode Path\n");
102101 else {
102102 - struct sock *s = v;
102103 + struct sock *s = v, *peer;
102104 struct unix_sock *u = unix_sk(s);
102105 unix_state_lock(s);
102106 + peer = unix_peer(s);
102107 + unix_state_unlock(s);
102108 +
102109 + unix_state_double_lock(s, peer);
102110
102111 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
102112 s,
102113 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
102114 }
102115 for ( ; i < len; i++)
102116 seq_putc(seq, u->addr->name->sun_path[i]);
102117 - }
102118 - unix_state_unlock(s);
102119 + } else if (peer)
102120 + seq_printf(seq, " P%lu", sock_i_ino(peer));
102121 +
102122 + unix_state_double_unlock(s, peer);
102123 seq_putc(seq, '\n');
102124 }
102125
102126 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
102127 index b3d5150..ff3a837 100644
102128 --- a/net/unix/sysctl_net_unix.c
102129 +++ b/net/unix/sysctl_net_unix.c
102130 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
102131
102132 int __net_init unix_sysctl_register(struct net *net)
102133 {
102134 - struct ctl_table *table;
102135 + ctl_table_no_const *table;
102136
102137 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
102138 if (table == NULL)
102139 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
102140 index 9a73074..aecba9a 100644
102141 --- a/net/vmw_vsock/vmci_transport_notify.c
102142 +++ b/net/vmw_vsock/vmci_transport_notify.c
102143 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
102144
102145 /* Socket control packet based operations. */
102146 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
102147 - vmci_transport_notify_pkt_socket_init,
102148 - vmci_transport_notify_pkt_socket_destruct,
102149 - vmci_transport_notify_pkt_poll_in,
102150 - vmci_transport_notify_pkt_poll_out,
102151 - vmci_transport_notify_pkt_handle_pkt,
102152 - vmci_transport_notify_pkt_recv_init,
102153 - vmci_transport_notify_pkt_recv_pre_block,
102154 - vmci_transport_notify_pkt_recv_pre_dequeue,
102155 - vmci_transport_notify_pkt_recv_post_dequeue,
102156 - vmci_transport_notify_pkt_send_init,
102157 - vmci_transport_notify_pkt_send_pre_block,
102158 - vmci_transport_notify_pkt_send_pre_enqueue,
102159 - vmci_transport_notify_pkt_send_post_enqueue,
102160 - vmci_transport_notify_pkt_process_request,
102161 - vmci_transport_notify_pkt_process_negotiate,
102162 + .socket_init = vmci_transport_notify_pkt_socket_init,
102163 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
102164 + .poll_in = vmci_transport_notify_pkt_poll_in,
102165 + .poll_out = vmci_transport_notify_pkt_poll_out,
102166 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
102167 + .recv_init = vmci_transport_notify_pkt_recv_init,
102168 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
102169 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
102170 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
102171 + .send_init = vmci_transport_notify_pkt_send_init,
102172 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
102173 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
102174 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
102175 + .process_request = vmci_transport_notify_pkt_process_request,
102176 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
102177 };
102178 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
102179 index 622bd7a..b92086c 100644
102180 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
102181 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
102182 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
102183
102184 /* Socket always on control packet based operations. */
102185 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
102186 - vmci_transport_notify_pkt_socket_init,
102187 - vmci_transport_notify_pkt_socket_destruct,
102188 - vmci_transport_notify_pkt_poll_in,
102189 - vmci_transport_notify_pkt_poll_out,
102190 - vmci_transport_notify_pkt_handle_pkt,
102191 - vmci_transport_notify_pkt_recv_init,
102192 - vmci_transport_notify_pkt_recv_pre_block,
102193 - vmci_transport_notify_pkt_recv_pre_dequeue,
102194 - vmci_transport_notify_pkt_recv_post_dequeue,
102195 - vmci_transport_notify_pkt_send_init,
102196 - vmci_transport_notify_pkt_send_pre_block,
102197 - vmci_transport_notify_pkt_send_pre_enqueue,
102198 - vmci_transport_notify_pkt_send_post_enqueue,
102199 - vmci_transport_notify_pkt_process_request,
102200 - vmci_transport_notify_pkt_process_negotiate,
102201 + .socket_init = vmci_transport_notify_pkt_socket_init,
102202 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
102203 + .poll_in = vmci_transport_notify_pkt_poll_in,
102204 + .poll_out = vmci_transport_notify_pkt_poll_out,
102205 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
102206 + .recv_init = vmci_transport_notify_pkt_recv_init,
102207 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
102208 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
102209 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
102210 + .send_init = vmci_transport_notify_pkt_send_init,
102211 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
102212 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
102213 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
102214 + .process_request = vmci_transport_notify_pkt_process_request,
102215 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
102216 };
102217 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
102218 index c8717c1..08539f5 100644
102219 --- a/net/wireless/wext-core.c
102220 +++ b/net/wireless/wext-core.c
102221 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102222 */
102223
102224 /* Support for very large requests */
102225 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
102226 - (user_length > descr->max_tokens)) {
102227 + if (user_length > descr->max_tokens) {
102228 /* Allow userspace to GET more than max so
102229 * we can support any size GET requests.
102230 * There is still a limit : -ENOMEM.
102231 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
102232 }
102233 }
102234
102235 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
102236 - /*
102237 - * If this is a GET, but not NOMAX, it means that the extra
102238 - * data is not bounded by userspace, but by max_tokens. Thus
102239 - * set the length to max_tokens. This matches the extra data
102240 - * allocation.
102241 - * The driver should fill it with the number of tokens it
102242 - * provided, and it may check iwp->length rather than having
102243 - * knowledge of max_tokens. If the driver doesn't change the
102244 - * iwp->length, this ioctl just copies back max_token tokens
102245 - * filled with zeroes. Hopefully the driver isn't claiming
102246 - * them to be valid data.
102247 - */
102248 - iwp->length = descr->max_tokens;
102249 - }
102250 -
102251 err = handler(dev, info, (union iwreq_data *) iwp, extra);
102252
102253 iwp->length += essid_compat;
102254 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
102255 index 4323952..a06dfe1 100644
102256 --- a/net/x25/sysctl_net_x25.c
102257 +++ b/net/x25/sysctl_net_x25.c
102258 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
102259 .mode = 0644,
102260 .proc_handler = proc_dointvec,
102261 },
102262 - { 0, },
102263 + { },
102264 };
102265
102266 void __init x25_register_sysctl(void)
102267 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
102268 index 1d5c7bf..f762f1f 100644
102269 --- a/net/xfrm/xfrm_policy.c
102270 +++ b/net/xfrm/xfrm_policy.c
102271 @@ -327,7 +327,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
102272 {
102273 policy->walk.dead = 1;
102274
102275 - atomic_inc(&policy->genid);
102276 + atomic_inc_unchecked(&policy->genid);
102277
102278 if (del_timer(&policy->polq.hold_timer))
102279 xfrm_pol_put(policy);
102280 @@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
102281 hlist_add_head(&policy->bydst, chain);
102282 xfrm_pol_hold(policy);
102283 net->xfrm.policy_count[dir]++;
102284 - atomic_inc(&flow_cache_genid);
102285 + atomic_inc_unchecked(&flow_cache_genid);
102286
102287 /* After previous checking, family can either be AF_INET or AF_INET6 */
102288 if (policy->family == AF_INET)
102289 @@ -1761,7 +1761,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
102290
102291 xdst->num_pols = num_pols;
102292 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
102293 - xdst->policy_genid = atomic_read(&pols[0]->genid);
102294 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
102295
102296 return xdst;
102297 }
102298 @@ -2572,11 +2572,12 @@ void xfrm_garbage_collect(struct net *net)
102299 }
102300 EXPORT_SYMBOL(xfrm_garbage_collect);
102301
102302 -static void xfrm_garbage_collect_deferred(struct net *net)
102303 +void xfrm_garbage_collect_deferred(struct net *net)
102304 {
102305 flow_cache_flush_deferred();
102306 __xfrm_garbage_collect(net);
102307 }
102308 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
102309
102310 static void xfrm_init_pmtu(struct dst_entry *dst)
102311 {
102312 @@ -2626,7 +2627,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
102313 if (xdst->xfrm_genid != dst->xfrm->genid)
102314 return 0;
102315 if (xdst->num_pols > 0 &&
102316 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
102317 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
102318 return 0;
102319
102320 mtu = dst_mtu(dst->child);
102321 @@ -2714,8 +2715,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
102322 dst_ops->link_failure = xfrm_link_failure;
102323 if (likely(dst_ops->neigh_lookup == NULL))
102324 dst_ops->neigh_lookup = xfrm_neigh_lookup;
102325 - if (likely(afinfo->garbage_collect == NULL))
102326 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
102327 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
102328 }
102329 spin_unlock(&xfrm_policy_afinfo_lock);
102330 @@ -2769,7 +2768,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
102331 dst_ops->check = NULL;
102332 dst_ops->negative_advice = NULL;
102333 dst_ops->link_failure = NULL;
102334 - afinfo->garbage_collect = NULL;
102335 }
102336 return err;
102337 }
102338 @@ -3159,7 +3157,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
102339 sizeof(pol->xfrm_vec[i].saddr));
102340 pol->xfrm_vec[i].encap_family = mp->new_family;
102341 /* flush bundles */
102342 - atomic_inc(&pol->genid);
102343 + atomic_inc_unchecked(&pol->genid);
102344 }
102345 }
102346
102347 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
102348 index 40f1b3e..e33fdfa 100644
102349 --- a/net/xfrm/xfrm_state.c
102350 +++ b/net/xfrm/xfrm_state.c
102351 @@ -172,12 +172,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
102352
102353 if (unlikely(afinfo == NULL))
102354 return -EAFNOSUPPORT;
102355 - typemap = afinfo->type_map;
102356 + typemap = (const struct xfrm_type **)afinfo->type_map;
102357 spin_lock_bh(&xfrm_type_lock);
102358
102359 - if (likely(typemap[type->proto] == NULL))
102360 + if (likely(typemap[type->proto] == NULL)) {
102361 + pax_open_kernel();
102362 typemap[type->proto] = type;
102363 - else
102364 + pax_close_kernel();
102365 + } else
102366 err = -EEXIST;
102367 spin_unlock_bh(&xfrm_type_lock);
102368 xfrm_state_put_afinfo(afinfo);
102369 @@ -193,13 +195,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
102370
102371 if (unlikely(afinfo == NULL))
102372 return -EAFNOSUPPORT;
102373 - typemap = afinfo->type_map;
102374 + typemap = (const struct xfrm_type **)afinfo->type_map;
102375 spin_lock_bh(&xfrm_type_lock);
102376
102377 if (unlikely(typemap[type->proto] != type))
102378 err = -ENOENT;
102379 - else
102380 + else {
102381 + pax_open_kernel();
102382 typemap[type->proto] = NULL;
102383 + pax_close_kernel();
102384 + }
102385 spin_unlock_bh(&xfrm_type_lock);
102386 xfrm_state_put_afinfo(afinfo);
102387 return err;
102388 @@ -209,7 +214,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
102389 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
102390 {
102391 struct xfrm_state_afinfo *afinfo;
102392 - const struct xfrm_type **typemap;
102393 const struct xfrm_type *type;
102394 int modload_attempted = 0;
102395
102396 @@ -217,9 +221,8 @@ retry:
102397 afinfo = xfrm_state_get_afinfo(family);
102398 if (unlikely(afinfo == NULL))
102399 return NULL;
102400 - typemap = afinfo->type_map;
102401
102402 - type = typemap[proto];
102403 + type = afinfo->type_map[proto];
102404 if (unlikely(type && !try_module_get(type->owner)))
102405 type = NULL;
102406 if (!type && !modload_attempted) {
102407 @@ -253,7 +256,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102408 return -EAFNOSUPPORT;
102409
102410 err = -EEXIST;
102411 - modemap = afinfo->mode_map;
102412 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102413 spin_lock_bh(&xfrm_mode_lock);
102414 if (modemap[mode->encap])
102415 goto out;
102416 @@ -262,8 +265,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102417 if (!try_module_get(afinfo->owner))
102418 goto out;
102419
102420 - mode->afinfo = afinfo;
102421 + pax_open_kernel();
102422 + *(const void **)&mode->afinfo = afinfo;
102423 modemap[mode->encap] = mode;
102424 + pax_close_kernel();
102425 err = 0;
102426
102427 out:
102428 @@ -287,10 +292,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
102429 return -EAFNOSUPPORT;
102430
102431 err = -ENOENT;
102432 - modemap = afinfo->mode_map;
102433 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102434 spin_lock_bh(&xfrm_mode_lock);
102435 if (likely(modemap[mode->encap] == mode)) {
102436 + pax_open_kernel();
102437 modemap[mode->encap] = NULL;
102438 + pax_close_kernel();
102439 module_put(mode->afinfo->owner);
102440 err = 0;
102441 }
102442 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
102443 u32 xfrm_get_acqseq(void)
102444 {
102445 u32 res;
102446 - static atomic_t acqseq;
102447 + static atomic_unchecked_t acqseq;
102448
102449 do {
102450 - res = atomic_inc_return(&acqseq);
102451 + res = atomic_inc_return_unchecked(&acqseq);
102452 } while (!res);
102453
102454 return res;
102455 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
102456 index 05a6e3d..6716ec9 100644
102457 --- a/net/xfrm/xfrm_sysctl.c
102458 +++ b/net/xfrm/xfrm_sysctl.c
102459 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
102460
102461 int __net_init xfrm_sysctl_init(struct net *net)
102462 {
102463 - struct ctl_table *table;
102464 + ctl_table_no_const *table;
102465
102466 __xfrm_sysctl_init(net);
102467
102468 diff --git a/scripts/Makefile b/scripts/Makefile
102469 index 01e7adb..6176d5d 100644
102470 --- a/scripts/Makefile
102471 +++ b/scripts/Makefile
102472 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
102473
102474 # Let clean descend into subdirs
102475 subdir- += basic kconfig package selinux
102476 +
102477 +clean-files := randstruct.seed
102478 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
102479 index d5d859c..781cbcb 100644
102480 --- a/scripts/Makefile.build
102481 +++ b/scripts/Makefile.build
102482 @@ -111,7 +111,7 @@ endif
102483 endif
102484
102485 # Do not include host rules unless needed
102486 -ifneq ($(hostprogs-y)$(hostprogs-m),)
102487 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
102488 include scripts/Makefile.host
102489 endif
102490
102491 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
102492 index 686cb0d..9d653bf 100644
102493 --- a/scripts/Makefile.clean
102494 +++ b/scripts/Makefile.clean
102495 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
102496 __clean-files := $(extra-y) $(always) \
102497 $(targets) $(clean-files) \
102498 $(host-progs) \
102499 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
102500 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
102501 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
102502
102503 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
102504
102505 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
102506 index 1ac414f..38575f7 100644
102507 --- a/scripts/Makefile.host
102508 +++ b/scripts/Makefile.host
102509 @@ -31,6 +31,8 @@
102510 # Note: Shared libraries consisting of C++ files are not supported
102511
102512 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
102513 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
102514 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
102515
102516 # C code
102517 # Executables compiled from a single .c file
102518 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
102519 # Shared libaries (only .c supported)
102520 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
102521 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
102522 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
102523 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
102524 # Remove .so files from "xxx-objs"
102525 host-cobjs := $(filter-out %.so,$(host-cobjs))
102526 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
102527
102528 -#Object (.o) files used by the shared libaries
102529 +# Object (.o) files used by the shared libaries
102530 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
102531 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
102532
102533 # output directory for programs/.o files
102534 # hostprogs-y := tools/build may have been specified. Retrieve directory
102535 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
102536 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
102537 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
102538 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
102539 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
102540 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
102541 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
102542 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
102543
102544 obj-dirs += $(host-objdirs)
102545 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
102546 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
102547 $(call if_changed_dep,host-cshobjs)
102548
102549 +# Compile .c file, create position independent .o file
102550 +# host-cxxshobjs -> .o
102551 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
102552 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
102553 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
102554 + $(call if_changed_dep,host-cxxshobjs)
102555 +
102556 # Link a shared library, based on position independent .o files
102557 # *.o -> .so shared library (host-cshlib)
102558 quiet_cmd_host-cshlib = HOSTLLD -shared $@
102559 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
102560 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
102561 $(call if_changed,host-cshlib)
102562
102563 +# Link a shared library, based on position independent .o files
102564 +# *.o -> .so shared library (host-cxxshlib)
102565 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
102566 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
102567 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
102568 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
102569 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
102570 + $(call if_changed,host-cxxshlib)
102571 +
102572 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
102573 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
102574 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
102575
102576 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
102577 index 078fe1d..fbdb363 100644
102578 --- a/scripts/basic/fixdep.c
102579 +++ b/scripts/basic/fixdep.c
102580 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
102581 /*
102582 * Lookup a value in the configuration string.
102583 */
102584 -static int is_defined_config(const char *name, int len, unsigned int hash)
102585 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
102586 {
102587 struct item *aux;
102588
102589 @@ -211,10 +211,10 @@ static void clear_config(void)
102590 /*
102591 * Record the use of a CONFIG_* word.
102592 */
102593 -static void use_config(const char *m, int slen)
102594 +static void use_config(const char *m, unsigned int slen)
102595 {
102596 unsigned int hash = strhash(m, slen);
102597 - int c, i;
102598 + unsigned int c, i;
102599
102600 if (is_defined_config(m, slen, hash))
102601 return;
102602 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
102603
102604 static void parse_config_file(const char *map, size_t len)
102605 {
102606 - const int *end = (const int *) (map + len);
102607 + const unsigned int *end = (const unsigned int *) (map + len);
102608 /* start at +1, so that p can never be < map */
102609 - const int *m = (const int *) map + 1;
102610 + const unsigned int *m = (const unsigned int *) map + 1;
102611 const char *p, *q;
102612
102613 for (; m < end; m++) {
102614 @@ -435,7 +435,7 @@ static void print_deps(void)
102615 static void traps(void)
102616 {
102617 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
102618 - int *p = (int *)test;
102619 + unsigned int *p = (unsigned int *)test;
102620
102621 if (*p != INT_CONF) {
102622 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
102623 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
102624 new file mode 100644
102625 index 0000000..edcbc3a
102626 --- /dev/null
102627 +++ b/scripts/gcc-plugin.sh
102628 @@ -0,0 +1,16 @@
102629 +#!/bin/bash
102630 +srctree=$(dirname "$0")
102631 +gccplugins_dir=$($3 -print-file-name=plugin)
102632 +plugincc=$($1 -E -shared - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
102633 +#include "gcc-common.h"
102634 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
102635 +#warning $2
102636 +#else
102637 +#warning $1
102638 +#endif
102639 +EOF
102640 +)
102641 +if [ $? -eq 0 ]
102642 +then
102643 + ( [[ "$plugincc" =~ "$1" ]] && echo "$1" ) || ( [[ "$plugincc" =~ "$2" ]] && echo "$2" )
102644 +fi
102645 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
102646 index 5de5660..d3deb89 100644
102647 --- a/scripts/headers_install.sh
102648 +++ b/scripts/headers_install.sh
102649 @@ -32,6 +32,7 @@ do
102650 FILE="$(basename "$i")"
102651 sed -r \
102652 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
102653 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
102654 -e 's/__attribute_const__([ \t]|$)/\1/g' \
102655 -e 's@^#include <linux/compiler.h>@@' \
102656 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
102657 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
102658 index 2dcb377..a82c500 100644
102659 --- a/scripts/link-vmlinux.sh
102660 +++ b/scripts/link-vmlinux.sh
102661 @@ -162,7 +162,7 @@ else
102662 fi;
102663
102664 # final build of init/
102665 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
102666 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
102667
102668 kallsymso=""
102669 kallsyms_vmlinux=""
102670 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
102671 index 25e5cb0..6e85821 100644
102672 --- a/scripts/mod/file2alias.c
102673 +++ b/scripts/mod/file2alias.c
102674 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
102675 unsigned long size, unsigned long id_size,
102676 void *symval)
102677 {
102678 - int i;
102679 + unsigned int i;
102680
102681 if (size % id_size || size < id_size) {
102682 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
102683 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
102684 /* USB is special because the bcdDevice can be matched against a numeric range */
102685 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
102686 static void do_usb_entry(void *symval,
102687 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
102688 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
102689 unsigned char range_lo, unsigned char range_hi,
102690 unsigned char max, struct module *mod)
102691 {
102692 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
102693 {
102694 unsigned int devlo, devhi;
102695 unsigned char chi, clo, max;
102696 - int ndigits;
102697 + unsigned int ndigits;
102698
102699 DEF_FIELD(symval, usb_device_id, match_flags);
102700 DEF_FIELD(symval, usb_device_id, idVendor);
102701 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
102702 for (i = 0; i < count; i++) {
102703 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
102704 char acpi_id[sizeof(*id)];
102705 - int j;
102706 + unsigned int j;
102707
102708 buf_printf(&mod->dev_table_buf,
102709 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
102710 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102711
102712 for (j = 0; j < PNP_MAX_DEVICES; j++) {
102713 const char *id = (char *)(*devs)[j].id;
102714 - int i2, j2;
102715 + unsigned int i2, j2;
102716 int dup = 0;
102717
102718 if (!id[0])
102719 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102720 /* add an individual alias for every device entry */
102721 if (!dup) {
102722 char acpi_id[PNP_ID_LEN];
102723 - int k;
102724 + unsigned int k;
102725
102726 buf_printf(&mod->dev_table_buf,
102727 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
102728 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
102729 static int do_dmi_entry(const char *filename, void *symval,
102730 char *alias)
102731 {
102732 - int i, j;
102733 + unsigned int i, j;
102734 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
102735 sprintf(alias, "dmi*");
102736
102737 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
102738 index 99a45fd..4b995a3 100644
102739 --- a/scripts/mod/modpost.c
102740 +++ b/scripts/mod/modpost.c
102741 @@ -945,6 +945,7 @@ enum mismatch {
102742 ANY_INIT_TO_ANY_EXIT,
102743 ANY_EXIT_TO_ANY_INIT,
102744 EXPORT_TO_INIT_EXIT,
102745 + DATA_TO_TEXT
102746 };
102747
102748 struct sectioncheck {
102749 @@ -1031,6 +1032,12 @@ const struct sectioncheck sectioncheck[] = {
102750 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
102751 .mismatch = EXPORT_TO_INIT_EXIT,
102752 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
102753 +},
102754 +/* Do not reference code from writable data */
102755 +{
102756 + .fromsec = { DATA_SECTIONS, NULL },
102757 + .tosec = { TEXT_SECTIONS, NULL },
102758 + .mismatch = DATA_TO_TEXT
102759 }
102760 };
102761
102762 @@ -1151,10 +1158,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
102763 continue;
102764 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
102765 continue;
102766 - if (sym->st_value == addr)
102767 - return sym;
102768 /* Find a symbol nearby - addr are maybe negative */
102769 d = sym->st_value - addr;
102770 + if (d == 0)
102771 + return sym;
102772 if (d < 0)
102773 d = addr - sym->st_value;
102774 if (d < distance) {
102775 @@ -1432,6 +1439,14 @@ static void report_sec_mismatch(const char *modname,
102776 tosym, prl_to, prl_to, tosym);
102777 free(prl_to);
102778 break;
102779 + case DATA_TO_TEXT:
102780 +#if 0
102781 + fprintf(stderr,
102782 + "The %s %s:%s references\n"
102783 + "the %s %s:%s%s\n",
102784 + from, fromsec, fromsym, to, tosec, tosym, to_p);
102785 +#endif
102786 + break;
102787 }
102788 fprintf(stderr, "\n");
102789 }
102790 @@ -1679,7 +1694,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
102791 static void check_sec_ref(struct module *mod, const char *modname,
102792 struct elf_info *elf)
102793 {
102794 - int i;
102795 + unsigned int i;
102796 Elf_Shdr *sechdrs = elf->sechdrs;
102797
102798 /* Walk through all sections */
102799 @@ -1798,7 +1813,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
102800 va_end(ap);
102801 }
102802
102803 -void buf_write(struct buffer *buf, const char *s, int len)
102804 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
102805 {
102806 if (buf->size - buf->pos < len) {
102807 buf->size += len + SZ;
102808 @@ -2017,7 +2032,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
102809 if (fstat(fileno(file), &st) < 0)
102810 goto close_write;
102811
102812 - if (st.st_size != b->pos)
102813 + if (st.st_size != (off_t)b->pos)
102814 goto close_write;
102815
102816 tmp = NOFAIL(malloc(b->pos));
102817 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
102818 index 51207e4..f7d603d 100644
102819 --- a/scripts/mod/modpost.h
102820 +++ b/scripts/mod/modpost.h
102821 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
102822
102823 struct buffer {
102824 char *p;
102825 - int pos;
102826 - int size;
102827 + unsigned int pos;
102828 + unsigned int size;
102829 };
102830
102831 void __attribute__((format(printf, 2, 3)))
102832 buf_printf(struct buffer *buf, const char *fmt, ...);
102833
102834 void
102835 -buf_write(struct buffer *buf, const char *s, int len);
102836 +buf_write(struct buffer *buf, const char *s, unsigned int len);
102837
102838 struct module {
102839 struct module *next;
102840 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
102841 index deb2994..af4f63e 100644
102842 --- a/scripts/mod/sumversion.c
102843 +++ b/scripts/mod/sumversion.c
102844 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
102845 goto out;
102846 }
102847
102848 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
102849 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
102850 warn("writing sum in %s failed: %s\n",
102851 filename, strerror(errno));
102852 goto out;
102853 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
102854 index 0865b3e..7235dd4 100644
102855 --- a/scripts/module-common.lds
102856 +++ b/scripts/module-common.lds
102857 @@ -6,6 +6,10 @@
102858 SECTIONS {
102859 /DISCARD/ : { *(.discard) }
102860
102861 + .rodata : {
102862 + *(.rodata) *(.rodata.*)
102863 + *(.data..read_only)
102864 + }
102865 __ksymtab : { *(SORT(___ksymtab+*)) }
102866 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
102867 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
102868 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
102869 index f46e4dd..090e168 100644
102870 --- a/scripts/package/builddeb
102871 +++ b/scripts/package/builddeb
102872 @@ -291,6 +291,7 @@ fi
102873 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
102874 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
102875 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
102876 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
102877 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
102878 mkdir -p "$destdir"
102879 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
102880 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
102881 index 68bb4ef..2f419e1 100644
102882 --- a/scripts/pnmtologo.c
102883 +++ b/scripts/pnmtologo.c
102884 @@ -244,14 +244,14 @@ static void write_header(void)
102885 fprintf(out, " * Linux logo %s\n", logoname);
102886 fputs(" */\n\n", out);
102887 fputs("#include <linux/linux_logo.h>\n\n", out);
102888 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
102889 + fprintf(out, "static unsigned char %s_data[] = {\n",
102890 logoname);
102891 }
102892
102893 static void write_footer(void)
102894 {
102895 fputs("\n};\n\n", out);
102896 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
102897 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
102898 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
102899 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
102900 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
102901 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
102902 fputs("\n};\n\n", out);
102903
102904 /* write logo clut */
102905 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
102906 + fprintf(out, "static unsigned char %s_clut[] = {\n",
102907 logoname);
102908 write_hex_cnt = 0;
102909 for (i = 0; i < logo_clutsize; i++) {
102910 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
102911 index 8fac3fd..32ff38d 100644
102912 --- a/scripts/sortextable.h
102913 +++ b/scripts/sortextable.h
102914 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
102915 const char *secstrtab;
102916 const char *strtab;
102917 char *extab_image;
102918 - int extab_index = 0;
102919 - int i;
102920 - int idx;
102921 + unsigned int extab_index = 0;
102922 + unsigned int i;
102923 + unsigned int idx;
102924 unsigned int num_sections;
102925 unsigned int secindex_strings;
102926
102927 diff --git a/security/Kconfig b/security/Kconfig
102928 index beb86b5..1ea5a01 100644
102929 --- a/security/Kconfig
102930 +++ b/security/Kconfig
102931 @@ -4,6 +4,960 @@
102932
102933 menu "Security options"
102934
102935 +menu "Grsecurity"
102936 +
102937 + config ARCH_TRACK_EXEC_LIMIT
102938 + bool
102939 +
102940 + config PAX_KERNEXEC_PLUGIN
102941 + bool
102942 +
102943 + config PAX_PER_CPU_PGD
102944 + bool
102945 +
102946 + config TASK_SIZE_MAX_SHIFT
102947 + int
102948 + depends on X86_64
102949 + default 47 if !PAX_PER_CPU_PGD
102950 + default 42 if PAX_PER_CPU_PGD
102951 +
102952 + config PAX_ENABLE_PAE
102953 + bool
102954 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
102955 +
102956 + config PAX_USERCOPY_SLABS
102957 + bool
102958 +
102959 +config GRKERNSEC
102960 + bool "Grsecurity"
102961 + select CRYPTO
102962 + select CRYPTO_SHA256
102963 + select PROC_FS
102964 + select STOP_MACHINE
102965 + select TTY
102966 + select DEBUG_KERNEL
102967 + select DEBUG_LIST
102968 + help
102969 + If you say Y here, you will be able to configure many features
102970 + that will enhance the security of your system. It is highly
102971 + recommended that you say Y here and read through the help
102972 + for each option so that you fully understand the features and
102973 + can evaluate their usefulness for your machine.
102974 +
102975 +choice
102976 + prompt "Configuration Method"
102977 + depends on GRKERNSEC
102978 + default GRKERNSEC_CONFIG_CUSTOM
102979 + help
102980 +
102981 +config GRKERNSEC_CONFIG_AUTO
102982 + bool "Automatic"
102983 + help
102984 + If you choose this configuration method, you'll be able to answer a small
102985 + number of simple questions about how you plan to use this kernel.
102986 + The settings of grsecurity and PaX will be automatically configured for
102987 + the highest commonly-used settings within the provided constraints.
102988 +
102989 + If you require additional configuration, custom changes can still be made
102990 + from the "custom configuration" menu.
102991 +
102992 +config GRKERNSEC_CONFIG_CUSTOM
102993 + bool "Custom"
102994 + help
102995 + If you choose this configuration method, you'll be able to configure all
102996 + grsecurity and PaX settings manually. Via this method, no options are
102997 + automatically enabled.
102998 +
102999 +endchoice
103000 +
103001 +choice
103002 + prompt "Usage Type"
103003 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103004 + default GRKERNSEC_CONFIG_SERVER
103005 + help
103006 +
103007 +config GRKERNSEC_CONFIG_SERVER
103008 + bool "Server"
103009 + help
103010 + Choose this option if you plan to use this kernel on a server.
103011 +
103012 +config GRKERNSEC_CONFIG_DESKTOP
103013 + bool "Desktop"
103014 + help
103015 + Choose this option if you plan to use this kernel on a desktop.
103016 +
103017 +endchoice
103018 +
103019 +choice
103020 + prompt "Virtualization Type"
103021 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
103022 + default GRKERNSEC_CONFIG_VIRT_NONE
103023 + help
103024 +
103025 +config GRKERNSEC_CONFIG_VIRT_NONE
103026 + bool "None"
103027 + help
103028 + Choose this option if this kernel will be run on bare metal.
103029 +
103030 +config GRKERNSEC_CONFIG_VIRT_GUEST
103031 + bool "Guest"
103032 + help
103033 + Choose this option if this kernel will be run as a VM guest.
103034 +
103035 +config GRKERNSEC_CONFIG_VIRT_HOST
103036 + bool "Host"
103037 + help
103038 + Choose this option if this kernel will be run as a VM host.
103039 +
103040 +endchoice
103041 +
103042 +choice
103043 + prompt "Virtualization Hardware"
103044 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
103045 + help
103046 +
103047 +config GRKERNSEC_CONFIG_VIRT_EPT
103048 + bool "EPT/RVI Processor Support"
103049 + depends on X86
103050 + help
103051 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
103052 + hardware virtualization. This allows for additional kernel hardening protections
103053 + to operate without additional performance impact.
103054 +
103055 + To see if your Intel processor supports EPT, see:
103056 + http://ark.intel.com/Products/VirtualizationTechnology
103057 + (Most Core i3/5/7 support EPT)
103058 +
103059 + To see if your AMD processor supports RVI, see:
103060 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
103061 +
103062 +config GRKERNSEC_CONFIG_VIRT_SOFT
103063 + bool "First-gen/No Hardware Virtualization"
103064 + help
103065 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
103066 + support hardware virtualization or doesn't support the EPT/RVI extensions.
103067 +
103068 +endchoice
103069 +
103070 +choice
103071 + prompt "Virtualization Software"
103072 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
103073 + help
103074 +
103075 +config GRKERNSEC_CONFIG_VIRT_XEN
103076 + bool "Xen"
103077 + help
103078 + Choose this option if this kernel is running as a Xen guest or host.
103079 +
103080 +config GRKERNSEC_CONFIG_VIRT_VMWARE
103081 + bool "VMWare"
103082 + help
103083 + Choose this option if this kernel is running as a VMWare guest or host.
103084 +
103085 +config GRKERNSEC_CONFIG_VIRT_KVM
103086 + bool "KVM"
103087 + help
103088 + Choose this option if this kernel is running as a KVM guest or host.
103089 +
103090 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
103091 + bool "VirtualBox"
103092 + help
103093 + Choose this option if this kernel is running as a VirtualBox guest or host.
103094 +
103095 +endchoice
103096 +
103097 +choice
103098 + prompt "Required Priorities"
103099 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103100 + default GRKERNSEC_CONFIG_PRIORITY_PERF
103101 + help
103102 +
103103 +config GRKERNSEC_CONFIG_PRIORITY_PERF
103104 + bool "Performance"
103105 + help
103106 + Choose this option if performance is of highest priority for this deployment
103107 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
103108 + clearing of structures intended for userland, and freed memory sanitizing will
103109 + be disabled.
103110 +
103111 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
103112 + bool "Security"
103113 + help
103114 + Choose this option if security is of highest priority for this deployment of
103115 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
103116 + for userland, and freed memory sanitizing will be enabled for this kernel.
103117 + In a worst-case scenario, these features can introduce a 20% performance hit
103118 + (UDEREF on x64 contributing half of this hit).
103119 +
103120 +endchoice
103121 +
103122 +menu "Default Special Groups"
103123 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
103124 +
103125 +config GRKERNSEC_PROC_GID
103126 + int "GID exempted from /proc restrictions"
103127 + default 1001
103128 + help
103129 + Setting this GID determines which group will be exempted from
103130 + grsecurity's /proc restrictions, allowing users of the specified
103131 + group to view network statistics and the existence of other users'
103132 + processes on the system. This GID may also be chosen at boot time
103133 + via "grsec_proc_gid=" on the kernel commandline.
103134 +
103135 +config GRKERNSEC_TPE_UNTRUSTED_GID
103136 + int "GID for TPE-untrusted users"
103137 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
103138 + default 1005
103139 + help
103140 + Setting this GID determines which group untrusted users should
103141 + be added to. These users will be placed under grsecurity's Trusted Path
103142 + Execution mechanism, preventing them from executing their own binaries.
103143 + The users will only be able to execute binaries in directories owned and
103144 + writable only by the root user. If the sysctl option is enabled, a sysctl
103145 + option with name "tpe_gid" is created.
103146 +
103147 +config GRKERNSEC_TPE_TRUSTED_GID
103148 + int "GID for TPE-trusted users"
103149 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
103150 + default 1005
103151 + help
103152 + Setting this GID determines what group TPE restrictions will be
103153 + *disabled* for. If the sysctl option is enabled, a sysctl option
103154 + with name "tpe_gid" is created.
103155 +
103156 +config GRKERNSEC_SYMLINKOWN_GID
103157 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
103158 + depends on GRKERNSEC_CONFIG_SERVER
103159 + default 1006
103160 + help
103161 + Setting this GID determines what group kernel-enforced
103162 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
103163 + is enabled, a sysctl option with name "symlinkown_gid" is created.
103164 +
103165 +
103166 +endmenu
103167 +
103168 +menu "Customize Configuration"
103169 +depends on GRKERNSEC
103170 +
103171 +menu "PaX"
103172 +
103173 +config PAX
103174 + bool "Enable various PaX features"
103175 + default y if GRKERNSEC_CONFIG_AUTO
103176 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
103177 + help
103178 + This allows you to enable various PaX features. PaX adds
103179 + intrusion prevention mechanisms to the kernel that reduce
103180 + the risks posed by exploitable memory corruption bugs.
103181 +
103182 +menu "PaX Control"
103183 + depends on PAX
103184 +
103185 +config PAX_SOFTMODE
103186 + bool 'Support soft mode'
103187 + help
103188 + Enabling this option will allow you to run PaX in soft mode, that
103189 + is, PaX features will not be enforced by default, only on executables
103190 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
103191 + support as they are the only way to mark executables for soft mode use.
103192 +
103193 + Soft mode can be activated by using the "pax_softmode=1" kernel command
103194 + line option on boot. Furthermore you can control various PaX features
103195 + at runtime via the entries in /proc/sys/kernel/pax.
103196 +
103197 +config PAX_EI_PAX
103198 + bool 'Use legacy ELF header marking'
103199 + default y if GRKERNSEC_CONFIG_AUTO
103200 + help
103201 + Enabling this option will allow you to control PaX features on
103202 + a per executable basis via the 'chpax' utility available at
103203 + http://pax.grsecurity.net/. The control flags will be read from
103204 + an otherwise reserved part of the ELF header. This marking has
103205 + numerous drawbacks (no support for soft-mode, toolchain does not
103206 + know about the non-standard use of the ELF header) therefore it
103207 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
103208 + support.
103209 +
103210 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
103211 + support as well, they will override the legacy EI_PAX marks.
103212 +
103213 + If you enable none of the marking options then all applications
103214 + will run with PaX enabled on them by default.
103215 +
103216 +config PAX_PT_PAX_FLAGS
103217 + bool 'Use ELF program header marking'
103218 + default y if GRKERNSEC_CONFIG_AUTO
103219 + help
103220 + Enabling this option will allow you to control PaX features on
103221 + a per executable basis via the 'paxctl' utility available at
103222 + http://pax.grsecurity.net/. The control flags will be read from
103223 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
103224 + has the benefits of supporting both soft mode and being fully
103225 + integrated into the toolchain (the binutils patch is available
103226 + from http://pax.grsecurity.net).
103227 +
103228 + Note that if you enable the legacy EI_PAX marking support as well,
103229 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
103230 +
103231 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103232 + must make sure that the marks are the same if a binary has both marks.
103233 +
103234 + If you enable none of the marking options then all applications
103235 + will run with PaX enabled on them by default.
103236 +
103237 +config PAX_XATTR_PAX_FLAGS
103238 + bool 'Use filesystem extended attributes marking'
103239 + default y if GRKERNSEC_CONFIG_AUTO
103240 + select CIFS_XATTR if CIFS
103241 + select EXT2_FS_XATTR if EXT2_FS
103242 + select EXT3_FS_XATTR if EXT3_FS
103243 + select JFFS2_FS_XATTR if JFFS2_FS
103244 + select REISERFS_FS_XATTR if REISERFS_FS
103245 + select SQUASHFS_XATTR if SQUASHFS
103246 + select TMPFS_XATTR if TMPFS
103247 + select UBIFS_FS_XATTR if UBIFS_FS
103248 + help
103249 + Enabling this option will allow you to control PaX features on
103250 + a per executable basis via the 'setfattr' utility. The control
103251 + flags will be read from the user.pax.flags extended attribute of
103252 + the file. This marking has the benefit of supporting binary-only
103253 + applications that self-check themselves (e.g., skype) and would
103254 + not tolerate chpax/paxctl changes. The main drawback is that
103255 + extended attributes are not supported by some filesystems (e.g.,
103256 + isofs, udf, vfat) so copying files through such filesystems will
103257 + lose the extended attributes and these PaX markings.
103258 +
103259 + Note that if you enable the legacy EI_PAX marking support as well,
103260 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
103261 +
103262 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103263 + must make sure that the marks are the same if a binary has both marks.
103264 +
103265 + If you enable none of the marking options then all applications
103266 + will run with PaX enabled on them by default.
103267 +
103268 +choice
103269 + prompt 'MAC system integration'
103270 + default PAX_HAVE_ACL_FLAGS
103271 + help
103272 + Mandatory Access Control systems have the option of controlling
103273 + PaX flags on a per executable basis, choose the method supported
103274 + by your particular system.
103275 +
103276 + - "none": if your MAC system does not interact with PaX,
103277 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
103278 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
103279 +
103280 + NOTE: this option is for developers/integrators only.
103281 +
103282 + config PAX_NO_ACL_FLAGS
103283 + bool 'none'
103284 +
103285 + config PAX_HAVE_ACL_FLAGS
103286 + bool 'direct'
103287 +
103288 + config PAX_HOOK_ACL_FLAGS
103289 + bool 'hook'
103290 +endchoice
103291 +
103292 +endmenu
103293 +
103294 +menu "Non-executable pages"
103295 + depends on PAX
103296 +
103297 +config PAX_NOEXEC
103298 + bool "Enforce non-executable pages"
103299 + default y if GRKERNSEC_CONFIG_AUTO
103300 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
103301 + help
103302 + By design some architectures do not allow for protecting memory
103303 + pages against execution or even if they do, Linux does not make
103304 + use of this feature. In practice this means that if a page is
103305 + readable (such as the stack or heap) it is also executable.
103306 +
103307 + There is a well known exploit technique that makes use of this
103308 + fact and a common programming mistake where an attacker can
103309 + introduce code of his choice somewhere in the attacked program's
103310 + memory (typically the stack or the heap) and then execute it.
103311 +
103312 + If the attacked program was running with different (typically
103313 + higher) privileges than that of the attacker, then he can elevate
103314 + his own privilege level (e.g. get a root shell, write to files for
103315 + which he does not have write access to, etc).
103316 +
103317 + Enabling this option will let you choose from various features
103318 + that prevent the injection and execution of 'foreign' code in
103319 + a program.
103320 +
103321 + This will also break programs that rely on the old behaviour and
103322 + expect that dynamically allocated memory via the malloc() family
103323 + of functions is executable (which it is not). Notable examples
103324 + are the XFree86 4.x server, the java runtime and wine.
103325 +
103326 +config PAX_PAGEEXEC
103327 + bool "Paging based non-executable pages"
103328 + default y if GRKERNSEC_CONFIG_AUTO
103329 + 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)
103330 + select ARCH_TRACK_EXEC_LIMIT if X86_32
103331 + help
103332 + This implementation is based on the paging feature of the CPU.
103333 + On i386 without hardware non-executable bit support there is a
103334 + variable but usually low performance impact, however on Intel's
103335 + P4 core based CPUs it is very high so you should not enable this
103336 + for kernels meant to be used on such CPUs.
103337 +
103338 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
103339 + with hardware non-executable bit support there is no performance
103340 + impact, on ppc the impact is negligible.
103341 +
103342 + Note that several architectures require various emulations due to
103343 + badly designed userland ABIs, this will cause a performance impact
103344 + but will disappear as soon as userland is fixed. For example, ppc
103345 + userland MUST have been built with secure-plt by a recent toolchain.
103346 +
103347 +config PAX_SEGMEXEC
103348 + bool "Segmentation based non-executable pages"
103349 + default y if GRKERNSEC_CONFIG_AUTO
103350 + depends on PAX_NOEXEC && X86_32
103351 + help
103352 + This implementation is based on the segmentation feature of the
103353 + CPU and has a very small performance impact, however applications
103354 + will be limited to a 1.5 GB address space instead of the normal
103355 + 3 GB.
103356 +
103357 +config PAX_EMUTRAMP
103358 + bool "Emulate trampolines"
103359 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
103360 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
103361 + help
103362 + There are some programs and libraries that for one reason or
103363 + another attempt to execute special small code snippets from
103364 + non-executable memory pages. Most notable examples are the
103365 + signal handler return code generated by the kernel itself and
103366 + the GCC trampolines.
103367 +
103368 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
103369 + such programs will no longer work under your kernel.
103370 +
103371 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
103372 + utilities to enable trampoline emulation for the affected programs
103373 + yet still have the protection provided by the non-executable pages.
103374 +
103375 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
103376 + your system will not even boot.
103377 +
103378 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
103379 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
103380 + for the affected files.
103381 +
103382 + NOTE: enabling this feature *may* open up a loophole in the
103383 + protection provided by non-executable pages that an attacker
103384 + could abuse. Therefore the best solution is to not have any
103385 + files on your system that would require this option. This can
103386 + be achieved by not using libc5 (which relies on the kernel
103387 + signal handler return code) and not using or rewriting programs
103388 + that make use of the nested function implementation of GCC.
103389 + Skilled users can just fix GCC itself so that it implements
103390 + nested function calls in a way that does not interfere with PaX.
103391 +
103392 +config PAX_EMUSIGRT
103393 + bool "Automatically emulate sigreturn trampolines"
103394 + depends on PAX_EMUTRAMP && PARISC
103395 + default y
103396 + help
103397 + Enabling this option will have the kernel automatically detect
103398 + and emulate signal return trampolines executing on the stack
103399 + that would otherwise lead to task termination.
103400 +
103401 + This solution is intended as a temporary one for users with
103402 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
103403 + Modula-3 runtime, etc) or executables linked to such, basically
103404 + everything that does not specify its own SA_RESTORER function in
103405 + normal executable memory like glibc 2.1+ does.
103406 +
103407 + On parisc you MUST enable this option, otherwise your system will
103408 + not even boot.
103409 +
103410 + NOTE: this feature cannot be disabled on a per executable basis
103411 + and since it *does* open up a loophole in the protection provided
103412 + by non-executable pages, the best solution is to not have any
103413 + files on your system that would require this option.
103414 +
103415 +config PAX_MPROTECT
103416 + bool "Restrict mprotect()"
103417 + default y if GRKERNSEC_CONFIG_AUTO
103418 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
103419 + help
103420 + Enabling this option will prevent programs from
103421 + - changing the executable status of memory pages that were
103422 + not originally created as executable,
103423 + - making read-only executable pages writable again,
103424 + - creating executable pages from anonymous memory,
103425 + - making read-only-after-relocations (RELRO) data pages writable again.
103426 +
103427 + You should say Y here to complete the protection provided by
103428 + the enforcement of non-executable pages.
103429 +
103430 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103431 + this feature on a per file basis.
103432 +
103433 +config PAX_MPROTECT_COMPAT
103434 + bool "Use legacy/compat protection demoting (read help)"
103435 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103436 + depends on PAX_MPROTECT
103437 + help
103438 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
103439 + by sending the proper error code to the application. For some broken
103440 + userland, this can cause problems with Python or other applications. The
103441 + current implementation however allows for applications like clamav to
103442 + detect if JIT compilation/execution is allowed and to fall back gracefully
103443 + to an interpreter-based mode if it does not. While we encourage everyone
103444 + to use the current implementation as-is and push upstream to fix broken
103445 + userland (note that the RWX logging option can assist with this), in some
103446 + environments this may not be possible. Having to disable MPROTECT
103447 + completely on certain binaries reduces the security benefit of PaX,
103448 + so this option is provided for those environments to revert to the old
103449 + behavior.
103450 +
103451 +config PAX_ELFRELOCS
103452 + bool "Allow ELF text relocations (read help)"
103453 + depends on PAX_MPROTECT
103454 + default n
103455 + help
103456 + Non-executable pages and mprotect() restrictions are effective
103457 + in preventing the introduction of new executable code into an
103458 + attacked task's address space. There remain only two venues
103459 + for this kind of attack: if the attacker can execute already
103460 + existing code in the attacked task then he can either have it
103461 + create and mmap() a file containing his code or have it mmap()
103462 + an already existing ELF library that does not have position
103463 + independent code in it and use mprotect() on it to make it
103464 + writable and copy his code there. While protecting against
103465 + the former approach is beyond PaX, the latter can be prevented
103466 + by having only PIC ELF libraries on one's system (which do not
103467 + need to relocate their code). If you are sure this is your case,
103468 + as is the case with all modern Linux distributions, then leave
103469 + this option disabled. You should say 'n' here.
103470 +
103471 +config PAX_ETEXECRELOCS
103472 + bool "Allow ELF ET_EXEC text relocations"
103473 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
103474 + select PAX_ELFRELOCS
103475 + default y
103476 + help
103477 + On some architectures there are incorrectly created applications
103478 + that require text relocations and would not work without enabling
103479 + this option. If you are an alpha, ia64 or parisc user, you should
103480 + enable this option and disable it once you have made sure that
103481 + none of your applications need it.
103482 +
103483 +config PAX_EMUPLT
103484 + bool "Automatically emulate ELF PLT"
103485 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
103486 + default y
103487 + help
103488 + Enabling this option will have the kernel automatically detect
103489 + and emulate the Procedure Linkage Table entries in ELF files.
103490 + On some architectures such entries are in writable memory, and
103491 + become non-executable leading to task termination. Therefore
103492 + it is mandatory that you enable this option on alpha, parisc,
103493 + sparc and sparc64, otherwise your system would not even boot.
103494 +
103495 + NOTE: this feature *does* open up a loophole in the protection
103496 + provided by the non-executable pages, therefore the proper
103497 + solution is to modify the toolchain to produce a PLT that does
103498 + not need to be writable.
103499 +
103500 +config PAX_DLRESOLVE
103501 + bool 'Emulate old glibc resolver stub'
103502 + depends on PAX_EMUPLT && SPARC
103503 + default n
103504 + help
103505 + This option is needed if userland has an old glibc (before 2.4)
103506 + that puts a 'save' instruction into the runtime generated resolver
103507 + stub that needs special emulation.
103508 +
103509 +config PAX_KERNEXEC
103510 + bool "Enforce non-executable kernel pages"
103511 + default y if GRKERNSEC_CONFIG_AUTO && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
103512 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
103513 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
103514 + select PAX_KERNEXEC_PLUGIN if X86_64
103515 + help
103516 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
103517 + that is, enabling this option will make it harder to inject
103518 + and execute 'foreign' code in kernel memory itself.
103519 +
103520 +choice
103521 + prompt "Return Address Instrumentation Method"
103522 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
103523 + depends on PAX_KERNEXEC_PLUGIN
103524 + help
103525 + Select the method used to instrument function pointer dereferences.
103526 + Note that binary modules cannot be instrumented by this approach.
103527 +
103528 + Note that the implementation requires a gcc with plugin support,
103529 + i.e., gcc 4.5 or newer. You may need to install the supporting
103530 + headers explicitly in addition to the normal gcc package.
103531 +
103532 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
103533 + bool "bts"
103534 + help
103535 + This method is compatible with binary only modules but has
103536 + a higher runtime overhead.
103537 +
103538 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
103539 + bool "or"
103540 + depends on !PARAVIRT
103541 + help
103542 + This method is incompatible with binary only modules but has
103543 + a lower runtime overhead.
103544 +endchoice
103545 +
103546 +config PAX_KERNEXEC_PLUGIN_METHOD
103547 + string
103548 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
103549 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
103550 + default ""
103551 +
103552 +config PAX_KERNEXEC_MODULE_TEXT
103553 + int "Minimum amount of memory reserved for module code"
103554 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
103555 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103556 + depends on PAX_KERNEXEC && X86_32
103557 + help
103558 + Due to implementation details the kernel must reserve a fixed
103559 + amount of memory for runtime allocated code (such as modules)
103560 + at compile time that cannot be changed at runtime. Here you
103561 + can specify the minimum amount in MB that will be reserved.
103562 + Due to the same implementation details this size will always
103563 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
103564 + the actually available memory for runtime allocated code will
103565 + usually be more than this minimum.
103566 +
103567 + The default 4 MB should be enough for most users but if you have
103568 + an excessive number of modules (e.g., most distribution configs
103569 + compile many drivers as modules) or use huge modules such as
103570 + nvidia's kernel driver, you will need to adjust this amount.
103571 + A good rule of thumb is to look at your currently loaded kernel
103572 + modules and add up their sizes.
103573 +
103574 +endmenu
103575 +
103576 +menu "Address Space Layout Randomization"
103577 + depends on PAX
103578 +
103579 +config PAX_ASLR
103580 + bool "Address Space Layout Randomization"
103581 + default y if GRKERNSEC_CONFIG_AUTO
103582 + help
103583 + Many if not most exploit techniques rely on the knowledge of
103584 + certain addresses in the attacked program. The following options
103585 + will allow the kernel to apply a certain amount of randomization
103586 + to specific parts of the program thereby forcing an attacker to
103587 + guess them in most cases. Any failed guess will most likely crash
103588 + the attacked program which allows the kernel to detect such attempts
103589 + and react on them. PaX itself provides no reaction mechanisms,
103590 + instead it is strongly encouraged that you make use of Nergal's
103591 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
103592 + (http://www.grsecurity.net/) built-in crash detection features or
103593 + develop one yourself.
103594 +
103595 + By saying Y here you can choose to randomize the following areas:
103596 + - top of the task's kernel stack
103597 + - top of the task's userland stack
103598 + - base address for mmap() requests that do not specify one
103599 + (this includes all libraries)
103600 + - base address of the main executable
103601 +
103602 + It is strongly recommended to say Y here as address space layout
103603 + randomization has negligible impact on performance yet it provides
103604 + a very effective protection.
103605 +
103606 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103607 + this feature on a per file basis.
103608 +
103609 +config PAX_RANDKSTACK
103610 + bool "Randomize kernel stack base"
103611 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
103612 + depends on X86_TSC && X86
103613 + help
103614 + By saying Y here the kernel will randomize every task's kernel
103615 + stack on every system call. This will not only force an attacker
103616 + to guess it but also prevent him from making use of possible
103617 + leaked information about it.
103618 +
103619 + Since the kernel stack is a rather scarce resource, randomization
103620 + may cause unexpected stack overflows, therefore you should very
103621 + carefully test your system. Note that once enabled in the kernel
103622 + configuration, this feature cannot be disabled on a per file basis.
103623 +
103624 +config PAX_RANDUSTACK
103625 + bool "Randomize user stack base"
103626 + default y if GRKERNSEC_CONFIG_AUTO
103627 + depends on PAX_ASLR
103628 + help
103629 + By saying Y here the kernel will randomize every task's userland
103630 + stack. The randomization is done in two steps where the second
103631 + one may apply a big amount of shift to the top of the stack and
103632 + cause problems for programs that want to use lots of memory (more
103633 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
103634 + For this reason the second step can be controlled by 'chpax' or
103635 + 'paxctl' on a per file basis.
103636 +
103637 +config PAX_RANDMMAP
103638 + bool "Randomize mmap() base"
103639 + default y if GRKERNSEC_CONFIG_AUTO
103640 + depends on PAX_ASLR
103641 + help
103642 + By saying Y here the kernel will use a randomized base address for
103643 + mmap() requests that do not specify one themselves. As a result
103644 + all dynamically loaded libraries will appear at random addresses
103645 + and therefore be harder to exploit by a technique where an attacker
103646 + attempts to execute library code for his purposes (e.g. spawn a
103647 + shell from an exploited program that is running at an elevated
103648 + privilege level).
103649 +
103650 + Furthermore, if a program is relinked as a dynamic ELF file, its
103651 + base address will be randomized as well, completing the full
103652 + randomization of the address space layout. Attacking such programs
103653 + becomes a guess game. You can find an example of doing this at
103654 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
103655 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
103656 +
103657 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
103658 + feature on a per file basis.
103659 +
103660 +endmenu
103661 +
103662 +menu "Miscellaneous hardening features"
103663 +
103664 +config PAX_MEMORY_SANITIZE
103665 + bool "Sanitize all freed memory"
103666 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103667 + help
103668 + By saying Y here the kernel will erase memory pages and slab objects
103669 + as soon as they are freed. This in turn reduces the lifetime of data
103670 + stored in them, making it less likely that sensitive information such
103671 + as passwords, cryptographic secrets, etc stay in memory for too long.
103672 +
103673 + This is especially useful for programs whose runtime is short, long
103674 + lived processes and the kernel itself benefit from this as long as
103675 + they ensure timely freeing of memory that may hold sensitive
103676 + information.
103677 +
103678 + A nice side effect of the sanitization of slab objects is the
103679 + reduction of possible info leaks caused by padding bytes within the
103680 + leaky structures. Use-after-free bugs for structures containing
103681 + pointers can also be detected as dereferencing the sanitized pointer
103682 + will generate an access violation.
103683 +
103684 + The tradeoff is performance impact, on a single CPU system kernel
103685 + compilation sees a 3% slowdown, other systems and workloads may vary
103686 + and you are advised to test this feature on your expected workload
103687 + before deploying it.
103688 +
103689 + To reduce the performance penalty by sanitizing pages only, albeit
103690 + limiting the effectiveness of this feature at the same time, slab
103691 + sanitization can be disabled with the kernel commandline parameter
103692 + "pax_sanitize_slab=0".
103693 +
103694 + Note that this feature does not protect data stored in live pages,
103695 + e.g., process memory swapped to disk may stay there for a long time.
103696 +
103697 +config PAX_MEMORY_STACKLEAK
103698 + bool "Sanitize kernel stack"
103699 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103700 + depends on X86
103701 + help
103702 + By saying Y here the kernel will erase the kernel stack before it
103703 + returns from a system call. This in turn reduces the information
103704 + that a kernel stack leak bug can reveal.
103705 +
103706 + Note that such a bug can still leak information that was put on
103707 + the stack by the current system call (the one eventually triggering
103708 + the bug) but traces of earlier system calls on the kernel stack
103709 + cannot leak anymore.
103710 +
103711 + The tradeoff is performance impact: on a single CPU system kernel
103712 + compilation sees a 1% slowdown, other systems and workloads may vary
103713 + and you are advised to test this feature on your expected workload
103714 + before deploying it.
103715 +
103716 + Note that the full feature requires a gcc with plugin support,
103717 + i.e., gcc 4.5 or newer. You may need to install the supporting
103718 + headers explicitly in addition to the normal gcc package. Using
103719 + older gcc versions means that functions with large enough stack
103720 + frames may leave uninitialized memory behind that may be exposed
103721 + to a later syscall leaking the stack.
103722 +
103723 +config PAX_MEMORY_STRUCTLEAK
103724 + bool "Forcibly initialize local variables copied to userland"
103725 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103726 + help
103727 + By saying Y here the kernel will zero initialize some local
103728 + variables that are going to be copied to userland. This in
103729 + turn prevents unintended information leakage from the kernel
103730 + stack should later code forget to explicitly set all parts of
103731 + the copied variable.
103732 +
103733 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
103734 + at a much smaller coverage.
103735 +
103736 + Note that the implementation requires a gcc with plugin support,
103737 + i.e., gcc 4.5 or newer. You may need to install the supporting
103738 + headers explicitly in addition to the normal gcc package.
103739 +
103740 +config PAX_MEMORY_UDEREF
103741 + bool "Prevent invalid userland pointer dereference"
103742 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
103743 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
103744 + select PAX_PER_CPU_PGD if X86_64
103745 + help
103746 + By saying Y here the kernel will be prevented from dereferencing
103747 + userland pointers in contexts where the kernel expects only kernel
103748 + pointers. This is both a useful runtime debugging feature and a
103749 + security measure that prevents exploiting a class of kernel bugs.
103750 +
103751 + The tradeoff is that some virtualization solutions may experience
103752 + a huge slowdown and therefore you should not enable this feature
103753 + for kernels meant to run in such environments. Whether a given VM
103754 + solution is affected or not is best determined by simply trying it
103755 + out, the performance impact will be obvious right on boot as this
103756 + mechanism engages from very early on. A good rule of thumb is that
103757 + VMs running on CPUs without hardware virtualization support (i.e.,
103758 + the majority of IA-32 CPUs) will likely experience the slowdown.
103759 +
103760 + On X86_64 the kernel will make use of PCID support when available
103761 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
103762 + or performance impact. Pass pax_weakuderef on the kernel command
103763 + line to choose the latter.
103764 +
103765 +config PAX_REFCOUNT
103766 + bool "Prevent various kernel object reference counter overflows"
103767 + default y if GRKERNSEC_CONFIG_AUTO
103768 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
103769 + help
103770 + By saying Y here the kernel will detect and prevent overflowing
103771 + various (but not all) kinds of object reference counters. Such
103772 + overflows can normally occur due to bugs only and are often, if
103773 + not always, exploitable.
103774 +
103775 + The tradeoff is that data structures protected by an overflowed
103776 + refcount will never be freed and therefore will leak memory. Note
103777 + that this leak also happens even without this protection but in
103778 + that case the overflow can eventually trigger the freeing of the
103779 + data structure while it is still being used elsewhere, resulting
103780 + in the exploitable situation that this feature prevents.
103781 +
103782 + Since this has a negligible performance impact, you should enable
103783 + this feature.
103784 +
103785 +config PAX_CONSTIFY_PLUGIN
103786 + bool "Automatically constify eligible structures"
103787 + default y
103788 + depends on !UML && PAX_KERNEXEC
103789 + help
103790 + By saying Y here the compiler will automatically constify a class
103791 + of types that contain only function pointers. This reduces the
103792 + kernel's attack surface and also produces a better memory layout.
103793 +
103794 + Note that the implementation requires a gcc with plugin support,
103795 + i.e., gcc 4.5 or newer. You may need to install the supporting
103796 + headers explicitly in addition to the normal gcc package.
103797 +
103798 + Note that if some code really has to modify constified variables
103799 + then the source code will have to be patched to allow it. Examples
103800 + can be found in PaX itself (the no_const attribute) and for some
103801 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
103802 +
103803 +config PAX_USERCOPY
103804 + bool "Harden heap object copies between kernel and userland"
103805 + default y if GRKERNSEC_CONFIG_AUTO
103806 + depends on ARM || IA64 || PPC || SPARC || X86
103807 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
103808 + select PAX_USERCOPY_SLABS
103809 + help
103810 + By saying Y here the kernel will enforce the size of heap objects
103811 + when they are copied in either direction between the kernel and
103812 + userland, even if only a part of the heap object is copied.
103813 +
103814 + Specifically, this checking prevents information leaking from the
103815 + kernel heap during kernel to userland copies (if the kernel heap
103816 + object is otherwise fully initialized) and prevents kernel heap
103817 + overflows during userland to kernel copies.
103818 +
103819 + Note that the current implementation provides the strictest bounds
103820 + checks for the SLUB allocator.
103821 +
103822 + Enabling this option also enables per-slab cache protection against
103823 + data in a given cache being copied into/out of via userland
103824 + accessors. Though the whitelist of regions will be reduced over
103825 + time, it notably protects important data structures like task structs.
103826 +
103827 + If frame pointers are enabled on x86, this option will also restrict
103828 + copies into and out of the kernel stack to local variables within a
103829 + single frame.
103830 +
103831 + Since this has a negligible performance impact, you should enable
103832 + this feature.
103833 +
103834 +config PAX_USERCOPY_DEBUG
103835 + bool
103836 + depends on X86 && PAX_USERCOPY
103837 + default n
103838 +
103839 +config PAX_SIZE_OVERFLOW
103840 + bool "Prevent various integer overflows in function size parameters"
103841 + default y if GRKERNSEC_CONFIG_AUTO
103842 + depends on X86
103843 + help
103844 + By saying Y here the kernel recomputes expressions of function
103845 + arguments marked by a size_overflow attribute with double integer
103846 + precision (DImode/TImode for 32/64 bit integer types).
103847 +
103848 + The recomputed argument is checked against TYPE_MAX and an event
103849 + is logged on overflow and the triggering process is killed.
103850 +
103851 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
103852 +
103853 + Note that the implementation requires a gcc with plugin support,
103854 + i.e., gcc 4.5 or newer. You may need to install the supporting
103855 + headers explicitly in addition to the normal gcc package.
103856 +
103857 +config PAX_LATENT_ENTROPY
103858 + bool "Generate some entropy during boot and runtime"
103859 + default y if GRKERNSEC_CONFIG_AUTO
103860 + help
103861 + By saying Y here the kernel will instrument some kernel code to
103862 + extract some entropy from both original and artificially created
103863 + program state. This will help especially embedded systems where
103864 + there is little 'natural' source of entropy normally. The cost
103865 + is some slowdown of the boot process and fork and irq processing.
103866 +
103867 + When pax_extra_latent_entropy is passed on the kernel command line,
103868 + entropy will be extracted from up to the first 4GB of RAM while the
103869 + runtime memory allocator is being initialized. This costs even more
103870 + slowdown of the boot process.
103871 +
103872 + Note that the implementation requires a gcc with plugin support,
103873 + i.e., gcc 4.5 or newer. You may need to install the supporting
103874 + headers explicitly in addition to the normal gcc package.
103875 +
103876 + Note that entropy extracted this way is not cryptographically
103877 + secure!
103878 +
103879 +endmenu
103880 +
103881 +endmenu
103882 +
103883 +source grsecurity/Kconfig
103884 +
103885 +endmenu
103886 +
103887 +endmenu
103888 +
103889 source security/keys/Kconfig
103890
103891 config SECURITY_DMESG_RESTRICT
103892 @@ -103,7 +1057,7 @@ config INTEL_TXT
103893 config LSM_MMAP_MIN_ADDR
103894 int "Low address space for LSM to protect from user allocation"
103895 depends on SECURITY && SECURITY_SELINUX
103896 - default 32768 if ARM || (ARM64 && COMPAT)
103897 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
103898 default 65536
103899 help
103900 This is the portion of low virtual memory which should be protected
103901 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
103902 index fdaa50c..2761dcb 100644
103903 --- a/security/apparmor/file.c
103904 +++ b/security/apparmor/file.c
103905 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
103906 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
103907 struct path *new_dir, struct dentry *new_dentry)
103908 {
103909 - struct path link = { new_dir->mnt, new_dentry };
103910 - struct path target = { new_dir->mnt, old_dentry };
103911 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
103912 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
103913 struct path_cond cond = {
103914 old_dentry->d_inode->i_uid,
103915 old_dentry->d_inode->i_mode
103916 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
103917 index 4257b7e..2d0732d 100644
103918 --- a/security/apparmor/lsm.c
103919 +++ b/security/apparmor/lsm.c
103920 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103921 struct dentry *dentry, u32 mask,
103922 struct path_cond *cond)
103923 {
103924 - struct path path = { dir->mnt, dentry };
103925 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
103926
103927 return common_perm(op, &path, mask, cond);
103928 }
103929 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103930 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
103931 struct dentry *dentry, u32 mask)
103932 {
103933 - struct path path = { mnt, dentry };
103934 + struct path path = { .mnt = mnt, .dentry = dentry };
103935 struct path_cond cond = { dentry->d_inode->i_uid,
103936 dentry->d_inode->i_mode
103937 };
103938 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
103939
103940 profile = aa_current_profile();
103941 if (!unconfined(profile)) {
103942 - struct path old_path = { old_dir->mnt, old_dentry };
103943 - struct path new_path = { new_dir->mnt, new_dentry };
103944 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
103945 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
103946 struct path_cond cond = { old_dentry->d_inode->i_uid,
103947 old_dentry->d_inode->i_mode
103948 };
103949 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
103950 return error;
103951 }
103952
103953 -static struct security_operations apparmor_ops = {
103954 +static struct security_operations apparmor_ops __read_only = {
103955 .name = "apparmor",
103956
103957 .ptrace_access_check = apparmor_ptrace_access_check,
103958 diff --git a/security/commoncap.c b/security/commoncap.c
103959 index b9d613e..f68305c 100644
103960 --- a/security/commoncap.c
103961 +++ b/security/commoncap.c
103962 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
103963 return 0;
103964 }
103965
103966 +/* returns:
103967 + 1 for suid privilege
103968 + 2 for sgid privilege
103969 + 3 for fscap privilege
103970 +*/
103971 +int is_privileged_binary(const struct dentry *dentry)
103972 +{
103973 + struct cpu_vfs_cap_data capdata;
103974 + struct inode *inode = dentry->d_inode;
103975 +
103976 + if (!inode || S_ISDIR(inode->i_mode))
103977 + return 0;
103978 +
103979 + if (inode->i_mode & S_ISUID)
103980 + return 1;
103981 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
103982 + return 2;
103983 +
103984 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
103985 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
103986 + return 3;
103987 + }
103988 +
103989 + return 0;
103990 +}
103991 +
103992 /*
103993 * Attempt to get the on-exec apply capability sets for an executable file from
103994 * its xattrs and, if present, apply them to the proposed credentials being
103995 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
103996 const struct cred *cred = current_cred();
103997 kuid_t root_uid = make_kuid(cred->user_ns, 0);
103998
103999 + if (gr_acl_enable_at_secure())
104000 + return 1;
104001 +
104002 if (!uid_eq(cred->uid, root_uid)) {
104003 if (bprm->cap_effective)
104004 return 1;
104005 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
104006 index f79fa8b..6161868 100644
104007 --- a/security/integrity/ima/ima.h
104008 +++ b/security/integrity/ima/ima.h
104009 @@ -118,8 +118,8 @@ int ima_init_template(void);
104010 extern spinlock_t ima_queue_lock;
104011
104012 struct ima_h_table {
104013 - atomic_long_t len; /* number of stored measurements in the list */
104014 - atomic_long_t violations;
104015 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
104016 + atomic_long_unchecked_t violations;
104017 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
104018 };
104019 extern struct ima_h_table ima_htable;
104020 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
104021 index c38bbce..f45133d 100644
104022 --- a/security/integrity/ima/ima_api.c
104023 +++ b/security/integrity/ima/ima_api.c
104024 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
104025 int result;
104026
104027 /* can overflow, only indicator */
104028 - atomic_long_inc(&ima_htable.violations);
104029 + atomic_long_inc_unchecked(&ima_htable.violations);
104030
104031 result = ima_alloc_init_template(NULL, file, filename,
104032 NULL, 0, &entry);
104033 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
104034 index 468a3ba..9af5cae 100644
104035 --- a/security/integrity/ima/ima_fs.c
104036 +++ b/security/integrity/ima/ima_fs.c
104037 @@ -28,12 +28,12 @@
104038 static int valid_policy = 1;
104039 #define TMPBUFLEN 12
104040 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
104041 - loff_t *ppos, atomic_long_t *val)
104042 + loff_t *ppos, atomic_long_unchecked_t *val)
104043 {
104044 char tmpbuf[TMPBUFLEN];
104045 ssize_t len;
104046
104047 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
104048 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
104049 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
104050 }
104051
104052 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
104053 index d85e997..6992813 100644
104054 --- a/security/integrity/ima/ima_queue.c
104055 +++ b/security/integrity/ima/ima_queue.c
104056 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
104057 INIT_LIST_HEAD(&qe->later);
104058 list_add_tail_rcu(&qe->later, &ima_measurements);
104059
104060 - atomic_long_inc(&ima_htable.len);
104061 + atomic_long_inc_unchecked(&ima_htable.len);
104062 key = ima_hash_key(entry->digest);
104063 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
104064 return 0;
104065 diff --git a/security/keys/compat.c b/security/keys/compat.c
104066 index bbd32c7..c60c927 100644
104067 --- a/security/keys/compat.c
104068 +++ b/security/keys/compat.c
104069 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
104070 if (ret == 0)
104071 goto no_payload_free;
104072
104073 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
104074 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
104075 err:
104076 if (iov != iovstack)
104077 kfree(iov);
104078 diff --git a/security/keys/internal.h b/security/keys/internal.h
104079 index 80b2aac..bb7ee65 100644
104080 --- a/security/keys/internal.h
104081 +++ b/security/keys/internal.h
104082 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
104083 extern long keyctl_invalidate_key(key_serial_t);
104084
104085 extern long keyctl_instantiate_key_common(key_serial_t,
104086 - const struct iovec *,
104087 + const struct iovec __user *,
104088 unsigned, size_t, key_serial_t);
104089 #ifdef CONFIG_PERSISTENT_KEYRINGS
104090 extern long keyctl_get_persistent(uid_t, key_serial_t);
104091 diff --git a/security/keys/key.c b/security/keys/key.c
104092 index 6e21c11..9ed67ca 100644
104093 --- a/security/keys/key.c
104094 +++ b/security/keys/key.c
104095 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
104096
104097 atomic_set(&key->usage, 1);
104098 init_rwsem(&key->sem);
104099 - lockdep_set_class(&key->sem, &type->lock_class);
104100 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
104101 key->index_key.type = type;
104102 key->user = user;
104103 key->quotalen = quotalen;
104104 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
104105 struct key_type *p;
104106 int ret;
104107
104108 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
104109 + pax_open_kernel();
104110 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
104111 + pax_close_kernel();
104112
104113 ret = -EEXIST;
104114 down_write(&key_types_sem);
104115 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
104116 }
104117
104118 /* store the type */
104119 - list_add(&ktype->link, &key_types_list);
104120 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
104121
104122 pr_notice("Key type %s registered\n", ktype->name);
104123 ret = 0;
104124 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
104125 void unregister_key_type(struct key_type *ktype)
104126 {
104127 down_write(&key_types_sem);
104128 - list_del_init(&ktype->link);
104129 + pax_list_del_init((struct list_head *)&ktype->link);
104130 downgrade_write(&key_types_sem);
104131 key_gc_keytype(ktype);
104132 pr_notice("Key type %s unregistered\n", ktype->name);
104133 @@ -1088,10 +1090,10 @@ void __init key_init(void)
104134 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
104135
104136 /* add the special key types */
104137 - list_add_tail(&key_type_keyring.link, &key_types_list);
104138 - list_add_tail(&key_type_dead.link, &key_types_list);
104139 - list_add_tail(&key_type_user.link, &key_types_list);
104140 - list_add_tail(&key_type_logon.link, &key_types_list);
104141 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
104142 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
104143 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
104144 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
104145
104146 /* record the root user tracking */
104147 rb_link_node(&root_key_user.node,
104148 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
104149 index cee72ce..e46074a 100644
104150 --- a/security/keys/keyctl.c
104151 +++ b/security/keys/keyctl.c
104152 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
104153 /*
104154 * Copy the iovec data from userspace
104155 */
104156 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
104157 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
104158 unsigned ioc)
104159 {
104160 for (; ioc > 0; ioc--) {
104161 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
104162 * If successful, 0 will be returned.
104163 */
104164 long keyctl_instantiate_key_common(key_serial_t id,
104165 - const struct iovec *payload_iov,
104166 + const struct iovec __user *payload_iov,
104167 unsigned ioc,
104168 size_t plen,
104169 key_serial_t ringid)
104170 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
104171 [0].iov_len = plen
104172 };
104173
104174 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
104175 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
104176 }
104177
104178 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
104179 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
104180 if (ret == 0)
104181 goto no_payload_free;
104182
104183 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
104184 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
104185 err:
104186 if (iov != iovstack)
104187 kfree(iov);
104188 diff --git a/security/min_addr.c b/security/min_addr.c
104189 index f728728..6457a0c 100644
104190 --- a/security/min_addr.c
104191 +++ b/security/min_addr.c
104192 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
104193 */
104194 static void update_mmap_min_addr(void)
104195 {
104196 +#ifndef SPARC
104197 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
104198 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
104199 mmap_min_addr = dac_mmap_min_addr;
104200 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
104201 #else
104202 mmap_min_addr = dac_mmap_min_addr;
104203 #endif
104204 +#endif
104205 }
104206
104207 /*
104208 diff --git a/security/security.c b/security/security.c
104209 index 919cad9..2127be1 100644
104210 --- a/security/security.c
104211 +++ b/security/security.c
104212 @@ -33,8 +33,8 @@
104213 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
104214 CONFIG_DEFAULT_SECURITY;
104215
104216 -static struct security_operations *security_ops;
104217 -static struct security_operations default_security_ops = {
104218 +struct security_operations *security_ops __read_only;
104219 +struct security_operations default_security_ops __read_only = {
104220 .name = "default",
104221 };
104222
104223 @@ -73,11 +73,6 @@ int __init security_init(void)
104224 return 0;
104225 }
104226
104227 -void reset_security_ops(void)
104228 -{
104229 - security_ops = &default_security_ops;
104230 -}
104231 -
104232 /* Save user chosen LSM */
104233 static int __init choose_lsm(char *str)
104234 {
104235 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
104236 index fc3e662..7844c60 100644
104237 --- a/security/selinux/avc.c
104238 +++ b/security/selinux/avc.c
104239 @@ -59,7 +59,7 @@ struct avc_node {
104240 struct avc_cache {
104241 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
104242 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
104243 - atomic_t lru_hint; /* LRU hint for reclaim scan */
104244 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
104245 atomic_t active_nodes;
104246 u32 latest_notif; /* latest revocation notification */
104247 };
104248 @@ -167,7 +167,7 @@ void __init avc_init(void)
104249 spin_lock_init(&avc_cache.slots_lock[i]);
104250 }
104251 atomic_set(&avc_cache.active_nodes, 0);
104252 - atomic_set(&avc_cache.lru_hint, 0);
104253 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
104254
104255 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
104256 0, SLAB_PANIC, NULL);
104257 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
104258 spinlock_t *lock;
104259
104260 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
104261 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104262 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104263 head = &avc_cache.slots[hvalue];
104264 lock = &avc_cache.slots_lock[hvalue];
104265
104266 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
104267 index e294b86..eda45c55 100644
104268 --- a/security/selinux/hooks.c
104269 +++ b/security/selinux/hooks.c
104270 @@ -95,8 +95,6 @@
104271 #include "audit.h"
104272 #include "avc_ss.h"
104273
104274 -extern struct security_operations *security_ops;
104275 -
104276 /* SECMARK reference count */
104277 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
104278
104279 @@ -5759,7 +5757,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
104280
104281 #endif
104282
104283 -static struct security_operations selinux_ops = {
104284 +static struct security_operations selinux_ops __read_only = {
104285 .name = "selinux",
104286
104287 .ptrace_access_check = selinux_ptrace_access_check,
104288 @@ -6112,6 +6110,9 @@ static void selinux_nf_ip_exit(void)
104289 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
104290 static int selinux_disabled;
104291
104292 +extern struct security_operations *security_ops;
104293 +extern struct security_operations default_security_ops;
104294 +
104295 int selinux_disable(void)
104296 {
104297 if (ss_initialized) {
104298 @@ -6129,7 +6130,9 @@ int selinux_disable(void)
104299 selinux_disabled = 1;
104300 selinux_enabled = 0;
104301
104302 - reset_security_ops();
104303 + pax_open_kernel();
104304 + security_ops = &default_security_ops;
104305 + pax_close_kernel();
104306
104307 /* Try to destroy the avc node cache */
104308 avc_disable();
104309 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
104310 index 9f05847..7933395 100644
104311 --- a/security/selinux/include/xfrm.h
104312 +++ b/security/selinux/include/xfrm.h
104313 @@ -46,7 +46,7 @@ static inline void selinux_xfrm_notify_policyload(void)
104314 {
104315 struct net *net;
104316
104317 - atomic_inc(&flow_cache_genid);
104318 + atomic_inc_unchecked(&flow_cache_genid);
104319 rtnl_lock();
104320 for_each_net(net)
104321 rt_genid_bump_all(net);
104322 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
104323 index 14f52be..7352368 100644
104324 --- a/security/smack/smack_lsm.c
104325 +++ b/security/smack/smack_lsm.c
104326 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
104327 return 0;
104328 }
104329
104330 -struct security_operations smack_ops = {
104331 +struct security_operations smack_ops __read_only = {
104332 .name = "smack",
104333
104334 .ptrace_access_check = smack_ptrace_access_check,
104335 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
104336 index 4003907..13a2b55 100644
104337 --- a/security/tomoyo/file.c
104338 +++ b/security/tomoyo/file.c
104339 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
104340 {
104341 struct tomoyo_request_info r;
104342 struct tomoyo_obj_info obj = {
104343 - .path1 = *path,
104344 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104345 };
104346 int error = -ENOMEM;
104347 struct tomoyo_path_info buf;
104348 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
104349 struct tomoyo_path_info buf;
104350 struct tomoyo_request_info r;
104351 struct tomoyo_obj_info obj = {
104352 - .path1 = *path,
104353 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104354 };
104355 int idx;
104356
104357 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
104358 {
104359 struct tomoyo_request_info r;
104360 struct tomoyo_obj_info obj = {
104361 - .path1 = *path,
104362 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104363 };
104364 int error;
104365 struct tomoyo_path_info buf;
104366 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
104367 {
104368 struct tomoyo_request_info r;
104369 struct tomoyo_obj_info obj = {
104370 - .path1 = *path,
104371 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104372 };
104373 int error = -ENOMEM;
104374 struct tomoyo_path_info buf;
104375 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
104376 struct tomoyo_path_info buf2;
104377 struct tomoyo_request_info r;
104378 struct tomoyo_obj_info obj = {
104379 - .path1 = *path1,
104380 - .path2 = *path2,
104381 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
104382 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
104383 };
104384 int idx;
104385
104386 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
104387 index 390c646..f2f8db3 100644
104388 --- a/security/tomoyo/mount.c
104389 +++ b/security/tomoyo/mount.c
104390 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
104391 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
104392 need_dev = -1; /* dev_name is a directory */
104393 } else {
104394 + if (!capable(CAP_SYS_ADMIN)) {
104395 + error = -EPERM;
104396 + goto out;
104397 + }
104398 fstype = get_fs_type(type);
104399 if (!fstype) {
104400 error = -ENODEV;
104401 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
104402 index f0b756e..8aa497b 100644
104403 --- a/security/tomoyo/tomoyo.c
104404 +++ b/security/tomoyo/tomoyo.c
104405 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
104406 */
104407 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
104408 {
104409 - struct path path = { mnt, dentry };
104410 + struct path path = { .mnt = mnt, .dentry = dentry };
104411 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
104412 }
104413
104414 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
104415 */
104416 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104417 {
104418 - struct path path = { parent->mnt, dentry };
104419 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104420 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
104421 }
104422
104423 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104424 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104425 umode_t mode)
104426 {
104427 - struct path path = { parent->mnt, dentry };
104428 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104429 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
104430 mode & S_IALLUGO);
104431 }
104432 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104433 */
104434 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104435 {
104436 - struct path path = { parent->mnt, dentry };
104437 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104438 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
104439 }
104440
104441 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104442 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104443 const char *old_name)
104444 {
104445 - struct path path = { parent->mnt, dentry };
104446 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104447 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
104448 }
104449
104450 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104451 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104452 umode_t mode, unsigned int dev)
104453 {
104454 - struct path path = { parent->mnt, dentry };
104455 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104456 int type = TOMOYO_TYPE_CREATE;
104457 const unsigned int perm = mode & S_IALLUGO;
104458
104459 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104460 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
104461 struct dentry *new_dentry)
104462 {
104463 - struct path path1 = { new_dir->mnt, old_dentry };
104464 - struct path path2 = { new_dir->mnt, new_dentry };
104465 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
104466 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
104467 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
104468 }
104469
104470 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
104471 struct path *new_parent,
104472 struct dentry *new_dentry)
104473 {
104474 - struct path path1 = { old_parent->mnt, old_dentry };
104475 - struct path path2 = { new_parent->mnt, new_dentry };
104476 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
104477 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
104478 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
104479 }
104480
104481 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
104482 */
104483 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
104484 {
104485 - struct path path = { mnt, mnt->mnt_root };
104486 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
104487 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
104488 }
104489
104490 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
104491 * tomoyo_security_ops is a "struct security_operations" which is used for
104492 * registering TOMOYO.
104493 */
104494 -static struct security_operations tomoyo_security_ops = {
104495 +static struct security_operations tomoyo_security_ops __read_only = {
104496 .name = "tomoyo",
104497 .cred_alloc_blank = tomoyo_cred_alloc_blank,
104498 .cred_prepare = tomoyo_cred_prepare,
104499 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
104500 index 20ef514..4182bed 100644
104501 --- a/security/yama/Kconfig
104502 +++ b/security/yama/Kconfig
104503 @@ -1,6 +1,6 @@
104504 config SECURITY_YAMA
104505 bool "Yama support"
104506 - depends on SECURITY
104507 + depends on SECURITY && !GRKERNSEC
104508 select SECURITYFS
104509 select SECURITY_PATH
104510 default n
104511 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
104512 index 13c88fbc..f8c115e 100644
104513 --- a/security/yama/yama_lsm.c
104514 +++ b/security/yama/yama_lsm.c
104515 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
104516 }
104517
104518 #ifndef CONFIG_SECURITY_YAMA_STACKED
104519 -static struct security_operations yama_ops = {
104520 +static struct security_operations yama_ops __read_only = {
104521 .name = "yama",
104522
104523 .ptrace_access_check = yama_ptrace_access_check,
104524 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
104525 #endif
104526
104527 #ifdef CONFIG_SYSCTL
104528 +static int zero __read_only;
104529 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
104530 +
104531 static int yama_dointvec_minmax(struct ctl_table *table, int write,
104532 void __user *buffer, size_t *lenp, loff_t *ppos)
104533 {
104534 - int rc;
104535 + ctl_table_no_const yama_table;
104536
104537 if (write && !capable(CAP_SYS_PTRACE))
104538 return -EPERM;
104539
104540 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
104541 - if (rc)
104542 - return rc;
104543 -
104544 + yama_table = *table;
104545 /* Lock the max value if it ever gets set. */
104546 - if (write && *(int *)table->data == *(int *)table->extra2)
104547 - table->extra1 = table->extra2;
104548 -
104549 - return rc;
104550 + if (ptrace_scope == max_scope)
104551 + yama_table.extra1 = &max_scope;
104552 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
104553 }
104554
104555 -static int zero;
104556 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
104557 -
104558 struct ctl_path yama_sysctl_path[] = {
104559 { .procname = "kernel", },
104560 { .procname = "yama", },
104561 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
104562 index 4cedc69..e59d8a3 100644
104563 --- a/sound/aoa/codecs/onyx.c
104564 +++ b/sound/aoa/codecs/onyx.c
104565 @@ -54,7 +54,7 @@ struct onyx {
104566 spdif_locked:1,
104567 analog_locked:1,
104568 original_mute:2;
104569 - int open_count;
104570 + local_t open_count;
104571 struct codec_info *codec_info;
104572
104573 /* mutex serializes concurrent access to the device
104574 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
104575 struct onyx *onyx = cii->codec_data;
104576
104577 mutex_lock(&onyx->mutex);
104578 - onyx->open_count++;
104579 + local_inc(&onyx->open_count);
104580 mutex_unlock(&onyx->mutex);
104581
104582 return 0;
104583 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
104584 struct onyx *onyx = cii->codec_data;
104585
104586 mutex_lock(&onyx->mutex);
104587 - onyx->open_count--;
104588 - if (!onyx->open_count)
104589 + if (local_dec_and_test(&onyx->open_count))
104590 onyx->spdif_locked = onyx->analog_locked = 0;
104591 mutex_unlock(&onyx->mutex);
104592
104593 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
104594 index ffd2025..df062c9 100644
104595 --- a/sound/aoa/codecs/onyx.h
104596 +++ b/sound/aoa/codecs/onyx.h
104597 @@ -11,6 +11,7 @@
104598 #include <linux/i2c.h>
104599 #include <asm/pmac_low_i2c.h>
104600 #include <asm/prom.h>
104601 +#include <asm/local.h>
104602
104603 /* PCM3052 register definitions */
104604
104605 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
104606 index 4c1cc51..16040040 100644
104607 --- a/sound/core/oss/pcm_oss.c
104608 +++ b/sound/core/oss/pcm_oss.c
104609 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
104610 if (in_kernel) {
104611 mm_segment_t fs;
104612 fs = snd_enter_user();
104613 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104614 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104615 snd_leave_user(fs);
104616 } else {
104617 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104618 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104619 }
104620 if (ret != -EPIPE && ret != -ESTRPIPE)
104621 break;
104622 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
104623 if (in_kernel) {
104624 mm_segment_t fs;
104625 fs = snd_enter_user();
104626 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104627 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104628 snd_leave_user(fs);
104629 } else {
104630 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104631 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104632 }
104633 if (ret == -EPIPE) {
104634 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
104635 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
104636 struct snd_pcm_plugin_channel *channels;
104637 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
104638 if (!in_kernel) {
104639 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
104640 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
104641 return -EFAULT;
104642 buf = runtime->oss.buffer;
104643 }
104644 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
104645 }
104646 } else {
104647 tmp = snd_pcm_oss_write2(substream,
104648 - (const char __force *)buf,
104649 + (const char __force_kernel *)buf,
104650 runtime->oss.period_bytes, 0);
104651 if (tmp <= 0)
104652 goto err;
104653 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
104654 struct snd_pcm_runtime *runtime = substream->runtime;
104655 snd_pcm_sframes_t frames, frames1;
104656 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
104657 - char __user *final_dst = (char __force __user *)buf;
104658 + char __user *final_dst = (char __force_user *)buf;
104659 if (runtime->oss.plugin_first) {
104660 struct snd_pcm_plugin_channel *channels;
104661 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
104662 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
104663 xfer += tmp;
104664 runtime->oss.buffer_used -= tmp;
104665 } else {
104666 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
104667 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
104668 runtime->oss.period_bytes, 0);
104669 if (tmp <= 0)
104670 goto err;
104671 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
104672 size1);
104673 size1 /= runtime->channels; /* frames */
104674 fs = snd_enter_user();
104675 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
104676 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
104677 snd_leave_user(fs);
104678 }
104679 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
104680 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
104681 index af49721..e85058e 100644
104682 --- a/sound/core/pcm_compat.c
104683 +++ b/sound/core/pcm_compat.c
104684 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
104685 int err;
104686
104687 fs = snd_enter_user();
104688 - err = snd_pcm_delay(substream, &delay);
104689 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
104690 snd_leave_user(fs);
104691 if (err < 0)
104692 return err;
104693 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
104694 index 01a5e05..c6bb425 100644
104695 --- a/sound/core/pcm_native.c
104696 +++ b/sound/core/pcm_native.c
104697 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
104698 switch (substream->stream) {
104699 case SNDRV_PCM_STREAM_PLAYBACK:
104700 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
104701 - (void __user *)arg);
104702 + (void __force_user *)arg);
104703 break;
104704 case SNDRV_PCM_STREAM_CAPTURE:
104705 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
104706 - (void __user *)arg);
104707 + (void __force_user *)arg);
104708 break;
104709 default:
104710 result = -EINVAL;
104711 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
104712 index 8d4d5e8..fdd0826 100644
104713 --- a/sound/core/seq/oss/seq_oss.c
104714 +++ b/sound/core/seq/oss/seq_oss.c
104715 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
104716 {
104717 int rc;
104718 static struct snd_seq_dev_ops ops = {
104719 - snd_seq_oss_synth_register,
104720 - snd_seq_oss_synth_unregister,
104721 + .init_device = snd_seq_oss_synth_register,
104722 + .free_device = snd_seq_oss_synth_unregister,
104723 };
104724
104725 snd_seq_autoload_lock();
104726 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
104727 index 040c60e..989a19a 100644
104728 --- a/sound/core/seq/seq_device.c
104729 +++ b/sound/core/seq/seq_device.c
104730 @@ -64,7 +64,7 @@ struct ops_list {
104731 int argsize; /* argument size */
104732
104733 /* operators */
104734 - struct snd_seq_dev_ops ops;
104735 + struct snd_seq_dev_ops *ops;
104736
104737 /* registered devices */
104738 struct list_head dev_list; /* list of devices */
104739 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
104740
104741 mutex_lock(&ops->reg_mutex);
104742 /* copy driver operators */
104743 - ops->ops = *entry;
104744 + ops->ops = entry;
104745 ops->driver |= DRIVER_LOADED;
104746 ops->argsize = argsize;
104747
104748 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
104749 dev->name, ops->id, ops->argsize, dev->argsize);
104750 return -EINVAL;
104751 }
104752 - if (ops->ops.init_device(dev) >= 0) {
104753 + if (ops->ops->init_device(dev) >= 0) {
104754 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
104755 ops->num_init_devices++;
104756 } else {
104757 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
104758 dev->name, ops->id, ops->argsize, dev->argsize);
104759 return -EINVAL;
104760 }
104761 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
104762 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
104763 dev->status = SNDRV_SEQ_DEVICE_FREE;
104764 dev->driver_data = NULL;
104765 ops->num_init_devices--;
104766 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
104767 index 64069db..3c6d392 100644
104768 --- a/sound/core/seq/seq_midi.c
104769 +++ b/sound/core/seq/seq_midi.c
104770 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
104771 static int __init alsa_seq_midi_init(void)
104772 {
104773 static struct snd_seq_dev_ops ops = {
104774 - snd_seq_midisynth_register_port,
104775 - snd_seq_midisynth_unregister_port,
104776 + .init_device = snd_seq_midisynth_register_port,
104777 + .free_device = snd_seq_midisynth_unregister_port,
104778 };
104779 memset(&synths, 0, sizeof(synths));
104780 snd_seq_autoload_lock();
104781 diff --git a/sound/core/sound.c b/sound/core/sound.c
104782 index 437c25e..cd040ab 100644
104783 --- a/sound/core/sound.c
104784 +++ b/sound/core/sound.c
104785 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
104786 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
104787 default: return;
104788 }
104789 - request_module(str);
104790 + request_module("%s", str);
104791 }
104792
104793 #endif /* modular kernel */
104794 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
104795 index 4e0dd22..7a1f32c 100644
104796 --- a/sound/drivers/mts64.c
104797 +++ b/sound/drivers/mts64.c
104798 @@ -29,6 +29,7 @@
104799 #include <sound/initval.h>
104800 #include <sound/rawmidi.h>
104801 #include <sound/control.h>
104802 +#include <asm/local.h>
104803
104804 #define CARD_NAME "Miditerminal 4140"
104805 #define DRIVER_NAME "MTS64"
104806 @@ -67,7 +68,7 @@ struct mts64 {
104807 struct pardevice *pardev;
104808 int pardev_claimed;
104809
104810 - int open_count;
104811 + local_t open_count;
104812 int current_midi_output_port;
104813 int current_midi_input_port;
104814 u8 mode[MTS64_NUM_INPUT_PORTS];
104815 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104816 {
104817 struct mts64 *mts = substream->rmidi->private_data;
104818
104819 - if (mts->open_count == 0) {
104820 + if (local_read(&mts->open_count) == 0) {
104821 /* We don't need a spinlock here, because this is just called
104822 if the device has not been opened before.
104823 So there aren't any IRQs from the device */
104824 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104825
104826 msleep(50);
104827 }
104828 - ++(mts->open_count);
104829 + local_inc(&mts->open_count);
104830
104831 return 0;
104832 }
104833 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104834 struct mts64 *mts = substream->rmidi->private_data;
104835 unsigned long flags;
104836
104837 - --(mts->open_count);
104838 - if (mts->open_count == 0) {
104839 + if (local_dec_return(&mts->open_count) == 0) {
104840 /* We need the spinlock_irqsave here because we can still
104841 have IRQs at this point */
104842 spin_lock_irqsave(&mts->lock, flags);
104843 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104844
104845 msleep(500);
104846
104847 - } else if (mts->open_count < 0)
104848 - mts->open_count = 0;
104849 + } else if (local_read(&mts->open_count) < 0)
104850 + local_set(&mts->open_count, 0);
104851
104852 return 0;
104853 }
104854 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
104855 index 6839953..7a0f4b9 100644
104856 --- a/sound/drivers/opl3/opl3_seq.c
104857 +++ b/sound/drivers/opl3/opl3_seq.c
104858 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
104859 {
104860 static struct snd_seq_dev_ops ops =
104861 {
104862 - snd_opl3_seq_new_device,
104863 - snd_opl3_seq_delete_device
104864 + .init_device = snd_opl3_seq_new_device,
104865 + .free_device = snd_opl3_seq_delete_device
104866 };
104867
104868 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
104869 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
104870 index b953fb4..1999c01 100644
104871 --- a/sound/drivers/opl4/opl4_lib.c
104872 +++ b/sound/drivers/opl4/opl4_lib.c
104873 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
104874 MODULE_DESCRIPTION("OPL4 driver");
104875 MODULE_LICENSE("GPL");
104876
104877 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
104878 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
104879 {
104880 int timeout = 10;
104881 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
104882 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
104883 index 9919769..d7de36c 100644
104884 --- a/sound/drivers/opl4/opl4_seq.c
104885 +++ b/sound/drivers/opl4/opl4_seq.c
104886 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
104887 static int __init alsa_opl4_synth_init(void)
104888 {
104889 static struct snd_seq_dev_ops ops = {
104890 - snd_opl4_seq_new_device,
104891 - snd_opl4_seq_delete_device
104892 + .init_device = snd_opl4_seq_new_device,
104893 + .free_device = snd_opl4_seq_delete_device
104894 };
104895
104896 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
104897 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
104898 index 991018d..8984740 100644
104899 --- a/sound/drivers/portman2x4.c
104900 +++ b/sound/drivers/portman2x4.c
104901 @@ -48,6 +48,7 @@
104902 #include <sound/initval.h>
104903 #include <sound/rawmidi.h>
104904 #include <sound/control.h>
104905 +#include <asm/local.h>
104906
104907 #define CARD_NAME "Portman 2x4"
104908 #define DRIVER_NAME "portman"
104909 @@ -85,7 +86,7 @@ struct portman {
104910 struct pardevice *pardev;
104911 int pardev_claimed;
104912
104913 - int open_count;
104914 + local_t open_count;
104915 int mode[PORTMAN_NUM_INPUT_PORTS];
104916 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
104917 };
104918 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
104919 index 9048777..2d8b1fc 100644
104920 --- a/sound/firewire/amdtp.c
104921 +++ b/sound/firewire/amdtp.c
104922 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
104923 ptr = s->pcm_buffer_pointer + data_blocks;
104924 if (ptr >= pcm->runtime->buffer_size)
104925 ptr -= pcm->runtime->buffer_size;
104926 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
104927 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
104928
104929 s->pcm_period_pointer += data_blocks;
104930 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
104931 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
104932 */
104933 void amdtp_out_stream_update(struct amdtp_out_stream *s)
104934 {
104935 - ACCESS_ONCE(s->source_node_id_field) =
104936 + ACCESS_ONCE_RW(s->source_node_id_field) =
104937 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
104938 }
104939 EXPORT_SYMBOL(amdtp_out_stream_update);
104940 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
104941 index 2746ecd..c35dedd 100644
104942 --- a/sound/firewire/amdtp.h
104943 +++ b/sound/firewire/amdtp.h
104944 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
104945 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
104946 struct snd_pcm_substream *pcm)
104947 {
104948 - ACCESS_ONCE(s->pcm) = pcm;
104949 + ACCESS_ONCE_RW(s->pcm) = pcm;
104950 }
104951
104952 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
104953 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
104954 index fd42e6b..c041971 100644
104955 --- a/sound/firewire/isight.c
104956 +++ b/sound/firewire/isight.c
104957 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
104958 ptr += count;
104959 if (ptr >= runtime->buffer_size)
104960 ptr -= runtime->buffer_size;
104961 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
104962 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
104963
104964 isight->period_counter += count;
104965 if (isight->period_counter >= runtime->period_size) {
104966 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
104967 if (err < 0)
104968 return err;
104969
104970 - ACCESS_ONCE(isight->pcm_active) = true;
104971 + ACCESS_ONCE_RW(isight->pcm_active) = true;
104972
104973 return 0;
104974 }
104975 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
104976 {
104977 struct isight *isight = substream->private_data;
104978
104979 - ACCESS_ONCE(isight->pcm_active) = false;
104980 + ACCESS_ONCE_RW(isight->pcm_active) = false;
104981
104982 mutex_lock(&isight->mutex);
104983 isight_stop_streaming(isight);
104984 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
104985
104986 switch (cmd) {
104987 case SNDRV_PCM_TRIGGER_START:
104988 - ACCESS_ONCE(isight->pcm_running) = true;
104989 + ACCESS_ONCE_RW(isight->pcm_running) = true;
104990 break;
104991 case SNDRV_PCM_TRIGGER_STOP:
104992 - ACCESS_ONCE(isight->pcm_running) = false;
104993 + ACCESS_ONCE_RW(isight->pcm_running) = false;
104994 break;
104995 default:
104996 return -EINVAL;
104997 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
104998 index 858023c..83b3d3c 100644
104999 --- a/sound/firewire/scs1x.c
105000 +++ b/sound/firewire/scs1x.c
105001 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
105002 {
105003 struct scs *scs = stream->rmidi->private_data;
105004
105005 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
105006 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
105007 if (up) {
105008 scs->output_idle = false;
105009 tasklet_schedule(&scs->tasklet);
105010 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
105011 {
105012 struct scs *scs = stream->rmidi->private_data;
105013
105014 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
105015 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
105016 }
105017
105018 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
105019 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
105020
105021 snd_card_disconnect(scs->card);
105022
105023 - ACCESS_ONCE(scs->output) = NULL;
105024 - ACCESS_ONCE(scs->input) = NULL;
105025 + ACCESS_ONCE_RW(scs->output) = NULL;
105026 + ACCESS_ONCE_RW(scs->input) = NULL;
105027
105028 wait_event(scs->idle_wait, scs->output_idle);
105029
105030 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
105031 index 4e3fcfb..ab45a9d 100644
105032 --- a/sound/isa/sb/emu8000_synth.c
105033 +++ b/sound/isa/sb/emu8000_synth.c
105034 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
105035 {
105036
105037 static struct snd_seq_dev_ops ops = {
105038 - snd_emu8000_new_device,
105039 - snd_emu8000_delete_device,
105040 + .init_device = snd_emu8000_new_device,
105041 + .free_device = snd_emu8000_delete_device,
105042 };
105043 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
105044 sizeof(struct snd_emu8000*));
105045 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
105046 index 048439a..3be9f6f 100644
105047 --- a/sound/oss/sb_audio.c
105048 +++ b/sound/oss/sb_audio.c
105049 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
105050 buf16 = (signed short *)(localbuf + localoffs);
105051 while (c)
105052 {
105053 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
105054 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
105055 if (copy_from_user(lbuf8,
105056 userbuf+useroffs + p,
105057 locallen))
105058 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
105059 index f851fd0..92576fb 100644
105060 --- a/sound/oss/swarm_cs4297a.c
105061 +++ b/sound/oss/swarm_cs4297a.c
105062 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
105063 {
105064 struct cs4297a_state *s;
105065 u32 pwr, id;
105066 - mm_segment_t fs;
105067 int rval;
105068 #ifndef CONFIG_BCM_CS4297A_CSWARM
105069 u64 cfg;
105070 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
105071 if (!rval) {
105072 char *sb1250_duart_present;
105073
105074 +#if 0
105075 + mm_segment_t fs;
105076 fs = get_fs();
105077 set_fs(KERNEL_DS);
105078 -#if 0
105079 val = SOUND_MASK_LINE;
105080 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
105081 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
105082 val = initvol[i].vol;
105083 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
105084 }
105085 + set_fs(fs);
105086 // cs4297a_write_ac97(s, 0x18, 0x0808);
105087 #else
105088 // cs4297a_write_ac97(s, 0x5e, 0x180);
105089 cs4297a_write_ac97(s, 0x02, 0x0808);
105090 cs4297a_write_ac97(s, 0x18, 0x0808);
105091 #endif
105092 - set_fs(fs);
105093
105094 list_add(&s->list, &cs4297a_devs);
105095
105096 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
105097 index 4c41c90..37f3631 100644
105098 --- a/sound/pci/emu10k1/emu10k1_synth.c
105099 +++ b/sound/pci/emu10k1/emu10k1_synth.c
105100 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
105101 {
105102
105103 static struct snd_seq_dev_ops ops = {
105104 - snd_emu10k1_synth_new_device,
105105 - snd_emu10k1_synth_delete_device,
105106 + .init_device = snd_emu10k1_synth_new_device,
105107 + .free_device = snd_emu10k1_synth_delete_device,
105108 };
105109 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
105110 sizeof(struct snd_emu10k1_synth_arg));
105111 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
105112 index dafcf82..dd9356f 100644
105113 --- a/sound/pci/hda/hda_codec.c
105114 +++ b/sound/pci/hda/hda_codec.c
105115 @@ -983,14 +983,10 @@ find_codec_preset(struct hda_codec *codec)
105116 mutex_unlock(&preset_mutex);
105117
105118 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
105119 - char name[32];
105120 if (!mod_requested)
105121 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
105122 - codec->vendor_id);
105123 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
105124 else
105125 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
105126 - (codec->vendor_id >> 16) & 0xffff);
105127 - request_module(name);
105128 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
105129 mod_requested++;
105130 goto again;
105131 }
105132 @@ -2739,7 +2735,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
105133 /* FIXME: set_fs() hack for obtaining user-space TLV data */
105134 mm_segment_t fs = get_fs();
105135 set_fs(get_ds());
105136 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
105137 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
105138 tlv = _tlv;
105139 set_fs(fs);
105140 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
105141 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
105142 index 4631a23..001ae57 100644
105143 --- a/sound/pci/ymfpci/ymfpci.h
105144 +++ b/sound/pci/ymfpci/ymfpci.h
105145 @@ -358,7 +358,7 @@ struct snd_ymfpci {
105146 spinlock_t reg_lock;
105147 spinlock_t voice_lock;
105148 wait_queue_head_t interrupt_sleep;
105149 - atomic_t interrupt_sleep_count;
105150 + atomic_unchecked_t interrupt_sleep_count;
105151 struct snd_info_entry *proc_entry;
105152 const struct firmware *dsp_microcode;
105153 const struct firmware *controller_microcode;
105154 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
105155 index d591c15..8cb8f94 100644
105156 --- a/sound/pci/ymfpci/ymfpci_main.c
105157 +++ b/sound/pci/ymfpci/ymfpci_main.c
105158 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
105159 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
105160 break;
105161 }
105162 - if (atomic_read(&chip->interrupt_sleep_count)) {
105163 - atomic_set(&chip->interrupt_sleep_count, 0);
105164 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
105165 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105166 wake_up(&chip->interrupt_sleep);
105167 }
105168 __end:
105169 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
105170 continue;
105171 init_waitqueue_entry(&wait, current);
105172 add_wait_queue(&chip->interrupt_sleep, &wait);
105173 - atomic_inc(&chip->interrupt_sleep_count);
105174 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
105175 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
105176 remove_wait_queue(&chip->interrupt_sleep, &wait);
105177 }
105178 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
105179 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
105180 spin_unlock(&chip->reg_lock);
105181
105182 - if (atomic_read(&chip->interrupt_sleep_count)) {
105183 - atomic_set(&chip->interrupt_sleep_count, 0);
105184 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
105185 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105186 wake_up(&chip->interrupt_sleep);
105187 }
105188 }
105189 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
105190 spin_lock_init(&chip->reg_lock);
105191 spin_lock_init(&chip->voice_lock);
105192 init_waitqueue_head(&chip->interrupt_sleep);
105193 - atomic_set(&chip->interrupt_sleep_count, 0);
105194 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
105195 chip->card = card;
105196 chip->pci = pci;
105197 chip->irq = -1;
105198 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
105199 index 5428a1f..474f651 100644
105200 --- a/sound/soc/fsl/fsl_ssi.c
105201 +++ b/sound/soc/fsl/fsl_ssi.c
105202 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
105203 {
105204 struct fsl_ssi_private *ssi_private;
105205 int ret = 0;
105206 - struct device_attribute *dev_attr = NULL;
105207 struct device_node *np = pdev->dev.of_node;
105208 const struct of_device_id *of_id;
105209 enum fsl_ssi_type hw_type;
105210 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
105211 &ssi_private->cpu_dai_drv, 1);
105212 if (ret) {
105213 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
105214 - goto error_dev;
105215 + goto error_clk;
105216 }
105217
105218 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
105219 @@ -1562,9 +1561,6 @@ error_pcm:
105220 error_dbgfs:
105221 snd_soc_unregister_component(&pdev->dev);
105222
105223 -error_dev:
105224 - device_remove_file(&pdev->dev, dev_attr);
105225 -
105226 error_clk:
105227 if (ssi_private->ssi_on_imx) {
105228 if (!IS_ERR(ssi_private->baudclk))
105229 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
105230 index fe1df50..09d3be6 100644
105231 --- a/sound/soc/soc-core.c
105232 +++ b/sound/soc/soc-core.c
105233 @@ -2254,8 +2254,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
105234 if (ret)
105235 return ret;
105236
105237 - ops->warm_reset = snd_soc_ac97_warm_reset;
105238 - ops->reset = snd_soc_ac97_reset;
105239 + pax_open_kernel();
105240 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
105241 + *(void **)&ops->reset = snd_soc_ac97_reset;
105242 + pax_close_kernel();
105243
105244 snd_ac97_rst_cfg = cfg;
105245 return 0;
105246 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
105247 index 7778b8e..3d619fc 100644
105248 --- a/sound/synth/emux/emux_seq.c
105249 +++ b/sound/synth/emux/emux_seq.c
105250 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
105251 * MIDI emulation operators
105252 */
105253 static struct snd_midi_op emux_ops = {
105254 - snd_emux_note_on,
105255 - snd_emux_note_off,
105256 - snd_emux_key_press,
105257 - snd_emux_terminate_note,
105258 - snd_emux_control,
105259 - snd_emux_nrpn,
105260 - snd_emux_sysex,
105261 + .note_on = snd_emux_note_on,
105262 + .note_off = snd_emux_note_off,
105263 + .key_press = snd_emux_key_press,
105264 + .note_terminate = snd_emux_terminate_note,
105265 + .control = snd_emux_control,
105266 + .nrpn = snd_emux_nrpn,
105267 + .sysex = snd_emux_sysex,
105268 };
105269
105270
105271 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
105272 new file mode 100644
105273 index 0000000..4c2c45c
105274 --- /dev/null
105275 +++ b/tools/gcc/.gitignore
105276 @@ -0,0 +1,2 @@
105277 +randomize_layout_seed.h
105278 +size_overflow_hash.h
105279 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
105280 new file mode 100644
105281 index 0000000..5ca9688
105282 --- /dev/null
105283 +++ b/tools/gcc/Makefile
105284 @@ -0,0 +1,62 @@
105285 +#CC := gcc
105286 +#PLUGIN_SOURCE_FILES := pax_plugin.c
105287 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
105288 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
105289 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
105290 +
105291 +ifeq ($(PLUGINCC),$(HOSTCC))
105292 +HOSTLIBS := hostlibs
105293 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
105294 +else
105295 +HOSTLIBS := hostcxxlibs
105296 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing
105297 +endif
105298 +
105299 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
105300 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
105301 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
105302 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
105303 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
105304 +$(HOSTLIBS)-y += colorize_plugin.so
105305 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
105306 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
105307 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
105308 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
105309 +
105310 +always := $($(HOSTLIBS)-y)
105311 +
105312 +constify_plugin-objs := constify_plugin.o
105313 +stackleak_plugin-objs := stackleak_plugin.o
105314 +kallocstat_plugin-objs := kallocstat_plugin.o
105315 +kernexec_plugin-objs := kernexec_plugin.o
105316 +checker_plugin-objs := checker_plugin.o
105317 +colorize_plugin-objs := colorize_plugin.o
105318 +size_overflow_plugin-objs := size_overflow_plugin.o
105319 +latent_entropy_plugin-objs := latent_entropy_plugin.o
105320 +structleak_plugin-objs := structleak_plugin.o
105321 +randomize_layout_plugin-objs := randomize_layout_plugin.o
105322 +
105323 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
105324 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
105325 +
105326 +quiet_cmd_build_size_overflow_hash = GENHASH $@
105327 + cmd_build_size_overflow_hash = \
105328 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
105329 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
105330 + $(call if_changed,build_size_overflow_hash)
105331 +
105332 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
105333 + cmd_build_size_overflow_hash_aux = \
105334 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
105335 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
105336 + $(call if_changed,build_size_overflow_hash_aux)
105337 +
105338 +targets += size_overflow_hash.h size_overflow_hash_aux.h
105339 +
105340 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
105341 + cmd_create_randomize_layout_seed = \
105342 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
105343 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
105344 + $(call if_changed,create_randomize_layout_seed)
105345 +
105346 +targets += size_overflow_hash.h randomize_layout_seed.h randomize_layout_hash.h
105347 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
105348 new file mode 100644
105349 index 0000000..5452feea
105350 --- /dev/null
105351 +++ b/tools/gcc/checker_plugin.c
105352 @@ -0,0 +1,150 @@
105353 +/*
105354 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105355 + * Licensed under the GPL v2
105356 + *
105357 + * Note: the choice of the license means that the compilation process is
105358 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105359 + * but for the kernel it doesn't matter since it doesn't link against
105360 + * any of the gcc libraries
105361 + *
105362 + * gcc plugin to implement various sparse (source code checker) features
105363 + *
105364 + * TODO:
105365 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
105366 + *
105367 + * BUGS:
105368 + * - none known
105369 + */
105370 +
105371 +#include "gcc-common.h"
105372 +
105373 +extern void c_register_addr_space (const char *str, addr_space_t as);
105374 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
105375 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
105376 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
105377 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
105378 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
105379 +
105380 +int plugin_is_GPL_compatible;
105381 +
105382 +static struct plugin_info checker_plugin_info = {
105383 + .version = "201304082245",
105384 + .help = NULL,
105385 +};
105386 +
105387 +#define ADDR_SPACE_KERNEL 0
105388 +#define ADDR_SPACE_FORCE_KERNEL 1
105389 +#define ADDR_SPACE_USER 2
105390 +#define ADDR_SPACE_FORCE_USER 3
105391 +#define ADDR_SPACE_IOMEM 0
105392 +#define ADDR_SPACE_FORCE_IOMEM 0
105393 +#define ADDR_SPACE_PERCPU 0
105394 +#define ADDR_SPACE_FORCE_PERCPU 0
105395 +#define ADDR_SPACE_RCU 0
105396 +#define ADDR_SPACE_FORCE_RCU 0
105397 +
105398 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
105399 +{
105400 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
105401 +}
105402 +
105403 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
105404 +{
105405 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
105406 +}
105407 +
105408 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
105409 +{
105410 + return default_addr_space_valid_pointer_mode(mode, as);
105411 +}
105412 +
105413 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
105414 +{
105415 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
105416 +}
105417 +
105418 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
105419 +{
105420 + return default_addr_space_legitimize_address(x, oldx, mode, as);
105421 +}
105422 +
105423 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
105424 +{
105425 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
105426 + return true;
105427 +
105428 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
105429 + return true;
105430 +
105431 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
105432 + return true;
105433 +
105434 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
105435 + return true;
105436 +
105437 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
105438 + return true;
105439 +
105440 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
105441 + return true;
105442 +
105443 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
105444 + return true;
105445 +
105446 + return subset == superset;
105447 +}
105448 +
105449 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
105450 +{
105451 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
105452 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
105453 +
105454 + return op;
105455 +}
105456 +
105457 +static void register_checker_address_spaces(void *event_data, void *data)
105458 +{
105459 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
105460 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
105461 + c_register_addr_space("__user", ADDR_SPACE_USER);
105462 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
105463 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
105464 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
105465 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
105466 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
105467 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
105468 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
105469 +
105470 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
105471 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
105472 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
105473 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
105474 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
105475 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
105476 + targetm.addr_space.convert = checker_addr_space_convert;
105477 +}
105478 +
105479 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105480 +{
105481 + const char * const plugin_name = plugin_info->base_name;
105482 + const int argc = plugin_info->argc;
105483 + const struct plugin_argument * const argv = plugin_info->argv;
105484 + int i;
105485 +
105486 + if (!plugin_default_version_check(version, &gcc_version)) {
105487 + error(G_("incompatible gcc/plugin versions"));
105488 + return 1;
105489 + }
105490 +
105491 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
105492 +
105493 + for (i = 0; i < argc; ++i)
105494 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105495 +
105496 + if (TARGET_64BIT == 0)
105497 + return 0;
105498 +
105499 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
105500 +
105501 + return 0;
105502 +}
105503 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
105504 new file mode 100644
105505 index 0000000..54461af
105506 --- /dev/null
105507 +++ b/tools/gcc/colorize_plugin.c
105508 @@ -0,0 +1,210 @@
105509 +/*
105510 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
105511 + * Licensed under the GPL v2
105512 + *
105513 + * Note: the choice of the license means that the compilation process is
105514 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105515 + * but for the kernel it doesn't matter since it doesn't link against
105516 + * any of the gcc libraries
105517 + *
105518 + * gcc plugin to colorize diagnostic output
105519 + *
105520 + */
105521 +
105522 +#include "gcc-common.h"
105523 +
105524 +int plugin_is_GPL_compatible;
105525 +
105526 +static struct plugin_info colorize_plugin_info = {
105527 + .version = "201404202350",
105528 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
105529 +};
105530 +
105531 +#define GREEN "\033[32m\033[K"
105532 +#define LIGHTGREEN "\033[1;32m\033[K"
105533 +#define YELLOW "\033[33m\033[K"
105534 +#define LIGHTYELLOW "\033[1;33m\033[K"
105535 +#define RED "\033[31m\033[K"
105536 +#define LIGHTRED "\033[1;31m\033[K"
105537 +#define BLUE "\033[34m\033[K"
105538 +#define LIGHTBLUE "\033[1;34m\033[K"
105539 +#define BRIGHT "\033[1;m\033[K"
105540 +#define NORMAL "\033[m\033[K"
105541 +
105542 +static diagnostic_starter_fn old_starter;
105543 +static diagnostic_finalizer_fn old_finalizer;
105544 +
105545 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105546 +{
105547 + const char *color;
105548 + char *newprefix;
105549 +
105550 + switch (diagnostic->kind) {
105551 + case DK_NOTE:
105552 + color = LIGHTBLUE;
105553 + break;
105554 +
105555 + case DK_PEDWARN:
105556 + case DK_WARNING:
105557 + color = LIGHTYELLOW;
105558 + break;
105559 +
105560 + case DK_ERROR:
105561 + case DK_FATAL:
105562 + case DK_ICE:
105563 + case DK_PERMERROR:
105564 + case DK_SORRY:
105565 + color = LIGHTRED;
105566 + break;
105567 +
105568 + default:
105569 + color = NORMAL;
105570 + }
105571 +
105572 + old_starter(context, diagnostic);
105573 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
105574 + return;
105575 + pp_destroy_prefix(context->printer);
105576 + pp_set_prefix(context->printer, newprefix);
105577 +}
105578 +
105579 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105580 +{
105581 + old_finalizer(context, diagnostic);
105582 +}
105583 +
105584 +static void colorize_arm(void)
105585 +{
105586 + old_starter = diagnostic_starter(global_dc);
105587 + old_finalizer = diagnostic_finalizer(global_dc);
105588 +
105589 + diagnostic_starter(global_dc) = start_colorize;
105590 + diagnostic_finalizer(global_dc) = finalize_colorize;
105591 +}
105592 +
105593 +static unsigned int execute_colorize_rearm(void)
105594 +{
105595 + if (diagnostic_starter(global_dc) == start_colorize)
105596 + return 0;
105597 +
105598 + colorize_arm();
105599 + return 0;
105600 +}
105601 +
105602 +#if BUILDING_GCC_VERSION >= 4009
105603 +static const struct pass_data colorize_rearm_pass_data = {
105604 +#else
105605 +struct simple_ipa_opt_pass colorize_rearm_pass = {
105606 + .pass = {
105607 +#endif
105608 + .type = SIMPLE_IPA_PASS,
105609 + .name = "colorize_rearm",
105610 +#if BUILDING_GCC_VERSION >= 4008
105611 + .optinfo_flags = OPTGROUP_NONE,
105612 +#endif
105613 +#if BUILDING_GCC_VERSION >= 4009
105614 + .has_gate = false,
105615 + .has_execute = true,
105616 +#else
105617 + .gate = NULL,
105618 + .execute = execute_colorize_rearm,
105619 + .sub = NULL,
105620 + .next = NULL,
105621 + .static_pass_number = 0,
105622 +#endif
105623 + .tv_id = TV_NONE,
105624 + .properties_required = 0,
105625 + .properties_provided = 0,
105626 + .properties_destroyed = 0,
105627 + .todo_flags_start = 0,
105628 + .todo_flags_finish = 0
105629 +#if BUILDING_GCC_VERSION < 4009
105630 + }
105631 +#endif
105632 +};
105633 +
105634 +#if BUILDING_GCC_VERSION >= 4009
105635 +namespace {
105636 +class colorize_rearm_pass : public simple_ipa_opt_pass {
105637 +public:
105638 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
105639 + unsigned int execute() { return execute_colorize_rearm(); }
105640 +};
105641 +}
105642 +
105643 +static opt_pass *make_colorize_rearm_pass(void)
105644 +{
105645 + return new colorize_rearm_pass();
105646 +}
105647 +#else
105648 +static struct opt_pass *make_colorize_rearm_pass(void)
105649 +{
105650 + return &colorize_rearm_pass.pass;
105651 +}
105652 +#endif
105653 +
105654 +static void colorize_start_unit(void *gcc_data, void *user_data)
105655 +{
105656 + colorize_arm();
105657 +}
105658 +
105659 +static bool should_colorize(void)
105660 +{
105661 +#if BUILDING_GCC_VERSION >= 4009
105662 + return false;
105663 +#else
105664 + char const *t = getenv("TERM");
105665 +
105666 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
105667 +#endif
105668 +}
105669 +
105670 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105671 +{
105672 + const char * const plugin_name = plugin_info->base_name;
105673 + const int argc = plugin_info->argc;
105674 + const struct plugin_argument * const argv = plugin_info->argv;
105675 + int i;
105676 + struct register_pass_info colorize_rearm_pass_info;
105677 + bool colorize;
105678 +
105679 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
105680 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
105681 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
105682 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105683 +
105684 + if (!plugin_default_version_check(version, &gcc_version)) {
105685 + error(G_("incompatible gcc/plugin versions"));
105686 + return 1;
105687 + }
105688 +
105689 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
105690 +
105691 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
105692 +
105693 + for (i = 0; i < argc; ++i) {
105694 + if (!strcmp(argv[i].key, "color")) {
105695 + if (!argv[i].value) {
105696 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105697 + continue;
105698 + }
105699 + if (!strcmp(argv[i].value, "always"))
105700 + colorize = true;
105701 + else if (!strcmp(argv[i].value, "never"))
105702 + colorize = false;
105703 + else if (!strcmp(argv[i].value, "auto"))
105704 + colorize = should_colorize();
105705 + else
105706 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
105707 + continue;
105708 + }
105709 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105710 + }
105711 +
105712 + if (colorize) {
105713 + // TODO: parse GCC_COLORS as used by gcc 4.9+
105714 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
105715 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
105716 + }
105717 + return 0;
105718 +}
105719 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
105720 new file mode 100644
105721 index 0000000..82bc5a8
105722 --- /dev/null
105723 +++ b/tools/gcc/constify_plugin.c
105724 @@ -0,0 +1,557 @@
105725 +/*
105726 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
105727 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
105728 + * Licensed under the GPL v2, or (at your option) v3
105729 + *
105730 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
105731 + *
105732 + * Homepage:
105733 + * http://www.grsecurity.net/~ephox/const_plugin/
105734 + *
105735 + * Usage:
105736 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
105737 + * $ gcc -fplugin=constify_plugin.so test.c -O2
105738 + */
105739 +
105740 +#include "gcc-common.h"
105741 +
105742 +// unused C type flag in all versions 4.5-4.9
105743 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
105744 +
105745 +int plugin_is_GPL_compatible;
105746 +
105747 +static struct plugin_info const_plugin_info = {
105748 + .version = "201401270210",
105749 + .help = "no-constify\tturn off constification\n",
105750 +};
105751 +
105752 +typedef struct {
105753 + bool has_fptr_field;
105754 + bool has_writable_field;
105755 + bool has_do_const_field;
105756 + bool has_no_const_field;
105757 +} constify_info;
105758 +
105759 +static const_tree get_field_type(const_tree field)
105760 +{
105761 + return strip_array_types(TREE_TYPE(field));
105762 +}
105763 +
105764 +static bool is_fptr(const_tree field)
105765 +{
105766 + const_tree ptr = get_field_type(field);
105767 +
105768 + if (TREE_CODE(ptr) != POINTER_TYPE)
105769 + return false;
105770 +
105771 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
105772 +}
105773 +
105774 +/*
105775 + * determine whether the given structure type meets the requirements for automatic constification,
105776 + * including the constification attributes on nested structure types
105777 + */
105778 +static void constifiable(const_tree node, constify_info *cinfo)
105779 +{
105780 + const_tree field;
105781 +
105782 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105783 +
105784 + // e.g., pointer to structure fields while still constructing the structure type
105785 + if (TYPE_FIELDS(node) == NULL_TREE)
105786 + return;
105787 +
105788 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
105789 + const_tree type = get_field_type(field);
105790 + enum tree_code code = TREE_CODE(type);
105791 +
105792 + if (node == type)
105793 + continue;
105794 +
105795 + if (is_fptr(field))
105796 + cinfo->has_fptr_field = true;
105797 + else if (!TREE_READONLY(field))
105798 + cinfo->has_writable_field = true;
105799 +
105800 + if (code == RECORD_TYPE || code == UNION_TYPE) {
105801 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105802 + cinfo->has_do_const_field = true;
105803 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
105804 + cinfo->has_no_const_field = true;
105805 + else
105806 + constifiable(type, cinfo);
105807 + }
105808 + }
105809 +}
105810 +
105811 +static bool constified(const_tree node)
105812 +{
105813 + constify_info cinfo = {
105814 + .has_fptr_field = false,
105815 + .has_writable_field = false,
105816 + .has_do_const_field = false,
105817 + .has_no_const_field = false
105818 + };
105819 +
105820 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105821 +
105822 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
105823 +// gcc_assert(!TYPE_READONLY(node));
105824 + return false;
105825 + }
105826 +
105827 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
105828 + gcc_assert(TYPE_READONLY(node));
105829 + return true;
105830 + }
105831 +
105832 + constifiable(node, &cinfo);
105833 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
105834 + return false;
105835 +
105836 + return TYPE_READONLY(node);
105837 +}
105838 +
105839 +static void deconstify_tree(tree node);
105840 +
105841 +static void deconstify_type(tree type)
105842 +{
105843 + tree field;
105844 +
105845 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
105846 +
105847 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
105848 + const_tree fieldtype = get_field_type(field);
105849 +
105850 + // special case handling of simple ptr-to-same-array-type members
105851 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
105852 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
105853 +
105854 + if (TREE_TYPE(TREE_TYPE(field)) == type)
105855 + continue;
105856 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
105857 + continue;
105858 + if (!constified(ptrtype))
105859 + continue;
105860 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
105861 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
105862 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
105863 + }
105864 + continue;
105865 + }
105866 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
105867 + continue;
105868 + if (!constified(fieldtype))
105869 + continue;
105870 +
105871 + deconstify_tree(field);
105872 + TREE_READONLY(field) = 0;
105873 + }
105874 + TYPE_READONLY(type) = 0;
105875 + C_TYPE_FIELDS_READONLY(type) = 0;
105876 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105877 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105878 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
105879 + }
105880 +}
105881 +
105882 +static void deconstify_tree(tree node)
105883 +{
105884 + tree old_type, new_type, field;
105885 +
105886 + old_type = TREE_TYPE(node);
105887 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
105888 + node = TREE_TYPE(node) = copy_node(old_type);
105889 + old_type = TREE_TYPE(old_type);
105890 + }
105891 +
105892 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
105893 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
105894 +
105895 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
105896 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
105897 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
105898 + DECL_FIELD_CONTEXT(field) = new_type;
105899 +
105900 + deconstify_type(new_type);
105901 +
105902 + TREE_TYPE(node) = new_type;
105903 +}
105904 +
105905 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105906 +{
105907 + tree type;
105908 + constify_info cinfo = {
105909 + .has_fptr_field = false,
105910 + .has_writable_field = false,
105911 + .has_do_const_field = false,
105912 + .has_no_const_field = false
105913 + };
105914 +
105915 + *no_add_attrs = true;
105916 + if (TREE_CODE(*node) == FUNCTION_DECL) {
105917 + error("%qE attribute does not apply to functions (%qF)", name, *node);
105918 + return NULL_TREE;
105919 + }
105920 +
105921 + if (TREE_CODE(*node) == PARM_DECL) {
105922 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
105923 + return NULL_TREE;
105924 + }
105925 +
105926 + if (TREE_CODE(*node) == VAR_DECL) {
105927 + error("%qE attribute does not apply to variables (%qD)", name, *node);
105928 + return NULL_TREE;
105929 + }
105930 +
105931 + if (TYPE_P(*node)) {
105932 + type = *node;
105933 + } else {
105934 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
105935 + type = TREE_TYPE(*node);
105936 + }
105937 +
105938 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
105939 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
105940 + return NULL_TREE;
105941 + }
105942 +
105943 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
105944 + error("%qE attribute is already applied to the type %qT", name, type);
105945 + return NULL_TREE;
105946 + }
105947 +
105948 + if (TYPE_P(*node)) {
105949 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105950 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
105951 + else
105952 + *no_add_attrs = false;
105953 + return NULL_TREE;
105954 + }
105955 +
105956 + constifiable(type, &cinfo);
105957 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105958 + deconstify_tree(*node);
105959 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
105960 + return NULL_TREE;
105961 + }
105962 +
105963 + error("%qE attribute used on type %qT that is not constified", name, type);
105964 + return NULL_TREE;
105965 +}
105966 +
105967 +static void constify_type(tree type)
105968 +{
105969 + TYPE_READONLY(type) = 1;
105970 + C_TYPE_FIELDS_READONLY(type) = 1;
105971 + TYPE_CONSTIFY_VISITED(type) = 1;
105972 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105973 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
105974 +}
105975 +
105976 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105977 +{
105978 + *no_add_attrs = true;
105979 + if (!TYPE_P(*node)) {
105980 + error("%qE attribute applies to types only (%qD)", name, *node);
105981 + return NULL_TREE;
105982 + }
105983 +
105984 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
105985 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
105986 + return NULL_TREE;
105987 + }
105988 +
105989 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
105990 + error("%qE attribute used on %qT is already applied to the type", name, *node);
105991 + return NULL_TREE;
105992 + }
105993 +
105994 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
105995 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
105996 + return NULL_TREE;
105997 + }
105998 +
105999 + *no_add_attrs = false;
106000 + return NULL_TREE;
106001 +}
106002 +
106003 +static struct attribute_spec no_const_attr = {
106004 + .name = "no_const",
106005 + .min_length = 0,
106006 + .max_length = 0,
106007 + .decl_required = false,
106008 + .type_required = false,
106009 + .function_type_required = false,
106010 + .handler = handle_no_const_attribute,
106011 +#if BUILDING_GCC_VERSION >= 4007
106012 + .affects_type_identity = true
106013 +#endif
106014 +};
106015 +
106016 +static struct attribute_spec do_const_attr = {
106017 + .name = "do_const",
106018 + .min_length = 0,
106019 + .max_length = 0,
106020 + .decl_required = false,
106021 + .type_required = false,
106022 + .function_type_required = false,
106023 + .handler = handle_do_const_attribute,
106024 +#if BUILDING_GCC_VERSION >= 4007
106025 + .affects_type_identity = true
106026 +#endif
106027 +};
106028 +
106029 +static void register_attributes(void *event_data, void *data)
106030 +{
106031 + register_attribute(&no_const_attr);
106032 + register_attribute(&do_const_attr);
106033 +}
106034 +
106035 +static void finish_type(void *event_data, void *data)
106036 +{
106037 + tree type = (tree)event_data;
106038 + constify_info cinfo = {
106039 + .has_fptr_field = false,
106040 + .has_writable_field = false,
106041 + .has_do_const_field = false,
106042 + .has_no_const_field = false
106043 + };
106044 +
106045 + if (type == NULL_TREE || type == error_mark_node)
106046 + return;
106047 +
106048 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
106049 + return;
106050 +
106051 + constifiable(type, &cinfo);
106052 +
106053 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
106054 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
106055 + deconstify_type(type);
106056 + TYPE_CONSTIFY_VISITED(type) = 1;
106057 + } else
106058 + error("'no_const' attribute used on type %qT that is not constified", type);
106059 + return;
106060 + }
106061 +
106062 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
106063 + if (!cinfo.has_writable_field) {
106064 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
106065 + return;
106066 + }
106067 + constify_type(type);
106068 + return;
106069 + }
106070 +
106071 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
106072 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
106073 + error("'do_const' attribute used on type %qT that is constified", type);
106074 + return;
106075 + }
106076 + constify_type(type);
106077 + return;
106078 + }
106079 +
106080 + deconstify_type(type);
106081 + TYPE_CONSTIFY_VISITED(type) = 1;
106082 +}
106083 +
106084 +static void check_global_variables(void *event_data, void *data)
106085 +{
106086 +#if BUILDING_GCC_VERSION >= 4009
106087 + varpool_node *node;
106088 +#else
106089 + struct varpool_node *node;
106090 +#endif
106091 +
106092 + FOR_EACH_VARIABLE(node) {
106093 + tree var = NODE_DECL(node);
106094 + tree type = TREE_TYPE(var);
106095 +
106096 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106097 + continue;
106098 +
106099 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
106100 + continue;
106101 +
106102 + if (!TYPE_CONSTIFY_VISITED(type))
106103 + continue;
106104 +
106105 + if (DECL_EXTERNAL(var))
106106 + continue;
106107 +
106108 + if (DECL_INITIAL(var))
106109 + continue;
106110 +
106111 + // this works around a gcc bug/feature where uninitialized globals
106112 + // are moved into the .bss section regardless of any constification
106113 + DECL_INITIAL(var) = build_constructor(type, NULL);
106114 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
106115 + }
106116 +}
106117 +
106118 +static unsigned int check_local_variables(void)
106119 +{
106120 + unsigned int ret = 0;
106121 + tree var;
106122 +
106123 + unsigned int i;
106124 +
106125 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
106126 + tree type = TREE_TYPE(var);
106127 +
106128 + gcc_assert(DECL_P(var));
106129 + if (is_global_var(var))
106130 + continue;
106131 +
106132 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106133 + continue;
106134 +
106135 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
106136 + continue;
106137 +
106138 + if (!TYPE_CONSTIFY_VISITED(type))
106139 + continue;
106140 +
106141 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
106142 + ret = 1;
106143 + }
106144 + return ret;
106145 +}
106146 +
106147 +#if BUILDING_GCC_VERSION >= 4009
106148 +static const struct pass_data check_local_variables_pass_data = {
106149 +#else
106150 +static struct gimple_opt_pass check_local_variables_pass = {
106151 + .pass = {
106152 +#endif
106153 + .type = GIMPLE_PASS,
106154 + .name = "check_local_variables",
106155 +#if BUILDING_GCC_VERSION >= 4008
106156 + .optinfo_flags = OPTGROUP_NONE,
106157 +#endif
106158 +#if BUILDING_GCC_VERSION >= 4009
106159 + .has_gate = false,
106160 + .has_execute = true,
106161 +#else
106162 + .gate = NULL,
106163 + .execute = check_local_variables,
106164 + .sub = NULL,
106165 + .next = NULL,
106166 + .static_pass_number = 0,
106167 +#endif
106168 + .tv_id = TV_NONE,
106169 + .properties_required = 0,
106170 + .properties_provided = 0,
106171 + .properties_destroyed = 0,
106172 + .todo_flags_start = 0,
106173 + .todo_flags_finish = 0
106174 +#if BUILDING_GCC_VERSION < 4009
106175 + }
106176 +#endif
106177 +};
106178 +
106179 +#if BUILDING_GCC_VERSION >= 4009
106180 +namespace {
106181 +class check_local_variables_pass : public gimple_opt_pass {
106182 +public:
106183 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
106184 + unsigned int execute() { return check_local_variables(); }
106185 +};
106186 +}
106187 +
106188 +static opt_pass *make_check_local_variables_pass(void)
106189 +{
106190 + return new check_local_variables_pass();
106191 +}
106192 +#else
106193 +static struct opt_pass *make_check_local_variables_pass(void)
106194 +{
106195 + return &check_local_variables_pass.pass;
106196 +}
106197 +#endif
106198 +
106199 +static struct {
106200 + const char *name;
106201 + const char *asm_op;
106202 +} sections[] = {
106203 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
106204 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
106205 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
106206 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
106207 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
106208 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
106209 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
106210 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
106211 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
106212 +};
106213 +
106214 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
106215 +
106216 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
106217 +{
106218 + size_t i;
106219 +
106220 + for (i = 0; i < ARRAY_SIZE(sections); i++)
106221 + if (!strcmp(sections[i].name, name))
106222 + return 0;
106223 + return old_section_type_flags(decl, name, reloc);
106224 +}
106225 +
106226 +static void constify_start_unit(void *gcc_data, void *user_data)
106227 +{
106228 +// size_t i;
106229 +
106230 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
106231 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
106232 +// sections[i].section = get_section(sections[i].name, 0, NULL);
106233 +
106234 + old_section_type_flags = targetm.section_type_flags;
106235 + targetm.section_type_flags = constify_section_type_flags;
106236 +}
106237 +
106238 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106239 +{
106240 + const char * const plugin_name = plugin_info->base_name;
106241 + const int argc = plugin_info->argc;
106242 + const struct plugin_argument * const argv = plugin_info->argv;
106243 + int i;
106244 + bool constify = true;
106245 +
106246 + struct register_pass_info check_local_variables_pass_info;
106247 +
106248 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
106249 + check_local_variables_pass_info.reference_pass_name = "ssa";
106250 + check_local_variables_pass_info.ref_pass_instance_number = 1;
106251 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106252 +
106253 + if (!plugin_default_version_check(version, &gcc_version)) {
106254 + error(G_("incompatible gcc/plugin versions"));
106255 + return 1;
106256 + }
106257 +
106258 + for (i = 0; i < argc; ++i) {
106259 + if (!(strcmp(argv[i].key, "no-constify"))) {
106260 + constify = false;
106261 + continue;
106262 + }
106263 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106264 + }
106265 +
106266 + if (strcmp(lang_hooks.name, "GNU C")) {
106267 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
106268 + constify = false;
106269 + }
106270 +
106271 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
106272 + if (constify) {
106273 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
106274 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
106275 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
106276 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
106277 + }
106278 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106279 +
106280 + return 0;
106281 +}
106282 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
106283 new file mode 100644
106284 index 0000000..8af3693
106285 --- /dev/null
106286 +++ b/tools/gcc/gcc-common.h
106287 @@ -0,0 +1,287 @@
106288 +#ifndef GCC_COMMON_H_INCLUDED
106289 +#define GCC_COMMON_H_INCLUDED
106290 +
106291 +#include "plugin.h"
106292 +#include "bversion.h"
106293 +#include "plugin-version.h"
106294 +#include "config.h"
106295 +#include "system.h"
106296 +#include "coretypes.h"
106297 +#include "tm.h"
106298 +#include "line-map.h"
106299 +#include "input.h"
106300 +#include "tree.h"
106301 +
106302 +#include "tree-inline.h"
106303 +#include "version.h"
106304 +#include "rtl.h"
106305 +#include "tm_p.h"
106306 +#include "flags.h"
106307 +//#include "insn-attr.h"
106308 +//#include "insn-config.h"
106309 +//#include "insn-flags.h"
106310 +#include "hard-reg-set.h"
106311 +//#include "recog.h"
106312 +#include "output.h"
106313 +#include "except.h"
106314 +#include "function.h"
106315 +#include "toplev.h"
106316 +//#include "expr.h"
106317 +#include "basic-block.h"
106318 +#include "intl.h"
106319 +#include "ggc.h"
106320 +//#include "regs.h"
106321 +#include "timevar.h"
106322 +
106323 +#include "params.h"
106324 +#include "pointer-set.h"
106325 +#include "emit-rtl.h"
106326 +//#include "reload.h"
106327 +//#include "ira.h"
106328 +//#include "dwarf2asm.h"
106329 +#include "debug.h"
106330 +#include "target.h"
106331 +#include "langhooks.h"
106332 +#include "cfgloop.h"
106333 +//#include "hosthooks.h"
106334 +#include "cgraph.h"
106335 +#include "opts.h"
106336 +//#include "coverage.h"
106337 +//#include "value-prof.h"
106338 +
106339 +#if BUILDING_GCC_VERSION >= 4007
106340 +#include "tree-pretty-print.h"
106341 +#include "gimple-pretty-print.h"
106342 +#include "c-tree.h"
106343 +//#include "alloc-pool.h"
106344 +#endif
106345 +
106346 +#if BUILDING_GCC_VERSION <= 4008
106347 +#include "tree-flow.h"
106348 +#else
106349 +#include "tree-cfgcleanup.h"
106350 +#endif
106351 +
106352 +#include "diagnostic.h"
106353 +//#include "tree-diagnostic.h"
106354 +#include "tree-dump.h"
106355 +#include "tree-pass.h"
106356 +//#include "df.h"
106357 +#include "predict.h"
106358 +//#include "lto-streamer.h"
106359 +#include "ipa-utils.h"
106360 +
106361 +#if BUILDING_GCC_VERSION >= 4009
106362 +#include "varasm.h"
106363 +#include "stor-layout.h"
106364 +#include "internal-fn.h"
106365 +#include "gimple-expr.h"
106366 +//#include "diagnostic-color.h"
106367 +#include "context.h"
106368 +#include "tree-ssa-alias.h"
106369 +#include "stringpool.h"
106370 +#include "tree-ssanames.h"
106371 +#include "print-tree.h"
106372 +#include "tree-eh.h"
106373 +#endif
106374 +
106375 +#include "gimple.h"
106376 +
106377 +#if BUILDING_GCC_VERSION >= 4009
106378 +#include "tree-ssa-operands.h"
106379 +#include "tree-phinodes.h"
106380 +#include "tree-cfg.h"
106381 +#include "gimple-iterator.h"
106382 +#include "gimple-ssa.h"
106383 +#include "ssa-iterators.h"
106384 +#endif
106385 +
106386 +//#include "expr.h" where are you...
106387 +extern rtx emit_move_insn(rtx x, rtx y);
106388 +
106389 +// missing from basic_block.h...
106390 +extern void debug_dominance_info(enum cdi_direction dir);
106391 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
106392 +
106393 +#define __unused __attribute__((__unused__))
106394 +
106395 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
106396 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
106397 +
106398 +#if BUILDING_GCC_VERSION == 4005
106399 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
106400 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
106401 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
106402 +#define TODO_rebuild_cgraph_edges 0
106403 +
106404 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
106405 +{
106406 + tree fndecl;
106407 +
106408 + if (!is_gimple_call(stmt))
106409 + return false;
106410 + fndecl = gimple_call_fndecl(stmt);
106411 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
106412 + return false;
106413 +// print_node(stderr, "pax", fndecl, 4);
106414 + return DECL_FUNCTION_CODE(fndecl) == code;
106415 +}
106416 +
106417 +static inline bool is_simple_builtin(tree decl)
106418 +{
106419 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
106420 + return false;
106421 +
106422 + switch (DECL_FUNCTION_CODE(decl)) {
106423 + /* Builtins that expand to constants. */
106424 + case BUILT_IN_CONSTANT_P:
106425 + case BUILT_IN_EXPECT:
106426 + case BUILT_IN_OBJECT_SIZE:
106427 + case BUILT_IN_UNREACHABLE:
106428 + /* Simple register moves or loads from stack. */
106429 + case BUILT_IN_RETURN_ADDRESS:
106430 + case BUILT_IN_EXTRACT_RETURN_ADDR:
106431 + case BUILT_IN_FROB_RETURN_ADDR:
106432 + case BUILT_IN_RETURN:
106433 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
106434 + case BUILT_IN_FRAME_ADDRESS:
106435 + case BUILT_IN_VA_END:
106436 + case BUILT_IN_STACK_SAVE:
106437 + case BUILT_IN_STACK_RESTORE:
106438 + /* Exception state returns or moves registers around. */
106439 + case BUILT_IN_EH_FILTER:
106440 + case BUILT_IN_EH_POINTER:
106441 + case BUILT_IN_EH_COPY_VALUES:
106442 + return true;
106443 +
106444 + default:
106445 + return false;
106446 + }
106447 +}
106448 +#endif
106449 +
106450 +#if BUILDING_GCC_VERSION <= 4006
106451 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
106452 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
106453 +
106454 +// should come from c-tree.h if only it were installed for gcc 4.5...
106455 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
106456 +
106457 +#define get_random_seed(noinit) ({ \
106458 + unsigned HOST_WIDE_INT seed; \
106459 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
106460 + seed * seed; })
106461 +
106462 +static inline bool gimple_clobber_p(gimple s)
106463 +{
106464 + return false;
106465 +}
106466 +
106467 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
106468 +{
106469 + return implicit_built_in_decls[fncode];
106470 +}
106471 +
106472 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
106473 +{
106474 + struct cgraph_node *node = cgraph_get_node(decl);
106475 +
106476 + return node ? node : cgraph_node(decl);
106477 +}
106478 +
106479 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
106480 +{
106481 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
106482 +}
106483 +
106484 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
106485 +{
106486 + struct cgraph_node *node;
106487 +
106488 + for (node = cgraph_nodes; node; node = node->next)
106489 + if (cgraph_function_with_gimple_body_p(node))
106490 + return node;
106491 + return NULL;
106492 +}
106493 +
106494 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
106495 +{
106496 + for (node = node->next; node; node = node->next)
106497 + if (cgraph_function_with_gimple_body_p(node))
106498 + return node;
106499 + return NULL;
106500 +}
106501 +
106502 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
106503 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
106504 + (node) = cgraph_next_function_with_gimple_body(node))
106505 +#endif
106506 +
106507 +#if BUILDING_GCC_VERSION == 4006
106508 +extern void debug_gimple_stmt(gimple);
106509 +extern void debug_gimple_seq(gimple_seq);
106510 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
106511 +extern void print_gimple_stmt(FILE *, gimple, int, int);
106512 +extern void print_gimple_expr(FILE *, gimple, int, int);
106513 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
106514 +#endif
106515 +
106516 +#if BUILDING_GCC_VERSION <= 4007
106517 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
106518 +#define PROP_loops 0
106519 +
106520 +static inline int bb_loop_depth(const_basic_block bb)
106521 +{
106522 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
106523 +}
106524 +
106525 +static inline bool gimple_store_p(gimple gs)
106526 +{
106527 + tree lhs = gimple_get_lhs(gs);
106528 + return lhs && !is_gimple_reg(lhs);
106529 +}
106530 +#endif
106531 +
106532 +#if BUILDING_GCC_VERSION >= 4007
106533 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
106534 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
106535 +#endif
106536 +
106537 +#if BUILDING_GCC_VERSION <= 4008
106538 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
106539 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
106540 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
106541 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
106542 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
106543 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
106544 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
106545 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
106546 +
106547 +static inline const char *get_tree_code_name(enum tree_code code)
106548 +{
106549 + gcc_assert(code < MAX_TREE_CODES);
106550 + return tree_code_name[code];
106551 +}
106552 +
106553 +#define ipa_remove_stmt_references(cnode, stmt)
106554 +#endif
106555 +
106556 +#if BUILDING_GCC_VERSION == 4008
106557 +#define NODE_DECL(node) node->symbol.decl
106558 +#else
106559 +#define NODE_DECL(node) node->decl
106560 +#endif
106561 +
106562 +#if BUILDING_GCC_VERSION >= 4008
106563 +#define add_referenced_var(var)
106564 +#define mark_sym_for_renaming(var)
106565 +#define varpool_mark_needed_node(node)
106566 +#define TODO_dump_func 0
106567 +#define TODO_dump_cgraph 0
106568 +#endif
106569 +
106570 +#if BUILDING_GCC_VERSION >= 4009
106571 +#define TODO_ggc_collect 0
106572 +#endif
106573 +
106574 +#endif
106575 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
106576 new file mode 100644
106577 index 0000000..7514850
106578 --- /dev/null
106579 +++ b/tools/gcc/gen-random-seed.sh
106580 @@ -0,0 +1,8 @@
106581 +#!/bin/sh
106582 +
106583 +if [ ! -f "$1" ]; then
106584 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
106585 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
106586 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
106587 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
106588 +fi
106589 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
106590 new file mode 100644
106591 index 0000000..791ca76
106592 --- /dev/null
106593 +++ b/tools/gcc/generate_size_overflow_hash.sh
106594 @@ -0,0 +1,97 @@
106595 +#!/bin/bash
106596 +
106597 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
106598 +
106599 +header1="size_overflow_hash.h"
106600 +database="size_overflow_hash.data"
106601 +n=65536
106602 +hashtable_name="size_overflow_hash"
106603 +
106604 +usage() {
106605 +cat <<EOF
106606 +usage: $0 options
106607 +OPTIONS:
106608 + -h|--help help
106609 + -o header file
106610 + -d database file
106611 + -n hash array size
106612 + -s name of the hash table
106613 +EOF
106614 + return 0
106615 +}
106616 +
106617 +while true
106618 +do
106619 + case "$1" in
106620 + -h|--help) usage && exit 0;;
106621 + -n) n=$2; shift 2;;
106622 + -o) header1="$2"; shift 2;;
106623 + -d) database="$2"; shift 2;;
106624 + -s) hashtable_name="$2"; shift 2;;
106625 + --) shift 1; break ;;
106626 + *) break ;;
106627 + esac
106628 +done
106629 +
106630 +create_defines() {
106631 + for i in `seq 0 31`
106632 + do
106633 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
106634 + done
106635 + echo >> "$header1"
106636 +}
106637 +
106638 +create_structs() {
106639 + rm -f "$header1"
106640 +
106641 + create_defines
106642 +
106643 + cat "$database" | while read data
106644 + do
106645 + data_array=($data)
106646 + struct_hash_name="${data_array[0]}"
106647 + funcn="${data_array[1]}"
106648 + params="${data_array[2]}"
106649 + next="${data_array[4]}"
106650 +
106651 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
106652 +
106653 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
106654 + echo -en "\t.param\t= " >> "$header1"
106655 + line=
106656 + for param_num in ${params//-/ };
106657 + do
106658 + line="${line}PARAM"$param_num"|"
106659 + done
106660 +
106661 + echo -e "${line%?},\n};\n" >> "$header1"
106662 + done
106663 +}
106664 +
106665 +create_headers() {
106666 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
106667 +}
106668 +
106669 +create_array_elements() {
106670 + index=0
106671 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
106672 + do
106673 + data_array=($data)
106674 + i="${data_array[3]}"
106675 + hash="${data_array[0]}"
106676 + while [[ $index -lt $i ]]
106677 + do
106678 + echo -e "\t["$index"]\t= NULL," >> "$header1"
106679 + index=$(($index + 1))
106680 + done
106681 + index=$(($index + 1))
106682 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
106683 + done
106684 + echo '};' >> $header1
106685 +}
106686 +
106687 +create_structs
106688 +create_headers
106689 +create_array_elements
106690 +
106691 +exit 0
106692 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
106693 new file mode 100644
106694 index 0000000..d81c094
106695 --- /dev/null
106696 +++ b/tools/gcc/kallocstat_plugin.c
106697 @@ -0,0 +1,183 @@
106698 +/*
106699 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106700 + * Licensed under the GPL v2
106701 + *
106702 + * Note: the choice of the license means that the compilation process is
106703 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106704 + * but for the kernel it doesn't matter since it doesn't link against
106705 + * any of the gcc libraries
106706 + *
106707 + * gcc plugin to find the distribution of k*alloc sizes
106708 + *
106709 + * TODO:
106710 + *
106711 + * BUGS:
106712 + * - none known
106713 + */
106714 +
106715 +#include "gcc-common.h"
106716 +
106717 +int plugin_is_GPL_compatible;
106718 +
106719 +static struct plugin_info kallocstat_plugin_info = {
106720 + .version = "201401260140",
106721 + .help = NULL
106722 +};
106723 +
106724 +static const char * const kalloc_functions[] = {
106725 + "__kmalloc",
106726 + "kmalloc",
106727 + "kmalloc_large",
106728 + "kmalloc_node",
106729 + "kmalloc_order",
106730 + "kmalloc_order_trace",
106731 + "kmalloc_slab",
106732 + "kzalloc",
106733 + "kzalloc_node",
106734 +};
106735 +
106736 +static bool is_kalloc(const char *fnname)
106737 +{
106738 + size_t i;
106739 +
106740 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
106741 + if (!strcmp(fnname, kalloc_functions[i]))
106742 + return true;
106743 + return false;
106744 +}
106745 +
106746 +static unsigned int execute_kallocstat(void)
106747 +{
106748 + basic_block bb;
106749 +
106750 + // 1. loop through BBs and GIMPLE statements
106751 + FOR_EACH_BB_FN(bb, cfun) {
106752 + gimple_stmt_iterator gsi;
106753 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106754 + // gimple match:
106755 + tree fndecl, size;
106756 + gimple stmt;
106757 + const char *fnname;
106758 +
106759 + // is it a call
106760 + stmt = gsi_stmt(gsi);
106761 + if (!is_gimple_call(stmt))
106762 + continue;
106763 + fndecl = gimple_call_fndecl(stmt);
106764 + if (fndecl == NULL_TREE)
106765 + continue;
106766 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
106767 + continue;
106768 +
106769 + // is it a call to k*alloc
106770 + fnname = DECL_NAME_POINTER(fndecl);
106771 + if (!is_kalloc(fnname))
106772 + continue;
106773 +
106774 + // is the size arg const or the result of a simple const assignment
106775 + size = gimple_call_arg(stmt, 0);
106776 + while (true) {
106777 + expanded_location xloc;
106778 + size_t size_val;
106779 +
106780 + if (TREE_CONSTANT(size)) {
106781 + xloc = expand_location(gimple_location(stmt));
106782 + if (!xloc.file)
106783 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
106784 + size_val = TREE_INT_CST_LOW(size);
106785 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
106786 + break;
106787 + }
106788 +
106789 + if (TREE_CODE(size) != SSA_NAME)
106790 + break;
106791 + stmt = SSA_NAME_DEF_STMT(size);
106792 +//debug_gimple_stmt(stmt);
106793 +//debug_tree(size);
106794 + if (!stmt || !is_gimple_assign(stmt))
106795 + break;
106796 + if (gimple_num_ops(stmt) != 2)
106797 + break;
106798 + size = gimple_assign_rhs1(stmt);
106799 + }
106800 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106801 +//debug_tree(gimple_call_fn(call_stmt));
106802 +//print_node(stderr, "pax", fndecl, 4);
106803 + }
106804 + }
106805 +
106806 + return 0;
106807 +}
106808 +
106809 +#if BUILDING_GCC_VERSION >= 4009
106810 +static const struct pass_data kallocstat_pass_data = {
106811 +#else
106812 +static struct gimple_opt_pass kallocstat_pass = {
106813 + .pass = {
106814 +#endif
106815 + .type = GIMPLE_PASS,
106816 + .name = "kallocstat",
106817 +#if BUILDING_GCC_VERSION >= 4008
106818 + .optinfo_flags = OPTGROUP_NONE,
106819 +#endif
106820 +#if BUILDING_GCC_VERSION >= 4009
106821 + .has_gate = false,
106822 + .has_execute = true,
106823 +#else
106824 + .gate = NULL,
106825 + .execute = execute_kallocstat,
106826 + .sub = NULL,
106827 + .next = NULL,
106828 + .static_pass_number = 0,
106829 +#endif
106830 + .tv_id = TV_NONE,
106831 + .properties_required = 0,
106832 + .properties_provided = 0,
106833 + .properties_destroyed = 0,
106834 + .todo_flags_start = 0,
106835 + .todo_flags_finish = 0
106836 +#if BUILDING_GCC_VERSION < 4009
106837 + }
106838 +#endif
106839 +};
106840 +
106841 +#if BUILDING_GCC_VERSION >= 4009
106842 +namespace {
106843 +class kallocstat_pass : public gimple_opt_pass {
106844 +public:
106845 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
106846 + unsigned int execute() { return execute_kallocstat(); }
106847 +};
106848 +}
106849 +
106850 +static opt_pass *make_kallocstat_pass(void)
106851 +{
106852 + return new kallocstat_pass();
106853 +}
106854 +#else
106855 +static struct opt_pass *make_kallocstat_pass(void)
106856 +{
106857 + return &kallocstat_pass.pass;
106858 +}
106859 +#endif
106860 +
106861 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106862 +{
106863 + const char * const plugin_name = plugin_info->base_name;
106864 + struct register_pass_info kallocstat_pass_info;
106865 +
106866 + kallocstat_pass_info.pass = make_kallocstat_pass();
106867 + kallocstat_pass_info.reference_pass_name = "ssa";
106868 + kallocstat_pass_info.ref_pass_instance_number = 1;
106869 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106870 +
106871 + if (!plugin_default_version_check(version, &gcc_version)) {
106872 + error(G_("incompatible gcc/plugin versions"));
106873 + return 1;
106874 + }
106875 +
106876 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
106877 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
106878 +
106879 + return 0;
106880 +}
106881 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
106882 new file mode 100644
106883 index 0000000..89f256d
106884 --- /dev/null
106885 +++ b/tools/gcc/kernexec_plugin.c
106886 @@ -0,0 +1,522 @@
106887 +/*
106888 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106889 + * Licensed under the GPL v2
106890 + *
106891 + * Note: the choice of the license means that the compilation process is
106892 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106893 + * but for the kernel it doesn't matter since it doesn't link against
106894 + * any of the gcc libraries
106895 + *
106896 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
106897 + *
106898 + * TODO:
106899 + *
106900 + * BUGS:
106901 + * - none known
106902 + */
106903 +
106904 +#include "gcc-common.h"
106905 +
106906 +int plugin_is_GPL_compatible;
106907 +
106908 +static struct plugin_info kernexec_plugin_info = {
106909 + .version = "201401260140",
106910 + .help = "method=[bts|or]\tinstrumentation method\n"
106911 +};
106912 +
106913 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
106914 +static void (*kernexec_instrument_retaddr)(rtx);
106915 +
106916 +/*
106917 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
106918 + */
106919 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
106920 +{
106921 + gimple asm_movabs_stmt;
106922 +
106923 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
106924 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
106925 + gimple_asm_set_volatile(asm_movabs_stmt, true);
106926 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
106927 + update_stmt(asm_movabs_stmt);
106928 +}
106929 +
106930 +/*
106931 + * find all asm() stmts that clobber r12 and add a reload of r12
106932 + */
106933 +static unsigned int execute_kernexec_reload(void)
106934 +{
106935 + basic_block bb;
106936 +
106937 + // 1. loop through BBs and GIMPLE statements
106938 + FOR_EACH_BB_FN(bb, cfun) {
106939 + gimple_stmt_iterator gsi;
106940 +
106941 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106942 + // gimple match: __asm__ ("" : : : "r12");
106943 + gimple asm_stmt;
106944 + size_t nclobbers;
106945 +
106946 + // is it an asm ...
106947 + asm_stmt = gsi_stmt(gsi);
106948 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
106949 + continue;
106950 +
106951 + // ... clobbering r12
106952 + nclobbers = gimple_asm_nclobbers(asm_stmt);
106953 + while (nclobbers--) {
106954 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
106955 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
106956 + continue;
106957 + kernexec_reload_fptr_mask(&gsi);
106958 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
106959 + break;
106960 + }
106961 + }
106962 + }
106963 +
106964 + return 0;
106965 +}
106966 +
106967 +/*
106968 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
106969 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
106970 + */
106971 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
106972 +{
106973 + gimple assign_intptr, assign_new_fptr, call_stmt;
106974 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
106975 +
106976 + call_stmt = gsi_stmt(*gsi);
106977 + old_fptr = gimple_call_fn(call_stmt);
106978 +
106979 + // create temporary unsigned long variable used for bitops and cast fptr to it
106980 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
106981 + add_referenced_var(intptr);
106982 + intptr = make_ssa_name(intptr, NULL);
106983 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
106984 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106985 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106986 + update_stmt(assign_intptr);
106987 +
106988 + // apply logical or to temporary unsigned long and bitmask
106989 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
106990 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
106991 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
106992 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
106993 + assign_intptr = gimple_build_assign(intptr, orptr);
106994 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106995 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106996 + update_stmt(assign_intptr);
106997 +
106998 + // cast temporary unsigned long back to a temporary fptr variable
106999 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
107000 + add_referenced_var(new_fptr);
107001 + new_fptr = make_ssa_name(new_fptr, NULL);
107002 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
107003 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
107004 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
107005 + update_stmt(assign_new_fptr);
107006 +
107007 + // replace call stmt fn with the new fptr
107008 + gimple_call_set_fn(call_stmt, new_fptr);
107009 + update_stmt(call_stmt);
107010 +}
107011 +
107012 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
107013 +{
107014 + gimple asm_or_stmt, call_stmt;
107015 + tree old_fptr, new_fptr, input, output;
107016 +#if BUILDING_GCC_VERSION <= 4007
107017 + VEC(tree, gc) *inputs = NULL;
107018 + VEC(tree, gc) *outputs = NULL;
107019 +#else
107020 + vec<tree, va_gc> *inputs = NULL;
107021 + vec<tree, va_gc> *outputs = NULL;
107022 +#endif
107023 +
107024 + call_stmt = gsi_stmt(*gsi);
107025 + old_fptr = gimple_call_fn(call_stmt);
107026 +
107027 + // create temporary fptr variable
107028 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
107029 + add_referenced_var(new_fptr);
107030 + new_fptr = make_ssa_name(new_fptr, NULL);
107031 +
107032 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
107033 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
107034 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
107035 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
107036 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
107037 +#if BUILDING_GCC_VERSION <= 4007
107038 + VEC_safe_push(tree, gc, inputs, input);
107039 + VEC_safe_push(tree, gc, outputs, output);
107040 +#else
107041 + vec_safe_push(inputs, input);
107042 + vec_safe_push(outputs, output);
107043 +#endif
107044 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
107045 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
107046 + gimple_asm_set_volatile(asm_or_stmt, true);
107047 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
107048 + update_stmt(asm_or_stmt);
107049 +
107050 + // replace call stmt fn with the new fptr
107051 + gimple_call_set_fn(call_stmt, new_fptr);
107052 + update_stmt(call_stmt);
107053 +}
107054 +
107055 +/*
107056 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
107057 + */
107058 +static unsigned int execute_kernexec_fptr(void)
107059 +{
107060 + basic_block bb;
107061 +
107062 + // 1. loop through BBs and GIMPLE statements
107063 + FOR_EACH_BB_FN(bb, cfun) {
107064 + gimple_stmt_iterator gsi;
107065 +
107066 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
107067 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
107068 + tree fn;
107069 + gimple call_stmt;
107070 +
107071 + // is it a call ...
107072 + call_stmt = gsi_stmt(gsi);
107073 + if (!is_gimple_call(call_stmt))
107074 + continue;
107075 + fn = gimple_call_fn(call_stmt);
107076 + if (TREE_CODE(fn) == ADDR_EXPR)
107077 + continue;
107078 + if (TREE_CODE(fn) != SSA_NAME)
107079 + gcc_unreachable();
107080 +
107081 + // ... through a function pointer
107082 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
107083 + fn = SSA_NAME_VAR(fn);
107084 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
107085 + debug_tree(fn);
107086 + gcc_unreachable();
107087 + }
107088 + }
107089 + fn = TREE_TYPE(fn);
107090 + if (TREE_CODE(fn) != POINTER_TYPE)
107091 + continue;
107092 + fn = TREE_TYPE(fn);
107093 + if (TREE_CODE(fn) != FUNCTION_TYPE)
107094 + continue;
107095 +
107096 + kernexec_instrument_fptr(&gsi);
107097 +
107098 +//debug_tree(gimple_call_fn(call_stmt));
107099 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
107100 + }
107101 + }
107102 +
107103 + return 0;
107104 +}
107105 +
107106 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
107107 +static void kernexec_instrument_retaddr_bts(rtx insn)
107108 +{
107109 + rtx btsq;
107110 + rtvec argvec, constraintvec, labelvec;
107111 + int line;
107112 +
107113 + // create asm volatile("btsq $63,(%%rsp)":::)
107114 + argvec = rtvec_alloc(0);
107115 + constraintvec = rtvec_alloc(0);
107116 + labelvec = rtvec_alloc(0);
107117 + line = expand_location(RTL_LOCATION(insn)).line;
107118 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
107119 + MEM_VOLATILE_P(btsq) = 1;
107120 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
107121 + emit_insn_before(btsq, insn);
107122 +}
107123 +
107124 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
107125 +static void kernexec_instrument_retaddr_or(rtx insn)
107126 +{
107127 + rtx orq;
107128 + rtvec argvec, constraintvec, labelvec;
107129 + int line;
107130 +
107131 + // create asm volatile("orq %%r12,(%%rsp)":::)
107132 + argvec = rtvec_alloc(0);
107133 + constraintvec = rtvec_alloc(0);
107134 + labelvec = rtvec_alloc(0);
107135 + line = expand_location(RTL_LOCATION(insn)).line;
107136 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
107137 + MEM_VOLATILE_P(orq) = 1;
107138 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
107139 + emit_insn_before(orq, insn);
107140 +}
107141 +
107142 +/*
107143 + * find all asm level function returns and forcibly set the highest bit of the return address
107144 + */
107145 +static unsigned int execute_kernexec_retaddr(void)
107146 +{
107147 + rtx insn;
107148 +
107149 +// if (stack_realign_drap)
107150 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107151 +
107152 + // 1. find function returns
107153 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
107154 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
107155 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
107156 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
107157 + rtx body;
107158 +
107159 + // is it a retn
107160 + if (!JUMP_P(insn))
107161 + continue;
107162 + body = PATTERN(insn);
107163 + if (GET_CODE(body) == PARALLEL)
107164 + body = XVECEXP(body, 0, 0);
107165 + if (!ANY_RETURN_P(body))
107166 + continue;
107167 + kernexec_instrument_retaddr(insn);
107168 + }
107169 +
107170 +// print_simple_rtl(stderr, get_insns());
107171 +// print_rtl(stderr, get_insns());
107172 +
107173 + return 0;
107174 +}
107175 +
107176 +static bool kernexec_cmodel_check(void)
107177 +{
107178 + tree section;
107179 +
107180 + if (ix86_cmodel != CM_KERNEL)
107181 + return false;
107182 +
107183 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
107184 + if (!section || !TREE_VALUE(section))
107185 + return true;
107186 +
107187 + section = TREE_VALUE(TREE_VALUE(section));
107188 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
107189 + return true;
107190 +
107191 + return false;
107192 +}
107193 +
107194 +#if BUILDING_GCC_VERSION >= 4009
107195 +static const struct pass_data kernexec_reload_pass_data = {
107196 +#else
107197 +static struct gimple_opt_pass kernexec_reload_pass = {
107198 + .pass = {
107199 +#endif
107200 + .type = GIMPLE_PASS,
107201 + .name = "kernexec_reload",
107202 +#if BUILDING_GCC_VERSION >= 4008
107203 + .optinfo_flags = OPTGROUP_NONE,
107204 +#endif
107205 +#if BUILDING_GCC_VERSION >= 4009
107206 + .has_gate = true,
107207 + .has_execute = true,
107208 +#else
107209 + .gate = kernexec_cmodel_check,
107210 + .execute = execute_kernexec_reload,
107211 + .sub = NULL,
107212 + .next = NULL,
107213 + .static_pass_number = 0,
107214 +#endif
107215 + .tv_id = TV_NONE,
107216 + .properties_required = 0,
107217 + .properties_provided = 0,
107218 + .properties_destroyed = 0,
107219 + .todo_flags_start = 0,
107220 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
107221 +#if BUILDING_GCC_VERSION < 4009
107222 + }
107223 +#endif
107224 +};
107225 +
107226 +#if BUILDING_GCC_VERSION >= 4009
107227 +static const struct pass_data kernexec_fptr_pass_data = {
107228 +#else
107229 +static struct gimple_opt_pass kernexec_fptr_pass = {
107230 + .pass = {
107231 +#endif
107232 + .type = GIMPLE_PASS,
107233 + .name = "kernexec_fptr",
107234 +#if BUILDING_GCC_VERSION >= 4008
107235 + .optinfo_flags = OPTGROUP_NONE,
107236 +#endif
107237 +#if BUILDING_GCC_VERSION >= 4009
107238 + .has_gate = true,
107239 + .has_execute = true,
107240 +#else
107241 + .gate = kernexec_cmodel_check,
107242 + .execute = execute_kernexec_fptr,
107243 + .sub = NULL,
107244 + .next = NULL,
107245 + .static_pass_number = 0,
107246 +#endif
107247 + .tv_id = TV_NONE,
107248 + .properties_required = 0,
107249 + .properties_provided = 0,
107250 + .properties_destroyed = 0,
107251 + .todo_flags_start = 0,
107252 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
107253 +#if BUILDING_GCC_VERSION < 4009
107254 + }
107255 +#endif
107256 +};
107257 +
107258 +#if BUILDING_GCC_VERSION >= 4009
107259 +static const struct pass_data kernexec_retaddr_pass_data = {
107260 +#else
107261 +static struct rtl_opt_pass kernexec_retaddr_pass = {
107262 + .pass = {
107263 +#endif
107264 + .type = RTL_PASS,
107265 + .name = "kernexec_retaddr",
107266 +#if BUILDING_GCC_VERSION >= 4008
107267 + .optinfo_flags = OPTGROUP_NONE,
107268 +#endif
107269 +#if BUILDING_GCC_VERSION >= 4009
107270 + .has_gate = true,
107271 + .has_execute = true,
107272 +#else
107273 + .gate = kernexec_cmodel_check,
107274 + .execute = execute_kernexec_retaddr,
107275 + .sub = NULL,
107276 + .next = NULL,
107277 + .static_pass_number = 0,
107278 +#endif
107279 + .tv_id = TV_NONE,
107280 + .properties_required = 0,
107281 + .properties_provided = 0,
107282 + .properties_destroyed = 0,
107283 + .todo_flags_start = 0,
107284 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
107285 +#if BUILDING_GCC_VERSION < 4009
107286 + }
107287 +#endif
107288 +};
107289 +
107290 +#if BUILDING_GCC_VERSION >= 4009
107291 +namespace {
107292 +class kernexec_reload_pass : public gimple_opt_pass {
107293 +public:
107294 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
107295 + bool gate() { return kernexec_cmodel_check(); }
107296 + unsigned int execute() { return execute_kernexec_reload(); }
107297 +};
107298 +
107299 +class kernexec_fptr_pass : public gimple_opt_pass {
107300 +public:
107301 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
107302 + bool gate() { return kernexec_cmodel_check(); }
107303 + unsigned int execute() { return execute_kernexec_fptr(); }
107304 +};
107305 +
107306 +class kernexec_retaddr_pass : public rtl_opt_pass {
107307 +public:
107308 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
107309 + bool gate() { return kernexec_cmodel_check(); }
107310 + unsigned int execute() { return execute_kernexec_retaddr(); }
107311 +};
107312 +}
107313 +
107314 +static opt_pass *make_kernexec_reload_pass(void)
107315 +{
107316 + return new kernexec_reload_pass();
107317 +}
107318 +
107319 +static opt_pass *make_kernexec_fptr_pass(void)
107320 +{
107321 + return new kernexec_fptr_pass();
107322 +}
107323 +
107324 +static opt_pass *make_kernexec_retaddr_pass(void)
107325 +{
107326 + return new kernexec_retaddr_pass();
107327 +}
107328 +#else
107329 +static struct opt_pass *make_kernexec_reload_pass(void)
107330 +{
107331 + return &kernexec_reload_pass.pass;
107332 +}
107333 +
107334 +static struct opt_pass *make_kernexec_fptr_pass(void)
107335 +{
107336 + return &kernexec_fptr_pass.pass;
107337 +}
107338 +
107339 +static struct opt_pass *make_kernexec_retaddr_pass(void)
107340 +{
107341 + return &kernexec_retaddr_pass.pass;
107342 +}
107343 +#endif
107344 +
107345 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107346 +{
107347 + const char * const plugin_name = plugin_info->base_name;
107348 + const int argc = plugin_info->argc;
107349 + const struct plugin_argument * const argv = plugin_info->argv;
107350 + int i;
107351 + struct register_pass_info kernexec_reload_pass_info;
107352 + struct register_pass_info kernexec_fptr_pass_info;
107353 + struct register_pass_info kernexec_retaddr_pass_info;
107354 +
107355 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
107356 + kernexec_reload_pass_info.reference_pass_name = "ssa";
107357 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
107358 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107359 +
107360 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
107361 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
107362 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
107363 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107364 +
107365 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
107366 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
107367 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
107368 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107369 +
107370 + if (!plugin_default_version_check(version, &gcc_version)) {
107371 + error(G_("incompatible gcc/plugin versions"));
107372 + return 1;
107373 + }
107374 +
107375 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
107376 +
107377 + if (TARGET_64BIT == 0)
107378 + return 0;
107379 +
107380 + for (i = 0; i < argc; ++i) {
107381 + if (!strcmp(argv[i].key, "method")) {
107382 + if (!argv[i].value) {
107383 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107384 + continue;
107385 + }
107386 + if (!strcmp(argv[i].value, "bts")) {
107387 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
107388 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
107389 + } else if (!strcmp(argv[i].value, "or")) {
107390 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
107391 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
107392 + fix_register("r12", 1, 1);
107393 + } else
107394 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107395 + continue;
107396 + }
107397 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107398 + }
107399 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
107400 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
107401 +
107402 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
107403 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
107404 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
107405 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
107406 +
107407 + return 0;
107408 +}
107409 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
107410 new file mode 100644
107411 index 0000000..39d7cc7
107412 --- /dev/null
107413 +++ b/tools/gcc/latent_entropy_plugin.c
107414 @@ -0,0 +1,462 @@
107415 +/*
107416 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
107417 + * Licensed under the GPL v2
107418 + *
107419 + * Note: the choice of the license means that the compilation process is
107420 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107421 + * but for the kernel it doesn't matter since it doesn't link against
107422 + * any of the gcc libraries
107423 + *
107424 + * gcc plugin to help generate a little bit of entropy from program state,
107425 + * used throughout the uptime of the kernel
107426 + *
107427 + * TODO:
107428 + * - add ipa pass to identify not explicitly marked candidate functions
107429 + * - mix in more program state (function arguments/return values, loop variables, etc)
107430 + * - more instrumentation control via attribute parameters
107431 + *
107432 + * BUGS:
107433 + * - LTO needs -flto-partition=none for now
107434 + */
107435 +
107436 +#include "gcc-common.h"
107437 +
107438 +int plugin_is_GPL_compatible;
107439 +
107440 +static tree latent_entropy_decl;
107441 +
107442 +static struct plugin_info latent_entropy_plugin_info = {
107443 + .version = "201403280150",
107444 + .help = NULL
107445 +};
107446 +
107447 +static unsigned HOST_WIDE_INT seed;
107448 +static unsigned HOST_WIDE_INT get_random_const(void)
107449 +{
107450 + unsigned int i;
107451 + unsigned HOST_WIDE_INT ret = 0;
107452 +
107453 + for (i = 0; i < 8 * sizeof ret; i++) {
107454 + ret = (ret << 1) | (seed & 1);
107455 + seed >>= 1;
107456 + if (ret & 1)
107457 + seed ^= 0xD800000000000000ULL;
107458 + }
107459 +
107460 + return ret;
107461 +}
107462 +
107463 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107464 +{
107465 + tree type;
107466 + unsigned long long mask;
107467 +#if BUILDING_GCC_VERSION <= 4007
107468 + VEC(constructor_elt, gc) *vals;
107469 +#else
107470 + vec<constructor_elt, va_gc> *vals;
107471 +#endif
107472 +
107473 + switch (TREE_CODE(*node)) {
107474 + default:
107475 + *no_add_attrs = true;
107476 + error("%qE attribute only applies to functions and variables", name);
107477 + break;
107478 +
107479 + case VAR_DECL:
107480 + if (DECL_INITIAL(*node)) {
107481 + *no_add_attrs = true;
107482 + error("variable %qD with %qE attribute must not be initialized", *node, name);
107483 + break;
107484 + }
107485 +
107486 + if (!TREE_STATIC(*node)) {
107487 + *no_add_attrs = true;
107488 + error("variable %qD with %qE attribute must not be local", *node, name);
107489 + break;
107490 + }
107491 +
107492 + type = TREE_TYPE(*node);
107493 + switch (TREE_CODE(type)) {
107494 + default:
107495 + *no_add_attrs = true;
107496 + error("variable %qD with %qE attribute must be an integer or a fixed length integer array type or a fixed sized structure with integer fields", *node, name);
107497 + break;
107498 +
107499 + case RECORD_TYPE: {
107500 + tree field;
107501 + unsigned int nelt = 0;
107502 +
107503 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
107504 + tree fieldtype;
107505 +
107506 + fieldtype = TREE_TYPE(field);
107507 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
107508 + *no_add_attrs = true;
107509 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
107510 + break;
107511 + }
107512 + }
107513 +
107514 + if (field)
107515 + break;
107516 +
107517 +#if BUILDING_GCC_VERSION <= 4007
107518 + vals = VEC_alloc(constructor_elt, gc, nelt);
107519 +#else
107520 + vec_alloc(vals, nelt);
107521 +#endif
107522 +
107523 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107524 + tree fieldtype;
107525 +
107526 + fieldtype = TREE_TYPE(field);
107527 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
107528 + mask = 2 * (mask - 1) + 1;
107529 +
107530 + if (TYPE_UNSIGNED(fieldtype))
107531 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
107532 + else
107533 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
107534 + }
107535 +
107536 + DECL_INITIAL(*node) = build_constructor(type, vals);
107537 +//debug_tree(DECL_INITIAL(*node));
107538 + break;
107539 + }
107540 +
107541 + case INTEGER_TYPE:
107542 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
107543 + mask = 2 * (mask - 1) + 1;
107544 +
107545 + if (TYPE_UNSIGNED(type))
107546 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
107547 + else
107548 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
107549 + break;
107550 +
107551 + case ARRAY_TYPE: {
107552 + tree elt_type, array_size, elt_size;
107553 + unsigned int i, nelt;
107554 +
107555 + elt_type = TREE_TYPE(type);
107556 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
107557 + array_size = TYPE_SIZE_UNIT(type);
107558 +
107559 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
107560 + *no_add_attrs = true;
107561 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
107562 + break;
107563 + }
107564 +
107565 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
107566 +#if BUILDING_GCC_VERSION <= 4007
107567 + vals = VEC_alloc(constructor_elt, gc, nelt);
107568 +#else
107569 + vec_alloc(vals, nelt);
107570 +#endif
107571 +
107572 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
107573 + mask = 2 * (mask - 1) + 1;
107574 +
107575 + for (i = 0; i < nelt; i++)
107576 + if (TYPE_UNSIGNED(elt_type))
107577 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
107578 + else
107579 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
107580 +
107581 + DECL_INITIAL(*node) = build_constructor(type, vals);
107582 +//debug_tree(DECL_INITIAL(*node));
107583 + break;
107584 + }
107585 + }
107586 + break;
107587 +
107588 + case FUNCTION_DECL:
107589 + break;
107590 + }
107591 +
107592 + return NULL_TREE;
107593 +}
107594 +
107595 +static struct attribute_spec latent_entropy_attr = {
107596 + .name = "latent_entropy",
107597 + .min_length = 0,
107598 + .max_length = 0,
107599 + .decl_required = true,
107600 + .type_required = false,
107601 + .function_type_required = false,
107602 + .handler = handle_latent_entropy_attribute,
107603 +#if BUILDING_GCC_VERSION >= 4007
107604 + .affects_type_identity = false
107605 +#endif
107606 +};
107607 +
107608 +static void register_attributes(void *event_data, void *data)
107609 +{
107610 + register_attribute(&latent_entropy_attr);
107611 +}
107612 +
107613 +static bool gate_latent_entropy(void)
107614 +{
107615 + // don't bother with noreturn functions for now
107616 + if (TREE_THIS_VOLATILE(current_function_decl))
107617 + return false;
107618 +
107619 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
107620 +}
107621 +
107622 +static enum tree_code get_op(tree *rhs)
107623 +{
107624 + static enum tree_code op;
107625 + unsigned HOST_WIDE_INT random_const;
107626 +
107627 + random_const = get_random_const();
107628 +
107629 + switch (op) {
107630 + case BIT_XOR_EXPR:
107631 + op = PLUS_EXPR;
107632 + break;
107633 +
107634 + case PLUS_EXPR:
107635 + if (rhs) {
107636 + op = LROTATE_EXPR;
107637 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
107638 + break;
107639 + }
107640 +
107641 + case LROTATE_EXPR:
107642 + default:
107643 + op = BIT_XOR_EXPR;
107644 + break;
107645 + }
107646 + if (rhs)
107647 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
107648 + return op;
107649 +}
107650 +
107651 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
107652 +{
107653 + gimple_stmt_iterator gsi;
107654 + gimple assign;
107655 + tree addxorrol, rhs;
107656 + enum tree_code op;
107657 +
107658 + op = get_op(&rhs);
107659 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
107660 + assign = gimple_build_assign(local_entropy, addxorrol);
107661 + gsi = gsi_after_labels(bb);
107662 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
107663 + update_stmt(assign);
107664 +//debug_bb(bb);
107665 +}
107666 +
107667 +static void perturb_latent_entropy(basic_block bb, tree rhs)
107668 +{
107669 + gimple_stmt_iterator gsi;
107670 + gimple assign;
107671 + tree addxorrol, temp;
107672 +
107673 + // 1. create temporary copy of latent_entropy
107674 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
107675 + add_referenced_var(temp);
107676 +
107677 + // 2. read...
107678 + temp = make_ssa_name(temp, NULL);
107679 + assign = gimple_build_assign(temp, latent_entropy_decl);
107680 + SSA_NAME_DEF_STMT(temp) = assign;
107681 + add_referenced_var(latent_entropy_decl);
107682 + gsi = gsi_after_labels(bb);
107683 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107684 + update_stmt(assign);
107685 +
107686 + // 3. ...modify...
107687 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
107688 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
107689 + assign = gimple_build_assign(temp, addxorrol);
107690 + SSA_NAME_DEF_STMT(temp) = assign;
107691 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107692 + update_stmt(assign);
107693 +
107694 + // 4. ...write latent_entropy
107695 + assign = gimple_build_assign(latent_entropy_decl, temp);
107696 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107697 + update_stmt(assign);
107698 +}
107699 +
107700 +static unsigned int execute_latent_entropy(void)
107701 +{
107702 + basic_block bb;
107703 + gimple assign;
107704 + gimple_stmt_iterator gsi;
107705 + tree local_entropy;
107706 +
107707 + if (!latent_entropy_decl) {
107708 +#if BUILDING_GCC_VERSION >= 4009
107709 + varpool_node *node;
107710 +#else
107711 + struct varpool_node *node;
107712 +#endif
107713 +
107714 + FOR_EACH_VARIABLE(node) {
107715 + tree var = NODE_DECL(node);
107716 +
107717 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
107718 + continue;
107719 + latent_entropy_decl = var;
107720 +// debug_tree(var);
107721 + break;
107722 + }
107723 + if (!latent_entropy_decl) {
107724 +// debug_tree(current_function_decl);
107725 + return 0;
107726 + }
107727 + }
107728 +
107729 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107730 +
107731 + // 1. create local entropy variable
107732 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
107733 + add_referenced_var(local_entropy);
107734 + mark_sym_for_renaming(local_entropy);
107735 +
107736 + // 2. initialize local entropy variable
107737 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
107738 + if (dom_info_available_p(CDI_DOMINATORS))
107739 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
107740 + gsi = gsi_start_bb(bb);
107741 +
107742 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
107743 +// gimple_set_location(assign, loc);
107744 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107745 + update_stmt(assign);
107746 +//debug_bb(bb);
107747 + gcc_assert(single_succ_p(bb));
107748 + bb = single_succ(bb);
107749 +
107750 + // 3. instrument each BB with an operation on the local entropy variable
107751 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
107752 + perturb_local_entropy(bb, local_entropy);
107753 +//debug_bb(bb);
107754 + bb = bb->next_bb;
107755 + };
107756 +
107757 + // 4. mix local entropy into the global entropy variable
107758 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107759 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
107760 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107761 + return 0;
107762 +}
107763 +
107764 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
107765 +{
107766 + tree latent_entropy_type;
107767 +
107768 + seed = get_random_seed(false);
107769 +
107770 + if (in_lto_p)
107771 + return;
107772 +
107773 + // extern volatile u64 latent_entropy
107774 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
107775 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
107776 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
107777 +
107778 + TREE_STATIC(latent_entropy_decl) = 1;
107779 + TREE_PUBLIC(latent_entropy_decl) = 1;
107780 + TREE_USED(latent_entropy_decl) = 1;
107781 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
107782 + DECL_EXTERNAL(latent_entropy_decl) = 1;
107783 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
107784 + lang_hooks.decls.pushdecl(latent_entropy_decl);
107785 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
107786 +// varpool_finalize_decl(latent_entropy_decl);
107787 +// varpool_mark_needed_node(latent_entropy_decl);
107788 +}
107789 +
107790 +#if BUILDING_GCC_VERSION >= 4009
107791 +static const struct pass_data latent_entropy_pass_data = {
107792 +#else
107793 +static struct gimple_opt_pass latent_entropy_pass = {
107794 + .pass = {
107795 +#endif
107796 + .type = GIMPLE_PASS,
107797 + .name = "latent_entropy",
107798 +#if BUILDING_GCC_VERSION >= 4008
107799 + .optinfo_flags = OPTGROUP_NONE,
107800 +#endif
107801 +#if BUILDING_GCC_VERSION >= 4009
107802 + .has_gate = true,
107803 + .has_execute = true,
107804 +#else
107805 + .gate = gate_latent_entropy,
107806 + .execute = execute_latent_entropy,
107807 + .sub = NULL,
107808 + .next = NULL,
107809 + .static_pass_number = 0,
107810 +#endif
107811 + .tv_id = TV_NONE,
107812 + .properties_required = PROP_gimple_leh | PROP_cfg,
107813 + .properties_provided = 0,
107814 + .properties_destroyed = 0,
107815 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
107816 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
107817 +#if BUILDING_GCC_VERSION < 4009
107818 + }
107819 +#endif
107820 +};
107821 +
107822 +#if BUILDING_GCC_VERSION >= 4009
107823 +namespace {
107824 +class latent_entropy_pass : public gimple_opt_pass {
107825 +public:
107826 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
107827 + bool gate() { return gate_latent_entropy(); }
107828 + unsigned int execute() { return execute_latent_entropy(); }
107829 +};
107830 +}
107831 +
107832 +static opt_pass *make_latent_entropy_pass(void)
107833 +{
107834 + return new latent_entropy_pass();
107835 +}
107836 +#else
107837 +static struct opt_pass *make_latent_entropy_pass(void)
107838 +{
107839 + return &latent_entropy_pass.pass;
107840 +}
107841 +#endif
107842 +
107843 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107844 +{
107845 + const char * const plugin_name = plugin_info->base_name;
107846 + struct register_pass_info latent_entropy_pass_info;
107847 +
107848 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
107849 + latent_entropy_pass_info.reference_pass_name = "optimized";
107850 + latent_entropy_pass_info.ref_pass_instance_number = 1;
107851 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107852 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
107853 + {
107854 + .base = &latent_entropy_decl,
107855 + .nelt = 1,
107856 + .stride = sizeof(latent_entropy_decl),
107857 + .cb = &gt_ggc_mx_tree_node,
107858 + .pchw = &gt_pch_nx_tree_node
107859 + },
107860 + LAST_GGC_ROOT_TAB
107861 + };
107862 +
107863 + if (!plugin_default_version_check(version, &gcc_version)) {
107864 + error(G_("incompatible gcc/plugin versions"));
107865 + return 1;
107866 + }
107867 +
107868 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
107869 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
107870 + if (!in_lto_p)
107871 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
107872 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
107873 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107874 +
107875 + return 0;
107876 +}
107877 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
107878 new file mode 100644
107879 index 0000000..8dafb22
107880 --- /dev/null
107881 +++ b/tools/gcc/randomize_layout_plugin.c
107882 @@ -0,0 +1,910 @@
107883 +/*
107884 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
107885 + * and PaX Team <pageexec@freemail.hu>
107886 + * Licensed under the GPL v2
107887 + *
107888 + * Usage:
107889 + * $ # for 4.5/4.6/C based 4.7
107890 + * $ 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
107891 + * $ # for C++ based 4.7/4.8+
107892 + * $ 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
107893 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
107894 + */
107895 +
107896 +#include "gcc-common.h"
107897 +#include "randomize_layout_seed.h"
107898 +
107899 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
107900 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
107901 +#endif
107902 +
107903 +#define ORIG_TYPE_NAME(node) \
107904 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
107905 +
107906 +int plugin_is_GPL_compatible;
107907 +
107908 +static int performance_mode;
107909 +
107910 +static struct plugin_info randomize_layout_plugin_info = {
107911 + .version = "201402201816",
107912 + .help = "disable\t\t\tdo not activate plugin\n"
107913 + "performance-mode\tenable cacheline-aware layout randomization\n"
107914 +};
107915 +
107916 +/* from old Linux dcache.h */
107917 +static inline unsigned long
107918 +partial_name_hash(unsigned long c, unsigned long prevhash)
107919 +{
107920 + return (prevhash + (c << 4) + (c >> 4)) * 11;
107921 +}
107922 +static inline unsigned int
107923 +name_hash(const unsigned char *name)
107924 +{
107925 + unsigned long hash = 0;
107926 + unsigned int len = strlen((const char *)name);
107927 + while (len--)
107928 + hash = partial_name_hash(*name++, hash);
107929 + return (unsigned int)hash;
107930 +}
107931 +
107932 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107933 +{
107934 + tree type;
107935 +
107936 + *no_add_attrs = true;
107937 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107938 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107939 + return NULL_TREE;
107940 + }
107941 +
107942 + if (TREE_CODE(*node) == PARM_DECL) {
107943 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107944 + return NULL_TREE;
107945 + }
107946 +
107947 + if (TREE_CODE(*node) == VAR_DECL) {
107948 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107949 + return NULL_TREE;
107950 + }
107951 +
107952 + if (TYPE_P(*node)) {
107953 + type = *node;
107954 + } else {
107955 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107956 + type = TREE_TYPE(*node);
107957 + }
107958 +
107959 + if (TREE_CODE(type) != RECORD_TYPE) {
107960 + error("%qE attribute used on %qT applies to struct types only", name, type);
107961 + return NULL_TREE;
107962 + }
107963 +
107964 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107965 + error("%qE attribute is already applied to the type %qT", name, type);
107966 + return NULL_TREE;
107967 + }
107968 +
107969 + *no_add_attrs = false;
107970 +
107971 + return NULL_TREE;
107972 +}
107973 +
107974 +/* set on complete types that we don't need to inspect further at all */
107975 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107976 +{
107977 + *no_add_attrs = false;
107978 + return NULL_TREE;
107979 +}
107980 +
107981 +/*
107982 + * set on types that we've performed a shuffle on, to prevent re-shuffling
107983 + * this does not preclude us from inspecting its fields for potential shuffles
107984 + */
107985 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107986 +{
107987 + *no_add_attrs = false;
107988 + return NULL_TREE;
107989 +}
107990 +
107991 +/*
107992 + * 64bit variant of Bob Jenkins' public domain PRNG
107993 + * 256 bits of internal state
107994 + */
107995 +
107996 +typedef unsigned long long u64;
107997 +
107998 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
107999 +
108000 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
108001 +static u64 ranval(ranctx *x) {
108002 + u64 e = x->a - rot(x->b, 7);
108003 + x->a = x->b ^ rot(x->c, 13);
108004 + x->b = x->c + rot(x->d, 37);
108005 + x->c = x->d + e;
108006 + x->d = e + x->a;
108007 + return x->d;
108008 +}
108009 +
108010 +static void raninit(ranctx *x, u64 *seed) {
108011 + int i;
108012 +
108013 + x->a = seed[0];
108014 + x->b = seed[1];
108015 + x->c = seed[2];
108016 + x->d = seed[3];
108017 +
108018 + for (i=0; i < 30; ++i)
108019 + (void)ranval(x);
108020 +}
108021 +
108022 +static u64 shuffle_seed[4];
108023 +
108024 +struct partition_group {
108025 + tree tree_start;
108026 + unsigned long start;
108027 + unsigned long length;
108028 +};
108029 +
108030 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
108031 +{
108032 + unsigned long i;
108033 + unsigned long accum_size = 0;
108034 + unsigned long accum_length = 0;
108035 + unsigned long group_idx = 0;
108036 +
108037 + gcc_assert(length < INT_MAX);
108038 +
108039 + memset(size_groups, 0, sizeof(struct partition_group) * length);
108040 +
108041 + for (i = 0; i < length; i++) {
108042 + if (size_groups[group_idx].tree_start == NULL_TREE) {
108043 + size_groups[group_idx].tree_start = fields[i];
108044 + size_groups[group_idx].start = i;
108045 + accum_length = 0;
108046 + accum_size = 0;
108047 + }
108048 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
108049 + accum_length++;
108050 + if (accum_size >= 64) {
108051 + size_groups[group_idx].length = accum_length;
108052 + accum_length = 0;
108053 + group_idx++;
108054 + }
108055 + }
108056 +
108057 + if (size_groups[group_idx].tree_start != NULL_TREE &&
108058 + !size_groups[group_idx].length) {
108059 + size_groups[group_idx].length = accum_length;
108060 + group_idx++;
108061 + }
108062 +
108063 + *num_groups = group_idx;
108064 +}
108065 +
108066 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
108067 +{
108068 + unsigned long i, x;
108069 + struct partition_group size_group[length];
108070 + unsigned long num_groups = 0;
108071 + unsigned long randnum;
108072 +
108073 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
108074 + for (i = num_groups - 1; i > 0; i--) {
108075 + struct partition_group tmp;
108076 + randnum = ranval(prng_state) % (i + 1);
108077 + tmp = size_group[i];
108078 + size_group[i] = size_group[randnum];
108079 + size_group[randnum] = tmp;
108080 + }
108081 +
108082 + for (x = 0; x < num_groups; x++) {
108083 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
108084 + tree tmp;
108085 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
108086 + continue;
108087 + randnum = ranval(prng_state) % (i + 1);
108088 + // we could handle this case differently if desired
108089 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
108090 + continue;
108091 + tmp = newtree[i];
108092 + newtree[i] = newtree[randnum];
108093 + newtree[randnum] = tmp;
108094 + }
108095 + }
108096 +}
108097 +
108098 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
108099 +{
108100 + unsigned long i, randnum;
108101 +
108102 + for (i = length - 1; i > 0; i--) {
108103 + tree tmp;
108104 + randnum = ranval(prng_state) % (i + 1);
108105 + tmp = newtree[i];
108106 + newtree[i] = newtree[randnum];
108107 + newtree[randnum] = tmp;
108108 + }
108109 +}
108110 +
108111 +/* modern in-place Fisher-Yates shuffle */
108112 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
108113 +{
108114 + unsigned long i;
108115 + u64 seed[4];
108116 + ranctx prng_state;
108117 + const unsigned char *structname;
108118 +
108119 + if (length == 0)
108120 + return;
108121 +
108122 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108123 +
108124 + structname = ORIG_TYPE_NAME(type);
108125 +
108126 +#ifdef __DEBUG_PLUGIN
108127 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
108128 +#ifdef __DEBUG_VERBOSE
108129 + debug_tree((tree)type);
108130 +#endif
108131 +#endif
108132 +
108133 + for (i = 0; i < 4; i++) {
108134 + seed[i] = shuffle_seed[i];
108135 + seed[i] ^= name_hash(structname);
108136 + }
108137 +
108138 + raninit(&prng_state, (u64 *)&seed);
108139 +
108140 + if (performance_mode)
108141 + performance_shuffle(newtree, length, &prng_state);
108142 + else
108143 + full_shuffle(newtree, length, &prng_state);
108144 +}
108145 +
108146 +static bool is_flexible_array(const_tree field)
108147 +{
108148 + const_tree fieldtype;
108149 + const_tree typesize;
108150 + const_tree elemtype;
108151 + const_tree elemsize;
108152 +
108153 + fieldtype = TREE_TYPE(field);
108154 + typesize = TYPE_SIZE(fieldtype);
108155 +
108156 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
108157 + return false;
108158 +
108159 + elemtype = TREE_TYPE(fieldtype);
108160 + elemsize = TYPE_SIZE(elemtype);
108161 +
108162 + /* size of type is represented in bits */
108163 +
108164 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
108165 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
108166 + return true;
108167 +
108168 + if (typesize != NULL_TREE &&
108169 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
108170 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
108171 + return true;
108172 +
108173 + return false;
108174 +}
108175 +
108176 +static int relayout_struct(tree type)
108177 +{
108178 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
108179 + unsigned long shuffle_length = num_fields;
108180 + tree field;
108181 + tree newtree[num_fields];
108182 + unsigned long i;
108183 + tree list;
108184 + tree variant;
108185 + expanded_location xloc;
108186 +
108187 + if (TYPE_FIELDS(type) == NULL_TREE)
108188 + return 0;
108189 +
108190 + if (num_fields < 2)
108191 + return 0;
108192 +
108193 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108194 +
108195 + gcc_assert(num_fields < INT_MAX);
108196 +
108197 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
108198 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
108199 + return 0;
108200 +
108201 + /* throw out any structs in uapi */
108202 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
108203 +
108204 + if (strstr(xloc.file, "/uapi/"))
108205 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
108206 +
108207 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
108208 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
108209 + newtree[i] = field;
108210 + }
108211 +
108212 + /*
108213 + * enforce that we don't randomize the layout of the last
108214 + * element of a struct if it's a 0 or 1-length array
108215 + * or a proper flexible array
108216 + */
108217 + if (is_flexible_array(newtree[num_fields - 1]))
108218 + shuffle_length--;
108219 +
108220 + shuffle(type, (tree *)newtree, shuffle_length);
108221 +
108222 + /*
108223 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
108224 + * as gcc provides no other way to detect such code
108225 + */
108226 + list = make_node(FIELD_DECL);
108227 + TREE_CHAIN(list) = newtree[0];
108228 + TREE_TYPE(list) = void_type_node;
108229 + DECL_SIZE(list) = bitsize_zero_node;
108230 + DECL_NONADDRESSABLE_P(list) = 1;
108231 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
108232 + DECL_SIZE_UNIT(list) = size_zero_node;
108233 + DECL_FIELD_OFFSET(list) = size_zero_node;
108234 + // to satisfy the constify plugin
108235 + TREE_READONLY(list) = 1;
108236 +
108237 + for (i = 0; i < num_fields - 1; i++)
108238 + TREE_CHAIN(newtree[i]) = newtree[i+1];
108239 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
108240 +
108241 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108242 + TYPE_FIELDS(variant) = list;
108243 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
108244 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
108245 + // force a re-layout
108246 + TYPE_SIZE(variant) = NULL_TREE;
108247 + layout_type(variant);
108248 + }
108249 +
108250 + return 1;
108251 +}
108252 +
108253 +/* from constify plugin */
108254 +static const_tree get_field_type(const_tree field)
108255 +{
108256 + return strip_array_types(TREE_TYPE(field));
108257 +}
108258 +
108259 +/* from constify plugin */
108260 +static bool is_fptr(const_tree fieldtype)
108261 +{
108262 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
108263 + return false;
108264 +
108265 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
108266 +}
108267 +
108268 +/* derived from constify plugin */
108269 +static int is_pure_ops_struct(const_tree node)
108270 +{
108271 + const_tree field;
108272 +
108273 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
108274 +
108275 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
108276 + const_tree fieldtype = get_field_type(field);
108277 + enum tree_code code = TREE_CODE(fieldtype);
108278 +
108279 + if (node == fieldtype)
108280 + continue;
108281 +
108282 + if (!is_fptr(fieldtype))
108283 + return 0;
108284 +
108285 + if (code != RECORD_TYPE && code != UNION_TYPE)
108286 + continue;
108287 +
108288 + if (!is_pure_ops_struct(fieldtype))
108289 + return 0;
108290 + }
108291 +
108292 + return 1;
108293 +}
108294 +
108295 +static void randomize_type(tree type)
108296 +{
108297 + tree variant;
108298 +
108299 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108300 +
108301 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108302 + return;
108303 +
108304 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
108305 + relayout_struct(type);
108306 +
108307 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108308 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
108309 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
108310 + }
108311 +#ifdef __DEBUG_PLUGIN
108312 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
108313 +#ifdef __DEBUG_VERBOSE
108314 + debug_tree(type);
108315 +#endif
108316 +#endif
108317 +}
108318 +
108319 +static void randomize_layout_finish_decl(void *event_data, void *data)
108320 +{
108321 + tree decl = (tree)event_data;
108322 + tree type;
108323 +
108324 + if (decl == NULL_TREE || decl == error_mark_node)
108325 + return;
108326 +
108327 + type = TREE_TYPE(decl);
108328 +
108329 + if (TREE_CODE(decl) != VAR_DECL)
108330 + return;
108331 +
108332 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108333 + return;
108334 +
108335 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
108336 + return;
108337 +
108338 + relayout_decl(decl);
108339 +}
108340 +
108341 +static void finish_type(void *event_data, void *data)
108342 +{
108343 + tree type = (tree)event_data;
108344 +
108345 + if (type == NULL_TREE || type == error_mark_node)
108346 + return;
108347 +
108348 + if (TREE_CODE(type) != RECORD_TYPE)
108349 + return;
108350 +
108351 + if (TYPE_FIELDS(type) == NULL_TREE)
108352 + return;
108353 +
108354 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108355 + return;
108356 +
108357 +#ifdef __DEBUG_PLUGIN
108358 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
108359 +#endif
108360 +#ifdef __DEBUG_VERBOSE
108361 + debug_tree(type);
108362 +#endif
108363 + randomize_type(type);
108364 +
108365 + return;
108366 +}
108367 +
108368 +static struct attribute_spec randomize_layout_attr = {
108369 + .name = "randomize_layout",
108370 + // related to args
108371 + .min_length = 0,
108372 + .max_length = 0,
108373 + .decl_required = false,
108374 + // need type declaration
108375 + .type_required = true,
108376 + .function_type_required = false,
108377 + .handler = handle_randomize_layout_attr,
108378 +#if BUILDING_GCC_VERSION >= 4007
108379 + .affects_type_identity = true
108380 +#endif
108381 +};
108382 +
108383 +static struct attribute_spec no_randomize_layout_attr = {
108384 + .name = "no_randomize_layout",
108385 + // related to args
108386 + .min_length = 0,
108387 + .max_length = 0,
108388 + .decl_required = false,
108389 + // need type declaration
108390 + .type_required = true,
108391 + .function_type_required = false,
108392 + .handler = handle_randomize_layout_attr,
108393 +#if BUILDING_GCC_VERSION >= 4007
108394 + .affects_type_identity = true
108395 +#endif
108396 +};
108397 +
108398 +static struct attribute_spec randomize_considered_attr = {
108399 + .name = "randomize_considered",
108400 + // related to args
108401 + .min_length = 0,
108402 + .max_length = 0,
108403 + .decl_required = false,
108404 + // need type declaration
108405 + .type_required = true,
108406 + .function_type_required = false,
108407 + .handler = handle_randomize_considered_attr,
108408 +#if BUILDING_GCC_VERSION >= 4007
108409 + .affects_type_identity = false
108410 +#endif
108411 +};
108412 +
108413 +static struct attribute_spec randomize_performed_attr = {
108414 + .name = "randomize_performed",
108415 + // related to args
108416 + .min_length = 0,
108417 + .max_length = 0,
108418 + .decl_required = false,
108419 + // need type declaration
108420 + .type_required = true,
108421 + .function_type_required = false,
108422 + .handler = handle_randomize_performed_attr,
108423 +#if BUILDING_GCC_VERSION >= 4007
108424 + .affects_type_identity = false
108425 +#endif
108426 +};
108427 +
108428 +static void register_attributes(void *event_data, void *data)
108429 +{
108430 + register_attribute(&randomize_layout_attr);
108431 + register_attribute(&no_randomize_layout_attr);
108432 + register_attribute(&randomize_considered_attr);
108433 + register_attribute(&randomize_performed_attr);
108434 +}
108435 +
108436 +static void check_bad_casts_in_constructor(tree var, tree init)
108437 +{
108438 + unsigned HOST_WIDE_INT idx;
108439 + tree field, val;
108440 + tree field_type, val_type;
108441 +
108442 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
108443 + if (TREE_CODE(val) == CONSTRUCTOR) {
108444 + check_bad_casts_in_constructor(var, val);
108445 + continue;
108446 + }
108447 +
108448 + /* pipacs' plugin creates franken-arrays that differ from those produced by
108449 + normal code which all have valid 'field' trees. work around this */
108450 + if (field == NULL_TREE)
108451 + continue;
108452 + field_type = TREE_TYPE(field);
108453 + val_type = TREE_TYPE(val);
108454 +
108455 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
108456 + continue;
108457 +
108458 + if (field_type == val_type)
108459 + continue;
108460 +
108461 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
108462 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
108463 +
108464 + if (field_type == void_type_node)
108465 + continue;
108466 + if (field_type == val_type)
108467 + continue;
108468 + if (TREE_CODE(val_type) != RECORD_TYPE)
108469 + continue;
108470 +
108471 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
108472 + continue;
108473 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
108474 + }
108475 +}
108476 +
108477 +/* derived from the constify plugin */
108478 +static void check_global_variables(void *event_data, void *data)
108479 +{
108480 + struct varpool_node *node;
108481 + tree init;
108482 +
108483 + FOR_EACH_VARIABLE(node) {
108484 + tree var = NODE_DECL(node);
108485 + init = DECL_INITIAL(var);
108486 + if (init == NULL_TREE)
108487 + continue;
108488 +
108489 + if (TREE_CODE(init) != CONSTRUCTOR)
108490 + continue;
108491 +
108492 + check_bad_casts_in_constructor(var, init);
108493 + }
108494 +}
108495 +
108496 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
108497 +{
108498 + basic_block dom;
108499 + gimple dom_stmt;
108500 + gimple call_stmt;
108501 + const_tree dom_lhs;
108502 + const_tree poss_is_err_cond;
108503 + const_tree poss_is_err_func;
108504 + const_tree is_err_arg;
108505 +
108506 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
108507 + if (!dom)
108508 + return false;
108509 +
108510 + dom_stmt = last_stmt(dom);
108511 + if (!dom_stmt)
108512 + return false;
108513 +
108514 + if (gimple_code(dom_stmt) != GIMPLE_COND)
108515 + return false;
108516 +
108517 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
108518 + return false;
108519 +
108520 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
108521 + return false;
108522 +
108523 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
108524 +
108525 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
108526 + return false;
108527 +
108528 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
108529 +
108530 + if (gimple_code(call_stmt) != GIMPLE_CALL)
108531 + return false;
108532 +
108533 + dom_lhs = gimple_get_lhs(call_stmt);
108534 + poss_is_err_func = gimple_call_fndecl(call_stmt);
108535 + if (!poss_is_err_func)
108536 + return false;
108537 + if (dom_lhs != poss_is_err_cond)
108538 + return false;
108539 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
108540 + return false;
108541 +
108542 + is_err_arg = gimple_call_arg(call_stmt, 0);
108543 + if (!is_err_arg)
108544 + return false;
108545 +
108546 + if (is_err_arg != rhs)
108547 + return false;
108548 +
108549 + return true;
108550 +}
108551 +
108552 +static void handle_local_var_initializers(void)
108553 +{
108554 + tree var;
108555 + unsigned int i;
108556 +
108557 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108558 + tree init = DECL_INITIAL(var);
108559 + if (!init)
108560 + continue;
108561 + if (TREE_CODE(init) != CONSTRUCTOR)
108562 + continue;
108563 + check_bad_casts_in_constructor(var, init);
108564 + }
108565 +}
108566 +
108567 +/*
108568 + * iterate over all statements to find "bad" casts:
108569 + * those where the address of the start of a structure is cast
108570 + * to a pointer of a structure of a different type, or a
108571 + * structure pointer type is cast to a different structure pointer type
108572 + */
108573 +static unsigned int find_bad_casts(void)
108574 +{
108575 + basic_block bb;
108576 +
108577 + handle_local_var_initializers();
108578 +
108579 + FOR_ALL_BB_FN(bb, cfun) {
108580 + gimple_stmt_iterator gsi;
108581 +
108582 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108583 + gimple stmt;
108584 + const_tree lhs;
108585 + const_tree lhs_type;
108586 + const_tree rhs1;
108587 + const_tree rhs_type;
108588 + const_tree ptr_lhs_type;
108589 + const_tree ptr_rhs_type;
108590 + const_tree op0;
108591 + const_tree op0_type;
108592 + enum tree_code rhs_code;
108593 +
108594 + stmt = gsi_stmt(gsi);
108595 +
108596 +#ifdef __DEBUG_PLUGIN
108597 +#ifdef __DEBUG_VERBOSE
108598 + debug_gimple_stmt(stmt);
108599 + debug_tree(gimple_get_lhs(stmt));
108600 +#endif
108601 +#endif
108602 +
108603 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
108604 + continue;
108605 +
108606 +#ifdef __DEBUG_PLUGIN
108607 +#ifdef __DEBUG_VERBOSE
108608 + debug_tree(gimple_assign_rhs1(stmt));
108609 +#endif
108610 +#endif
108611 +
108612 + rhs_code = gimple_assign_rhs_code(stmt);
108613 +
108614 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
108615 + continue;
108616 +
108617 + lhs = gimple_get_lhs(stmt);
108618 + lhs_type = TREE_TYPE(lhs);
108619 + rhs1 = gimple_assign_rhs1(stmt);
108620 + rhs_type = TREE_TYPE(rhs1);
108621 +
108622 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
108623 + TREE_CODE(lhs_type) != POINTER_TYPE)
108624 + continue;
108625 +
108626 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
108627 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
108628 +
108629 + if (ptr_rhs_type == void_type_node)
108630 + continue;
108631 +
108632 + if (ptr_lhs_type == void_type_node)
108633 + continue;
108634 +
108635 + if (dominated_by_is_err(rhs1, bb))
108636 + continue;
108637 +
108638 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
108639 +#ifndef __DEBUG_PLUGIN
108640 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
108641 +#endif
108642 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108643 + continue;
108644 + }
108645 +
108646 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
108647 + continue;
108648 +
108649 + if (rhs_code == ADDR_EXPR) {
108650 + op0 = TREE_OPERAND(rhs1, 0);
108651 +
108652 + if (op0 == NULL_TREE)
108653 + continue;
108654 +
108655 + if (TREE_CODE(op0) != VAR_DECL)
108656 + continue;
108657 +
108658 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
108659 + if (op0_type == ptr_lhs_type)
108660 + continue;
108661 +
108662 +#ifndef __DEBUG_PLUGIN
108663 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
108664 +#endif
108665 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
108666 + } else {
108667 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
108668 + /* skip bogus type casts introduced by container_of */
108669 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
108670 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
108671 + continue;
108672 +#ifndef __DEBUG_PLUGIN
108673 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
108674 +#endif
108675 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108676 + }
108677 +
108678 + }
108679 + }
108680 + return 0;
108681 +}
108682 +
108683 +#if BUILDING_GCC_VERSION >= 4009
108684 +static const struct pass_data randomize_layout_bad_cast_data = {
108685 +#else
108686 +static struct gimple_opt_pass randomize_layout_bad_cast = {
108687 + .pass = {
108688 +#endif
108689 + .type = GIMPLE_PASS,
108690 + .name = "randomize_layout_bad_cast",
108691 +#if BUILDING_GCC_VERSION >= 4008
108692 + .optinfo_flags = OPTGROUP_NONE,
108693 +#endif
108694 +#if BUILDING_GCC_VERSION >= 4009
108695 + .has_gate = false,
108696 + .has_execute = true,
108697 +#else
108698 + .gate = NULL,
108699 + .execute = find_bad_casts,
108700 + .sub = NULL,
108701 + .next = NULL,
108702 + .static_pass_number = 0,
108703 +#endif
108704 + .tv_id = TV_NONE,
108705 + .properties_required = PROP_cfg,
108706 + .properties_provided = 0,
108707 + .properties_destroyed = 0,
108708 + .todo_flags_start = 0,
108709 + .todo_flags_finish = TODO_dump_func
108710 +#if BUILDING_GCC_VERSION < 4009
108711 + }
108712 +#endif
108713 +};
108714 +
108715 +#if BUILDING_GCC_VERSION >= 4009
108716 +namespace {
108717 +class randomize_layout_bad_cast : public gimple_opt_pass {
108718 +public:
108719 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
108720 + unsigned int execute() { return find_bad_casts(); }
108721 +};
108722 +}
108723 +#endif
108724 +
108725 +static struct opt_pass *make_randomize_layout_bad_cast(void)
108726 +{
108727 +#if BUILDING_GCC_VERSION >= 4009
108728 + return new randomize_layout_bad_cast();
108729 +#else
108730 + return &randomize_layout_bad_cast.pass;
108731 +#endif
108732 +}
108733 +
108734 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108735 +{
108736 + int i;
108737 + const char * const plugin_name = plugin_info->base_name;
108738 + const int argc = plugin_info->argc;
108739 + const struct plugin_argument * const argv = plugin_info->argv;
108740 + bool enable = true;
108741 + int obtained_seed = 0;
108742 + struct register_pass_info randomize_layout_bad_cast_info;
108743 +
108744 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
108745 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
108746 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
108747 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
108748 +
108749 + if (!plugin_default_version_check(version, &gcc_version)) {
108750 + error(G_("incompatible gcc/plugin versions"));
108751 + return 1;
108752 + }
108753 +
108754 + if (strcmp(lang_hooks.name, "GNU C")) {
108755 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108756 + enable = false;
108757 + }
108758 +
108759 + for (i = 0; i < argc; ++i) {
108760 + if (!strcmp(argv[i].key, "disable")) {
108761 + enable = false;
108762 + continue;
108763 + }
108764 + if (!strcmp(argv[i].key, "performance-mode")) {
108765 + performance_mode = 1;
108766 + continue;
108767 + }
108768 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108769 + }
108770 +
108771 + if (strlen(randstruct_seed) != 64) {
108772 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
108773 + return 1;
108774 + }
108775 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
108776 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
108777 + if (obtained_seed != 4) {
108778 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
108779 + return 1;
108780 + }
108781 +
108782 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
108783 + if (enable) {
108784 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108785 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
108786 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108787 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
108788 + }
108789 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108790 +
108791 + return 0;
108792 +}
108793 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
108794 new file mode 100644
108795 index 0000000..ebbd9a3
108796 --- /dev/null
108797 +++ b/tools/gcc/size_overflow_hash.data
108798 @@ -0,0 +1,5933 @@
108799 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
108800 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
108801 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
108802 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
108803 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
108804 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
108805 +padzero_55 padzero 1 55 &sel_read_policyvers_55
108806 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
108807 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
108808 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
108809 +load_msg_95 load_msg 2 95 NULL
108810 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
108811 +init_q_132 init_q 4 132 NULL
108812 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
108813 +gfs2_glock_get_147 gfs2_glock_get 0 147 NULL
108814 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
108815 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
108816 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
108817 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
108818 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
108819 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
108820 +xfs_bmap_btalloc_192 xfs_bmap_btalloc 0 192 NULL
108821 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
108822 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
108823 +br_port_info_size_268 br_port_info_size 0 268 NULL
108824 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
108825 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
108826 +xfs_zero_last_block_298 xfs_zero_last_block 0 298 NULL
108827 +SYSC_connect_304 SYSC_connect 3 304 NULL
108828 +syslog_print_307 syslog_print 2 307 NULL
108829 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
108830 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
108831 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
108832 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
108833 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
108834 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
108835 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
108836 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
108837 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
108838 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
108839 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
108840 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
108841 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
108842 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
108843 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
108844 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
108845 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
108846 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
108847 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
108848 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
108849 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
108850 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
108851 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
108852 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
108853 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
108854 +unlink_queued_645 unlink_queued 4 645 NULL
108855 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
108856 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
108857 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
108858 +xfs_bmap_eof_728 xfs_bmap_eof 0 728 NULL
108859 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
108860 +dvb_video_write_754 dvb_video_write 3 754 NULL
108861 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
108862 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
108863 +if_writecmd_815 if_writecmd 2 815 NULL
108864 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
108865 +error_state_read_859 error_state_read 6 859 NULL
108866 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
108867 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
108868 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
108869 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
108870 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
108871 +mnt_want_write_975 mnt_want_write 0 975 NULL
108872 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
108873 +memcmp_990 memcmp 0 990 NULL
108874 +readreg_1017 readreg 0-1 1017 NULL
108875 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
108876 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
108877 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
108878 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
108879 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
108880 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
108881 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
108882 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
108883 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
108884 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
108885 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
108886 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
108887 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
108888 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
108889 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
108890 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
108891 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
108892 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
108893 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
108894 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
108895 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
108896 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
108897 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
108898 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
108899 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
108900 +tcf_hash_create_1305 tcf_hash_create 4 1305 NULL
108901 +ffs_1322 ffs 0 1322 NULL
108902 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
108903 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
108904 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
108905 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
108906 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
108907 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
108908 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
108909 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
108910 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
108911 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
108912 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
108913 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
108914 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
108915 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
108916 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
108917 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
108918 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
108919 +fpregs_set_1497 fpregs_set 4 1497 NULL
108920 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
108921 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
108922 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
108923 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
108924 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
108925 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
108926 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
108927 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
108928 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
108929 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
108930 +rmap_add_1677 rmap_add 3 1677 NULL
108931 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
108932 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
108933 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
108934 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
108935 +internal_create_group_1733 internal_create_group 0 1733 NULL
108936 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
108937 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
108938 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
108939 +cosa_write_1774 cosa_write 3 1774 NULL
108940 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
108941 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
108942 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
108943 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
108944 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
108945 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
108946 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
108947 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
108948 +bdev_erase_1933 bdev_erase 3 1933 NULL
108949 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
108950 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
108951 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
108952 +update_qd_1955 update_qd 0 1955 NULL
108953 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
108954 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
108955 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
108956 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
108957 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
108958 +xfs_mru_cache_insert_2013 xfs_mru_cache_insert 0 2013 NULL
108959 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
108960 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
108961 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
108962 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
108963 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
108964 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
108965 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
108966 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
108967 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
108968 +audit_expand_2098 audit_expand 0 2098 NULL
108969 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
108970 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
108971 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
108972 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
108973 +enable_read_2117 enable_read 3 2117 NULL
108974 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
108975 +xfs_recover_inode_owner_change_2132 xfs_recover_inode_owner_change 0 2132 NULL
108976 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
108977 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
108978 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
108979 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
108980 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
108981 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
108982 +xfs_inobt_update_2206 xfs_inobt_update 0 2206 NULL
108983 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
108984 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
108985 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
108986 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
108987 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
108988 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
108989 +do_update_counters_2259 do_update_counters 4 2259 NULL
108990 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
108991 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
108992 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
108993 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
108994 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
108995 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
108996 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
108997 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
108998 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
108999 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
109000 +ntfs_file_aio_write_nolock_2360 ntfs_file_aio_write_nolock 0 2360 NULL
109001 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
109002 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5-0 2368 NULL nohasharray
109003 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
109004 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
109005 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
109006 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
109007 +raid1_size_2419 raid1_size 0-2 2419 NULL
109008 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
109009 +wiphy_new_2482 wiphy_new 2 2482 NULL
109010 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
109011 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
109012 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
109013 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
109014 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
109015 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
109016 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
109017 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
109018 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
109019 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
109020 +slot_bytes_2609 slot_bytes 0 2609 NULL
109021 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
109022 +switch_status_2629 switch_status 5 2629 NULL
109023 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
109024 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
109025 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
109026 +oti6858_write_2692 oti6858_write 4 2692 NULL
109027 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
109028 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
109029 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
109030 +gfs2_glock_nq_num_2747 gfs2_glock_nq_num 0 2747 NULL
109031 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
109032 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
109033 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
109034 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
109035 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
109036 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
109037 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
109038 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
109039 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
109040 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
109041 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
109042 +nla_padlen_2883 nla_padlen 1 2883 NULL
109043 +cmm_write_2896 cmm_write 3 2896 NULL
109044 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
109045 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
109046 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
109047 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
109048 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
109049 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
109050 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
109051 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
109052 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
109053 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
109054 +_xfs_filestream_pick_ag_3007 _xfs_filestream_pick_ag 0 3007 NULL
109055 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
109056 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
109057 +depth_write_3021 depth_write 3 3021 NULL
109058 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
109059 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
109060 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
109061 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
109062 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
109063 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
109064 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
109065 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
109066 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
109067 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
109068 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
109069 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
109070 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
109071 +rb_alloc_3102 rb_alloc 1 3102 NULL
109072 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
109073 +print_time_3132 print_time 0 3132 NULL
109074 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
109075 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
109076 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
109077 +gfs2_rindex_update_3165 gfs2_rindex_update 0 3165 NULL
109078 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
109079 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
109080 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
109081 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
109082 +alloc_context_3194 alloc_context 1 3194 NULL
109083 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
109084 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
109085 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
109086 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
109087 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
109088 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
109089 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
109090 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
109091 +key_key_read_3241 key_key_read 3 3241 NULL
109092 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
109093 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
109094 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
109095 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
109096 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
109097 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
109098 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
109099 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
109100 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
109101 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
109102 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
109103 +scnprintf_3360 scnprintf 0-2 3360 NULL
109104 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
109105 +sr_read_3366 sr_read 3 3366 NULL
109106 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
109107 +send_stream_3397 send_stream 4 3397 NULL
109108 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
109109 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
109110 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
109111 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
109112 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
109113 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
109114 +softsynth_write_3455 softsynth_write 3 3455 NULL
109115 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
109116 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
109117 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
109118 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
109119 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
109120 +SyS_readv_3539 SyS_readv 3 3539 NULL
109121 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
109122 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
109123 +evtchn_read_3569 evtchn_read 3 3569 NULL
109124 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
109125 +vc_resize_3585 vc_resize 3-2 3585 NULL
109126 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
109127 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
109128 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
109129 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
109130 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
109131 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
109132 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
109133 +xfs_attr3_leaf_list_int_3661 xfs_attr3_leaf_list_int 0 3661 NULL
109134 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
109135 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
109136 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
109137 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
109138 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
109139 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
109140 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
109141 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
109142 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
109143 +get_fd_set_3866 get_fd_set 1 3866 NULL
109144 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
109145 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
109146 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
109147 +nvram_write_3894 nvram_write 3 3894 NULL
109148 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
109149 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
109150 +vcs_write_3910 vcs_write 3 3910 NULL
109151 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
109152 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
109153 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
109154 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
109155 +do_add_counters_3992 do_add_counters 3 3992 NULL
109156 +xfs_bmbt_lookup_eq_3997 xfs_bmbt_lookup_eq 0 3997 NULL
109157 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
109158 +userspace_status_4004 userspace_status 4 4004 NULL
109159 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
109160 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
109161 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
109162 +blk_end_request_4024 blk_end_request 3 4024 NULL
109163 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
109164 +xfs_free_ag_extent_4036 xfs_free_ag_extent 0 4036 NULL
109165 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
109166 +read_file_queues_4078 read_file_queues 3 4078 NULL
109167 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
109168 +tm6000_read_4151 tm6000_read 3 4151 NULL
109169 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
109170 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
109171 +get_alua_req_4166 get_alua_req 3 4166 NULL
109172 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
109173 +read_file_bool_4180 read_file_bool 3 4180 NULL
109174 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
109175 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
109176 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
109177 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
109178 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
109179 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
109180 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
109181 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
109182 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
109183 +count_strings_4315 count_strings 0 4315 NULL
109184 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
109185 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
109186 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
109187 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
109188 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
109189 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
109190 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
109191 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
109192 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
109193 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
109194 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
109195 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
109196 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
109197 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
109198 +set_link_security_4502 set_link_security 4 4502 NULL
109199 +xfs_btree_kill_root_4526 xfs_btree_kill_root 0 4526 NULL
109200 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
109201 +tty_register_device_4544 tty_register_device 2 4544 NULL
109202 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
109203 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
109204 +bch_alloc_4593 bch_alloc 1 4593 NULL
109205 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
109206 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
109207 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
109208 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
109209 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
109210 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
109211 +kone_receive_4690 kone_receive 4 4690 NULL
109212 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
109213 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
109214 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
109215 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
109216 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
109217 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
109218 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
109219 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
109220 +create_subvol_4791 create_subvol 4 4791 NULL
109221 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
109222 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
109223 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
109224 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
109225 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
109226 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
109227 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
109228 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
109229 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
109230 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
109231 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
109232 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
109233 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
109234 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
109235 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
109236 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
109237 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
109238 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
109239 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
109240 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
109241 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
109242 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
109243 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
109244 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
109245 +sound_write_5102 sound_write 3 5102 NULL
109246 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
109247 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
109248 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
109249 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
109250 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
109251 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
109252 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
109253 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
109254 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
109255 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
109256 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
109257 +cq_free_res_5355 cq_free_res 5 5355 NULL
109258 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
109259 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
109260 +xfs_free_extent_5411 xfs_free_extent 0 5411 NULL
109261 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
109262 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
109263 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
109264 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
109265 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
109266 +tty_write_5494 tty_write 3 5494 NULL
109267 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
109268 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
109269 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
109270 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
109271 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
109272 +le_readq_5557 le_readq 0 5557 NULL
109273 +inw_5558 inw 0 5558 NULL
109274 +gfs2_extent_map_5561 gfs2_extent_map 0 5561 NULL
109275 +bioset_create_5580 bioset_create 1 5580 NULL
109276 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
109277 +__remove_suid_5618 __remove_suid 0 5618 NULL
109278 +gfs2_unstuffer_page_5620 gfs2_unstuffer_page 0 5620 NULL
109279 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
109280 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
109281 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
109282 +get_arg_5694 get_arg 3 5694 NULL
109283 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
109284 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
109285 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
109286 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
109287 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
109288 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
109289 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
109290 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
109291 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
109292 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
109293 +setup_req_5848 setup_req 3 5848 NULL
109294 +ria_page_count_5849 ria_page_count 0 5849 NULL
109295 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
109296 +config_buf_5862 config_buf 0 5862 NULL
109297 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
109298 +port_show_regs_5904 port_show_regs 3 5904 NULL
109299 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
109300 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
109301 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
109302 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
109303 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
109304 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
109305 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
109306 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
109307 +alloc_msg_6072 alloc_msg 1 6072 NULL
109308 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
109309 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
109310 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
109311 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
109312 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
109313 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
109314 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
109315 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
109316 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
109317 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
109318 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
109319 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
109320 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
109321 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
109322 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
109323 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
109324 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
109325 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
109326 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
109327 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
109328 +serial_port_in_6291 serial_port_in 0 6291 NULL
109329 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
109330 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
109331 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
109332 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
109333 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
109334 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
109335 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
109336 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
109337 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
109338 +xfs_bmap_extents_to_btree_6387 xfs_bmap_extents_to_btree 0 6387 NULL
109339 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
109340 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
109341 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
109342 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
109343 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
109344 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
109345 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
109346 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
109347 +mei_read_6507 mei_read 3 6507 NULL
109348 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
109349 +wdm_read_6549 wdm_read 3 6549 NULL
109350 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
109351 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
109352 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
109353 +xfs_iozero_6573 xfs_iozero 0 6573 NULL
109354 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
109355 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
109356 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
109357 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
109358 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
109359 +mpeg_read_6708 mpeg_read 3 6708 NULL
109360 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
109361 +video_proc_write_6724 video_proc_write 3 6724 NULL
109362 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
109363 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
109364 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
109365 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
109366 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
109367 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
109368 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
109369 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
109370 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
109371 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
109372 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
109373 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
109374 +xfs_rtany_summary_6851 xfs_rtany_summary 0 6851 NULL
109375 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
109376 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
109377 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
109378 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
109379 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
109380 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
109381 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
109382 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
109383 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
109384 +lops_scan_elements_6916 lops_scan_elements 0 6916 NULL
109385 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
109386 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
109387 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
109388 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
109389 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
109390 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
109391 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
109392 +request_key_async_6990 request_key_async 4 6990 NULL
109393 +tpl_write_6998 tpl_write 3 6998 NULL
109394 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
109395 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
109396 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
109397 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
109398 +wimax_msg_7030 wimax_msg 4 7030 NULL
109399 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
109400 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
109401 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
109402 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
109403 +event_enable_read_7074 event_enable_read 3 7074 NULL
109404 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
109405 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
109406 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
109407 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
109408 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
109409 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
109410 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
109411 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
109412 +get_string_7302 get_string 0 7302 NULL
109413 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
109414 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
109415 +mgmt_control_7349 mgmt_control 3 7349 NULL
109416 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
109417 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
109418 +xfs_btree_delete_7384 xfs_btree_delete 0 7384 NULL
109419 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
109420 +hweight_long_7388 hweight_long 1-0 7388 NULL
109421 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
109422 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
109423 +readb_7401 readb 0 7401 NULL
109424 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
109425 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
109426 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
109427 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
109428 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
109429 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
109430 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
109431 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
109432 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
109433 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
109434 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
109435 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
109436 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
109437 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
109438 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
109439 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
109440 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
109441 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
109442 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
109443 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
109444 +xfs_bmap_btalloc_nullfb_7654 xfs_bmap_btalloc_nullfb 0 7654 NULL
109445 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
109446 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
109447 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
109448 +dev_write_7708 dev_write 3 7708 NULL
109449 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
109450 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
109451 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
109452 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
109453 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
109454 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
109455 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
109456 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
109457 +xfs_alloc_find_best_extent_7837 xfs_alloc_find_best_extent 0 7837 NULL
109458 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
109459 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
109460 +config_desc_7878 config_desc 0 7878 NULL
109461 +gfs2_permission_7884 gfs2_permission 0 7884 NULL
109462 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
109463 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
109464 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
109465 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
109466 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
109467 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
109468 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
109469 +vcs_read_8017 vcs_read 3 8017 NULL
109470 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
109471 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
109472 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
109473 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
109474 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
109475 +venus_lookup_8121 venus_lookup 4 8121 NULL
109476 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
109477 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
109478 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
109479 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
109480 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
109481 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
109482 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
109483 +play_iframe_8219 play_iframe 3 8219 NULL
109484 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
109485 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
109486 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
109487 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
109488 +init_cdev_8274 init_cdev 1 8274 NULL
109489 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
109490 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
109491 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
109492 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
109493 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
109494 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
109495 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
109496 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
109497 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
109498 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
109499 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
109500 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
109501 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
109502 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
109503 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
109504 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
109505 +dev_config_8506 dev_config 3 8506 NULL
109506 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
109507 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
109508 +user_on_off_8552 user_on_off 2 8552 NULL
109509 +profile_remove_8556 profile_remove 3 8556 NULL
109510 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
109511 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
109512 +tower_write_8580 tower_write 3 8580 NULL
109513 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
109514 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
109515 +xfs_qm_dqattach_locked_8625 xfs_qm_dqattach_locked 0 8625 NULL
109516 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
109517 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
109518 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
109519 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
109520 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
109521 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
109522 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
109523 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
109524 +arcfb_write_8702 arcfb_write 3 8702 NULL
109525 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
109526 +init_header_8703 init_header 0 8703 &i_size_read_8703
109527 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
109528 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
109529 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
109530 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
109531 +__create_irqs_8733 __create_irqs 2 8733 NULL
109532 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
109533 +compound_order_8750 compound_order 0 8750 NULL
109534 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
109535 +yurex_write_8761 yurex_write 3 8761 NULL
109536 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
109537 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
109538 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
109539 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
109540 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
109541 +gfs2_glock_nq_8808 gfs2_glock_nq 0 8808 NULL
109542 +ntfs_commit_pages_after_write_8809 ntfs_commit_pages_after_write 0 8809 NULL
109543 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
109544 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
109545 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
109546 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
109547 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
109548 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
109549 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
109550 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
109551 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
109552 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
109553 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
109554 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
109555 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
109556 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
109557 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
109558 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
109559 +write_file_ani_8918 write_file_ani 3 8918 NULL
109560 +layout_commit_8926 layout_commit 3 8926 NULL
109561 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
109562 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
109563 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
109564 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
109565 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
109566 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
109567 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
109568 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
109569 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
109570 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
109571 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
109572 +xfs_inobt_get_rec_9023 xfs_inobt_get_rec 0 9023 NULL
109573 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
109574 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
109575 +nla_put_9042 nla_put 3 9042 NULL
109576 +ffs_func_revmap_intf_9043 ffs_func_revmap_intf 0 9043 NULL
109577 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
109578 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
109579 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
109580 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
109581 +create_queues_9088 create_queues 2-3 9088 NULL
109582 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
109583 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
109584 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
109585 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110 nohasharray
109586 +jhead_scan_9110 jhead_scan 0 9110 &gfn_to_rmap_9110
109587 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
109588 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
109589 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
109590 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
109591 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
109592 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
109593 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
109594 +xfs_btree_rshift_9187 xfs_btree_rshift 0 9187 NULL
109595 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
109596 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
109597 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
109598 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
109599 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
109600 +xfs_error_trap_9239 xfs_error_trap 0-1 9239 NULL
109601 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
109602 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
109603 +flakey_status_9274 flakey_status 5 9274 NULL
109604 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
109605 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
109606 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
109607 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
109608 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
109609 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
109610 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
109611 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
109612 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
109613 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
109614 +read_9397 read 3 9397 NULL
109615 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
109616 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
109617 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
109618 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
109619 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
109620 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
109621 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
109622 +crypt_status_9492 crypt_status 5 9492 NULL
109623 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
109624 +lp_write_9511 lp_write 3 9511 NULL
109625 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
109626 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
109627 +read_file_dma_9530 read_file_dma 3 9530 NULL
109628 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
109629 +xfs_ialloc_read_agi_9545 xfs_ialloc_read_agi 0 9545 NULL
109630 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
109631 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
109632 +fw_node_create_9559 fw_node_create 2 9559 NULL
109633 +kobj_map_9566 kobj_map 2-3 9566 NULL
109634 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
109635 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
109636 +xfs_qm_dqattach_one_9612 xfs_qm_dqattach_one 0 9612 NULL
109637 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
109638 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
109639 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
109640 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
109641 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
109642 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
109643 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
109644 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
109645 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
109646 +dns_query_9676 dns_query 3 9676 NULL
109647 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
109648 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
109649 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
109650 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
109651 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
109652 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
109653 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
109654 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
109655 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
109656 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
109657 +shmem_replace_page_9740 shmem_replace_page 0 9740 NULL
109658 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
109659 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
109660 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
109661 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
109662 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
109663 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
109664 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
109665 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
109666 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
109667 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
109668 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
109669 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
109670 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
109671 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
109672 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
109673 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
109674 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
109675 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
109676 +read_file_misc_9948 read_file_misc 3 9948 NULL
109677 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
109678 +xfs_buf_geterror_9959 xfs_buf_geterror 0 9959 NULL
109679 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
109680 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
109681 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
109682 +gameport_read_9983 gameport_read 0 9983 NULL
109683 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
109684 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
109685 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
109686 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
109687 +xfs_attr_rmtval_get_10092 xfs_attr_rmtval_get 0 10092 NULL
109688 +xfs_btree_check_lptr_10104 xfs_btree_check_lptr 0 10104 NULL
109689 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
109690 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
109691 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
109692 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
109693 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
109694 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
109695 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
109696 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
109697 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
109698 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
109699 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
109700 +xfs_attr_rmtval_copyout_10222 xfs_attr_rmtval_copyout 0 10222 NULL nohasharray
109701 +xfs_btree_read_buf_block_10222 xfs_btree_read_buf_block 0 10222 &xfs_attr_rmtval_copyout_10222
109702 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
109703 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
109704 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
109705 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
109706 +read_emulate_10310 read_emulate 2-4 10310 NULL
109707 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
109708 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
109709 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
109710 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
109711 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
109712 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
109713 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
109714 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
109715 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
109716 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
109717 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
109718 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
109719 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
109720 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
109721 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
109722 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
109723 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
109724 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
109725 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
109726 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
109727 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
109728 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
109729 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
109730 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
109731 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
109732 +otp_read_10594 otp_read 2-4-5 10594 NULL
109733 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
109734 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
109735 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
109736 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
109737 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
109738 +parport_write_10669 parport_write 0 10669 NULL
109739 +edge_write_10692 edge_write 4 10692 NULL
109740 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
109741 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
109742 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
109743 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
109744 +spi_sync_10731 spi_sync 0 10731 NULL
109745 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
109746 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
109747 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
109748 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
109749 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
109750 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
109751 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
109752 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
109753 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
109754 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
109755 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
109756 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
109757 +get_scq_10897 get_scq 2 10897 NULL
109758 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
109759 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
109760 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
109761 +kobject_add_10919 kobject_add 0 10919 NULL
109762 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
109763 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
109764 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
109765 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
109766 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
109767 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
109768 +gfs2_dir_read_11017 gfs2_dir_read 0 11017 NULL
109769 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
109770 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
109771 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
109772 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
109773 +count_argc_11083 count_argc 0 11083 NULL
109774 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
109775 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
109776 +page_offset_11120 page_offset 0 11120 NULL
109777 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL nohasharray
109778 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 &tracing_buffers_read_11124
109779 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
109780 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
109781 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
109782 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
109783 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
109784 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
109785 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
109786 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
109787 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
109788 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
109789 +shmem_radix_tree_replace_11325 shmem_radix_tree_replace 0 11325 NULL
109790 +construct_key_11329 construct_key 3 11329 NULL nohasharray
109791 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
109792 +next_segment_11330 next_segment 0-2-1 11330 NULL
109793 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
109794 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
109795 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
109796 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
109797 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
109798 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
109799 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
109800 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
109801 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
109802 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
109803 +str_to_user_11411 str_to_user 2 11411 NULL
109804 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
109805 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
109806 +xfs_btree_lookup_11417 xfs_btree_lookup 0 11417 NULL nohasharray
109807 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 &xfs_btree_lookup_11417
109808 +trace_options_read_11419 trace_options_read 3 11419 NULL
109809 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
109810 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
109811 +bttv_read_11432 bttv_read 3 11432 NULL
109812 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
109813 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
109814 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
109815 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
109816 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4-0 11492 NULL
109817 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
109818 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
109819 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
109820 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
109821 +xfs_rtcheck_alloc_range_11553 xfs_rtcheck_alloc_range 0 11553 NULL
109822 +radix_tree_extend_11555 radix_tree_extend 0 11555 NULL
109823 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
109824 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
109825 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
109826 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
109827 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
109828 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
109829 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
109830 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
109831 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
109832 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
109833 +slab_ksize_11664 slab_ksize 0 11664 NULL
109834 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
109835 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
109836 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
109837 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
109838 +split_11691 split 2 11691 NULL
109839 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
109840 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
109841 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
109842 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
109843 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
109844 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
109845 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
109846 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
109847 +xfs_ialloc_11819 xfs_ialloc 0 11819 NULL
109848 +umc_device_register_11824 umc_device_register 0 11824 NULL
109849 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
109850 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
109851 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
109852 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
109853 +xfs_file_aio_write_checks_11851 xfs_file_aio_write_checks 0 11851 NULL
109854 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
109855 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
109856 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
109857 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
109858 +ti_write_11916 ti_write 4 11916 NULL
109859 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
109860 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
109861 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
109862 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
109863 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
109864 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
109865 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
109866 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
109867 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
109868 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
109869 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
109870 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
109871 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
109872 +gfs2_find_jhead_12117 gfs2_find_jhead 0 12117 NULL
109873 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
109874 +set_powered_12129 set_powered 4 12129 NULL
109875 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
109876 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
109877 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
109878 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
109879 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
109880 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
109881 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
109882 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
109883 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
109884 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
109885 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
109886 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
109887 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
109888 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
109889 +xfs_attr3_leaf_read_12222 xfs_attr3_leaf_read 0 12222 NULL
109890 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
109891 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
109892 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
109893 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
109894 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
109895 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
109896 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
109897 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
109898 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
109899 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
109900 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
109901 +xfs_bmap_last_extent_12335 xfs_bmap_last_extent 0 12335 NULL
109902 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
109903 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
109904 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
109905 +populate_dir_12391 populate_dir 0 12391 NULL nohasharray
109906 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
109907 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
109908 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
109909 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
109910 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
109911 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
109912 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
109913 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
109914 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
109915 +write_inode_now_12565 write_inode_now 0 12565 NULL
109916 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
109917 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
109918 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
109919 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
109920 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
109921 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
109922 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
109923 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
109924 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
109925 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
109926 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
109927 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
109928 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
109929 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
109930 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
109931 +ivtv_write_12721 ivtv_write 3 12721 NULL
109932 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
109933 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
109934 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
109935 +listxattr_12769 listxattr 3 12769 NULL
109936 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
109937 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
109938 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
109939 +readq_12825 readq 0 12825 NULL
109940 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
109941 +gfs2_log_reserve_12835 gfs2_log_reserve 0 12835 NULL
109942 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
109943 +spidev_sync_12842 spidev_sync 0 12842 NULL
109944 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
109945 +xfs_rtallocate_extent_exact_12865 xfs_rtallocate_extent_exact 0 12865 NULL
109946 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
109947 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
109948 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
109949 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
109950 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
109951 +bm_status_write_12964 bm_status_write 3 12964 NULL
109952 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
109953 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
109954 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
109955 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
109956 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
109957 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
109958 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
109959 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
109960 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
109961 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
109962 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
109963 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
109964 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
109965 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
109966 +blk_update_request_13146 blk_update_request 3 13146 NULL
109967 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
109968 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
109969 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
109970 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
109971 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
109972 +comedi_read_13199 comedi_read 3 13199 NULL
109973 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
109974 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
109975 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
109976 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
109977 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
109978 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
109979 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
109980 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
109981 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
109982 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
109983 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
109984 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
109985 +sd_major_13294 sd_major 0-1 13294 NULL
109986 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
109987 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
109988 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
109989 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
109990 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
109991 +xfs_btree_delrec_13364 xfs_btree_delrec 0 13364 NULL
109992 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
109993 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
109994 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
109995 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
109996 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
109997 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
109998 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
109999 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
110000 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
110001 +data_read_13494 data_read 3 13494 NULL
110002 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
110003 +core_status_13515 core_status 4 13515 NULL
110004 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
110005 +bm_init_13529 bm_init 2 13529 NULL
110006 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
110007 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
110008 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
110009 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
110010 +cache_write_13589 cache_write 3 13589 NULL
110011 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
110012 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
110013 +__ntfs_grab_cache_pages_13617 __ntfs_grab_cache_pages 0 13617 NULL
110014 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
110015 +packet_snd_13634 packet_snd 3 13634 NULL
110016 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
110017 +cache_downcall_13666 cache_downcall 3 13666 NULL
110018 +usb_get_string_13693 usb_get_string 0 13693 NULL
110019 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
110020 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
110021 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
110022 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
110023 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
110024 +random_read_13815 random_read 3 13815 NULL
110025 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
110026 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
110027 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
110028 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
110029 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
110030 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
110031 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
110032 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
110033 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
110034 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
110035 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
110036 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
110037 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
110038 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
110039 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
110040 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
110041 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
110042 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
110043 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
110044 +qcam_read_13977 qcam_read 3 13977 NULL
110045 +dsp_read_13980 dsp_read 2 13980 NULL
110046 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
110047 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
110048 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
110049 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
110050 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
110051 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
110052 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
110053 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
110054 +xfs_bmap_alloc_14044 xfs_bmap_alloc 0 14044 NULL
110055 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
110056 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
110057 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
110058 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
110059 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
110060 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
110061 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
110062 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
110063 +em_canid_change_14150 em_canid_change 3 14150 NULL
110064 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
110065 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
110066 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
110067 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
110068 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
110069 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
110070 +alloc_async_14208 alloc_async 1 14208 NULL
110071 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
110072 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
110073 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
110074 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
110075 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
110076 +rr_status_14293 rr_status 5 14293 NULL
110077 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
110078 +update_rgrp_lvb_14303 update_rgrp_lvb 0 14303 NULL
110079 +xfs_qm_qino_alloc_14309 xfs_qm_qino_alloc 0 14309 NULL
110080 +oo_objects_14319 oo_objects 0 14319 NULL
110081 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
110082 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
110083 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
110084 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
110085 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
110086 +lowpan_read_14369 lowpan_read 3 14369 NULL
110087 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
110088 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
110089 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
110090 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
110091 +block_size_14443 block_size 0 14443 NULL
110092 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
110093 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
110094 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
110095 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
110096 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
110097 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
110098 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
110099 +split_state_14491 split_state 0 14491 NULL
110100 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
110101 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
110102 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
110103 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
110104 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
110105 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
110106 +stuffed_readpage_14581 stuffed_readpage 0 14581 NULL
110107 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
110108 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
110109 +dbJoin_14644 dbJoin 0 14644 NULL
110110 +profile_replace_14652 profile_replace 3 14652 NULL
110111 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
110112 +add_to_page_cache_locked_14668 add_to_page_cache_locked 0 14668 NULL
110113 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
110114 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
110115 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
110116 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
110117 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
110118 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
110119 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
110120 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
110121 +vfd_write_14717 vfd_write 3 14717 NULL
110122 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
110123 +raid1_resize_14740 raid1_resize 2 14740 NULL
110124 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
110125 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
110126 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
110127 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
110128 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
110129 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
110130 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
110131 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
110132 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
110133 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
110134 +xfs_btree_kill_iroot_14824 xfs_btree_kill_iroot 0 14824 NULL
110135 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
110136 +lcd_write_14857 lcd_write 3 14857 NULL
110137 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
110138 +xfs_bmapi_convert_unwritten_14886 xfs_bmapi_convert_unwritten 0 14886 NULL
110139 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
110140 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
110141 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
110142 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
110143 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
110144 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
110145 +queue_cnt_14951 queue_cnt 0 14951 NULL
110146 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
110147 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
110148 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
110149 +setkey_14987 setkey 3 14987 NULL nohasharray
110150 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
110151 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
110152 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
110153 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
110154 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
110155 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
110156 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
110157 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
110158 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
110159 +xfs_btree_insrec_15090 xfs_btree_insrec 0 15090 NULL
110160 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
110161 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
110162 +start_port_15124 start_port 0 15124 NULL
110163 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
110164 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
110165 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
110166 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
110167 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
110168 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
110169 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
110170 +simple_strtol_15273 simple_strtol 0 15273 NULL
110171 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
110172 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
110173 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
110174 +ioread16_15342 ioread16 0 15342 NULL
110175 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
110176 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
110177 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
110178 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
110179 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
110180 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
110181 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
110182 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
110183 +get_modalias_15406 get_modalias 2 15406 NULL
110184 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
110185 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
110186 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
110187 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
110188 +memweight_15450 memweight 2 15450 NULL
110189 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
110190 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
110191 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
110192 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
110193 +persistent_status_15574 persistent_status 4 15574 NULL
110194 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
110195 +vme_user_write_15587 vme_user_write 3 15587 NULL
110196 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
110197 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
110198 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
110199 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
110200 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
110201 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
110202 +fs_path_add_15648 fs_path_add 3 15648 NULL
110203 +__do_readpage_15652 __do_readpage 0 15652 NULL
110204 +xsd_read_15653 xsd_read 3 15653 NULL
110205 +unix_bind_15668 unix_bind 3 15668 NULL
110206 +dm_read_15674 dm_read 3 15674 NULL nohasharray
110207 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
110208 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
110209 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
110210 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
110211 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
110212 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
110213 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
110214 +table_size_15851 table_size 0-1-2 15851 NULL
110215 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
110216 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
110217 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
110218 +native_read_msr_15905 native_read_msr 0 15905 NULL
110219 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
110220 +power_read_15939 power_read 3 15939 NULL
110221 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
110222 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
110223 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
110224 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
110225 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
110226 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
110227 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
110228 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
110229 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
110230 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
110231 +gfs2_jdesc_check_16122 gfs2_jdesc_check 0 16122 NULL
110232 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
110233 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
110234 +fsm_init_16134 fsm_init 2 16134 NULL
110235 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
110236 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
110237 +mapping_level_16188 mapping_level 2-0 16188 NULL
110238 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
110239 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
110240 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
110241 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
110242 +create_table_16213 create_table 2 16213 NULL
110243 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
110244 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
110245 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
110246 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
110247 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
110248 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
110249 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
110250 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
110251 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
110252 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
110253 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
110254 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
110255 +account_16283 account 0-4-2 16283 NULL nohasharray
110256 +mirror_status_16283 mirror_status 5 16283 &account_16283
110257 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
110258 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
110259 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
110260 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
110261 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
110262 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
110263 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
110264 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
110265 +xfs_inobt_lookup_16367 xfs_inobt_lookup 0 16367 NULL
110266 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
110267 +gfs2_dinode_in_16378 gfs2_dinode_in 0 16378 NULL
110268 +xfs_btree_check_block_16419 xfs_btree_check_block 0 16419 NULL
110269 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
110270 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
110271 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
110272 +cmdline_store_16442 cmdline_store 4 16442 NULL
110273 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
110274 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
110275 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
110276 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
110277 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
110278 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
110279 +raid10_resize_16537 raid10_resize 2 16537 NULL
110280 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
110281 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
110282 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
110283 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
110284 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
110285 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
110286 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
110287 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
110288 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
110289 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
110290 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
110291 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
110292 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
110293 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
110294 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
110295 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
110296 +xfs_dialloc_ag_16868 xfs_dialloc_ag 0 16868 NULL
110297 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL nohasharray
110298 +xfs_iget_16872 xfs_iget 0 16872 &alloc_idx_lebs_16872
110299 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
110300 +st_write_16874 st_write 3 16874 NULL
110301 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
110302 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
110303 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
110304 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
110305 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
110306 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
110307 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
110308 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
110309 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
110310 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
110311 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
110312 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
110313 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
110314 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
110315 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
110316 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
110317 +entry_length_17093 entry_length 0 17093 NULL
110318 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
110319 +write_mem_17114 write_mem 3 17114 NULL
110320 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
110321 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
110322 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
110323 +sep_read_17161 sep_read 3 17161 NULL
110324 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
110325 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
110326 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
110327 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
110328 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
110329 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
110330 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
110331 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
110332 +sync_request_17208 sync_request 2 17208 NULL
110333 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
110334 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
110335 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
110336 +alloc_ep_17269 alloc_ep 1 17269 NULL
110337 +pg_read_17276 pg_read 3 17276 NULL
110338 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
110339 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
110340 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
110341 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
110342 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
110343 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
110344 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
110345 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
110346 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
110347 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
110348 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
110349 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
110350 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
110351 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
110352 +xfs_btree_lshift_17448 xfs_btree_lshift 0 17448 NULL
110353 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
110354 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
110355 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
110356 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
110357 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
110358 +qp_free_res_17541 qp_free_res 5 17541 NULL
110359 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
110360 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
110361 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
110362 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
110363 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
110364 +osst_execute_17607 osst_execute 7-6 17607 NULL
110365 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
110366 +dma_map_page_17628 dma_map_page 0 17628 NULL
110367 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
110368 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
110369 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
110370 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
110371 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
110372 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
110373 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
110374 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
110375 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
110376 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
110377 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
110378 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
110379 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
110380 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
110381 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
110382 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
110383 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
110384 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
110385 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
110386 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
110387 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
110388 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
110389 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
110390 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
110391 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
110392 +xfs_rtallocate_extent_near_17916 xfs_rtallocate_extent_near 0 17916 NULL
110393 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
110394 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
110395 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
110396 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
110397 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
110398 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
110399 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
110400 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
110401 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
110402 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
110403 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
110404 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
110405 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
110406 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
110407 +fpregs_get_18066 fpregs_get 4 18066 NULL
110408 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
110409 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
110410 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
110411 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
110412 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
110413 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
110414 +svc_getnl_18120 svc_getnl 0 18120 NULL
110415 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
110416 +xfs_zero_eof_18134 xfs_zero_eof 0 18134 NULL
110417 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
110418 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
110419 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
110420 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
110421 +read_rindex_entry_18213 read_rindex_entry 0 18213 NULL
110422 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
110423 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
110424 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
110425 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
110426 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
110427 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
110428 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
110429 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
110430 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
110431 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
110432 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
110433 +um_idi_write_18293 um_idi_write 3 18293 NULL
110434 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
110435 +vga_r_18310 vga_r 0 18310 NULL
110436 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
110437 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
110438 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
110439 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
110440 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
110441 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
110442 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
110443 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
110444 +ep_io_18367 ep_io 0 18367 NULL
110445 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
110446 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
110447 +ci_role_write_18388 ci_role_write 3 18388 NULL
110448 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
110449 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
110450 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
110451 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
110452 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
110453 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
110454 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
110455 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
110456 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
110457 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
110458 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
110459 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
110460 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
110461 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
110462 +__block_write_begin_18511 __block_write_begin 0 18511 NULL
110463 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
110464 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
110465 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
110466 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
110467 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
110468 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
110469 +debug_output_18575 debug_output 3 18575 NULL
110470 +xfs_btree_read_bufl_18597 xfs_btree_read_bufl 0 18597 NULL
110471 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
110472 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
110473 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL
110474 +from_buffer_18625 from_buffer 3 18625 NULL
110475 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
110476 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
110477 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
110478 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
110479 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
110480 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
110481 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
110482 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
110483 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
110484 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
110485 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
110486 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
110487 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
110488 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
110489 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
110490 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
110491 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
110492 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
110493 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
110494 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
110495 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
110496 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
110497 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
110498 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
110499 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
110500 +clean_journal_18955 clean_journal 0 18955 NULL
110501 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
110502 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
110503 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
110504 +huge_page_size_19008 huge_page_size 0 19008 NULL
110505 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
110506 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
110507 +revalidate_19043 revalidate 2 19043 NULL
110508 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
110509 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
110510 +get_log_header_19063 get_log_header 0 19063 NULL
110511 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
110512 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
110513 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
110514 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
110515 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
110516 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
110517 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
110518 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
110519 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
110520 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
110521 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
110522 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
110523 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
110524 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
110525 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
110526 +ucma_query_19260 ucma_query 4 19260 NULL
110527 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
110528 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
110529 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
110530 +qc_capture_19298 qc_capture 3 19298 NULL
110531 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
110532 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
110533 +debug_read_19322 debug_read 3 19322 NULL
110534 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
110535 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
110536 +closure_sub_19359 closure_sub 2 19359 NULL
110537 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
110538 +read_zero_19366 read_zero 3 19366 NULL
110539 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
110540 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
110541 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
110542 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
110543 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
110544 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
110545 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
110546 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
110547 +sky2_read16_19475 sky2_read16 0 19475 NULL
110548 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
110549 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
110550 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
110551 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
110552 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
110553 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
110554 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
110555 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
110556 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
110557 +nfsd_read_19568 nfsd_read 5 19568 NULL
110558 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
110559 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
110560 +bm_status_read_19583 bm_status_read 3 19583 NULL
110561 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
110562 +fallocate_chunk_19610 fallocate_chunk 0 19610 NULL
110563 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
110564 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
110565 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
110566 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
110567 +read_reg_19723 read_reg 0 19723 NULL
110568 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
110569 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
110570 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
110571 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
110572 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
110573 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
110574 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
110575 +readhscx_19769 readhscx 0 19769 NULL
110576 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
110577 +xfs_bmap_add_extent_hole_real_19828 xfs_bmap_add_extent_hole_real 0 19828 NULL
110578 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
110579 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
110580 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
110581 +__nla_put_19857 __nla_put 3 19857 NULL
110582 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
110583 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
110584 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
110585 +mangle_name_19923 mangle_name 0 19923 NULL
110586 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
110587 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
110588 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
110589 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
110590 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
110591 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
110592 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
110593 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
110594 +event_trigger_write_20009 event_trigger_write 3 20009 NULL nohasharray
110595 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 &event_trigger_write_20009
110596 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
110597 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
110598 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
110599 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
110600 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
110601 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
110602 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
110603 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
110604 +team_options_register_20091 team_options_register 3 20091 NULL
110605 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
110606 +xfs_qm_dqget_20103 xfs_qm_dqget 0 20103 NULL
110607 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
110608 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
110609 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
110610 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
110611 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
110612 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
110613 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
110614 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
110615 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
110616 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
110617 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
110618 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
110619 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
110620 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
110621 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
110622 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
110623 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
110624 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
110625 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
110626 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
110627 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
110628 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
110629 +read_buf_20469 read_buf 2 20469 NULL
110630 +bio_trim_20472 bio_trim 2 20472 NULL
110631 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
110632 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
110633 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
110634 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
110635 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
110636 +venus_create_20555 venus_create 4 20555 NULL
110637 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
110638 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
110639 +xfs_bmap_isaeof_20570 xfs_bmap_isaeof 0 20570 NULL
110640 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
110641 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
110642 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
110643 +lirc_write_20604 lirc_write 3 20604 NULL
110644 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
110645 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
110646 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
110647 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
110648 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
110649 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
110650 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
110651 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
110652 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
110653 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
110654 +cpumask_size_20683 cpumask_size 0 20683 NULL
110655 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
110656 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
110657 +__maestro_read_20700 __maestro_read 0 20700 NULL
110658 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
110659 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
110660 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
110661 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
110662 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
110663 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
110664 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
110665 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
110666 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
110667 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
110668 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
110669 +lowpan_write_20800 lowpan_write 3 20800 NULL
110670 +strndup_user_20819 strndup_user 2 20819 NULL nohasharray
110671 +do_glock_20819 do_glock 0 20819 &strndup_user_20819
110672 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
110673 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
110674 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
110675 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
110676 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
110677 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
110678 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
110679 +srq_free_res_20868 srq_free_res 5 20868 NULL
110680 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
110681 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
110682 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
110683 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
110684 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
110685 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
110686 +htable_bits_20933 htable_bits 0 20933 NULL
110687 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
110688 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
110689 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
110690 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
110691 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
110692 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
110693 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
110694 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
110695 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
110696 +xfs_btree_new_root_21028 xfs_btree_new_root 0 21028 NULL
110697 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
110698 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
110699 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
110700 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
110701 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
110702 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
110703 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
110704 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
110705 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
110706 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
110707 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
110708 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
110709 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
110710 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
110711 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
110712 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
110713 +input_ff_create_21240 input_ff_create 2 21240 NULL
110714 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
110715 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
110716 +fru_length_21257 fru_length 0 21257 NULL
110717 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
110718 +xfs_alloc_ag_vextent_size_21276 xfs_alloc_ag_vextent_size 0 21276 NULL
110719 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
110720 +add_res_range_21310 add_res_range 4 21310 NULL
110721 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
110722 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
110723 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
110724 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
110725 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
110726 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
110727 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
110728 +insert_ptr_21386 insert_ptr 6 21386 NULL
110729 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
110730 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
110731 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
110732 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
110733 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
110734 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
110735 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
110736 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
110737 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
110738 +ReadISAR_21453 ReadISAR 0 21453 NULL
110739 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
110740 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
110741 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
110742 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
110743 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
110744 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
110745 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
110746 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
110747 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
110748 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
110749 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
110750 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
110751 +gfs2_glock_nq_init_21624 gfs2_glock_nq_init 0 21624 NULL
110752 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
110753 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
110754 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
110755 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
110756 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
110757 +xfs_btree_insert_21712 xfs_btree_insert 0 21712 NULL
110758 +update_time_21719 update_time 0 21719 NULL
110759 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
110760 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
110761 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
110762 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
110763 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
110764 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
110765 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
110766 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
110767 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
110768 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
110769 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
110770 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
110771 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
110772 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
110773 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
110774 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
110775 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
110776 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
110777 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
110778 +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
110779 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
110780 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
110781 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
110782 +lookup_metapath_22039 lookup_metapath 0 22039 NULL
110783 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
110784 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
110785 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
110786 +mem_rw_22085 mem_rw 3 22085 NULL
110787 +xfs_bmapi_reserve_delalloc_22086 xfs_bmapi_reserve_delalloc 0 22086 NULL
110788 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
110789 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
110790 +shmem_add_to_page_cache_22121 shmem_add_to_page_cache 0 22121 NULL
110791 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
110792 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
110793 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
110794 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
110795 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
110796 +mem_write_22232 mem_write 3 22232 NULL
110797 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
110798 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
110799 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
110800 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
110801 +add_res_tree_22263 add_res_tree 7 22263 NULL
110802 +__btrfs_direct_write_22273 __btrfs_direct_write 4-0 22273 NULL
110803 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
110804 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
110805 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
110806 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
110807 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
110808 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
110809 +atomic_read_22342 atomic_read 0 22342 NULL
110810 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
110811 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
110812 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
110813 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
110814 +zoran_write_22404 zoran_write 3 22404 NULL
110815 +queue_reply_22416 queue_reply 3 22416 NULL
110816 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
110817 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
110818 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
110819 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
110820 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
110821 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
110822 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
110823 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
110824 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
110825 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
110826 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
110827 +snapshot_read_22601 snapshot_read 3 22601 NULL
110828 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
110829 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
110830 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
110831 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
110832 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
110833 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
110834 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
110835 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
110836 +reg_umr_22686 reg_umr 5 22686 NULL
110837 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
110838 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
110839 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
110840 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
110841 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
110842 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
110843 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
110844 +print_frame_22769 print_frame 0 22769 NULL
110845 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
110846 +__break_lease_22777 __break_lease 0 22777 NULL
110847 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
110848 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
110849 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
110850 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
110851 +create_attr_set_22861 create_attr_set 1 22861 NULL
110852 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
110853 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
110854 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
110855 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
110856 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
110857 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
110858 +__set_xattr_22923 __set_xattr 0 22923 NULL
110859 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
110860 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
110861 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
110862 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
110863 +vme_get_size_22964 vme_get_size 0 22964 NULL
110864 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
110865 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
110866 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
110867 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
110868 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
110869 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
110870 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0 23029 NULL
110871 +st_status_23032 st_status 5 23032 NULL
110872 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
110873 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
110874 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
110875 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
110876 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
110877 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
110878 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
110879 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
110880 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
110881 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
110882 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
110883 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
110884 +xfs_dir_ialloc_23100 xfs_dir_ialloc 0 23100 NULL
110885 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
110886 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
110887 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
110888 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL nohasharray
110889 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 &nl80211_send_rx_auth_23111
110890 +__clear_user_23118 __clear_user 0-2 23118 NULL
110891 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
110892 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
110893 +read_file_ani_23161 read_file_ani 3 23161 NULL
110894 +usblp_write_23178 usblp_write 3 23178 NULL
110895 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
110896 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
110897 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
110898 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
110899 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
110900 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
110901 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
110902 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
110903 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
110904 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
110905 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
110906 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
110907 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
110908 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
110909 +page_readlink_23346 page_readlink 3 23346 NULL
110910 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
110911 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
110912 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
110913 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
110914 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
110915 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
110916 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
110917 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
110918 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
110919 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
110920 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
110921 +event_filter_read_23494 event_filter_read 3 23494 NULL
110922 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
110923 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
110924 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
110925 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
110926 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
110927 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
110928 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
110929 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
110930 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
110931 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
110932 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
110933 +xfs_qm_dqread_23613 xfs_qm_dqread 0 23613 NULL
110934 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
110935 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
110936 +sInW_23663 sInW 0 23663 NULL
110937 +SyS_connect_23669 SyS_connect 3 23669 NULL
110938 +cx18_read_23699 cx18_read 3 23699 NULL
110939 +at_get_23708 at_get 0 23708 NULL
110940 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
110941 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
110942 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
110943 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
110944 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
110945 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
110946 +map_write_23795 map_write 3 23795 NULL
110947 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
110948 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
110949 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
110950 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
110951 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-4-3 23829 NULL
110952 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
110953 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
110954 +p54_init_common_23850 p54_init_common 1 23850 NULL
110955 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
110956 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
110957 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
110958 +writeback_single_inode_23881 writeback_single_inode 0 23881 NULL nohasharray
110959 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 &writeback_single_inode_23881
110960 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
110961 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
110962 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
110963 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
110964 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
110965 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
110966 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
110967 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
110968 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
110969 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
110970 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
110971 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
110972 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
110973 +give_pages_24021 give_pages 3 24021 NULL
110974 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
110975 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
110976 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
110977 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
110978 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
110979 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
110980 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
110981 +lov_brw_24122 lov_brw 4 24122 NULL
110982 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
110983 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
110984 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL nohasharray
110985 +xfs_btree_increment_24139 xfs_btree_increment 0 24139 &irnet_ctrl_write_24139
110986 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
110987 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
110988 +adu_read_24177 adu_read 3 24177 NULL
110989 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
110990 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
110991 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
110992 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
110993 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
110994 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
110995 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
110996 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
110997 +xfs_bmap_rtalloc_24237 xfs_bmap_rtalloc 0 24237 NULL
110998 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
110999 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
111000 +thin_status_24278 thin_status 5 24278 NULL
111001 +msg_size_24288 msg_size 0 24288 NULL
111002 +gserial_connect_24302 gserial_connect 0 24302 NULL
111003 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
111004 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
111005 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
111006 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
111007 +prepare_pages_24349 prepare_pages 0 24349 NULL
111008 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
111009 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
111010 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
111011 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
111012 +igetword_24373 igetword 0 24373 NULL nohasharray
111013 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
111014 +max_io_len_24384 max_io_len 0-1 24384 NULL
111015 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
111016 +xfs_bmapi_read_24392 xfs_bmapi_read 0 24392 NULL
111017 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
111018 +getxattr_24398 getxattr 4 24398 NULL nohasharray
111019 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
111020 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
111021 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
111022 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
111023 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
111024 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
111025 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
111026 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
111027 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
111028 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
111029 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
111030 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
111031 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
111032 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
111033 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
111034 +pd_video_read_24510 pd_video_read 3 24510 NULL
111035 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
111036 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
111037 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
111038 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
111039 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
111040 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
111041 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
111042 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
111043 +SyS_poll_24620 SyS_poll 2 24620 NULL
111044 +context_alloc_24645 context_alloc 3 24645 NULL
111045 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
111046 +xfs_log_commit_cil_24653 xfs_log_commit_cil 0 24653 NULL
111047 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
111048 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
111049 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
111050 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
111051 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
111052 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
111053 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
111054 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
111055 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
111056 +cache_read_24790 cache_read 3 24790 NULL
111057 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
111058 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
111059 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
111060 +net2272_read_24825 net2272_read 0 24825 NULL
111061 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
111062 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
111063 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
111064 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
111065 +queues_read_24877 queues_read 3 24877 NULL
111066 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
111067 +xfs_qm_dqattach_24898 xfs_qm_dqattach 0 24898 NULL
111068 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
111069 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 NULL nohasharray
111070 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 &__btrfs_free_extent_24927
111071 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
111072 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
111073 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
111074 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
111075 +slot_get_24999 slot_get 0 24999 NULL
111076 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
111077 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
111078 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
111079 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
111080 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
111081 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
111082 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
111083 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
111084 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
111085 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
111086 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
111087 +gfs2_quota_check_25130 gfs2_quota_check 0 25130 NULL
111088 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
111089 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
111090 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
111091 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
111092 +stripe_status_25259 stripe_status 5 25259 NULL
111093 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
111094 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
111095 +vfs_writev_25278 vfs_writev 3 25278 NULL
111096 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
111097 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
111098 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
111099 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
111100 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
111101 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
111102 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
111103 +xfs_ialloc_pagi_init_25411 xfs_ialloc_pagi_init 0 25411 NULL
111104 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
111105 +xfs_qm_dqtobp_25448 xfs_qm_dqtobp 0 25448 NULL
111106 +generic_file_buffered_write_25464 generic_file_buffered_write 4-0-7 25464 NULL
111107 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
111108 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
111109 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
111110 +xfs_alloc_fix_freelist_25514 xfs_alloc_fix_freelist 0 25514 NULL
111111 +sb_permission_25523 sb_permission 0 25523 NULL
111112 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
111113 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
111114 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
111115 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
111116 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
111117 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
111118 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
111119 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
111120 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
111121 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
111122 +__direct_map_25647 __direct_map 5-6 25647 NULL
111123 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
111124 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
111125 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
111126 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
111127 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
111128 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
111129 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
111130 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
111131 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
111132 +sg_read_25799 sg_read 3 25799 NULL
111133 +xfs_alloc_ag_vextent_exact_25810 xfs_alloc_ag_vextent_exact 0 25810 NULL
111134 +system_enable_read_25815 system_enable_read 3 25815 NULL
111135 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
111136 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
111137 +parport_read_25855 parport_read 0 25855 NULL
111138 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
111139 +key_attr_size_25865 key_attr_size 0 25865 NULL
111140 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
111141 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
111142 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
111143 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
111144 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
111145 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
111146 +rcname_read_25919 rcname_read 3 25919 NULL
111147 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
111148 +key_flags_read_25931 key_flags_read 3 25931 NULL
111149 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
111150 +flush_25957 flush 2 25957 NULL
111151 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
111152 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
111153 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
111154 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
111155 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
111156 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
111157 +btrfs_wait_ordered_range_26086 btrfs_wait_ordered_range 0 26086 NULL
111158 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
111159 +read_sb_page_26119 read_sb_page 5 26119 NULL
111160 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
111161 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
111162 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
111163 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
111164 +disk_devt_26180 disk_devt 0 26180 NULL
111165 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
111166 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
111167 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
111168 +mce_write_26201 mce_write 3 26201 NULL
111169 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
111170 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
111171 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
111172 +simple_setattr_26234 simple_setattr 0 26234 NULL
111173 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
111174 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
111175 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
111176 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
111177 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
111178 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
111179 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
111180 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
111181 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
111182 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
111183 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
111184 +ntty_write_26404 ntty_write 3 26404 NULL
111185 +firmware_store_26408 firmware_store 4 26408 NULL
111186 +pagemap_read_26441 pagemap_read 3 26441 NULL
111187 +tower_read_26461 tower_read 3 26461 NULL nohasharray
111188 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
111189 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
111190 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
111191 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
111192 +read_vmcore_26501 read_vmcore 3 26501 NULL
111193 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
111194 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
111195 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
111196 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
111197 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
111198 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
111199 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
111200 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
111201 +xfs_rtcheck_range_26614 xfs_rtcheck_range 0 26614 NULL
111202 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
111203 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
111204 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
111205 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
111206 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
111207 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
111208 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
111209 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
111210 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
111211 +bos_desc_26752 bos_desc 0 26752 NULL
111212 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
111213 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
111214 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
111215 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
111216 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
111217 +smk_write_load_26829 smk_write_load 3 26829 NULL
111218 +xfs_alloc_pagf_init_26834 xfs_alloc_pagf_init 0 26834 NULL
111219 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
111220 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
111221 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
111222 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
111223 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
111224 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
111225 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
111226 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
111227 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
111228 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
111229 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
111230 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
111231 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
111232 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
111233 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
111234 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
111235 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
111236 +xfs_filestream_associate_27030 xfs_filestream_associate 0 27030 NULL
111237 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
111238 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
111239 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
111240 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
111241 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
111242 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
111243 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
111244 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
111245 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
111246 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
111247 +pms_capture_27142 pms_capture 4 27142 NULL
111248 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
111249 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
111250 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
111251 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
111252 +write_kmem_27225 write_kmem 3 27225 NULL
111253 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
111254 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
111255 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
111256 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
111257 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
111258 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
111259 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
111260 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
111261 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
111262 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
111263 +seq_read_27411 seq_read 3 27411 NULL
111264 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
111265 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
111266 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0 27422 NULL
111267 +cypress_write_27423 cypress_write 4 27423 NULL
111268 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
111269 +xfs_btree_lookup_get_block_27448 xfs_btree_lookup_get_block 0 27448 NULL
111270 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
111271 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
111272 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
111273 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
111274 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
111275 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
111276 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
111277 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
111278 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
111279 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
111280 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
111281 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
111282 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
111283 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
111284 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642 nohasharray
111285 +xfs_alloc_vextent_27642 xfs_alloc_vextent 0 27642 &ocfs2_direct_IO_27642
111286 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
111287 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
111288 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
111289 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
111290 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
111291 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
111292 +evm_write_key_27715 evm_write_key 3 27715 NULL
111293 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
111294 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
111295 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
111296 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
111297 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
111298 +SyS_readv_27804 SyS_readv 3 27804 NULL
111299 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
111300 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
111301 +init_header_complete_27833 init_header_complete 0 27833 NULL
111302 +read_profile_27859 read_profile 3 27859 NULL
111303 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
111304 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
111305 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
111306 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
111307 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
111308 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
111309 +device_register_27972 device_register 0 27972 NULL nohasharray
111310 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
111311 +xfs_alloc_fixup_trees_27975 xfs_alloc_fixup_trees 0 27975 NULL
111312 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL nohasharray
111313 +__kernfs_setattr_27977 __kernfs_setattr 0 27977 &pci_enable_device_flags_27977
111314 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
111315 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
111316 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
111317 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
111318 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
111319 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
111320 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
111321 +pool_status_28055 pool_status 5 28055 NULL
111322 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
111323 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
111324 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
111325 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
111326 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
111327 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
111328 +memblock_virt_alloc_from_nopanic_28146 memblock_virt_alloc_from_nopanic 1 28146 NULL
111329 +video_read_28148 video_read 3 28148 NULL
111330 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
111331 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
111332 +vread_28173 vread 0-3 28173 NULL
111333 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
111334 +counter_free_res_28187 counter_free_res 5 28187 NULL
111335 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
111336 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
111337 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
111338 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
111339 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
111340 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
111341 +usemap_size_28281 usemap_size 0 28281 NULL
111342 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
111343 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
111344 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
111345 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
111346 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
111347 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
111348 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
111349 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
111350 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
111351 +snapshot_write_28351 snapshot_write 3 28351 NULL
111352 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
111353 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
111354 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
111355 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
111356 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
111357 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
111358 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
111359 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
111360 +xfs_rtfind_back_28450 xfs_rtfind_back 0 28450 NULL
111361 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
111362 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
111363 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
111364 +__filemap_fdatawrite_28485 __filemap_fdatawrite 0 28485 NULL
111365 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
111366 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
111367 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
111368 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
111369 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
111370 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
111371 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
111372 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
111373 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
111374 +gfs2_meta_indirect_buffer_28573 gfs2_meta_indirect_buffer 0 28573 NULL
111375 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
111376 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
111377 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
111378 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
111379 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
111380 +xfs_bmap_finish_28644 xfs_bmap_finish 0 28644 NULL
111381 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
111382 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
111383 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
111384 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
111385 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
111386 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
111387 +spi_execute_28736 spi_execute 5 28736 NULL
111388 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
111389 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
111390 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
111391 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
111392 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
111393 +sel_write_member_28800 sel_write_member 3 28800 NULL
111394 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
111395 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
111396 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
111397 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
111398 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
111399 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
111400 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
111401 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
111402 +push_rx_28939 push_rx 3 28939 NULL
111403 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
111404 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
111405 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
111406 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
111407 +xfs_alloc_update_28982 xfs_alloc_update 0 28982 NULL
111408 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
111409 +bin_uuid_28999 bin_uuid 3 28999 NULL
111410 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
111411 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
111412 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
111413 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
111414 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
111415 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
111416 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
111417 +xfs_alloc_ag_vextent_small_29084 xfs_alloc_ag_vextent_small 0 29084 NULL
111418 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
111419 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
111420 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
111421 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
111422 +snprintf_29125 snprintf 0 29125 NULL
111423 +iov_shorten_29130 iov_shorten 0 29130 NULL
111424 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
111425 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
111426 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
111427 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
111428 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
111429 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
111430 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
111431 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
111432 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
111433 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
111434 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
111435 +xfs_bmap_btree_to_extents_29297 xfs_bmap_btree_to_extents 0 29297 NULL
111436 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
111437 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
111438 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
111439 +xfs_bmbt_change_owner_29325 xfs_bmbt_change_owner 0 29325 NULL
111440 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
111441 +tun_put_user_29337 tun_put_user 5 29337 NULL
111442 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
111443 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
111444 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
111445 +mempool_create_29437 mempool_create 1 29437 NULL
111446 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
111447 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
111448 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
111449 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
111450 +do_register_entry_29478 do_register_entry 4 29478 NULL
111451 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
111452 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
111453 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
111454 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
111455 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
111456 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
111457 +add_to_page_cache_lru_29534 add_to_page_cache_lru 0 29534 NULL
111458 +ftrace_write_29551 ftrace_write 3 29551 NULL
111459 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
111460 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
111461 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
111462 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
111463 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
111464 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
111465 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
111466 +slots_per_page_29601 slots_per_page 0 29601 NULL
111467 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
111468 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
111469 +gfs2_alloc_blocks_29630 gfs2_alloc_blocks 0 29630 NULL
111470 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
111471 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
111472 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
111473 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
111474 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
111475 +probes_write_29711 probes_write 3 29711 NULL
111476 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
111477 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
111478 +std_nic_write_29752 std_nic_write 3 29752 NULL
111479 +dbAlloc_29794 dbAlloc 0 29794 NULL
111480 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
111481 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
111482 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
111483 +count_partial_29850 count_partial 0 29850 NULL
111484 +xfs_rtfind_forw_29866 xfs_rtfind_forw 0 29866 NULL
111485 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
111486 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
111487 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
111488 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
111489 +xfs_alloc_read_agf_29893 xfs_alloc_read_agf 0 29893 NULL
111490 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
111491 +write_file_queue_29922 write_file_queue 3 29922 NULL
111492 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
111493 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
111494 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
111495 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
111496 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
111497 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
111498 +drp_wmove_30043 drp_wmove 4 30043 NULL
111499 +mem_cgroup_charge_common_30047 mem_cgroup_charge_common 0 30047 NULL
111500 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
111501 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
111502 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
111503 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
111504 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
111505 +xfs_iget_cache_miss_30115 xfs_iget_cache_miss 0 30115 NULL
111506 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
111507 +recv_stream_30138 recv_stream 4 30138 NULL
111508 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
111509 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
111510 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
111511 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
111512 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
111513 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
111514 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
111515 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
111516 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
111517 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
111518 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
111519 +shmem_unuse_inode_30263 shmem_unuse_inode 0 30263 NULL
111520 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
111521 +try_break_deleg_30271 try_break_deleg 0 30271 NULL nohasharray
111522 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 &try_break_deleg_30271
111523 +compat_readv_30273 compat_readv 3 30273 NULL
111524 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
111525 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
111526 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
111527 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
111528 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
111529 +i8254_read_30330 i8254_read 0 30330 NULL
111530 +resource_from_user_30341 resource_from_user 3 30341 NULL
111531 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
111532 +gfs2_trans_begin_30359 gfs2_trans_begin 0 30359 NULL
111533 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
111534 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
111535 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
111536 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
111537 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
111538 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
111539 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
111540 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
111541 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
111542 +enable_write_30456 enable_write 3 30456 NULL
111543 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
111544 +urandom_read_30462 urandom_read 3 30462 NULL
111545 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
111546 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
111547 +adu_write_30487 adu_write 3 30487 NULL
111548 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
111549 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
111550 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
111551 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
111552 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
111553 +set_config_30526 set_config 0 30526 NULL nohasharray
111554 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
111555 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
111556 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
111557 +set_le_30581 set_le 4 30581 NULL
111558 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
111559 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
111560 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
111561 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
111562 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
111563 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
111564 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
111565 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
111566 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
111567 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL nohasharray
111568 +xfs_bmap_add_extent_unwritten_real_30701 xfs_bmap_add_extent_unwritten_real 0 30701 &dccp_setsockopt_ccid_30701
111569 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
111570 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
111571 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
111572 +snapshot_status_30744 snapshot_status 5 30744 NULL
111573 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
111574 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
111575 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
111576 +xlog_grant_head_wait_30829 xlog_grant_head_wait 0 30829 NULL
111577 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
111578 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
111579 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
111580 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
111581 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
111582 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
111583 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
111584 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
111585 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
111586 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
111587 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
111588 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
111589 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
111590 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
111591 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
111592 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
111593 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
111594 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
111595 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
111596 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
111597 +depth_read_31112 depth_read 3 31112 NULL
111598 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
111599 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
111600 +size_inside_page_31141 size_inside_page 0 31141 NULL
111601 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
111602 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
111603 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
111604 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
111605 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
111606 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
111607 +__read_reg_31216 __read_reg 0 31216 NULL
111608 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
111609 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
111610 +cyy_readb_31240 cyy_readb 0 31240 NULL
111611 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
111612 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
111613 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
111614 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
111615 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
111616 +command_file_write_31318 command_file_write 3 31318 NULL
111617 +radix_tree_insert_31336 radix_tree_insert 0 31336 NULL
111618 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
111619 +outlen_write_31358 outlen_write 3 31358 NULL
111620 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
111621 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
111622 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
111623 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
111624 +inb_31388 inb 0 31388 NULL
111625 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
111626 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
111627 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
111628 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
111629 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
111630 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
111631 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
111632 +alg_setkey_31485 alg_setkey 3 31485 NULL
111633 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
111634 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
111635 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
111636 +hidraw_write_31536 hidraw_write 3 31536 NULL
111637 +usbvision_read_31555 usbvision_read 3 31555 NULL
111638 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
111639 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
111640 +osst_write_31581 osst_write 3 31581 NULL
111641 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
111642 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
111643 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
111644 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
111645 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
111646 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
111647 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
111648 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
111649 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
111650 +__lgread_31668 __lgread 4 31668 NULL
111651 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
111652 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
111653 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
111654 +gfs2_dir_check_31711 gfs2_dir_check 0 31711 NULL
111655 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
111656 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
111657 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
111658 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
111659 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
111660 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
111661 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
111662 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
111663 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
111664 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
111665 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
111666 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
111667 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
111668 +data_write_31805 data_write 3 31805 NULL
111669 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
111670 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
111671 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
111672 +clone_bio_31854 clone_bio 4-3 31854 NULL
111673 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
111674 +foreach_descriptor_31873 foreach_descriptor 0 31873 NULL
111675 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
111676 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
111677 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
111678 +xattr_permission_31907 xattr_permission 0 31907 NULL
111679 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
111680 +new_dir_31919 new_dir 3 31919 NULL
111681 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
111682 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
111683 +read_mem_31942 read_mem 3 31942 NULL nohasharray
111684 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
111685 +vb2_write_31948 vb2_write 3 31948 NULL
111686 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
111687 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
111688 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
111689 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
111690 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
111691 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
111692 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
111693 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
111694 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
111695 +calc_hmac_32010 calc_hmac 3 32010 NULL
111696 +aead_len_32021 aead_len 0 32021 NULL
111697 +stk_read_32038 stk_read 3 32038 NULL
111698 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
111699 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
111700 +xfs_buf_iowait_32068 xfs_buf_iowait 0 32068 NULL
111701 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
111702 +bio_alloc_32095 bio_alloc 2 32095 NULL
111703 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
111704 +disk_status_32120 disk_status 4 32120 NULL
111705 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
111706 +venus_link_32165 venus_link 5 32165 NULL
111707 +do_writepages_32173 do_writepages 0 32173 NULL
111708 +del_ptr_32197 del_ptr 4 32197 NULL
111709 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
111710 +__mem_cgroup_try_charge_swapin_32204 __mem_cgroup_try_charge_swapin 0 32204 NULL
111711 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
111712 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
111713 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
111714 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
111715 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
111716 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
111717 +SyS_select_32319 SyS_select 1 32319 NULL
111718 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
111719 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
111720 +xfs_bmap_extsize_align_32338 xfs_bmap_extsize_align 0 32338 NULL
111721 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
111722 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
111723 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
111724 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
111725 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
111726 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
111727 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
111728 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
111729 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
111730 +xfs_alloc_put_freelist_32437 xfs_alloc_put_freelist 0 32437 NULL
111731 +cache_status_32462 cache_status 5 32462 NULL
111732 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
111733 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
111734 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
111735 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
111736 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
111737 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
111738 +disconnect_32521 disconnect 4 32521 NULL
111739 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
111740 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL
111741 +ilo_read_32531 ilo_read 3 32531 NULL
111742 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
111743 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
111744 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
111745 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
111746 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
111747 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
111748 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
111749 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
111750 +xfs_bmap_last_offset_32614 xfs_bmap_last_offset 0 32614 NULL
111751 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
111752 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
111753 +kvmalloc_32646 kvmalloc 1 32646 NULL
111754 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
111755 +generic_readlink_32654 generic_readlink 3 32654 NULL
111756 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
111757 +apei_res_add_32674 apei_res_add 0 32674 NULL
111758 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
111759 +xfs_filestream_new_ag_32711 xfs_filestream_new_ag 0 32711 NULL
111760 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
111761 +xfs_bmbt_update_32713 xfs_bmbt_update 0 32713 NULL
111762 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
111763 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
111764 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
111765 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
111766 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
111767 +xfs_trans_read_buf_32795 xfs_trans_read_buf 0 32795 NULL
111768 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
111769 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
111770 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
111771 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
111772 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
111773 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
111774 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
111775 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
111776 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
111777 +xfs_log_reserve_32959 xfs_log_reserve 0 32959 NULL
111778 +compat_filldir_32999 compat_filldir 3 32999 NULL
111779 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
111780 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
111781 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
111782 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
111783 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
111784 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
111785 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
111786 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
111787 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
111788 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
111789 +alloc_tio_33077 alloc_tio 3 33077 NULL
111790 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
111791 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
111792 +notify_change_33143 notify_change 0 33143 NULL
111793 +SyS_poll_33152 SyS_poll 2 33152 NULL
111794 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
111795 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
111796 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
111797 +pp_read_33210 pp_read 3 33210 NULL
111798 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
111799 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
111800 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
111801 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
111802 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
111803 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
111804 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
111805 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
111806 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
111807 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
111808 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
111809 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
111810 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
111811 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
111812 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
111813 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
111814 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
111815 +filemap_fdatawrite_33415 filemap_fdatawrite 0 33415 NULL
111816 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
111817 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
111818 +message_stats_list_33440 message_stats_list 5 33440 NULL
111819 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
111820 +create_entry_33479 create_entry 2 33479 NULL
111821 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
111822 +res_counter_read_33499 res_counter_read 4 33499 NULL
111823 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
111824 +fb_read_33506 fb_read 3 33506 NULL
111825 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
111826 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
111827 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
111828 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
111829 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
111830 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
111831 +count_subheaders_33591 count_subheaders 0 33591 NULL
111832 +scsi_execute_33596 scsi_execute 5 33596 NULL
111833 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
111834 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
111835 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
111836 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
111837 +xfs_btree_check_sblock_33618 xfs_btree_check_sblock 0 33618 NULL
111838 +stride_page_count_33641 stride_page_count 2 33641 NULL
111839 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
111840 +inw_p_33668 inw_p 0 33668 NULL
111841 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
111842 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
111843 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
111844 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
111845 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
111846 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
111847 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
111848 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
111849 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
111850 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
111851 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
111852 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
111853 +hashtab_create_33769 hashtab_create 3 33769 NULL
111854 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
111855 +filter_write_33819 filter_write 3 33819 NULL
111856 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
111857 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
111858 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
111859 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
111860 +get_user_pages_33908 get_user_pages 0 33908 NULL
111861 +sg_nents_33909 sg_nents 0 33909 NULL
111862 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
111863 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
111864 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
111865 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
111866 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
111867 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
111868 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
111869 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
111870 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
111871 +ppp_write_34034 ppp_write 3 34034 NULL
111872 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
111873 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
111874 +xfs_dialloc_34078 xfs_dialloc 0 34078 NULL
111875 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
111876 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
111877 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
111878 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
111879 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
111880 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
111881 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
111882 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
111883 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
111884 +xfs_bmapi_write_34208 xfs_bmapi_write 0 34208 NULL
111885 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
111886 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
111887 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
111888 +device_private_init_34279 device_private_init 0 34279 NULL
111889 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
111890 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
111891 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
111892 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
111893 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
111894 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
111895 +ea_read_34378 ea_read 0 34378 NULL
111896 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
111897 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
111898 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
111899 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
111900 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
111901 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
111902 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
111903 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
111904 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
111905 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
111906 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
111907 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
111908 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
111909 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
111910 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
111911 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
111912 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
111913 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
111914 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
111915 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
111916 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
111917 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
111918 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
111919 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
111920 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
111921 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
111922 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
111923 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
111924 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
111925 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
111926 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
111927 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
111928 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
111929 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
111930 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
111931 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
111932 +port_print_34704 port_print 3 34704 NULL
111933 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
111934 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
111935 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
111936 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
111937 +bootmode_store_34762 bootmode_store 4 34762 NULL
111938 +device_add_34766 device_add 0 34766 NULL
111939 +xfs_iget_cache_hit_34767 xfs_iget_cache_hit 0 34767 NULL
111940 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
111941 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
111942 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
111943 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
111944 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
111945 +file_page_index_34820 file_page_index 0-2 34820 NULL
111946 +bio_segments_34832 bio_segments 0 34832 NULL
111947 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
111948 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
111949 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
111950 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
111951 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
111952 +msg_print_text_34889 msg_print_text 0 34889 NULL
111953 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
111954 +gfs2_glock_wait_34913 gfs2_glock_wait 0 34913 NULL
111955 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
111956 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
111957 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
111958 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
111959 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
111960 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
111961 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
111962 +print_message_35000 print_message 0 35000 NULL
111963 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
111964 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
111965 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
111966 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
111967 +xfs_rtallocate_extent_35052 xfs_rtallocate_extent 0 35052 NULL
111968 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
111969 +ntfs_attr_extend_initialized_35084 ntfs_attr_extend_initialized 0 35084 NULL
111970 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
111971 +capi_write_35104 capi_write 3 35104 NULL nohasharray
111972 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
111973 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
111974 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
111975 +message_stats_print_35158 message_stats_print 6 35158 NULL
111976 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
111977 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
111978 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
111979 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
111980 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
111981 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
111982 +set_fd_set_35249 set_fd_set 1 35249 NULL
111983 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
111984 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
111985 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
111986 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
111987 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
111988 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
111989 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
111990 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
111991 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
111992 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
111993 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
111994 +xfs_btree_check_lblock_35333 xfs_btree_check_lblock 0 35333 NULL
111995 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
111996 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
111997 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
111998 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
111999 +read_kmem_35372 read_kmem 3 35372 NULL
112000 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
112001 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
112002 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
112003 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
112004 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
112005 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
112006 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
112007 +async_setkey_35521 async_setkey 3 35521 NULL
112008 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
112009 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
112010 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
112011 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
112012 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
112013 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
112014 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
112015 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
112016 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
112017 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
112018 +kernel_readv_35617 kernel_readv 3 35617 NULL
112019 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
112020 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
112021 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
112022 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
112023 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
112024 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
112025 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
112026 +md_super_write_35703 md_super_write 4 35703 NULL
112027 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
112028 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
112029 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
112030 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
112031 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
112032 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
112033 +fls64_35862 fls64 0 35862 NULL
112034 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
112035 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
112036 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
112037 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
112038 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
112039 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
112040 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
112041 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
112042 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
112043 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
112044 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
112045 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
112046 +acl_alloc_35979 acl_alloc 1 35979 NULL
112047 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
112048 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
112049 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
112050 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
112051 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
112052 +account_shadowed_36048 account_shadowed 2 36048 NULL
112053 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
112054 +write_emulate_36065 write_emulate 2-4 36065 NULL
112055 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
112056 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
112057 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
112058 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
112059 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
112060 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
112061 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
112062 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
112063 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
112064 +twl_set_36154 twl_set 2 36154 NULL
112065 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
112066 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
112067 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
112068 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
112069 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
112070 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
112071 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
112072 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
112073 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
112074 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
112075 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
112076 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
112077 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
112078 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
112079 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
112080 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
112081 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
112082 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
112083 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
112084 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
112085 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
112086 +lc_create_36332 lc_create 4 36332 NULL
112087 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
112088 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
112089 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
112090 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
112091 +to_sector_36361 to_sector 0-1 36361 NULL
112092 +tunables_read_36385 tunables_read 3 36385 NULL
112093 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
112094 +sierra_write_36402 sierra_write 4 36402 NULL
112095 +qdsb_get_36409 qdsb_get 0 36409 NULL
112096 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
112097 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
112098 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
112099 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
112100 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
112101 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
112102 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
112103 +ip6_append_data_36490 ip6_append_data 4 36490 NULL nohasharray
112104 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
112105 +cmd_loop_36491 cmd_loop 0 36491 NULL
112106 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
112107 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
112108 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
112109 +get_param_l_36518 get_param_l 0 36518 NULL
112110 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
112111 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
112112 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
112113 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
112114 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
112115 +__erst_read_36579 __erst_read 0 36579 NULL
112116 +put_cmsg_36589 put_cmsg 4 36589 NULL
112117 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
112118 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
112119 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
112120 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
112121 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
112122 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
112123 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
112124 +xillybus_read_36678 xillybus_read 3 36678 NULL
112125 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
112126 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
112127 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
112128 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
112129 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
112130 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
112131 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
112132 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
112133 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
112134 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
112135 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
112136 +cm_write_36858 cm_write 3 36858 NULL
112137 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
112138 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
112139 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
112140 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
112141 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
112142 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
112143 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
112144 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
112145 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
112146 +xfs_btree_check_sptr_36984 xfs_btree_check_sptr 0 36984 NULL
112147 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
112148 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
112149 +setxattr_37006 setxattr 4 37006 NULL
112150 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
112151 +command_file_read_37038 command_file_read 3 37038 NULL
112152 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
112153 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
112154 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
112155 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
112156 +parse_command_37079 parse_command 2 37079 NULL
112157 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
112158 +tun_get_user_37094 tun_get_user 5 37094 NULL
112159 +xlog_grant_head_check_37116 xlog_grant_head_check 0 37116 NULL
112160 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
112161 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
112162 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
112163 +msg_word_37164 msg_word 0 37164 NULL
112164 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
112165 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
112166 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
112167 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
112168 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
112169 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
112170 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
112171 +__do_replace_37227 __do_replace 5 37227 NULL
112172 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
112173 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
112174 +xfs_reclaim_inode_37257 xfs_reclaim_inode 0 37257 NULL
112175 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
112176 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
112177 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
112178 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
112179 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
112180 +send_msg_37323 send_msg 4 37323 NULL
112181 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
112182 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
112183 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
112184 +xfs_iomap_write_allocate_37336 xfs_iomap_write_allocate 0 37336 NULL
112185 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
112186 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
112187 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
112188 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
112189 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
112190 +fru_alloc_37442 fru_alloc 1 37442 NULL
112191 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
112192 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
112193 +xfs_btree_dec_cursor_37452 xfs_btree_dec_cursor 0 37452 NULL
112194 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
112195 +get_est_timing_37484 get_est_timing 0 37484 NULL
112196 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
112197 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
112198 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
112199 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
112200 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
112201 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
112202 +hdr_size_37536 hdr_size 0 37536 NULL
112203 +extent_map_end_37550 extent_map_end 0 37550 NULL
112204 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
112205 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
112206 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
112207 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
112208 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
112209 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
112210 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
112211 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
112212 +may_delete_37656 may_delete 0 37656 NULL
112213 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
112214 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
112215 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
112216 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
112217 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
112218 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
112219 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
112220 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
112221 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
112222 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
112223 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
112224 +xfs_read_agf_37749 xfs_read_agf 0 37749 NULL
112225 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
112226 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
112227 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
112228 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
112229 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
112230 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
112231 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
112232 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
112233 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
112234 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
112235 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
112236 +set_registers_37883 set_registers 4 37883 NULL
112237 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
112238 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
112239 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
112240 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
112241 +write_file_bool_37957 write_file_bool 3 37957 NULL
112242 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
112243 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
112244 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
112245 +vfs_readv_38011 vfs_readv 3 38011 NULL
112246 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
112247 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
112248 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
112249 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
112250 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
112251 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
112252 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
112253 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
112254 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
112255 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
112256 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
112257 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
112258 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
112259 +ep0_read_38095 ep0_read 3 38095 NULL
112260 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
112261 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
112262 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
112263 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
112264 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
112265 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
112266 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
112267 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
112268 +cdev_add_38176 cdev_add 2-3 38176 NULL
112269 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
112270 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
112271 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL nohasharray
112272 +xfs_rtallocate_range_38223 xfs_rtallocate_range 0 38223 &osd_req_list_partition_collections_38223
112273 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
112274 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
112275 +xfs_qm_dqrepair_38262 xfs_qm_dqrepair 0 38262 NULL
112276 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
112277 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
112278 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
112279 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
112280 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
112281 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
112282 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
112283 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
112284 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
112285 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
112286 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
112287 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
112288 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
112289 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
112290 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
112291 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
112292 +dev_names_read_38509 dev_names_read 3 38509 NULL
112293 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
112294 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
112295 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
112296 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
112297 +kuc_len_38557 kuc_len 0-1 38557 NULL
112298 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
112299 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
112300 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
112301 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
112302 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
112303 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
112304 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
112305 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
112306 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
112307 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
112308 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
112309 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
112310 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
112311 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
112312 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
112313 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
112314 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
112315 +udf_readpages_38761 udf_readpages 4 38761 NULL
112316 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
112317 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
112318 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
112319 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
112320 +err_decode_38804 err_decode 2 38804 NULL
112321 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
112322 +direct_entry_38836 direct_entry 3 38836 NULL
112323 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
112324 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
112325 +interfaces_38859 interfaces 2 38859 NULL
112326 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
112327 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
112328 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
112329 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
112330 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
112331 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
112332 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
112333 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
112334 +get_nodes_39012 get_nodes 3 39012 NULL
112335 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
112336 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
112337 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
112338 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
112339 +ReadHFC_39104 ReadHFC 0 39104 NULL
112340 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
112341 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
112342 +ea_foreach_39133 ea_foreach 0 39133 NULL
112343 +generic_permission_39150 generic_permission 0 39150 NULL
112344 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
112345 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
112346 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
112347 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
112348 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
112349 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
112350 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
112351 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
112352 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 NULL nohasharray
112353 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 &pwr_cont_miss_bcns_spread_read_39250
112354 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
112355 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
112356 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
112357 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
112358 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
112359 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
112360 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
112361 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
112362 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
112363 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
112364 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
112365 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
112366 +__send_to_port_39386 __send_to_port 3 39386 NULL
112367 +xfs_btree_dup_cursor_39394 xfs_btree_dup_cursor 0 39394 NULL
112368 +gfs2_internal_read_39413 gfs2_internal_read 0 39413 NULL
112369 +user_power_read_39414 user_power_read 3 39414 NULL
112370 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
112371 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
112372 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
112373 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
112374 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
112375 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
112376 +int_proc_write_39542 int_proc_write 3 39542 NULL
112377 +pp_write_39554 pp_write 3 39554 NULL
112378 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
112379 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
112380 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
112381 +ext_depth_39607 ext_depth 0 39607 NULL
112382 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
112383 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
112384 +sdio_readb_39618 sdio_readb 0 39618 NULL
112385 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
112386 +set_dev_class_39645 set_dev_class 4 39645 NULL
112387 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
112388 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
112389 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
112390 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
112391 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
112392 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
112393 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
112394 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
112395 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
112396 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
112397 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
112398 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
112399 +pkt_add_39897 pkt_add 3 39897 NULL
112400 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
112401 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
112402 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
112403 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
112404 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
112405 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
112406 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
112407 +__spi_async_39932 __spi_async 0 39932 NULL
112408 +__get_order_39935 __get_order 0 39935 NULL
112409 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
112410 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
112411 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
112412 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
112413 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
112414 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
112415 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
112416 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
112417 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
112418 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
112419 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
112420 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
112421 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
112422 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
112423 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
112424 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
112425 +xfs_rtbuf_get_40107 xfs_rtbuf_get 0 40107 NULL
112426 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
112427 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
112428 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
112429 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
112430 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
112431 +pt_write_40159 pt_write 3 40159 NULL
112432 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
112433 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
112434 +allocate_probes_40204 allocate_probes 1 40204 NULL
112435 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
112436 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
112437 +osst_read_40237 osst_read 3 40237 NULL
112438 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
112439 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
112440 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
112441 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
112442 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
112443 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
112444 +SyS_bind_40303 SyS_bind 3 40303 NULL
112445 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
112446 +mmio_read_40348 mmio_read 4 40348 NULL
112447 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
112448 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
112449 +get_chars_40373 get_chars 3 40373 NULL
112450 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
112451 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
112452 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
112453 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
112454 +SyS_writev_40467 SyS_writev 3 40467 NULL
112455 +SyS_select_40473 SyS_select 1 40473 NULL
112456 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
112457 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
112458 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
112459 +xfs_iread_extents_40510 xfs_iread_extents 0 40510 NULL
112460 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
112461 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
112462 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
112463 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
112464 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
112465 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
112466 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
112467 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
112468 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
112469 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
112470 +fops_read_40672 fops_read 3 40672 NULL
112471 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
112472 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
112473 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
112474 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
112475 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
112476 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
112477 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
112478 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
112479 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
112480 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
112481 +card_send_command_40757 card_send_command 3 40757 NULL
112482 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
112483 +pg_write_40766 pg_write 3 40766 NULL
112484 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
112485 +show_list_40775 show_list 3-0 40775 NULL
112486 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
112487 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
112488 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
112489 +add_action_40811 add_action 4 40811 NULL
112490 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
112491 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
112492 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
112493 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
112494 +read_file_queue_40895 read_file_queue 3 40895 NULL
112495 +waiters_read_40902 waiters_read 3 40902 NULL
112496 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
112497 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
112498 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
112499 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
112500 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
112501 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
112502 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
112503 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
112504 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
112505 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
112506 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
112507 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
112508 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
112509 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
112510 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
112511 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
112512 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
112513 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
112514 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
112515 +dma_attach_41094 dma_attach 5-6 41094 NULL
112516 +provide_user_output_41105 provide_user_output 3 41105 NULL
112517 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
112518 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
112519 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
112520 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
112521 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
112522 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
112523 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
112524 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
112525 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
112526 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
112527 +erst_read_41260 erst_read 0 41260 NULL
112528 +alloc_context_41283 alloc_context 1 41283 NULL
112529 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
112530 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
112531 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
112532 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
112533 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
112534 +kmp_init_41373 kmp_init 2 41373 NULL
112535 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
112536 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
112537 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
112538 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
112539 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
112540 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
112541 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4-0 41442 NULL
112542 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
112543 +se_io_cb_41461 se_io_cb 3 41461 NULL
112544 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
112545 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
112546 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
112547 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
112548 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
112549 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
112550 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
112551 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
112552 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
112553 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
112554 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
112555 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
112556 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
112557 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
112558 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
112559 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
112560 +vga_io_r_41609 vga_io_r 0 41609 NULL
112561 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
112562 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
112563 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
112564 +a2mp_send_41615 a2mp_send 4 41615 NULL
112565 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
112566 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
112567 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
112568 +get_std_timing_41654 get_std_timing 0 41654 NULL
112569 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
112570 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
112571 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
112572 +fillonedir_41746 fillonedir 3 41746 NULL
112573 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
112574 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
112575 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
112576 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
112577 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
112578 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
112579 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
112580 +xfs_rtget_summary_41864 xfs_rtget_summary 0 41864 NULL
112581 +pci_map_single_41869 pci_map_single 0 41869 NULL
112582 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
112583 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
112584 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
112585 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
112586 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
112587 +read_gssp_41947 read_gssp 3 41947 NULL
112588 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
112589 +portnames_read_41958 portnames_read 3 41958 NULL
112590 +dst_mtu_41969 dst_mtu 0 41969 NULL
112591 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
112592 +xfs_qm_dqalloc_41985 xfs_qm_dqalloc 0 41985 NULL
112593 +pool_allocate_42012 pool_allocate 3 42012 NULL
112594 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
112595 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
112596 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
112597 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
112598 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
112599 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
112600 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
112601 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
112602 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
112603 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
112604 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
112605 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
112606 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
112607 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
112608 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
112609 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
112610 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
112611 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
112612 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
112613 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
112614 +xfs_rtfree_range_42244 xfs_rtfree_range 0 42244 NULL
112615 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
112616 +find_last_bit_42260 find_last_bit 0 42260 NULL
112617 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
112618 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
112619 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
112620 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
112621 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
112622 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
112623 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
112624 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
112625 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
112626 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
112627 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
112628 +tipc_send_42374 tipc_send 3 42374 NULL
112629 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
112630 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
112631 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
112632 +krng_get_random_42420 krng_get_random 3 42420 NULL
112633 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
112634 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
112635 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
112636 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
112637 +kuc_free_42455 kuc_free 2 42455 NULL
112638 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
112639 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
112640 +bypass_write_42498 bypass_write 3 42498 NULL
112641 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
112642 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
112643 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
112644 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
112645 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
112646 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
112647 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
112648 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
112649 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
112650 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
112651 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
112652 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
112653 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
112654 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
112655 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
112656 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
112657 +vb2_read_42703 vb2_read 3 42703 NULL
112658 +read_status_42722 read_status 0 42722 NULL
112659 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
112660 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
112661 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
112662 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
112663 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
112664 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
112665 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
112666 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
112667 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
112668 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
112669 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
112670 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
112671 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
112672 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
112673 +set_arg_42824 set_arg 3 42824 NULL
112674 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
112675 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
112676 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
112677 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
112678 +hd_end_request_42904 hd_end_request 2 42904 NULL
112679 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
112680 +xfs_bmapi_allocate_42938 xfs_bmapi_allocate 0 42938 NULL
112681 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
112682 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
112683 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
112684 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
112685 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
112686 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
112687 +xfs_da_read_buf_43008 xfs_da_read_buf 0 43008 NULL
112688 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
112689 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
112690 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
112691 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
112692 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
112693 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
112694 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
112695 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
112696 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
112697 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
112698 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
112699 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
112700 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
112701 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
112702 +uio_write_43202 uio_write 3 43202 NULL
112703 +iso_callback_43208 iso_callback 3 43208 NULL
112704 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
112705 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
112706 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
112707 +inode_init_always_43225 inode_init_always 0 43225 NULL
112708 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
112709 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
112710 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
112711 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
112712 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
112713 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
112714 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
112715 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
112716 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
112717 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
112718 +xfs_log_regrant_43350 xfs_log_regrant 0 43350 NULL
112719 +gfs2_rgrp_bh_get_43375 gfs2_rgrp_bh_get 0 43375 NULL
112720 +xfs_btree_new_iroot_43392 xfs_btree_new_iroot 0 43392 NULL
112721 +xenfb_write_43412 xenfb_write 3 43412 NULL
112722 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
112723 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
112724 +cifs_writev_43437 cifs_writev 4 43437 NULL
112725 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
112726 +usb_string_43443 usb_string 0 43443 NULL nohasharray
112727 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
112728 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
112729 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
112730 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
112731 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
112732 +do_readlink_43518 do_readlink 2 43518 NULL
112733 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
112734 +read_events_43534 read_events 3 43534 NULL
112735 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
112736 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
112737 +request_resource_43548 request_resource 0 43548 NULL
112738 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
112739 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
112740 +proc_read_43614 proc_read 3 43614 NULL
112741 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
112742 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
112743 +random_write_43656 random_write 3 43656 NULL
112744 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
112745 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
112746 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
112747 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
112748 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
112749 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
112750 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
112751 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
112752 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
112753 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
112754 +xfs_alloc_lookup_eq_43775 xfs_alloc_lookup_eq 0 43775 NULL
112755 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
112756 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
112757 +xfs_trans_reserve_quota_bydquots_43797 xfs_trans_reserve_quota_bydquots 0 43797 NULL
112758 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
112759 +_xfs_filestream_update_ag_43824 _xfs_filestream_update_ag 0 43824 NULL
112760 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
112761 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
112762 +read_flush_43851 read_flush 3 43851 NULL
112763 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
112764 +SendString_43928 SendString 3 43928 NULL
112765 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
112766 +xfs_trans_dqresv_43960 xfs_trans_dqresv 0 43960 NULL
112767 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
112768 +nla_reserve_43984 nla_reserve 3 43984 NULL
112769 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
112770 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
112771 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
112772 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
112773 +ulist_add_43994 ulist_add 0 43994 NULL
112774 +emit_flags_44006 emit_flags 4-3 44006 NULL
112775 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
112776 +fru_strlen_44046 fru_strlen 0 44046 NULL
112777 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
112778 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
112779 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL nohasharray
112780 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 &pci_msix_vec_count_44093
112781 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
112782 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
112783 +file_remove_suid_44122 file_remove_suid 0 44122 NULL nohasharray
112784 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 &file_remove_suid_44122
112785 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
112786 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
112787 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
112788 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
112789 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
112790 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
112791 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
112792 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
112793 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
112794 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
112795 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
112796 +device_create_file_44285 device_create_file 0 44285 NULL
112797 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
112798 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
112799 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
112800 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
112801 +rs_init_44327 rs_init 1 44327 NULL
112802 +radix_tree_maybe_preload_44346 radix_tree_maybe_preload 0 44346 NULL
112803 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
112804 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
112805 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
112806 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
112807 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
112808 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
112809 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
112810 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
112811 +xfs_mod_incore_sb_44439 xfs_mod_incore_sb 0 44439 NULL
112812 +write_file_debug_44476 write_file_debug 3 44476 NULL
112813 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
112814 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
112815 +bio_advance_44496 bio_advance 2 44496 NULL
112816 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
112817 +ac_register_board_44504 ac_register_board 3 44504 NULL
112818 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
112819 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
112820 +spidev_write_44510 spidev_write 3 44510 NULL
112821 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
112822 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
112823 +comm_write_44537 comm_write 3 44537 NULL
112824 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
112825 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
112826 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
112827 +xfs_bmapi_delay_44630 xfs_bmapi_delay 0 44630 NULL
112828 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
112829 +mpi_resize_44674 mpi_resize 2 44674 NULL
112830 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
112831 +ts_read_44687 ts_read 3 44687 NULL
112832 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
112833 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
112834 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
112835 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
112836 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
112837 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
112838 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
112839 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
112840 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
112841 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
112842 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
112843 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
112844 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
112845 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
112846 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
112847 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
112848 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
112849 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
112850 +sisusb_write_44834 sisusb_write 3 44834 NULL
112851 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
112852 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
112853 +copydesc_user_44855 copydesc_user 3 44855 NULL
112854 +set_advertising_44870 set_advertising 4 44870 NULL
112855 +init_rs_44873 init_rs 1 44873 NULL
112856 +skb_availroom_44883 skb_availroom 0 44883 NULL
112857 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
112858 +do_tty_write_44896 do_tty_write 5 44896 NULL
112859 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
112860 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
112861 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
112862 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
112863 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
112864 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
112865 +sel_write_user_45060 sel_write_user 3 45060 NULL
112866 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
112867 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
112868 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
112869 +usbdev_read_45114 usbdev_read 3 45114 NULL
112870 +send_to_tty_45141 send_to_tty 3 45141 NULL
112871 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
112872 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
112873 +device_write_45156 device_write 3 45156 NULL nohasharray
112874 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
112875 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
112876 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
112877 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
112878 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
112879 +__radix_tree_preload_45197 __radix_tree_preload 0 45197 NULL
112880 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
112881 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
112882 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
112883 +event_enable_write_45238 event_enable_write 3 45238 NULL
112884 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
112885 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
112886 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
112887 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
112888 +xfs_alert_fsblock_zero_45304 xfs_alert_fsblock_zero 0 45304 NULL
112889 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
112890 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
112891 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
112892 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
112893 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
112894 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
112895 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
112896 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
112897 +__node_remap_45458 __node_remap 4 45458 NULL
112898 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
112899 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
112900 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
112901 +xfs_btree_block_change_owner_45476 xfs_btree_block_change_owner 0 45476 NULL
112902 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
112903 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
112904 +copy_macs_45534 copy_macs 4 45534 NULL
112905 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
112906 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
112907 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
112908 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
112909 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
112910 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
112911 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
112912 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
112913 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
112914 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
112915 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
112916 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
112917 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
112918 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
112919 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
112920 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
112921 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
112922 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
112923 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
112924 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
112925 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
112926 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
112927 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
112928 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
112929 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
112930 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
112931 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
112932 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
112933 +insert_state_45848 insert_state 0 45848 NULL
112934 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
112935 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
112936 +isdn_write_45863 isdn_write 3 45863 NULL
112937 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
112938 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
112939 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
112940 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
112941 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
112942 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
112943 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
112944 +alloc_mr_45935 alloc_mr 1 45935 NULL
112945 +copy_to_45969 copy_to 3 45969 NULL
112946 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
112947 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
112948 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
112949 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
112950 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
112951 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
112952 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
112953 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
112954 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
112955 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
112956 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
112957 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
112958 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
112959 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
112960 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
112961 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
112962 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
112963 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
112964 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
112965 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
112966 +fq_resize_46195 fq_resize 2 46195 NULL
112967 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
112968 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
112969 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
112970 +dsp_write_46218 dsp_write 2 46218 NULL
112971 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
112972 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
112973 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
112974 +ReadReg_46277 ReadReg 0 46277 NULL
112975 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
112976 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
112977 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
112978 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
112979 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
112980 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
112981 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
112982 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
112983 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
112984 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
112985 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
112986 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
112987 +filldir64_46469 filldir64 3 46469 NULL
112988 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
112989 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
112990 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
112991 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
112992 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
112993 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
112994 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
112995 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
112996 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
112997 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
112998 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
112999 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
113000 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
113001 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
113002 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
113003 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
113004 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
113005 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
113006 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
113007 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
113008 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
113009 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
113010 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
113011 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
113012 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
113013 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
113014 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
113015 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
113016 +readreg_46845 readreg 0 46845 NULL
113017 +spi_async_46857 spi_async 0 46857 NULL
113018 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
113019 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
113020 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
113021 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
113022 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
113023 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
113024 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
113025 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
113026 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
113027 +fb_write_46924 fb_write 3 46924 NULL
113028 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
113029 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL nohasharray
113030 +ntfs_truncate_46953 ntfs_truncate 0 46953 &qla4xxx_post_aen_work_46953
113031 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
113032 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
113033 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
113034 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
113035 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
113036 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
113037 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
113038 +fs_path_len_47060 fs_path_len 0 47060 NULL
113039 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
113040 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
113041 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
113042 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
113043 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
113044 +mousedev_read_47123 mousedev_read 3 47123 NULL
113045 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
113046 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
113047 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
113048 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
113049 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
113050 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
113051 +xfs_btree_get_buf_block_47197 xfs_btree_get_buf_block 0 47197 NULL
113052 +options_write_47243 options_write 3 47243 NULL
113053 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
113054 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
113055 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
113056 +vsnprintf_47291 vsnprintf 0 47291 NULL
113057 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
113058 +xfs_trans_reserve_quota_nblks_47313 xfs_trans_reserve_quota_nblks 0 47313 NULL
113059 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
113060 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
113061 +gfs2_replay_read_block_47357 gfs2_replay_read_block 0 47357 NULL
113062 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
113063 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
113064 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
113065 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
113066 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
113067 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
113068 +nametbl_list_47391 nametbl_list 2 47391 NULL
113069 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
113070 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
113071 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
113072 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
113073 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
113074 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
113075 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
113076 +newpart_47485 newpart 6-4 47485 NULL
113077 +core_sys_select_47494 core_sys_select 1 47494 NULL
113078 +unlink_simple_47506 unlink_simple 3 47506 NULL
113079 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
113080 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
113081 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
113082 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
113083 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
113084 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
113085 +read_ldt_47570 read_ldt 2 47570 NULL
113086 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
113087 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
113088 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
113089 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
113090 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
113091 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
113092 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
113093 +get_size_47644 get_size 1-2 47644 NULL
113094 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
113095 +save_microcode_47717 save_microcode 3 47717 NULL
113096 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
113097 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
113098 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
113099 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
113100 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
113101 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
113102 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
113103 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
113104 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
113105 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
113106 +lov_packmd_47810 lov_packmd 0 47810 NULL
113107 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
113108 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
113109 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
113110 +vhci_read_47878 vhci_read 3 47878 NULL
113111 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
113112 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
113113 +comedi_write_47926 comedi_write 3 47926 NULL
113114 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
113115 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
113116 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
113117 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
113118 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
113119 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
113120 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
113121 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
113122 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
113123 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
113124 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
113125 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
113126 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
113127 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
113128 +disc_write_48070 disc_write 3 48070 NULL
113129 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
113130 +xfs_read_agi_48100 xfs_read_agi 0 48100 NULL
113131 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
113132 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
113133 +set_discoverable_48141 set_discoverable 4 48141 NULL
113134 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
113135 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
113136 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
113137 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
113138 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
113139 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
113140 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
113141 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
113142 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
113143 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
113144 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
113145 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
113146 +read_file_recv_48232 read_file_recv 3 48232 NULL
113147 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
113148 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
113149 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
113150 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
113151 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
113152 +trace_options_write_48275 trace_options_write 3 48275 NULL
113153 +send_set_info_48288 send_set_info 7 48288 NULL
113154 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
113155 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
113156 +hash_setkey_48310 hash_setkey 3 48310 NULL
113157 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
113158 +skb_add_data_48363 skb_add_data 3 48363 NULL
113159 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
113160 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
113161 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
113162 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
113163 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
113164 +print_filtered_48442 print_filtered 2-0 48442 NULL
113165 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
113166 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
113167 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
113168 +send_control_msg_48498 send_control_msg 6 48498 NULL
113169 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
113170 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
113171 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
113172 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
113173 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
113174 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
113175 +llog_data_len_48607 llog_data_len 1 48607 NULL
113176 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
113177 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
113178 +mtd_read_48655 mtd_read 0 48655 NULL
113179 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
113180 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
113181 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
113182 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
113183 +altera_drscan_48698 altera_drscan 2 48698 NULL
113184 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
113185 +recv_msg_48709 recv_msg 4 48709 NULL
113186 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
113187 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
113188 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
113189 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
113190 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
113191 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
113192 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
113193 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
113194 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
113195 +azx_get_position_48841 azx_get_position 0 48841 NULL
113196 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
113197 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
113198 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
113199 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
113200 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
113201 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
113202 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
113203 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
113204 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
113205 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
113206 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
113207 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
113208 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
113209 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
113210 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
113211 +xfs_trans_commit_48982 xfs_trans_commit 0 48982 NULL
113212 +gfs2_dir_add_48987 gfs2_dir_add 0 48987 NULL
113213 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
113214 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
113215 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
113216 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
113217 +transient_status_49027 transient_status 4 49027 NULL
113218 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
113219 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
113220 +scsi_register_49094 scsi_register 2 49094 NULL
113221 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
113222 +gfs2_diradd_alloc_required_49105 gfs2_diradd_alloc_required 0 49105 NULL
113223 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
113224 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
113225 +pt_read_49136 pt_read 3 49136 NULL
113226 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
113227 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
113228 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
113229 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
113230 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
113231 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
113232 +print_queue_49191 print_queue 4-0 49191 NULL
113233 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
113234 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
113235 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
113236 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
113237 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
113238 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
113239 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
113240 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
113241 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
113242 +uio_read_49300 uio_read 3 49300 NULL
113243 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
113244 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
113245 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
113246 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
113247 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
113248 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
113249 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
113250 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
113251 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
113252 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
113253 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
113254 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
113255 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
113256 +xfs_iformat_local_49472 xfs_iformat_local 4-0 49472 NULL
113257 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
113258 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
113259 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
113260 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
113261 +smk_write_access_49561 smk_write_access 3 49561 NULL
113262 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
113263 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
113264 +readfifo_49583 readfifo 1 49583 NULL
113265 +gfs2_quota_lock_49587 gfs2_quota_lock 0 49587 NULL
113266 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
113267 +tap_write_49595 tap_write 3 49595 NULL
113268 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
113269 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
113270 +heap_init_49617 heap_init 2 49617 NULL
113271 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
113272 +port_fops_read_49626 port_fops_read 3 49626 NULL
113273 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
113274 +xfs_ialloc_get_rec_49648 xfs_ialloc_get_rec 0 49648 NULL
113275 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
113276 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
113277 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
113278 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
113279 +write_pool_49718 write_pool 3 49718 NULL
113280 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
113281 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
113282 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
113283 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
113284 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
113285 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
113286 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
113287 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
113288 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
113289 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
113290 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
113291 +add_uuid_49831 add_uuid 4 49831 NULL
113292 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
113293 +twl4030_write_49846 twl4030_write 2 49846 NULL
113294 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
113295 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
113296 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
113297 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
113298 +osc_brw_49896 osc_brw 4 49896 NULL
113299 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
113300 +xfs_ialloc_ag_alloc_49960 xfs_ialloc_ag_alloc 0 49960 NULL
113301 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
113302 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
113303 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
113304 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
113305 +xfs_ialloc_inode_init_50015 xfs_ialloc_inode_init 0 50015 NULL
113306 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
113307 +isdn_read_50021 isdn_read 3 50021 NULL
113308 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
113309 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
113310 +ioread8_50049 ioread8 0 50049 NULL
113311 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
113312 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
113313 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
113314 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
113315 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
113316 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
113317 +read_file_slot_50111 read_file_slot 3 50111 NULL
113318 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
113319 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
113320 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
113321 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
113322 +xfs_bwrite_50154 xfs_bwrite 0 50154 NULL
113323 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
113324 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
113325 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
113326 +odev_update_50169 odev_update 2 50169 NULL
113327 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
113328 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
113329 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
113330 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
113331 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
113332 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
113333 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
113334 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
113335 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
113336 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
113337 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
113338 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
113339 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
113340 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
113341 +do_launder_page_50329 do_launder_page 0 50329 NULL
113342 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
113343 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
113344 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
113345 +tpm_read_50344 tpm_read 3 50344 NULL
113346 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
113347 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
113348 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
113349 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
113350 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
113351 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
113352 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
113353 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
113354 +xfs_alloc_update_counters_50441 xfs_alloc_update_counters 0 50441 NULL
113355 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
113356 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
113357 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
113358 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
113359 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
113360 +xfs_iformat_extents_50486 xfs_iformat_extents 0 50486 NULL
113361 +gfs2_block_map_50492 gfs2_block_map 0 50492 NULL
113362 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
113363 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
113364 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
113365 +bh_get_50543 bh_get 0 50543 NULL
113366 +gfs2_meta_inode_buffer_50544 gfs2_meta_inode_buffer 0 50544 NULL
113367 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
113368 +fat_readpages_50582 fat_readpages 4 50582 NULL
113369 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
113370 +xillybus_write_50605 xillybus_write 3 50605 NULL
113371 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
113372 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
113373 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
113374 +gfs2_unstuff_dinode_50644 gfs2_unstuff_dinode 0 50644 NULL
113375 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
113376 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
113377 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
113378 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
113379 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
113380 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
113381 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
113382 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
113383 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
113384 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
113385 +tpm_write_50798 tpm_write 3 50798 NULL
113386 +tun_do_read_50800 tun_do_read 4 50800 NULL
113387 +write_flush_50803 write_flush 3 50803 NULL
113388 +dvb_play_50814 dvb_play 3 50814 NULL
113389 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
113390 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
113391 +SetArea_50835 SetArea 4 50835 NULL
113392 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
113393 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
113394 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
113395 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
113396 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
113397 +xfs_alloc_get_freelist_50906 xfs_alloc_get_freelist 0 50906 NULL
113398 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
113399 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
113400 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
113401 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
113402 +show_device_status_50947 show_device_status 0 50947 NULL
113403 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
113404 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
113405 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
113406 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
113407 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
113408 +timeout_write_50991 timeout_write 3 50991 NULL
113409 +proc_write_51003 proc_write 3 51003 NULL
113410 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
113411 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
113412 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
113413 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
113414 +dump_midi_51040 dump_midi 3 51040 NULL
113415 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
113416 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
113417 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
113418 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
113419 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
113420 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
113421 +ti_recv_51110 ti_recv 3 51110 NULL
113422 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
113423 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
113424 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
113425 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
113426 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
113427 +drm_property_create_51239 drm_property_create 4 51239 NULL
113428 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
113429 +st_read_51251 st_read 3 51251 NULL
113430 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
113431 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
113432 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
113433 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
113434 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
113435 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
113436 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
113437 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
113438 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
113439 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
113440 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
113441 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
113442 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
113443 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
113444 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
113445 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
113446 +xfs_mod_incore_sb_unlocked_51439 xfs_mod_incore_sb_unlocked 0 51439 NULL
113447 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
113448 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
113449 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
113450 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
113451 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
113452 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
113453 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
113454 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
113455 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
113456 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
113457 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
113458 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
113459 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
113460 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
113461 +xfs_iformat_btree_51651 xfs_iformat_btree 0 51651 NULL
113462 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
113463 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
113464 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
113465 +sel_write_access_51704 sel_write_access 3 51704 NULL
113466 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
113467 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
113468 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
113469 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
113470 +cm4040_read_51732 cm4040_read 3 51732 NULL
113471 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
113472 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
113473 +if_write_51756 if_write 3 51756 NULL
113474 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
113475 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
113476 +ioread32_51847 ioread32 0 51847 NULL nohasharray
113477 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
113478 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
113479 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
113480 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
113481 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
113482 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
113483 +user_read_51881 user_read 3 51881 NULL
113484 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
113485 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
113486 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
113487 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
113488 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
113489 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
113490 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
113491 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
113492 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
113493 +get_zone_51981 get_zone 0-1 51981 NULL
113494 +cifs_strict_writev_51984 cifs_strict_writev 4 51984 NULL
113495 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
113496 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
113497 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
113498 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
113499 +rdmalt_52022 rdmalt 0 52022 NULL
113500 +override_release_52032 override_release 2 52032 NULL
113501 +end_port_52042 end_port 0 52042 NULL
113502 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
113503 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
113504 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
113505 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
113506 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
113507 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
113508 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
113509 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
113510 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
113511 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
113512 +retry_count_read_52129 retry_count_read 3 52129 NULL
113513 +xfs_btree_change_owner_52137 xfs_btree_change_owner 0 52137 NULL
113514 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
113515 +sub_alloc_52140 sub_alloc 0 52140 NULL
113516 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
113517 +htable_size_52148 htable_size 0-1 52148 NULL
113518 +gfs2_rs_alloc_52152 gfs2_rs_alloc 0 52152 NULL
113519 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
113520 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
113521 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
113522 +print_prefix_52176 print_prefix 0 52176 NULL
113523 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
113524 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
113525 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
113526 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
113527 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 0 52243 &fuse_request_alloc_52243
113528 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
113529 +shrink_slab_52261 shrink_slab 2 52261 NULL
113530 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
113531 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
113532 +read_file_reset_52310 read_file_reset 3 52310 NULL
113533 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
113534 +hwflags_read_52318 hwflags_read 3 52318 NULL
113535 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
113536 +hur_len_52339 hur_len 0 52339 NULL
113537 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
113538 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
113539 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
113540 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
113541 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
113542 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
113543 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
113544 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
113545 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
113546 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
113547 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
113548 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
113549 +delay_status_52431 delay_status 5 52431 NULL
113550 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
113551 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
113552 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
113553 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
113554 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
113555 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
113556 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
113557 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
113558 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
113559 +xfs_alloc_get_rec_52502 xfs_alloc_get_rec 0 52502 NULL
113560 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
113561 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
113562 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
113563 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
113564 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
113565 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
113566 +ntfs_prepare_pages_for_non_resident_write_52556 ntfs_prepare_pages_for_non_resident_write 0 52556 NULL
113567 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
113568 +kernfs_setattr_52583 kernfs_setattr 0 52583 NULL
113569 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
113570 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
113571 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
113572 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
113573 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
113574 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
113575 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
113576 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
113577 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
113578 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
113579 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
113580 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
113581 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
113582 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
113583 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
113584 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
113585 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
113586 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
113587 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
113588 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
113589 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
113590 +twlreg_write_52880 twlreg_write 3 52880 NULL
113591 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
113592 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
113593 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
113594 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
113595 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
113596 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
113597 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
113598 +send_packet_52960 send_packet 4 52960 NULL
113599 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
113600 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
113601 +num_node_state_52989 num_node_state 0 52989 NULL
113602 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
113603 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
113604 +xfs_rtfree_extent_53024 xfs_rtfree_extent 0 53024 NULL
113605 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
113606 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
113607 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
113608 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
113609 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
113610 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
113611 +verity_status_53120 verity_status 5 53120 NULL
113612 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
113613 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 NULL nohasharray
113614 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 &inode_newsize_ok_53140
113615 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
113616 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
113617 +find_good_lh_53183 find_good_lh 0 53183 NULL
113618 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
113619 +xfs_btree_updkey_53195 xfs_btree_updkey 0 53195 NULL
113620 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
113621 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
113622 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5-0 53258 NULL
113623 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
113624 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
113625 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
113626 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
113627 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
113628 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
113629 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
113630 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
113631 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
113632 +xfs_imap_53389 xfs_imap 0 53389 NULL
113633 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
113634 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
113635 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
113636 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
113637 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
113638 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
113639 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
113640 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
113641 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
113642 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
113643 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
113644 +check_acl_53512 check_acl 0 53512 NULL
113645 +ll_xattr_cache_update_53515 ll_xattr_cache_update 4 53515 NULL
113646 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
113647 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
113648 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
113649 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
113650 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
113651 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
113652 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
113653 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
113654 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
113655 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
113656 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
113657 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
113658 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
113659 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
113660 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
113661 +wdm_write_53735 wdm_write 3 53735 NULL
113662 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
113663 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
113664 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
113665 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
113666 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
113667 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
113668 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
113669 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
113670 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
113671 +setup_data_read_53822 setup_data_read 3 53822 NULL
113672 +pms_read_53873 pms_read 3 53873 NULL
113673 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
113674 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
113675 +posix_acl_chmod_53904 posix_acl_chmod 0 53904 NULL
113676 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
113677 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
113678 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
113679 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
113680 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
113681 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
113682 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
113683 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
113684 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
113685 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
113686 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
113687 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
113688 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
113689 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
113690 +_malloc_54077 _malloc 1 54077 NULL
113691 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
113692 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
113693 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2-0 54103 &altera_set_ir_pre_54103
113694 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
113695 +strn_len_54122 strn_len 0 54122 NULL
113696 +isku_receive_54130 isku_receive 4 54130 NULL
113697 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
113698 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
113699 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
113700 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
113701 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
113702 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
113703 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
113704 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
113705 +reada_add_block_54247 reada_add_block 2 54247 NULL
113706 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
113707 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
113708 +audio_write_54261 audio_write 4 54261 NULL nohasharray
113709 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
113710 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
113711 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
113712 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
113713 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
113714 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
113715 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
113716 +sprintf_54306 sprintf 0 54306 NULL
113717 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
113718 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
113719 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
113720 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
113721 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
113722 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
113723 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
113724 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
113725 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
113726 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
113727 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
113728 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
113729 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
113730 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
113731 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
113732 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
113733 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
113734 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
113735 +viacam_read_54526 viacam_read 3 54526 NULL
113736 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
113737 +setsockopt_54539 setsockopt 5 54539 NULL
113738 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
113739 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
113740 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
113741 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
113742 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
113743 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
113744 +port_fops_write_54627 port_fops_write 3 54627 NULL
113745 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
113746 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
113747 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
113748 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
113749 +bus_add_device_54665 bus_add_device 0 54665 NULL
113750 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
113751 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
113752 +evm_read_key_54674 evm_read_key 3 54674 NULL
113753 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
113754 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
113755 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
113756 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
113757 +kzalloc_54740 kzalloc 1 54740 NULL
113758 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
113759 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
113760 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
113761 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
113762 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
113763 +xfs_rtallocate_extent_block_54791 xfs_rtallocate_extent_block 0 54791 NULL
113764 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
113765 +nfsd_write_54809 nfsd_write 6 54809 NULL
113766 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
113767 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
113768 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
113769 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
113770 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
113771 +write_rio_54837 write_rio 3 54837 NULL
113772 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
113773 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
113774 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
113775 +printer_read_54851 printer_read 3 54851 NULL
113776 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
113777 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
113778 +xfs_alloc_read_agfl_54879 xfs_alloc_read_agfl 0 54879 NULL
113779 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
113780 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
113781 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
113782 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
113783 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
113784 +add_port_54941 add_port 2 54941 NULL
113785 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
113786 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
113787 +c4_add_card_54968 c4_add_card 3 54968 NULL
113788 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
113789 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
113790 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
113791 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
113792 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
113793 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
113794 +read_dma_55086 read_dma 3 55086 NULL
113795 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
113796 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
113797 +filldir_55137 filldir 3 55137 NULL
113798 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
113799 +xfs_check_agi_freecount_55149 xfs_check_agi_freecount 0 55149 NULL nohasharray
113800 +npages_to_npools_55149 npages_to_npools 0-1 55149 &xfs_check_agi_freecount_55149
113801 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
113802 +xfs_icsb_modify_counters_55156 xfs_icsb_modify_counters 0 55156 NULL
113803 +gfs2_ri_update_55185 gfs2_ri_update 0 55185 NULL
113804 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
113805 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
113806 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
113807 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
113808 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
113809 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
113810 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
113811 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
113812 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
113813 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
113814 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
113815 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
113816 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
113817 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
113818 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
113819 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
113820 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
113821 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
113822 +vme_user_read_55338 vme_user_read 3 55338 NULL
113823 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
113824 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
113825 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
113826 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
113827 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
113828 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
113829 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
113830 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
113831 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
113832 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
113833 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
113834 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
113835 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
113836 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
113837 +xfs_btree_split_55515 xfs_btree_split 0 55515 NULL
113838 +ea_get_55522 ea_get 3-0 55522 NULL
113839 +buffer_size_55534 buffer_size 0 55534 NULL
113840 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
113841 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
113842 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
113843 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
113844 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
113845 +add_partition_55588 add_partition 2 55588 NULL
113846 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
113847 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
113848 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
113849 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
113850 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
113851 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
113852 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
113853 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
113854 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
113855 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
113856 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
113857 +get_info_55681 get_info 3 55681 NULL
113858 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
113859 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
113860 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
113861 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
113862 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
113863 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
113864 +set_local_name_55757 set_local_name 4 55757 NULL
113865 +strlen_55778 strlen 0 55778 NULL
113866 +set_spte_55783 set_spte 4-5 55783 NULL
113867 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
113868 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
113869 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
113870 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
113871 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
113872 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
113873 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
113874 +hsc_write_55875 hsc_write 3 55875 NULL
113875 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
113876 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
113877 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
113878 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
113879 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
113880 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
113881 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
113882 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
113883 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
113884 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
113885 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
113886 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
113887 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
113888 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
113889 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
113890 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
113891 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
113892 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
113893 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
113894 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
113895 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
113896 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
113897 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
113898 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
113899 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
113900 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
113901 +fd_copyin_56247 fd_copyin 3 56247 NULL
113902 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
113903 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
113904 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
113905 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
113906 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
113907 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
113908 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
113909 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
113910 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
113911 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
113912 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
113913 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
113914 +qd_get_56365 qd_get 0 56365 NULL
113915 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
113916 +dev_read_56369 dev_read 3 56369 NULL
113917 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
113918 +write_gssp_56404 write_gssp 3 56404 NULL
113919 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
113920 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
113921 +store_msg_56417 store_msg 3 56417 NULL
113922 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
113923 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
113924 +fl_create_56435 fl_create 5 56435 NULL
113925 +gnttab_map_56439 gnttab_map 2 56439 NULL
113926 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
113927 +set_connectable_56458 set_connectable 4 56458 NULL
113928 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
113929 +putused_user_56467 putused_user 3 56467 NULL
113930 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
113931 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
113932 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
113933 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
113934 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
113935 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
113936 +init_map_ip_56508 init_map_ip 5 56508 NULL
113937 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3-0-2 56512 NULL
113938 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
113939 +ip_options_get_56538 ip_options_get 4 56538 NULL
113940 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
113941 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
113942 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
113943 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
113944 +event_filter_write_56609 event_filter_write 3 56609 NULL
113945 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
113946 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
113947 +gather_array_56641 gather_array 3 56641 NULL
113948 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
113949 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
113950 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
113951 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
113952 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
113953 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
113954 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
113955 +xfs_btree_decrement_56718 xfs_btree_decrement 0 56718 NULL
113956 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
113957 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
113958 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
113959 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
113960 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
113961 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
113962 +do_syslog_56807 do_syslog 3 56807 NULL
113963 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
113964 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
113965 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
113966 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
113967 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
113968 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
113969 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
113970 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
113971 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
113972 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
113973 +xfs_alloc_ag_vextent_56943 xfs_alloc_ag_vextent 0 56943 NULL
113974 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
113975 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
113976 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
113977 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
113978 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
113979 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
113980 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
113981 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
113982 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
113983 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
113984 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
113985 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
113986 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
113987 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
113988 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
113989 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
113990 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
113991 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
113992 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
113993 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
113994 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
113995 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
113996 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
113997 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
113998 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
113999 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
114000 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
114001 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
114002 +flush_space_57241 flush_space 0 57241 NULL
114003 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
114004 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
114005 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
114006 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
114007 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
114008 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
114009 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
114010 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
114011 +xfs_iread_57313 xfs_iread 0 57313 NULL nohasharray
114012 +write_file_regval_57313 write_file_regval 3 57313 &xfs_iread_57313
114013 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
114014 +usblp_read_57342 usblp_read 3 57342 NULL
114015 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
114016 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
114017 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
114018 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
114019 +read_file_blob_57406 read_file_blob 3 57406 NULL
114020 +enclosure_register_57412 enclosure_register 3 57412 NULL
114021 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
114022 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
114023 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
114024 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
114025 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
114026 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
114027 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
114028 +skb_headlen_57501 skb_headlen 0 57501 NULL
114029 +copy_in_user_57502 copy_in_user 3 57502 NULL
114030 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL nohasharray
114031 +gfs2_quota_hold_57505 gfs2_quota_hold 0 57505 &ckhdid_printf_57505
114032 +init_tag_map_57515 init_tag_map 3 57515 NULL
114033 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
114034 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
114035 +cmm_read_57520 cmm_read 3 57520 NULL
114036 +inode_permission_57531 inode_permission 0 57531 NULL
114037 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
114038 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
114039 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
114040 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
114041 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
114042 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
114043 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
114044 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
114045 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
114046 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
114047 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
114048 +mem_read_57631 mem_read 3 57631 NULL
114049 +xfs_alloc_ag_vextent_near_57653 xfs_alloc_ag_vextent_near 0 57653 NULL
114050 +r3964_write_57662 r3964_write 4 57662 NULL
114051 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
114052 +__lgwrite_57669 __lgwrite 4 57669 NULL
114053 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
114054 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
114055 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
114056 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
114057 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
114058 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
114059 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
114060 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
114061 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
114062 +ld2_57794 ld2 0 57794 NULL
114063 +ivtv_read_57796 ivtv_read 3 57796 NULL
114064 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
114065 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
114066 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
114067 +xfs_rtpick_extent_57843 xfs_rtpick_extent 0 57843 NULL nohasharray
114068 +flash_read_57843 flash_read 3 57843 &xfs_rtpick_extent_57843
114069 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
114070 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
114071 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
114072 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
114073 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
114074 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
114075 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
114076 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
114077 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
114078 +xfs_inode_item_format_convert_57937 xfs_inode_item_format_convert 0 57937 NULL
114079 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
114080 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
114081 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
114082 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
114083 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
114084 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
114085 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
114086 +mce_async_out_58056 mce_async_out 3 58056 NULL
114087 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
114088 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
114089 +cm4040_write_58079 cm4040_write 3 58079 NULL
114090 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
114091 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
114092 +rd_build_prot_space_58137 rd_build_prot_space 2 58137 NULL
114093 +xfs_bmap_add_extent_delay_real_58151 xfs_bmap_add_extent_delay_real 0 58151 NULL
114094 +xfs_btree_update_58167 xfs_btree_update 0 58167 NULL
114095 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
114096 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
114097 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
114098 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
114099 +read_file_debug_58256 read_file_debug 3 58256 NULL
114100 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
114101 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
114102 +profile_load_58267 profile_load 3 58267 NULL
114103 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
114104 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
114105 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
114106 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
114107 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
114108 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
114109 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
114110 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
114111 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
114112 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
114113 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
114114 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
114115 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
114116 +xfs_btree_get_rec_58410 xfs_btree_get_rec 0 58410 NULL
114117 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
114118 +capabilities_read_58457 capabilities_read 3 58457 NULL
114119 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
114120 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
114121 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
114122 +nv_rd08_58472 nv_rd08 0 58472 NULL
114123 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
114124 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
114125 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
114126 +btrfs_cont_expand_58498 btrfs_cont_expand 0-2-3 58498 NULL
114127 +gfs2_dir_get_new_buffer_58509 gfs2_dir_get_new_buffer 0 58509 NULL
114128 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
114129 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
114130 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
114131 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
114132 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
114133 +xip_file_read_58592 xip_file_read 3 58592 NULL
114134 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
114135 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
114136 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
114137 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
114138 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
114139 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
114140 +find_zero_58685 find_zero 0-1 58685 NULL
114141 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
114142 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
114143 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
114144 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
114145 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
114146 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
114147 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
114148 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
114149 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
114150 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
114151 +ep_read_58813 ep_read 3 58813 NULL
114152 +command_write_58841 command_write 3 58841 NULL
114153 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
114154 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
114155 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
114156 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
114157 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
114158 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
114159 +xfs_bmap_read_extents_58936 xfs_bmap_read_extents 0 58936 NULL
114160 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
114161 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
114162 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
114163 +__mem_cgroup_try_charge_58976 __mem_cgroup_try_charge 0 58976 NULL
114164 +init_list_set_59005 init_list_set 3 59005 NULL
114165 +ep_write_59008 ep_write 3 59008 NULL
114166 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
114167 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
114168 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
114169 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
114170 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
114171 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
114172 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
114173 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL nohasharray
114174 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 &scsi_io_completion_59122
114175 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
114176 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
114177 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
114178 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
114179 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
114180 +ksize_59176 ksize 0 59176 NULL
114181 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
114182 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
114183 +xfs_ialloc_next_rec_59193 xfs_ialloc_next_rec 0 59193 NULL
114184 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
114185 +dt3155_read_59226 dt3155_read 3 59226 NULL
114186 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
114187 +nla_len_59258 nla_len 0 59258 NULL
114188 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
114189 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
114190 +xfs_iformat_fork_59312 xfs_iformat_fork 0 59312 NULL
114191 +fd_copyout_59323 fd_copyout 3 59323 NULL
114192 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
114193 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
114194 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL nohasharray
114195 +xfs_alloc_lookup_le_59346 xfs_alloc_lookup_le 0 59346 &xfs_attrmulti_attr_set_59346
114196 +__map_request_59350 __map_request 0 59350 NULL
114197 +gfs2_quota_lock_check_59353 gfs2_quota_lock_check 0 59353 NULL
114198 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
114199 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
114200 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
114201 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
114202 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
114203 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
114204 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
114205 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
114206 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
114207 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
114208 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
114209 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
114210 +tunables_write_59563 tunables_write 3 59563 NULL
114211 +bio_split_59564 bio_split 2 59564 NULL
114212 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
114213 +write_pbl_59583 write_pbl 4 59583 NULL
114214 +memdup_user_59590 memdup_user 2 59590 NULL
114215 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
114216 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
114217 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
114218 +mtrr_write_59622 mtrr_write 3 59622 NULL
114219 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
114220 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
114221 +file_update_time_59647 file_update_time 0 59647 NULL
114222 +hidraw_read_59650 hidraw_read 3 59650 NULL
114223 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
114224 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
114225 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
114226 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
114227 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
114228 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
114229 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
114230 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
114231 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
114232 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
114233 +strnlen_59746 strnlen 0 59746 NULL
114234 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
114235 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
114236 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
114237 +venus_remove_59781 venus_remove 4 59781 NULL
114238 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
114239 +ipw_write_59807 ipw_write 3 59807 NULL
114240 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
114241 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
114242 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
114243 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
114244 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
114245 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
114246 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
114247 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
114248 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
114249 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
114250 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
114251 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
114252 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
114253 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
114254 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
114255 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
114256 +copy_items_60009 copy_items 7 60009 NULL
114257 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
114258 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
114259 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
114260 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
114261 +xfs_imap_to_bp_60034 xfs_imap_to_bp 0 60034 NULL
114262 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
114263 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
114264 +vcs_size_60050 vcs_size 0 60050 NULL
114265 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
114266 +compat_writev_60063 compat_writev 3 60063 NULL
114267 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
114268 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
114269 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
114270 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
114271 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
114272 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
114273 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
114274 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
114275 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
114276 +init_state_60165 init_state 2 60165 NULL
114277 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
114278 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
114279 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
114280 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
114281 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
114282 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
114283 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
114284 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
114285 +printer_write_60276 printer_write 3 60276 NULL
114286 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
114287 +getDataLength_60301 getDataLength 0 60301 NULL
114288 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
114289 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
114290 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
114291 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
114292 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
114293 +driver_names_read_60399 driver_names_read 3 60399 NULL
114294 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
114295 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
114296 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
114297 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
114298 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
114299 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
114300 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
114301 +xfs_btree_make_block_unfull_60511 xfs_btree_make_block_unfull 0 60511 NULL
114302 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
114303 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
114304 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
114305 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
114306 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
114307 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
114308 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
114309 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
114310 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
114311 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
114312 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
114313 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
114314 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
114315 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
114316 +raid_status_60755 raid_status 5 60755 NULL
114317 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
114318 +opticon_write_60775 opticon_write 4 60775 NULL
114319 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
114320 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
114321 +gfs2_bmap_alloc_60822 gfs2_bmap_alloc 0 60822 NULL
114322 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
114323 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 4-3 60861 NULL
114324 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
114325 +generic_writepages_60871 generic_writepages 0 60871 NULL
114326 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
114327 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
114328 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
114329 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
114330 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
114331 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
114332 +xfs_rtallocate_extent_size_60939 xfs_rtallocate_extent_size 0 60939 NULL
114333 +pti_char_write_60960 pti_char_write 3 60960 NULL
114334 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
114335 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
114336 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
114337 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
114338 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
114339 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
114340 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
114341 +symtab_init_61050 symtab_init 2 61050 NULL
114342 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
114343 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
114344 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
114345 +xfs_dabuf_map_61093 xfs_dabuf_map 0 61093 NULL
114346 +get_derived_key_61100 get_derived_key 4 61100 NULL
114347 +mem_cgroup_cache_charge_61101 mem_cgroup_cache_charge 0 61101 NULL
114348 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
114349 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
114350 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
114351 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
114352 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
114353 +pair_device_61175 pair_device 4 61175 NULL nohasharray
114354 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
114355 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
114356 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
114357 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
114358 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
114359 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
114360 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
114361 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270
114362 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
114363 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
114364 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
114365 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
114366 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
114367 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
114368 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
114369 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
114370 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
114371 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
114372 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
114373 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
114374 +system_enable_write_61396 system_enable_write 3 61396 NULL
114375 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
114376 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
114377 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
114378 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
114379 +erst_errno_61526 erst_errno 0 61526 NULL
114380 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
114381 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
114382 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
114383 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
114384 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
114385 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
114386 +seq_open_private_61589 seq_open_private 3 61589 NULL
114387 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
114388 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
114389 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
114390 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
114391 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
114392 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
114393 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
114394 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
114395 +resize_stripes_61650 resize_stripes 2 61650 NULL
114396 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
114397 +insert_one_name_61668 insert_one_name 7 61668 NULL
114398 +lock_loop_61681 lock_loop 1 61681 NULL
114399 +filter_read_61692 filter_read 3 61692 NULL
114400 +iov_length_61716 iov_length 0 61716 NULL
114401 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
114402 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
114403 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
114404 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
114405 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
114406 +gfs2_meta_wait_61773 gfs2_meta_wait 0 61773 NULL
114407 +xfs_file_dio_aio_write_61801 xfs_file_dio_aio_write 0 61801 NULL
114408 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
114409 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
114410 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
114411 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
114412 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
114413 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
114414 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
114415 +get_fw_name_61874 get_fw_name 3 61874 NULL
114416 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
114417 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
114418 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
114419 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
114420 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
114421 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
114422 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
114423 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
114424 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
114425 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
114426 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
114427 +fix_read_error_61965 fix_read_error 4 61965 NULL
114428 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
114429 +cow_file_range_61979 cow_file_range 3 61979 NULL
114430 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
114431 +dequeue_event_62000 dequeue_event 3 62000 NULL
114432 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
114433 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
114434 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
114435 +SYSC_select_62024 SYSC_select 1 62024 NULL
114436 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
114437 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
114438 +do_pselect_62061 do_pselect 1 62061 NULL
114439 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
114440 +_xfs_log_force_lsn_62083 _xfs_log_force_lsn 0 62083 NULL
114441 +fat_setattr_62084 fat_setattr 0 62084 NULL
114442 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
114443 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
114444 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
114445 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
114446 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
114447 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
114448 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
114449 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
114450 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
114451 +video_usercopy_62151 video_usercopy 2 62151 NULL
114452 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
114453 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
114454 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
114455 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
114456 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
114457 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
114458 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
114459 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
114460 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
114461 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
114462 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
114463 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
114464 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
114465 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
114466 +subseq_list_62332 subseq_list 3-0 62332 NULL
114467 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
114468 +flash_write_62354 flash_write 3 62354 NULL
114469 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
114470 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
114471 +altera_irscan_62396 altera_irscan 2 62396 NULL
114472 +set_ssp_62411 set_ssp 4 62411 NULL
114473 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
114474 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
114475 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
114476 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
114477 +debugfs_read_62535 debugfs_read 3 62535 NULL
114478 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
114479 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
114480 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
114481 +compute_bitstructs_62570 compute_bitstructs 0 62570 NULL
114482 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
114483 +get_subdir_62581 get_subdir 3 62581 NULL
114484 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
114485 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
114486 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
114487 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
114488 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
114489 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
114490 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
114491 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
114492 +rdm_62719 rdm 0 62719 NULL
114493 +add_to_page_cache_62724 add_to_page_cache 0 62724 NULL
114494 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
114495 +key_replays_read_62746 key_replays_read 3 62746 NULL
114496 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
114497 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
114498 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
114499 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
114500 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
114501 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
114502 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
114503 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
114504 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
114505 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
114506 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
114507 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
114508 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
114509 +xfs_rtmodify_range_62877 xfs_rtmodify_range 0 62877 NULL
114510 +aoechr_write_62883 aoechr_write 3 62883 NULL
114511 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
114512 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
114513 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
114514 +getdqbuf_62908 getdqbuf 1 62908 NULL
114515 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
114516 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
114517 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL nohasharray
114518 +xfs_trans_reserve_63026 xfs_trans_reserve 0 63026 &kstrtoull_from_user_63026
114519 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
114520 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
114521 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
114522 +unlink1_63059 unlink1 3 63059 NULL
114523 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
114524 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
114525 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
114526 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
114527 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
114528 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
114529 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
114530 +vme_master_read_63221 vme_master_read 0 63221 NULL
114531 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
114532 +ptp_read_63251 ptp_read 4 63251 NULL
114533 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
114534 +raid5_resize_63306 raid5_resize 2 63306 NULL
114535 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
114536 +proc_info_read_63344 proc_info_read 3 63344 NULL
114537 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
114538 +idmouse_read_63374 idmouse_read 3 63374 NULL
114539 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
114540 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
114541 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
114542 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
114543 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
114544 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
114545 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
114546 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
114547 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
114548 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
114549 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
114550 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
114551 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
114552 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
114553 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
114554 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
114555 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
114556 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
114557 +write_debug_level_63613 write_debug_level 3 63613 NULL
114558 +__spi_validate_63618 __spi_validate 0 63618 NULL
114559 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
114560 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
114561 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
114562 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
114563 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
114564 +vbi_read_63673 vbi_read 3 63673 NULL
114565 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
114566 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
114567 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
114568 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
114569 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
114570 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
114571 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
114572 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
114573 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
114574 +sel_write_load_63830 sel_write_load 3 63830 NULL
114575 +ll_readlink_63836 ll_readlink 3 63836 NULL
114576 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
114577 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
114578 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
114579 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
114580 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
114581 +__team_options_register_63941 __team_options_register 3 63941 NULL
114582 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
114583 +xfs_iflush_63956 xfs_iflush 0 63956 NULL
114584 +set_bredr_63975 set_bredr 4 63975 NULL
114585 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
114586 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
114587 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
114588 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
114589 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
114590 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
114591 +__generic_file_aio_write_64049 __generic_file_aio_write 0 64049 NULL
114592 +get_u8_64076 get_u8 0 64076 NULL
114593 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
114594 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
114595 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
114596 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
114597 +gfs2_inplace_reserve_64096 gfs2_inplace_reserve 0 64096 NULL nohasharray
114598 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 &gfs2_inplace_reserve_64096
114599 +to_bytes_64103 to_bytes 0-1 64103 NULL
114600 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
114601 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
114602 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
114603 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
114604 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
114605 +init_bch_64130 init_bch 1-2 64130 NULL
114606 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
114607 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
114608 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
114609 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
114610 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
114611 +read_pulse_64227 read_pulse 0-3 64227 NULL
114612 +ea_len_64229 ea_len 0 64229 NULL
114613 +xfs_rtmodify_summary_64265 xfs_rtmodify_summary 0 64265 NULL
114614 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
114615 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
114616 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
114617 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3-0 64288 NULL nohasharray
114618 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
114619 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
114620 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
114621 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
114622 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
114623 +ts_write_64336 ts_write 3 64336 NULL
114624 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
114625 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
114626 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
114627 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
114628 +reg_create_64372 reg_create 5 64372 NULL
114629 +ilo_write_64378 ilo_write 3 64378 NULL
114630 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
114631 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
114632 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
114633 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
114634 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
114635 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
114636 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
114637 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
114638 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
114639 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
114640 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
114641 +single_open_size_64483 single_open_size 4 64483 NULL
114642 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL nohasharray
114643 +xfs_inode_ag_walk_64493 xfs_inode_ag_walk 0 64493 &p54_parse_rssical_64493
114644 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
114645 +remove_uuid_64505 remove_uuid 4 64505 NULL
114646 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
114647 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
114648 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
114649 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
114650 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
114651 +SyS_bind_64544 SyS_bind 3 64544 NULL
114652 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
114653 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
114654 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
114655 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
114656 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
114657 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
114658 +do_erase_64574 do_erase 4 64574 NULL
114659 +fanotify_write_64623 fanotify_write 3 64623 NULL
114660 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
114661 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
114662 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
114663 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
114664 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
114665 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
114666 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
114667 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
114668 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
114669 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
114670 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
114671 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
114672 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
114673 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
114674 +message_for_md_64777 message_for_md 5 64777 NULL
114675 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
114676 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
114677 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
114678 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
114679 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
114680 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
114681 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
114682 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
114683 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
114684 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
114685 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
114686 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
114687 +xfs_imap_lookup_64906 xfs_imap_lookup 0 64906 NULL
114688 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
114689 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
114690 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
114691 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
114692 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
114693 +insert_dent_65034 insert_dent 7 65034 NULL
114694 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
114695 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
114696 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
114697 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
114698 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
114699 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
114700 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
114701 +__xfs_bmapi_allocate_65142 __xfs_bmapi_allocate 0 65142 NULL
114702 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
114703 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
114704 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
114705 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
114706 +xfs_btree_check_ptr_65281 xfs_btree_check_ptr 0 65281 NULL
114707 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
114708 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
114709 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
114710 +get_var_len_65304 get_var_len 0 65304 NULL
114711 +unpack_array_65318 unpack_array 0 65318 NULL
114712 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
114713 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
114714 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
114715 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
114716 +SyS_writev_65372 SyS_writev 3 65372 NULL
114717 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
114718 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
114719 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
114720 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
114721 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
114722 +device_add_groups_65423 device_add_groups 0 65423 NULL
114723 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
114724 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
114725 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
114726 +clear_user_65470 clear_user 2 65470 NULL
114727 +xfs_alloc_lookup_ge_65481 xfs_alloc_lookup_ge 0 65481 NULL
114728 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
114729 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
114730 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
114731 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
114732 diff --git a/tools/gcc/size_overflow_hash_aux.data b/tools/gcc/size_overflow_hash_aux.data
114733 new file mode 100644
114734 index 0000000..560cd7b
114735 --- /dev/null
114736 +++ b/tools/gcc/size_overflow_hash_aux.data
114737 @@ -0,0 +1,92 @@
114738 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
114739 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
114740 +mappedread_2627 mappedread 2 2627 NULL
114741 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
114742 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
114743 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
114744 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
114745 +dmu_write_6048 dmu_write 4-3 6048 NULL
114746 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
114747 +update_pages_6225 update_pages 2-3 6225 NULL
114748 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
114749 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
114750 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
114751 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
114752 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
114753 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
114754 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
114755 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
114756 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
114757 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
114758 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
114759 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
114760 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
114761 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
114762 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
114763 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
114764 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
114765 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
114766 +uiocopy_18680 uiocopy 2 18680 NULL
114767 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
114768 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
114769 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
114770 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
114771 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
114772 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
114773 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
114774 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
114775 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
114776 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
114777 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
114778 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
114779 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
114780 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
114781 +splat_write_30943 splat_write 3 30943 NULL
114782 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
114783 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
114784 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
114785 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
114786 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
114787 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
114788 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
114789 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
114790 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
114791 +copyinstr_36980 copyinstr 3 36980 NULL
114792 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
114793 +splat_read_38116 splat_read 3 38116 NULL
114794 +sa_setup_38756 sa_setup 4 38756 NULL
114795 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
114796 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
114797 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
114798 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
114799 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
114800 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
114801 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
114802 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
114803 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
114804 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
114805 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
114806 +kcopy_write_43683 kcopy_write 3 43683 NULL
114807 +uiomove_44355 uiomove 2 44355 NULL
114808 +dmu_read_44418 dmu_read 4-3 44418 NULL
114809 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
114810 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
114811 +copyin_45945 copyin 3 45945 NULL
114812 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
114813 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
114814 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
114815 +spa_history_write_49650 spa_history_write 3 49650 NULL
114816 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
114817 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
114818 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
114819 +copyout_51409 copyout 3 51409 NULL
114820 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
114821 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
114822 +get_nvlist_56685 get_nvlist 2 56685 NULL
114823 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
114824 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
114825 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
114826 +zpios_write_61823 zpios_write 3 61823 NULL
114827 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
114828 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
114829 +zpios_read_64734 zpios_read 3 64734 NULL
114830 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
114831 new file mode 100644
114832 index 0000000..948ec25
114833 --- /dev/null
114834 +++ b/tools/gcc/size_overflow_plugin.c
114835 @@ -0,0 +1,4169 @@
114836 +/*
114837 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114838 + * Licensed under the GPL v2, or (at your option) v3
114839 + *
114840 + * Homepage:
114841 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114842 + *
114843 + * Documentation:
114844 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114845 + *
114846 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114847 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114848 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114849 + *
114850 + * Usage:
114851 + * $ # for 4.5/4.6/C based 4.7
114852 + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -std=gnu99 -ggdb -o size_overflow_plugin.so size_overflow_plugin.c
114853 + * $ # for C++ based 4.7/4.8+
114854 + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -std=gnu++98 -fno-rtti -ggdb -o size_overflow_plugin.so size_overflow_plugin.c
114855 + *
114856 + * $ gcc -fplugin=./size_overflow_plugin.so test.c -O2
114857 + */
114858 +
114859 +#include "gcc-common.h"
114860 +
114861 +int plugin_is_GPL_compatible;
114862 +
114863 +static struct plugin_info size_overflow_plugin_info = {
114864 + .version = "20140407",
114865 + .help = "no-size-overflow\tturn off size overflow checking\n",
114866 +};
114867 +
114868 +#define BEFORE_STMT true
114869 +#define AFTER_STMT false
114870 +#define CREATE_NEW_VAR NULL_TREE
114871 +#define CODES_LIMIT 32
114872 +#define MAX_PARAM 31
114873 +#define VEC_LEN 128
114874 +#define RET_CHECK NULL_TREE
114875 +#define CANNOT_FIND_ARG 32
114876 +#define WRONG_NODE 32
114877 +#define NOT_INTENTIONAL_ASM NULL
114878 +#define MIN_CHECK true
114879 +#define MAX_CHECK false
114880 +
114881 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114882 +#define YES_ASM_STR "# size_overflow MARK_YES "
114883 +#define OK_ASM_STR "# size_overflow "
114884 +
114885 +struct size_overflow_hash {
114886 + const struct size_overflow_hash * const next;
114887 + const char * const name;
114888 + const unsigned int param;
114889 +};
114890 +
114891 +#include "size_overflow_hash.h"
114892 +#include "size_overflow_hash_aux.h"
114893 +
114894 +enum mark {
114895 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114896 +};
114897 +
114898 +static unsigned int call_count;
114899 +
114900 +enum stmt_flags {
114901 + MY_STMT, NO_CAST_CHECK, VISITED_STMT, NO_FLAGS
114902 +};
114903 +
114904 +struct visited {
114905 + struct visited *next;
114906 + const_tree fndecl;
114907 + unsigned int num;
114908 +};
114909 +
114910 +struct next_cgraph_node {
114911 + struct next_cgraph_node *next;
114912 + struct cgraph_node *current_function;
114913 + tree callee_fndecl;
114914 + unsigned int num;
114915 +};
114916 +
114917 +struct interesting_node {
114918 + struct interesting_node *next;
114919 + gimple first_stmt;
114920 + const_tree fndecl;
114921 + tree node;
114922 +#if BUILDING_GCC_VERSION <= 4007
114923 + VEC(tree, gc) *last_nodes;
114924 +#else
114925 + vec<tree, va_gc> *last_nodes;
114926 +#endif
114927 + unsigned int num;
114928 + enum mark intentional_attr_decl;
114929 + enum mark intentional_attr_cur_fndecl;
114930 + gimple intentional_mark_from_gimple;
114931 +};
114932 +
114933 +static tree report_size_overflow_decl;
114934 +
114935 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
114936 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
114937 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
114938 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114939 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114940 +
114941 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114942 +static tree get_size_overflow_type(gimple stmt, const_tree node);
114943 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114944 +
114945 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114946 +{
114947 + unsigned int arg_count;
114948 + enum tree_code code = TREE_CODE(*node);
114949 +
114950 + switch (code) {
114951 + case FUNCTION_DECL:
114952 + arg_count = type_num_arguments(TREE_TYPE(*node));
114953 + break;
114954 + case FUNCTION_TYPE:
114955 + case METHOD_TYPE:
114956 + arg_count = type_num_arguments(*node);
114957 + break;
114958 + default:
114959 + *no_add_attrs = true;
114960 + error("%s: %qE attribute only applies to functions", __func__, name);
114961 + return NULL_TREE;
114962 + }
114963 +
114964 + for (; args; args = TREE_CHAIN(args)) {
114965 + tree position = TREE_VALUE(args);
114966 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114967 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114968 + *no_add_attrs = true;
114969 + }
114970 + }
114971 + return NULL_TREE;
114972 +}
114973 +
114974 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114975 +{
114976 + unsigned int arg_count;
114977 + enum tree_code code = TREE_CODE(*node);
114978 +
114979 + switch (code) {
114980 + case FUNCTION_DECL:
114981 + arg_count = type_num_arguments(TREE_TYPE(*node));
114982 + break;
114983 + case FUNCTION_TYPE:
114984 + case METHOD_TYPE:
114985 + arg_count = type_num_arguments(*node);
114986 + break;
114987 + case FIELD_DECL:
114988 + return NULL_TREE;
114989 + default:
114990 + *no_add_attrs = true;
114991 + error("%qE attribute only applies to functions", name);
114992 + return NULL_TREE;
114993 + }
114994 +
114995 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
114996 + return NULL_TREE;
114997 +
114998 + for (; args; args = TREE_CHAIN(args)) {
114999 + tree position = TREE_VALUE(args);
115000 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
115001 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
115002 + *no_add_attrs = true;
115003 + }
115004 + }
115005 + return NULL_TREE;
115006 +}
115007 +
115008 +static struct attribute_spec size_overflow_attr = {
115009 + .name = "size_overflow",
115010 + .min_length = 1,
115011 + .max_length = -1,
115012 + .decl_required = true,
115013 + .type_required = false,
115014 + .function_type_required = false,
115015 + .handler = handle_size_overflow_attribute,
115016 +#if BUILDING_GCC_VERSION >= 4007
115017 + .affects_type_identity = false
115018 +#endif
115019 +};
115020 +
115021 +static struct attribute_spec intentional_overflow_attr = {
115022 + .name = "intentional_overflow",
115023 + .min_length = 1,
115024 + .max_length = -1,
115025 + .decl_required = true,
115026 + .type_required = false,
115027 + .function_type_required = false,
115028 + .handler = handle_intentional_overflow_attribute,
115029 +#if BUILDING_GCC_VERSION >= 4007
115030 + .affects_type_identity = false
115031 +#endif
115032 +};
115033 +
115034 +static void register_attributes(void __unused *event_data, void __unused *data)
115035 +{
115036 + register_attribute(&size_overflow_attr);
115037 + register_attribute(&intentional_overflow_attr);
115038 +}
115039 +
115040 +static enum stmt_flags get_stmt_flag(gimple stmt)
115041 +{
115042 + bool bit_1, bit_2;
115043 +
115044 + bit_1 = gimple_plf(stmt, GF_PLF_1);
115045 + bit_2 = gimple_plf(stmt, GF_PLF_2);
115046 +
115047 + if (!bit_1 && !bit_2)
115048 + return NO_FLAGS;
115049 + if (bit_1 && bit_2)
115050 + return MY_STMT;
115051 + if (!bit_1 && bit_2)
115052 + return VISITED_STMT;
115053 + return NO_CAST_CHECK;
115054 +}
115055 +
115056 +static void set_stmt_flag(gimple stmt, enum stmt_flags new_flag)
115057 +{
115058 + bool bit_1, bit_2;
115059 +
115060 + switch (new_flag) {
115061 + case NO_FLAGS:
115062 + bit_1 = bit_2 = false;
115063 + break;
115064 + case MY_STMT:
115065 + bit_1 = bit_2 = true;
115066 + break;
115067 + case VISITED_STMT:
115068 + bit_1 = false;
115069 + bit_2 = true;
115070 + break;
115071 + case NO_CAST_CHECK:
115072 + bit_1 = true;
115073 + bit_2 = false;
115074 + break;
115075 + default:
115076 + gcc_unreachable();
115077 + }
115078 +
115079 + gimple_set_plf(stmt, GF_PLF_1, bit_1);
115080 + gimple_set_plf(stmt, GF_PLF_2, bit_2);
115081 +}
115082 +
115083 +static bool is_bool(const_tree node)
115084 +{
115085 + const_tree type;
115086 +
115087 + if (node == NULL_TREE)
115088 + return false;
115089 +
115090 + type = TREE_TYPE(node);
115091 + if (!INTEGRAL_TYPE_P(type))
115092 + return false;
115093 + if (TREE_CODE(type) == BOOLEAN_TYPE)
115094 + return true;
115095 + if (TYPE_PRECISION(type) == 1)
115096 + return true;
115097 + return false;
115098 +}
115099 +
115100 +static bool skip_types(const_tree var)
115101 +{
115102 + tree type;
115103 + enum tree_code code;
115104 +
115105 + if (is_gimple_constant(var))
115106 + return true;
115107 +
115108 + switch (TREE_CODE(var)) {
115109 + case ADDR_EXPR:
115110 +#if BUILDING_GCC_VERSION >= 4006
115111 + case MEM_REF:
115112 +#endif
115113 + case ARRAY_REF:
115114 + case BIT_FIELD_REF:
115115 + case INDIRECT_REF:
115116 + case TARGET_MEM_REF:
115117 + case COMPONENT_REF:
115118 + case VAR_DECL:
115119 + case VIEW_CONVERT_EXPR:
115120 + return true;
115121 + default:
115122 + break;
115123 + }
115124 +
115125 + code = TREE_CODE(var);
115126 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
115127 +
115128 + type = TREE_TYPE(var);
115129 + switch (TREE_CODE(type)) {
115130 + case INTEGER_TYPE:
115131 + case ENUMERAL_TYPE:
115132 + return false;
115133 + case BOOLEAN_TYPE:
115134 + return is_bool(var);
115135 + default:
115136 + return true;
115137 + }
115138 +}
115139 +
115140 +static inline gimple get_def_stmt(const_tree node)
115141 +{
115142 + gcc_assert(node != NULL_TREE);
115143 +
115144 + if (skip_types(node))
115145 + return NULL;
115146 +
115147 + if (TREE_CODE(node) != SSA_NAME)
115148 + return NULL;
115149 + return SSA_NAME_DEF_STMT(node);
115150 +}
115151 +
115152 +static unsigned char get_tree_code(const_tree type)
115153 +{
115154 + switch (TREE_CODE(type)) {
115155 + case ARRAY_TYPE:
115156 + return 0;
115157 + case BOOLEAN_TYPE:
115158 + return 1;
115159 + case ENUMERAL_TYPE:
115160 + return 2;
115161 + case FUNCTION_TYPE:
115162 + return 3;
115163 + case INTEGER_TYPE:
115164 + return 4;
115165 + case POINTER_TYPE:
115166 + return 5;
115167 + case RECORD_TYPE:
115168 + return 6;
115169 + case UNION_TYPE:
115170 + return 7;
115171 + case VOID_TYPE:
115172 + return 8;
115173 + case REAL_TYPE:
115174 + return 9;
115175 + case VECTOR_TYPE:
115176 + return 10;
115177 + case REFERENCE_TYPE:
115178 + return 11;
115179 + case OFFSET_TYPE:
115180 + return 12;
115181 + case COMPLEX_TYPE:
115182 + return 13;
115183 + default:
115184 + debug_tree((tree)type);
115185 + gcc_unreachable();
115186 + }
115187 +}
115188 +
115189 +struct function_hash {
115190 + size_t tree_codes_len;
115191 + unsigned char tree_codes[CODES_LIMIT];
115192 + const_tree fndecl;
115193 + unsigned int hash;
115194 +};
115195 +
115196 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
115197 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
115198 +{
115199 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
115200 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
115201 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
115202 +
115203 + unsigned int m = 0x57559429;
115204 + unsigned int n = 0x5052acdb;
115205 + const unsigned int *key4 = (const unsigned int *)key;
115206 + unsigned int h = len;
115207 + unsigned int k = len + seed + n;
115208 + unsigned long long p;
115209 +
115210 + while (len >= 8) {
115211 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
115212 + len -= 8;
115213 + }
115214 + if (len >= 4) {
115215 + cwmixb(key4[0]) key4 += 1;
115216 + len -= 4;
115217 + }
115218 + if (len)
115219 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
115220 + cwmixb(h ^ (k + n));
115221 + return k ^ h;
115222 +
115223 +#undef cwfold
115224 +#undef cwmixa
115225 +#undef cwmixb
115226 +}
115227 +
115228 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
115229 +{
115230 + unsigned int fn, codes, seed = 0;
115231 +
115232 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
115233 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
115234 +
115235 + fn_hash_data->hash = fn ^ codes;
115236 +}
115237 +
115238 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
115239 +{
115240 + gcc_assert(type != NULL_TREE);
115241 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
115242 +
115243 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
115244 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
115245 + fn_hash_data->tree_codes_len++;
115246 + type = TREE_TYPE(type);
115247 + }
115248 +}
115249 +
115250 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
115251 +{
115252 + const_tree result;
115253 +
115254 + gcc_assert(node != NULL_TREE);
115255 +
115256 + if (DECL_P(node)) {
115257 + result = DECL_RESULT(node);
115258 + if (result != NULL_TREE)
115259 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
115260 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
115261 + }
115262 +
115263 + gcc_assert(TYPE_P(node));
115264 +
115265 + if (TREE_CODE(node) == FUNCTION_TYPE)
115266 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
115267 +
115268 + return set_node_codes(node, fn_hash_data);
115269 +}
115270 +
115271 +static void set_function_codes(struct function_hash *fn_hash_data)
115272 +{
115273 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
115274 + enum tree_code code = TREE_CODE(type);
115275 +
115276 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
115277 +
115278 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
115279 +
115280 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
115281 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
115282 +}
115283 +
115284 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
115285 +{
115286 + while (entry) {
115287 + if (!strcmp(entry->name, func_name))
115288 + return entry;
115289 + entry = entry->next;
115290 + }
115291 + return NULL;
115292 +}
115293 +
115294 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
115295 +{
115296 + const struct size_overflow_hash *entry;
115297 + struct function_hash fn_hash_data;
115298 + const char *func_name;
115299 +
115300 + // skip builtins __builtin_constant_p
115301 + if (DECL_BUILT_IN(fndecl))
115302 + return NULL;
115303 +
115304 + fn_hash_data.fndecl = fndecl;
115305 + fn_hash_data.tree_codes_len = 0;
115306 +
115307 + set_function_codes(&fn_hash_data);
115308 + gcc_assert(fn_hash_data.tree_codes_len != 0);
115309 +
115310 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
115311 + set_hash(func_name, &fn_hash_data);
115312 +
115313 + entry = size_overflow_hash[fn_hash_data.hash];
115314 + entry = get_proper_hash_chain(entry, func_name);
115315 + if (entry)
115316 + return entry;
115317 + entry = size_overflow_hash_aux[fn_hash_data.hash];
115318 + return get_proper_hash_chain(entry, func_name);
115319 +}
115320 +
115321 +static void print_missing_msg(const_tree func, unsigned int argnum)
115322 +{
115323 + location_t loc;
115324 + const char *curfunc;
115325 + struct function_hash fn_hash_data;
115326 +
115327 + fn_hash_data.fndecl = DECL_ORIGIN(func);
115328 + fn_hash_data.tree_codes_len = 0;
115329 +
115330 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
115331 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
115332 +
115333 + set_function_codes(&fn_hash_data);
115334 + set_hash(curfunc, &fn_hash_data);
115335 +
115336 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
115337 +}
115338 +
115339 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
115340 +{
115341 + tree var;
115342 + unsigned int argnum = 1;
115343 +
115344 + if (TREE_CODE(arg) == SSA_NAME)
115345 + arg = SSA_NAME_VAR(arg);
115346 +
115347 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
115348 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
115349 + continue;
115350 + if (!skip_types(var))
115351 + return argnum;
115352 + }
115353 +
115354 + return CANNOT_FIND_ARG;
115355 +}
115356 +
115357 +static tree create_new_var(tree type)
115358 +{
115359 + tree new_var = create_tmp_var(type, "cicus");
115360 +
115361 + add_referenced_var(new_var);
115362 + return new_var;
115363 +}
115364 +
115365 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
115366 +{
115367 + gimple assign;
115368 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115369 + tree type = TREE_TYPE(rhs1);
115370 + tree lhs = create_new_var(type);
115371 +
115372 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
115373 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
115374 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115375 +
115376 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
115377 + update_stmt(assign);
115378 + set_stmt_flag(assign, MY_STMT);
115379 + return assign;
115380 +}
115381 +
115382 +static tree cast_a_tree(tree type, tree var)
115383 +{
115384 + gcc_assert(type != NULL_TREE);
115385 + gcc_assert(var != NULL_TREE);
115386 + gcc_assert(fold_convertible_p(type, var));
115387 +
115388 + return fold_convert(type, var);
115389 +}
115390 +
115391 +static tree get_lhs(const_gimple stmt)
115392 +{
115393 + switch (gimple_code(stmt)) {
115394 + case GIMPLE_ASSIGN:
115395 + case GIMPLE_CALL:
115396 + return gimple_get_lhs(stmt);
115397 + case GIMPLE_PHI:
115398 + return gimple_phi_result(stmt);
115399 + default:
115400 + return NULL_TREE;
115401 + }
115402 +}
115403 +
115404 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
115405 +{
115406 + const_gimple def_stmt = get_def_stmt(rhs);
115407 +
115408 + if (force)
115409 + return false;
115410 +
115411 + if (is_gimple_constant(rhs))
115412 + return false;
115413 +
115414 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115415 + return false;
115416 +
115417 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
115418 + return false;
115419 +
115420 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
115421 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115422 + return false;
115423 +
115424 + return true;
115425 +}
115426 +
115427 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
115428 +{
115429 + gimple assign, def_stmt;
115430 +
115431 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
115432 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
115433 + gcc_unreachable();
115434 +
115435 + def_stmt = get_def_stmt(rhs);
115436 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && get_stmt_flag(def_stmt) == MY_STMT)
115437 + return def_stmt;
115438 +
115439 + if (lhs == CREATE_NEW_VAR)
115440 + lhs = create_new_var(dst_type);
115441 +
115442 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
115443 +
115444 + if (!gsi_end_p(*gsi)) {
115445 + location_t loc = gimple_location(gsi_stmt(*gsi));
115446 + gimple_set_location(assign, loc);
115447 + }
115448 +
115449 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115450 +
115451 + if (before)
115452 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
115453 + else
115454 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
115455 + update_stmt(assign);
115456 + return assign;
115457 +}
115458 +
115459 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
115460 +{
115461 + gimple_stmt_iterator gsi;
115462 + tree lhs;
115463 + gimple new_stmt;
115464 +
115465 + if (rhs == NULL_TREE)
115466 + return NULL_TREE;
115467 +
115468 + gsi = gsi_for_stmt(stmt);
115469 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115470 + set_stmt_flag(new_stmt, MY_STMT);
115471 +
115472 + lhs = get_lhs(new_stmt);
115473 + gcc_assert(lhs != NULL_TREE);
115474 + return lhs;
115475 +}
115476 +
115477 +static tree cast_to_TI_type(gimple stmt, tree node)
115478 +{
115479 + gimple_stmt_iterator gsi;
115480 + gimple cast_stmt;
115481 + tree type = TREE_TYPE(node);
115482 +
115483 + if (types_compatible_p(type, intTI_type_node))
115484 + return node;
115485 +
115486 + gsi = gsi_for_stmt(stmt);
115487 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115488 + set_stmt_flag(cast_stmt, MY_STMT);
115489 + return gimple_assign_lhs(cast_stmt);
115490 +}
115491 +
115492 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
115493 +{
115494 + tree lhs, new_lhs;
115495 + gimple_stmt_iterator gsi;
115496 +
115497 + if (rhs1 == NULL_TREE) {
115498 + debug_gimple_stmt(oldstmt);
115499 + error("%s: rhs1 is NULL_TREE", __func__);
115500 + gcc_unreachable();
115501 + }
115502 +
115503 + switch (gimple_code(oldstmt)) {
115504 + case GIMPLE_ASM:
115505 + lhs = rhs1;
115506 + break;
115507 + case GIMPLE_CALL:
115508 + case GIMPLE_ASSIGN:
115509 + lhs = gimple_get_lhs(oldstmt);
115510 + break;
115511 + default:
115512 + debug_gimple_stmt(oldstmt);
115513 + gcc_unreachable();
115514 + }
115515 +
115516 + gsi = gsi_for_stmt(oldstmt);
115517 + pointer_set_insert(visited, oldstmt);
115518 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115519 + basic_block next_bb, cur_bb;
115520 + const_edge e;
115521 +
115522 + gcc_assert(before == false);
115523 + gcc_assert(stmt_can_throw_internal(oldstmt));
115524 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115525 + gcc_assert(!gsi_end_p(gsi));
115526 +
115527 + cur_bb = gimple_bb(oldstmt);
115528 + next_bb = cur_bb->next_bb;
115529 + e = find_edge(cur_bb, next_bb);
115530 + gcc_assert(e != NULL);
115531 + gcc_assert(e->flags & EDGE_FALLTHRU);
115532 +
115533 + gsi = gsi_after_labels(next_bb);
115534 + gcc_assert(!gsi_end_p(gsi));
115535 +
115536 + before = true;
115537 + oldstmt = gsi_stmt(gsi);
115538 + }
115539 +
115540 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
115541 + return new_lhs;
115542 +}
115543 +
115544 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115545 +{
115546 + gimple stmt;
115547 + gimple_stmt_iterator gsi;
115548 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115549 +
115550 + if (get_stmt_flag(oldstmt) == MY_STMT)
115551 + return lhs;
115552 +
115553 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115554 + rhs1 = gimple_assign_rhs1(oldstmt);
115555 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115556 + }
115557 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115558 + rhs2 = gimple_assign_rhs2(oldstmt);
115559 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115560 + }
115561 +
115562 + stmt = gimple_copy(oldstmt);
115563 + gimple_set_location(stmt, gimple_location(oldstmt));
115564 + set_stmt_flag(stmt, MY_STMT);
115565 +
115566 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115567 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115568 +
115569 + size_overflow_type = get_size_overflow_type(oldstmt, node);
115570 +
115571 + new_var = create_new_var(size_overflow_type);
115572 + new_var = make_ssa_name(new_var, stmt);
115573 + gimple_assign_set_lhs(stmt, new_var);
115574 +
115575 + if (rhs1 != NULL_TREE)
115576 + gimple_assign_set_rhs1(stmt, rhs1);
115577 +
115578 + if (rhs2 != NULL_TREE)
115579 + gimple_assign_set_rhs2(stmt, rhs2);
115580 +#if BUILDING_GCC_VERSION >= 4006
115581 + if (rhs3 != NULL_TREE)
115582 + gimple_assign_set_rhs3(stmt, rhs3);
115583 +#endif
115584 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115585 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115586 +
115587 + gsi = gsi_for_stmt(oldstmt);
115588 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115589 + update_stmt(stmt);
115590 + pointer_set_insert(visited, oldstmt);
115591 + return gimple_assign_lhs(stmt);
115592 +}
115593 +
115594 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115595 +{
115596 + gimple assign;
115597 + gimple_stmt_iterator gsi;
115598 + basic_block first_bb;
115599 +
115600 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115601 +
115602 + if (bb->index == 0) {
115603 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115604 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115605 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115606 + bb = first_bb;
115607 + }
115608 +
115609 + gsi = gsi_after_labels(bb);
115610 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115611 + set_stmt_flag(assign, MY_STMT);
115612 +
115613 + return gimple_assign_lhs(assign);
115614 +}
115615 +
115616 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
115617 +{
115618 + gimple_stmt_iterator gsi;
115619 + gimple assign, def_stmt = get_def_stmt(new_arg);
115620 +
115621 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115622 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115623 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115624 + } else {
115625 + gsi = gsi_for_stmt(def_stmt);
115626 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115627 + }
115628 +
115629 + set_stmt_flag(assign, MY_STMT);
115630 + return gimple_assign_lhs(assign);
115631 +}
115632 +
115633 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
115634 +{
115635 + basic_block bb;
115636 + gimple_stmt_iterator gsi;
115637 + const_gimple def_stmt;
115638 + gimple assign;
115639 +
115640 + def_stmt = get_def_stmt(arg);
115641 + bb = gimple_bb(def_stmt);
115642 + gcc_assert(bb->index != 0);
115643 + gsi = gsi_after_labels(bb);
115644 +
115645 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115646 + set_stmt_flag(assign, MY_STMT);
115647 + return gimple_assign_lhs(assign);
115648 +}
115649 +
115650 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115651 +{
115652 + tree size_overflow_type;
115653 + tree arg;
115654 + const_gimple def_stmt;
115655 +
115656 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115657 + return new_arg;
115658 +
115659 + arg = gimple_phi_arg_def(oldstmt, i);
115660 + def_stmt = get_def_stmt(arg);
115661 + gcc_assert(def_stmt != NULL);
115662 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
115663 +
115664 + switch (gimple_code(def_stmt)) {
115665 + case GIMPLE_PHI:
115666 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
115667 + case GIMPLE_NOP: {
115668 + basic_block bb;
115669 +
115670 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115671 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
115672 + }
115673 + case GIMPLE_ASM: {
115674 + gimple_stmt_iterator gsi;
115675 + gimple assign, stmt = get_def_stmt(arg);
115676 +
115677 + gsi = gsi_for_stmt(stmt);
115678 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115679 + set_stmt_flag(assign, MY_STMT);
115680 + return gimple_assign_lhs(assign);
115681 + }
115682 + default:
115683 + gcc_assert(new_arg != NULL_TREE);
115684 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115685 + return use_phi_ssa_name(ssa_name_var, new_arg);
115686 + }
115687 +}
115688 +
115689 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
115690 +{
115691 + basic_block bb;
115692 + gimple phi;
115693 + gimple_seq seq;
115694 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115695 +
115696 + bb = gsi_bb(gsi);
115697 +
115698 + if (result == NULL_TREE) {
115699 + tree old_result = gimple_phi_result(oldstmt);
115700 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
115701 +
115702 + result = create_new_var(size_overflow_type);
115703 + }
115704 +
115705 + phi = create_phi_node(result, bb);
115706 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115707 + seq = phi_nodes(bb);
115708 + gsi = gsi_last(seq);
115709 + gsi_remove(&gsi, false);
115710 +
115711 + gsi = gsi_for_stmt(oldstmt);
115712 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115713 + gimple_set_bb(phi, bb);
115714 + set_stmt_flag(phi, MY_STMT);
115715 + return phi;
115716 +}
115717 +
115718 +#if BUILDING_GCC_VERSION <= 4007
115719 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115720 +#else
115721 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115722 +#endif
115723 +{
115724 + gimple new_phi;
115725 + unsigned int i;
115726 + tree arg, result;
115727 + location_t loc = gimple_location(oldstmt);
115728 +
115729 +#if BUILDING_GCC_VERSION <= 4007
115730 + gcc_assert(!VEC_empty(tree, *args));
115731 +#else
115732 + gcc_assert(!args->is_empty());
115733 +#endif
115734 +
115735 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
115736 + result = gimple_phi_result(new_phi);
115737 + ssa_name_var = SSA_NAME_VAR(result);
115738 +
115739 +#if BUILDING_GCC_VERSION <= 4007
115740 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115741 +#else
115742 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115743 +#endif
115744 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
115745 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115746 + }
115747 +
115748 +#if BUILDING_GCC_VERSION <= 4007
115749 + VEC_free(tree, heap, *args);
115750 +#else
115751 + vec_free(args);
115752 +#endif
115753 + update_stmt(new_phi);
115754 + return result;
115755 +}
115756 +
115757 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
115758 +{
115759 + tree ssa_name_var = NULL_TREE;
115760 +#if BUILDING_GCC_VERSION <= 4007
115761 + VEC(tree, heap) *args = NULL;
115762 +#else
115763 + vec<tree, va_heap, vl_embed> *args = NULL;
115764 +#endif
115765 + gimple oldstmt = get_def_stmt(orig_result);
115766 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115767 +
115768 + pointer_set_insert(visited, oldstmt);
115769 + for (i = 0; i < len; i++) {
115770 + tree arg, new_arg;
115771 +
115772 + arg = gimple_phi_arg_def(oldstmt, i);
115773 + new_arg = expand(visited, caller_node, arg);
115774 +
115775 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115776 + ssa_name_var = SSA_NAME_VAR(new_arg);
115777 +
115778 + if (is_gimple_constant(arg)) {
115779 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
115780 +
115781 + new_arg = cast_a_tree(size_overflow_type, arg);
115782 + }
115783 +
115784 +#if BUILDING_GCC_VERSION <= 4007
115785 + VEC_safe_push(tree, heap, args, new_arg);
115786 +#else
115787 + vec_safe_push(args, new_arg);
115788 +#endif
115789 + }
115790 +
115791 +#if BUILDING_GCC_VERSION <= 4007
115792 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
115793 +#else
115794 + return create_new_phi_node(args, ssa_name_var, oldstmt);
115795 +#endif
115796 +}
115797 +
115798 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
115799 +{
115800 + gimple assign;
115801 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115802 + tree origtype = TREE_TYPE(orig_rhs);
115803 +
115804 + gcc_assert(is_gimple_assign(stmt));
115805 +
115806 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115807 + set_stmt_flag(assign, MY_STMT);
115808 + return gimple_assign_lhs(assign);
115809 +}
115810 +
115811 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
115812 +{
115813 + const_tree rhs1, lhs, rhs1_type, lhs_type;
115814 + enum machine_mode lhs_mode, rhs_mode;
115815 + gimple def_stmt = get_def_stmt(no_const_rhs);
115816 +
115817 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115818 + return false;
115819 +
115820 + rhs1 = gimple_assign_rhs1(def_stmt);
115821 + lhs = gimple_assign_lhs(def_stmt);
115822 + rhs1_type = TREE_TYPE(rhs1);
115823 + lhs_type = TREE_TYPE(lhs);
115824 + rhs_mode = TYPE_MODE(rhs1_type);
115825 + lhs_mode = TYPE_MODE(lhs_type);
115826 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
115827 + return false;
115828 +
115829 + return true;
115830 +}
115831 +
115832 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
115833 +{
115834 + tree rhs1 = gimple_assign_rhs1(stmt);
115835 + tree lhs = gimple_assign_lhs(stmt);
115836 + const_tree rhs1_type = TREE_TYPE(rhs1);
115837 + const_tree lhs_type = TREE_TYPE(lhs);
115838 +
115839 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115840 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115841 +
115842 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115843 +}
115844 +
115845 +static bool no_uses(tree node)
115846 +{
115847 + imm_use_iterator imm_iter;
115848 + use_operand_p use_p;
115849 +
115850 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115851 + const_gimple use_stmt = USE_STMT(use_p);
115852 +
115853 + if (use_stmt == NULL)
115854 + return true;
115855 + if (is_gimple_debug(use_stmt))
115856 + continue;
115857 + return false;
115858 + }
115859 + return true;
115860 +}
115861 +
115862 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
115863 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
115864 +{
115865 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
115866 + gimple def_stmt = get_def_stmt(lhs);
115867 +
115868 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115869 + return false;
115870 +
115871 + rhs1 = gimple_assign_rhs1(def_stmt);
115872 + rhs_type = TREE_TYPE(rhs1);
115873 + lhs_type = TREE_TYPE(lhs);
115874 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
115875 + return false;
115876 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
115877 + return false;
115878 +
115879 + def_stmt = get_def_stmt(rhs1);
115880 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
115881 + return false;
115882 +
115883 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
115884 + return false;
115885 +
115886 + rhs1 = gimple_assign_rhs1(def_stmt);
115887 + rhs2 = gimple_assign_rhs2(def_stmt);
115888 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
115889 + return false;
115890 +
115891 + if (is_gimple_constant(rhs2))
115892 + not_const_rhs = rhs1;
115893 + else
115894 + not_const_rhs = rhs2;
115895 +
115896 + return no_uses(not_const_rhs);
115897 +}
115898 +
115899 +static bool skip_lhs_cast_check(const_gimple stmt)
115900 +{
115901 + const_tree rhs = gimple_assign_rhs1(stmt);
115902 + const_gimple def_stmt = get_def_stmt(rhs);
115903 +
115904 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115905 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115906 + return true;
115907 +
115908 + if (is_const_plus_unsigned_signed_truncation(rhs))
115909 + return true;
115910 +
115911 + return false;
115912 +}
115913 +
115914 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115915 +{
115916 + bool cast_lhs, cast_rhs;
115917 + tree lhs = gimple_assign_lhs(stmt);
115918 + tree rhs = gimple_assign_rhs1(stmt);
115919 + const_tree lhs_type = TREE_TYPE(lhs);
115920 + const_tree rhs_type = TREE_TYPE(rhs);
115921 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115922 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115923 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115924 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115925 +
115926 + static bool check_lhs[3][4] = {
115927 + // ss su us uu
115928 + { false, true, true, false }, // lhs > rhs
115929 + { false, false, false, false }, // lhs = rhs
115930 + { true, true, true, true }, // lhs < rhs
115931 + };
115932 +
115933 + static bool check_rhs[3][4] = {
115934 + // ss su us uu
115935 + { true, false, true, true }, // lhs > rhs
115936 + { true, false, true, true }, // lhs = rhs
115937 + { true, false, true, true }, // lhs < rhs
115938 + };
115939 +
115940 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115941 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115942 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115943 +
115944 + if (lhs_size > rhs_size) {
115945 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115946 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115947 + } else if (lhs_size == rhs_size) {
115948 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115949 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115950 + } else {
115951 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115952 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115953 + }
115954 +
115955 + if (!cast_lhs && !cast_rhs)
115956 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115957 +
115958 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115959 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115960 +
115961 + if (cast_rhs)
115962 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115963 +
115964 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115965 +}
115966 +
115967 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115968 +{
115969 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115970 +
115971 + if (get_stmt_flag(stmt) == MY_STMT)
115972 + return lhs;
115973 +
115974 + rhs1 = gimple_assign_rhs1(stmt);
115975 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115976 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115977 +
115978 + new_rhs1 = expand(visited, caller_node, rhs1);
115979 +
115980 + if (new_rhs1 == NULL_TREE)
115981 + return create_cast_assign(visited, stmt);
115982 +
115983 + if (get_stmt_flag(stmt) == NO_CAST_CHECK)
115984 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115985 +
115986 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
115987 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
115988 +
115989 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115990 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115991 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115992 + }
115993 +
115994 + if (!gimple_assign_cast_p(stmt))
115995 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115996 +
115997 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115998 +}
115999 +
116000 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
116001 +{
116002 + tree rhs1, lhs = gimple_assign_lhs(stmt);
116003 + gimple def_stmt = get_def_stmt(lhs);
116004 +
116005 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
116006 + rhs1 = gimple_assign_rhs1(def_stmt);
116007 +
116008 + if (is_gimple_constant(rhs1))
116009 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116010 +
116011 + switch (TREE_CODE(rhs1)) {
116012 + case SSA_NAME:
116013 + return handle_unary_rhs(visited, caller_node, def_stmt);
116014 + case ARRAY_REF:
116015 + case BIT_FIELD_REF:
116016 + case ADDR_EXPR:
116017 + case COMPONENT_REF:
116018 + case INDIRECT_REF:
116019 +#if BUILDING_GCC_VERSION >= 4006
116020 + case MEM_REF:
116021 +#endif
116022 + case TARGET_MEM_REF:
116023 + case VIEW_CONVERT_EXPR:
116024 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116025 + case PARM_DECL:
116026 + case VAR_DECL:
116027 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116028 +
116029 + default:
116030 + debug_gimple_stmt(def_stmt);
116031 + debug_tree(rhs1);
116032 + gcc_unreachable();
116033 + }
116034 +}
116035 +
116036 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
116037 +{
116038 + gimple cond_stmt;
116039 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
116040 +
116041 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
116042 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
116043 + update_stmt(cond_stmt);
116044 +}
116045 +
116046 +static tree create_string_param(tree string)
116047 +{
116048 + tree i_type, a_type;
116049 + const int length = TREE_STRING_LENGTH(string);
116050 +
116051 + gcc_assert(length > 0);
116052 +
116053 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
116054 + a_type = build_array_type(char_type_node, i_type);
116055 +
116056 + TREE_TYPE(string) = a_type;
116057 + TREE_CONSTANT(string) = 1;
116058 + TREE_READONLY(string) = 1;
116059 +
116060 + return build1(ADDR_EXPR, ptr_type_node, string);
116061 +}
116062 +
116063 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
116064 +{
116065 + gimple func_stmt;
116066 + const_gimple def_stmt;
116067 + const_tree loc_line;
116068 + tree loc_file, ssa_name, current_func;
116069 + expanded_location xloc;
116070 + char *ssa_name_buf;
116071 + int len;
116072 + struct cgraph_edge *edge;
116073 + struct cgraph_node *callee_node;
116074 + int frequency;
116075 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
116076 +
116077 + def_stmt = get_def_stmt(arg);
116078 + xloc = expand_location(gimple_location(def_stmt));
116079 +
116080 + if (!gimple_has_location(def_stmt)) {
116081 + xloc = expand_location(gimple_location(stmt));
116082 + if (!gimple_has_location(stmt))
116083 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
116084 + }
116085 +
116086 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
116087 +
116088 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
116089 + loc_file = create_string_param(loc_file);
116090 +
116091 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
116092 + current_func = create_string_param(current_func);
116093 +
116094 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
116095 + call_count++;
116096 + 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);
116097 + gcc_assert(len > 0);
116098 + ssa_name = build_string(len + 1, ssa_name_buf);
116099 + free(ssa_name_buf);
116100 + ssa_name = create_string_param(ssa_name);
116101 +
116102 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
116103 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
116104 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
116105 +
116106 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
116107 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
116108 +
116109 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
116110 + gcc_assert(edge != NULL);
116111 +}
116112 +
116113 +static void __unused print_the_code_insertions(const_gimple stmt)
116114 +{
116115 + location_t loc = gimple_location(stmt);
116116 +
116117 + inform(loc, "Integer size_overflow check applied here.");
116118 +}
116119 +
116120 +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)
116121 +{
116122 + basic_block cond_bb, join_bb, bb_true;
116123 + edge e;
116124 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116125 +
116126 + cond_bb = gimple_bb(stmt);
116127 + if (before)
116128 + gsi_prev(&gsi);
116129 + if (gsi_end_p(gsi))
116130 + e = split_block_after_labels(cond_bb);
116131 + else
116132 + e = split_block(cond_bb, gsi_stmt(gsi));
116133 + cond_bb = e->src;
116134 + join_bb = e->dest;
116135 + e->flags = EDGE_FALSE_VALUE;
116136 + e->probability = REG_BR_PROB_BASE;
116137 +
116138 + bb_true = create_empty_bb(cond_bb);
116139 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
116140 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
116141 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
116142 +
116143 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
116144 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
116145 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
116146 +
116147 + if (current_loops != NULL) {
116148 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
116149 + add_bb_to_loop(bb_true, cond_bb->loop_father);
116150 + }
116151 +
116152 + insert_cond(cond_bb, arg, cond_code, type_value);
116153 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
116154 +
116155 +// print_the_code_insertions(stmt);
116156 +}
116157 +
116158 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
116159 +{
116160 + const_tree rhs_type = TREE_TYPE(rhs);
116161 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
116162 +
116163 + gcc_assert(rhs_type != NULL_TREE);
116164 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
116165 + return;
116166 +
116167 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
116168 +
116169 + if (is_const_plus_unsigned_signed_truncation(rhs))
116170 + return;
116171 +
116172 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
116173 + // typemax (-1) < typemin (0)
116174 + if (TREE_OVERFLOW(type_max))
116175 + return;
116176 +
116177 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
116178 +
116179 + cast_rhs_type = TREE_TYPE(cast_rhs);
116180 + type_max_type = TREE_TYPE(type_max);
116181 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
116182 +
116183 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
116184 +
116185 + // special case: get_size_overflow_type(), 32, u64->s
116186 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
116187 + return;
116188 +
116189 + type_min_type = TREE_TYPE(type_min);
116190 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
116191 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
116192 +}
116193 +
116194 +static bool is_lt_signed_type_max(const_tree rhs)
116195 +{
116196 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
116197 +
116198 + if (!TYPE_UNSIGNED(type))
116199 + return true;
116200 +
116201 + switch (TYPE_MODE(type)) {
116202 + case QImode:
116203 + new_type = intQI_type_node;
116204 + break;
116205 + case HImode:
116206 + new_type = intHI_type_node;
116207 + break;
116208 + case SImode:
116209 + new_type = intSI_type_node;
116210 + break;
116211 + case DImode:
116212 + new_type = intDI_type_node;
116213 + break;
116214 + default:
116215 + debug_tree((tree)type);
116216 + gcc_unreachable();
116217 + }
116218 +
116219 + type_max = TYPE_MAX_VALUE(new_type);
116220 + if (!tree_int_cst_lt(type_max, rhs))
116221 + return true;
116222 +
116223 + return false;
116224 +}
116225 +
116226 +static bool is_gt_zero(const_tree rhs)
116227 +{
116228 + const_tree type = TREE_TYPE(rhs);
116229 +
116230 + if (TYPE_UNSIGNED(type))
116231 + return true;
116232 +
116233 + if (!tree_int_cst_lt(rhs, integer_zero_node))
116234 + return true;
116235 +
116236 + return false;
116237 +}
116238 +
116239 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
116240 +{
116241 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
116242 + return false;
116243 + if (!is_gimple_constant(rhs))
116244 + return false;
116245 +
116246 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
116247 +// if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
116248 +// return false;
116249 +
116250 + return true;
116251 +}
116252 +
116253 +static tree get_def_stmt_rhs(const_tree var)
116254 +{
116255 + tree rhs1, def_stmt_rhs1;
116256 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
116257 +
116258 + def_stmt = get_def_stmt(var);
116259 + if (!gimple_assign_cast_p(def_stmt))
116260 + return NULL_TREE;
116261 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && get_stmt_flag(def_stmt) == MY_STMT && gimple_assign_cast_p(def_stmt));
116262 +
116263 + rhs1 = gimple_assign_rhs1(def_stmt);
116264 + rhs1_def_stmt = get_def_stmt(rhs1);
116265 + if (!gimple_assign_cast_p(rhs1_def_stmt))
116266 + return rhs1;
116267 +
116268 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116269 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
116270 +
116271 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
116272 + case GIMPLE_CALL:
116273 + case GIMPLE_NOP:
116274 + case GIMPLE_ASM:
116275 + case GIMPLE_PHI:
116276 + return def_stmt_rhs1;
116277 + case GIMPLE_ASSIGN:
116278 + return rhs1;
116279 + default:
116280 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
116281 + gcc_unreachable();
116282 + }
116283 +}
116284 +
116285 +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)
116286 +{
116287 + tree new_rhs, orig_rhs;
116288 + void (*gimple_assign_set_rhs)(gimple, tree);
116289 + tree rhs1 = gimple_assign_rhs1(stmt);
116290 + tree rhs2 = gimple_assign_rhs2(stmt);
116291 + tree lhs = gimple_assign_lhs(stmt);
116292 +
116293 + if (!check_overflow)
116294 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116295 +
116296 + if (change_rhs == NULL_TREE)
116297 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116298 +
116299 + if (new_rhs2 == NULL_TREE) {
116300 + orig_rhs = rhs1;
116301 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
116302 + } else {
116303 + orig_rhs = rhs2;
116304 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
116305 + }
116306 +
116307 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
116308 +
116309 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
116310 + gimple_assign_set_rhs(stmt, new_rhs);
116311 + update_stmt(stmt);
116312 +
116313 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116314 +}
116315 +
116316 +static bool is_subtraction_special(const_gimple stmt)
116317 +{
116318 + gimple rhs1_def_stmt, rhs2_def_stmt;
116319 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
116320 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
116321 + const_tree rhs1 = gimple_assign_rhs1(stmt);
116322 + const_tree rhs2 = gimple_assign_rhs2(stmt);
116323 +
116324 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
116325 + return false;
116326 +
116327 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
116328 +
116329 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116330 + return false;
116331 +
116332 + rhs1_def_stmt = get_def_stmt(rhs1);
116333 + rhs2_def_stmt = get_def_stmt(rhs2);
116334 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116335 + return false;
116336 +
116337 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116338 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116339 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116340 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116341 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116342 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116343 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116344 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116345 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116346 + return false;
116347 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116348 + return false;
116349 +
116350 + set_stmt_flag(rhs1_def_stmt, NO_CAST_CHECK);
116351 + set_stmt_flag(rhs2_def_stmt, NO_CAST_CHECK);
116352 + return true;
116353 +}
116354 +
116355 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
116356 +{
116357 + tree new_rhs1, new_rhs2;
116358 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
116359 + gimple assign, stmt = get_def_stmt(lhs);
116360 + tree rhs1 = gimple_assign_rhs1(stmt);
116361 + tree rhs2 = gimple_assign_rhs2(stmt);
116362 +
116363 + if (!is_subtraction_special(stmt))
116364 + return NULL_TREE;
116365 +
116366 + new_rhs1 = expand(visited, caller_node, rhs1);
116367 + new_rhs2 = expand(visited, caller_node, rhs2);
116368 +
116369 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
116370 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
116371 +
116372 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
116373 + return NULL_TREE;
116374 +
116375 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
116376 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
116377 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
116378 + }
116379 +
116380 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
116381 + new_lhs = gimple_assign_lhs(assign);
116382 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
116383 +
116384 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116385 +}
116386 +
116387 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
116388 +{
116389 + const_gimple def_stmt;
116390 +
116391 + if (TREE_CODE(rhs) != SSA_NAME)
116392 + return false;
116393 +
116394 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
116395 + return false;
116396 +
116397 + def_stmt = get_def_stmt(rhs);
116398 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
116399 + return false;
116400 +
116401 + return true;
116402 +}
116403 +
116404 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116405 +{
116406 + tree rhs1, rhs2, new_lhs;
116407 + gimple def_stmt = get_def_stmt(lhs);
116408 + tree new_rhs1 = NULL_TREE;
116409 + tree new_rhs2 = NULL_TREE;
116410 +
116411 + rhs1 = gimple_assign_rhs1(def_stmt);
116412 + rhs2 = gimple_assign_rhs2(def_stmt);
116413 +
116414 + /* no DImode/TImode division in the 32/64 bit kernel */
116415 + switch (gimple_assign_rhs_code(def_stmt)) {
116416 + case RDIV_EXPR:
116417 + case TRUNC_DIV_EXPR:
116418 + case CEIL_DIV_EXPR:
116419 + case FLOOR_DIV_EXPR:
116420 + case ROUND_DIV_EXPR:
116421 + case TRUNC_MOD_EXPR:
116422 + case CEIL_MOD_EXPR:
116423 + case FLOOR_MOD_EXPR:
116424 + case ROUND_MOD_EXPR:
116425 + case EXACT_DIV_EXPR:
116426 + case POINTER_PLUS_EXPR:
116427 + case BIT_AND_EXPR:
116428 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116429 + default:
116430 + break;
116431 + }
116432 +
116433 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
116434 + if (new_lhs != NULL_TREE)
116435 + return new_lhs;
116436 +
116437 + if (TREE_CODE(rhs1) == SSA_NAME)
116438 + new_rhs1 = expand(visited, caller_node, rhs1);
116439 + if (TREE_CODE(rhs2) == SSA_NAME)
116440 + new_rhs2 = expand(visited, caller_node, rhs2);
116441 +
116442 + if (is_a_neg_overflow(def_stmt, rhs2))
116443 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
116444 + if (is_a_neg_overflow(def_stmt, rhs1))
116445 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
116446 +
116447 +
116448 + if (is_a_constant_overflow(def_stmt, rhs2))
116449 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
116450 + if (is_a_constant_overflow(def_stmt, rhs1))
116451 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
116452 +
116453 + // the const is between 0 and (signed) MAX
116454 + if (is_gimple_constant(rhs1))
116455 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
116456 + if (is_gimple_constant(rhs2))
116457 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
116458 +
116459 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116460 +}
116461 +
116462 +#if BUILDING_GCC_VERSION >= 4006
116463 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
116464 +{
116465 + if (is_gimple_constant(rhs))
116466 + return cast_a_tree(size_overflow_type, rhs);
116467 + if (TREE_CODE(rhs) != SSA_NAME)
116468 + return NULL_TREE;
116469 + return expand(visited, caller_node, rhs);
116470 +}
116471 +
116472 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116473 +{
116474 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
116475 + gimple def_stmt = get_def_stmt(lhs);
116476 +
116477 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
116478 +
116479 + rhs1 = gimple_assign_rhs1(def_stmt);
116480 + rhs2 = gimple_assign_rhs2(def_stmt);
116481 + rhs3 = gimple_assign_rhs3(def_stmt);
116482 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
116483 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
116484 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
116485 +
116486 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
116487 +}
116488 +#endif
116489 +
116490 +static tree get_size_overflow_type(gimple stmt, const_tree node)
116491 +{
116492 + const_tree type;
116493 + tree new_type;
116494 +
116495 + gcc_assert(node != NULL_TREE);
116496 +
116497 + type = TREE_TYPE(node);
116498 +
116499 + if (get_stmt_flag(stmt) == MY_STMT)
116500 + return TREE_TYPE(node);
116501 +
116502 + switch (TYPE_MODE(type)) {
116503 + case QImode:
116504 + new_type = intHI_type_node;
116505 + break;
116506 + case HImode:
116507 + new_type = intSI_type_node;
116508 + break;
116509 + case SImode:
116510 + new_type = intDI_type_node;
116511 + break;
116512 + case DImode:
116513 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
116514 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
116515 + else
116516 + new_type = intTI_type_node;
116517 + break;
116518 + case TImode:
116519 + gcc_assert(!TYPE_UNSIGNED(type));
116520 + new_type = intTI_type_node;
116521 + break;
116522 + default:
116523 + debug_tree((tree)node);
116524 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
116525 + gcc_unreachable();
116526 + }
116527 +
116528 + if (TYPE_QUALS(type) != 0)
116529 + return build_qualified_type(new_type, TYPE_QUALS(type));
116530 + return new_type;
116531 +}
116532 +
116533 +static tree expand_visited(gimple def_stmt)
116534 +{
116535 + const_gimple next_stmt;
116536 + gimple_stmt_iterator gsi;
116537 + enum gimple_code code = gimple_code(def_stmt);
116538 +
116539 + if (code == GIMPLE_ASM)
116540 + return NULL_TREE;
116541 +
116542 + gsi = gsi_for_stmt(def_stmt);
116543 + gsi_next(&gsi);
116544 +
116545 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
116546 + return NULL_TREE;
116547 + gcc_assert(!gsi_end_p(gsi));
116548 + next_stmt = gsi_stmt(gsi);
116549 +
116550 + if (gimple_code(def_stmt) == GIMPLE_PHI && get_stmt_flag((gimple)next_stmt) != MY_STMT)
116551 + return NULL_TREE;
116552 + gcc_assert(get_stmt_flag((gimple)next_stmt) == MY_STMT);
116553 +
116554 + return get_lhs(next_stmt);
116555 +}
116556 +
116557 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116558 +{
116559 + gimple def_stmt;
116560 +
116561 + def_stmt = get_def_stmt(lhs);
116562 +
116563 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
116564 + return NULL_TREE;
116565 +
116566 + if (get_stmt_flag(def_stmt) == MY_STMT)
116567 + return lhs;
116568 +
116569 + if (pointer_set_contains(visited, def_stmt))
116570 + return expand_visited(def_stmt);
116571 +
116572 + switch (gimple_code(def_stmt)) {
116573 + case GIMPLE_PHI:
116574 + return handle_phi(visited, caller_node, lhs);
116575 + case GIMPLE_CALL:
116576 + case GIMPLE_ASM:
116577 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116578 + case GIMPLE_ASSIGN:
116579 + switch (gimple_num_ops(def_stmt)) {
116580 + case 2:
116581 + return handle_unary_ops(visited, caller_node, def_stmt);
116582 + case 3:
116583 + return handle_binary_ops(visited, caller_node, lhs);
116584 +#if BUILDING_GCC_VERSION >= 4006
116585 + case 4:
116586 + return handle_ternary_ops(visited, caller_node, lhs);
116587 +#endif
116588 + }
116589 + default:
116590 + debug_gimple_stmt(def_stmt);
116591 + error("%s: unknown gimple code", __func__);
116592 + gcc_unreachable();
116593 + }
116594 +}
116595 +
116596 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
116597 +{
116598 + const_gimple assign;
116599 + tree orig_type = TREE_TYPE(orig_node);
116600 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116601 +
116602 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116603 + return gimple_assign_lhs(assign);
116604 +}
116605 +
116606 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
116607 +{
116608 + void (*set_rhs)(gimple, tree);
116609 + gimple stmt = cur_node->first_stmt;
116610 + const_tree orig_node = cur_node->node;
116611 +
116612 + switch (gimple_code(stmt)) {
116613 + case GIMPLE_RETURN:
116614 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116615 + break;
116616 + case GIMPLE_CALL:
116617 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
116618 + break;
116619 + case GIMPLE_ASSIGN:
116620 + switch (cur_node->num) {
116621 + case 1:
116622 + set_rhs = &gimple_assign_set_rhs1;
116623 + break;
116624 + case 2:
116625 + set_rhs = &gimple_assign_set_rhs2;
116626 + break;
116627 +#if BUILDING_GCC_VERSION >= 4006
116628 + case 3:
116629 + set_rhs = &gimple_assign_set_rhs3;
116630 + break;
116631 +#endif
116632 + default:
116633 + gcc_unreachable();
116634 + }
116635 +
116636 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116637 + break;
116638 + default:
116639 + debug_gimple_stmt(stmt);
116640 + gcc_unreachable();
116641 + }
116642 +
116643 + update_stmt(stmt);
116644 +}
116645 +
116646 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
116647 +{
116648 + const struct size_overflow_hash *hash;
116649 + unsigned int new_argnum;
116650 + tree arg;
116651 + const_tree origarg;
116652 +
116653 + if (argnum == 0)
116654 + return argnum;
116655 +
116656 + hash = get_function_hash(fndecl);
116657 + if (hash && hash->param & (1U << argnum))
116658 + return argnum;
116659 +
116660 + if (DECL_EXTERNAL(fndecl))
116661 + return argnum;
116662 +
116663 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
116664 + argnum--;
116665 + while (origarg && argnum) {
116666 + origarg = TREE_CHAIN(origarg);
116667 + argnum--;
116668 + }
116669 + gcc_assert(argnum == 0);
116670 + gcc_assert(origarg != NULL_TREE);
116671 +
116672 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
116673 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
116674 + return new_argnum;
116675 +
116676 + return CANNOT_FIND_ARG;
116677 +}
116678 +
116679 +// Don't want to duplicate entries in next_cgraph_node
116680 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
116681 +{
116682 + const_tree new_callee_fndecl;
116683 + struct next_cgraph_node *cur_node;
116684 +
116685 + if (fndecl == RET_CHECK)
116686 + new_callee_fndecl = NODE_DECL(node);
116687 + else
116688 + new_callee_fndecl = fndecl;
116689 +
116690 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116691 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
116692 + continue;
116693 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
116694 + continue;
116695 + if (num == cur_node->num)
116696 + return true;
116697 + }
116698 + return false;
116699 +}
116700 +
116701 +/* Add a next_cgraph_node into the list for handle_function().
116702 + * handle_function() iterates over all the next cgraph nodes and
116703 + * starts the overflow check insertion process.
116704 + */
116705 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
116706 +{
116707 + struct next_cgraph_node *new_node;
116708 +
116709 + if (is_in_next_cgraph_node(head, node, fndecl, num))
116710 + return head;
116711 +
116712 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
116713 + new_node->current_function = node;
116714 + new_node->next = NULL;
116715 + new_node->num = num;
116716 + if (fndecl == RET_CHECK)
116717 + new_node->callee_fndecl = NODE_DECL(node);
116718 + else
116719 + new_node->callee_fndecl = fndecl;
116720 +
116721 + if (!head)
116722 + return new_node;
116723 +
116724 + new_node->next = head;
116725 + return new_node;
116726 +}
116727 +
116728 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
116729 +{
116730 + struct cgraph_edge *e;
116731 +
116732 + if (num == 0)
116733 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116734 +
116735 + for (e = node->callers; e; e = e->next_caller) {
116736 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116737 +
116738 + gcc_assert(fndecl != NULL_TREE);
116739 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116740 + }
116741 +
116742 + return head;
116743 +}
116744 +
116745 +static bool is_a_return_check(const_tree node)
116746 +{
116747 + if (TREE_CODE(node) == FUNCTION_DECL)
116748 + return true;
116749 +
116750 + gcc_assert(TREE_CODE(node) == PARM_DECL);
116751 + return false;
116752 +}
116753 +
116754 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
116755 +{
116756 + const struct size_overflow_hash *hash;
116757 +
116758 + hash = get_function_hash(fndecl);
116759 + if (hash && (hash->param & (1U << num)))
116760 + return true;
116761 + return false;
116762 +}
116763 +
116764 +struct missing_functions {
116765 + struct missing_functions *next;
116766 + const_tree node;
116767 + tree fndecl;
116768 +};
116769 +
116770 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116771 +{
116772 + struct missing_functions *new_function;
116773 +
116774 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116775 + new_function->node = node;
116776 + new_function->next = NULL;
116777 +
116778 + if (TREE_CODE(node) == FUNCTION_DECL)
116779 + new_function->fndecl = node;
116780 + else
116781 + new_function->fndecl = current_function_decl;
116782 + gcc_assert(new_function->fndecl);
116783 +
116784 + if (!missing_fn_head)
116785 + return new_function;
116786 +
116787 + new_function->next = missing_fn_head;
116788 + return new_function;
116789 +}
116790 +
116791 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
116792 + * If the function is missing everywhere then print the missing message into stderr.
116793 + */
116794 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
116795 +{
116796 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
116797 +#if BUILDING_GCC_VERSION >= 4008
116798 + case BUILT_IN_BSWAP16:
116799 +#endif
116800 + case BUILT_IN_BSWAP32:
116801 + case BUILT_IN_BSWAP64:
116802 + case BUILT_IN_EXPECT:
116803 + case BUILT_IN_MEMCMP:
116804 + return false;
116805 + default:
116806 + break;
116807 + }
116808 +
116809 + // skip test.c
116810 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
116811 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
116812 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
116813 + }
116814 +
116815 + if (is_in_hash_table(orig_fndecl, num))
116816 + return false;
116817 +
116818 + print_missing_msg(orig_fndecl, num);
116819 + return true;
116820 +}
116821 +
116822 +// Get the argnum of a function decl, if node is a return then the argnum is 0
116823 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
116824 +{
116825 + if (is_a_return_check(node))
116826 + return 0;
116827 + else
116828 + return find_arg_number_tree(node, orig_fndecl);
116829 +}
116830 +
116831 +/* If the function is missing from the hash table and it is a static function
116832 + * then create a next_cgraph_node from it for handle_function()
116833 + */
116834 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116835 +{
116836 + unsigned int num;
116837 + const_tree orig_fndecl;
116838 + struct cgraph_node *next_node = NULL;
116839 +
116840 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116841 +
116842 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116843 + if (num == CANNOT_FIND_ARG)
116844 + return cnodes;
116845 +
116846 + if (!is_missing_function(orig_fndecl, num))
116847 + return cnodes;
116848 +
116849 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116850 + if (next_node && next_node->local.local)
116851 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116852 + return cnodes;
116853 +}
116854 +
116855 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116856 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116857 + */
116858 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116859 +{
116860 + unsigned int i;
116861 + tree node;
116862 + struct missing_functions *cur, *missing_fn_head = NULL;
116863 +
116864 +#if BUILDING_GCC_VERSION <= 4007
116865 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116866 +#else
116867 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116868 +#endif
116869 + switch (TREE_CODE(node)) {
116870 + case PARM_DECL:
116871 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116872 + break;
116873 + case FUNCTION_DECL:
116874 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116875 + break;
116876 + default:
116877 + break;
116878 + }
116879 + }
116880 +
116881 + while (missing_fn_head) {
116882 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116883 +
116884 + cur = missing_fn_head->next;
116885 + free(missing_fn_head);
116886 + missing_fn_head = cur;
116887 + }
116888 +
116889 + return cnodes;
116890 +}
116891 +
116892 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116893 +{
116894 + gimple phi = get_def_stmt(result);
116895 + unsigned int i, n = gimple_phi_num_args(phi);
116896 +
116897 + pointer_set_insert(visited, phi);
116898 + for (i = 0; i < n; i++) {
116899 + const_tree arg = gimple_phi_arg_def(phi, i);
116900 +
116901 + set_conditions(visited, interesting_conditions, arg);
116902 + }
116903 +}
116904 +
116905 +enum conditions {
116906 + FROM_CONST, NOT_UNARY, CAST
116907 +};
116908 +
116909 +// Search for constants, cast assignments and binary/ternary assignments
116910 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116911 +{
116912 + gimple def_stmt = get_def_stmt(lhs);
116913 +
116914 + if (is_gimple_constant(lhs)) {
116915 + interesting_conditions[FROM_CONST] = true;
116916 + return;
116917 + }
116918 +
116919 + if (!def_stmt)
116920 + return;
116921 +
116922 + if (pointer_set_contains(visited, def_stmt))
116923 + return;
116924 +
116925 + switch (gimple_code(def_stmt)) {
116926 + case GIMPLE_NOP:
116927 + case GIMPLE_CALL:
116928 + case GIMPLE_ASM:
116929 + return;
116930 + case GIMPLE_PHI:
116931 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116932 + case GIMPLE_ASSIGN:
116933 + if (gimple_num_ops(def_stmt) == 2) {
116934 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116935 +
116936 + if (gimple_assign_cast_p(def_stmt))
116937 + interesting_conditions[CAST] = true;
116938 +
116939 + return set_conditions(visited, interesting_conditions, rhs);
116940 + } else {
116941 + interesting_conditions[NOT_UNARY] = true;
116942 + return;
116943 + }
116944 + default:
116945 + debug_gimple_stmt(def_stmt);
116946 + gcc_unreachable();
116947 + }
116948 +}
116949 +
116950 +// determine whether duplication will be necessary or not.
116951 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116952 +{
116953 + struct pointer_set_t *visited;
116954 +
116955 + if (gimple_assign_cast_p(cur_node->first_stmt))
116956 + interesting_conditions[CAST] = true;
116957 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116958 + interesting_conditions[NOT_UNARY] = true;
116959 +
116960 + visited = pointer_set_create();
116961 + set_conditions(visited, interesting_conditions, cur_node->node);
116962 + pointer_set_destroy(visited);
116963 +}
116964 +
116965 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116966 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116967 +{
116968 + gimple assign;
116969 + gimple_stmt_iterator gsi;
116970 +
116971 + // already removed
116972 + if (gimple_bb(asm_stmt) == NULL)
116973 + return;
116974 + gsi = gsi_for_stmt(asm_stmt);
116975 +
116976 + assign = gimple_build_assign(lhs, rhs);
116977 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116978 + SSA_NAME_DEF_STMT(lhs) = assign;
116979 +
116980 + gsi_remove(&gsi, true);
116981 +}
116982 +
116983 +// Get the field decl of a component ref for intentional_overflow checking
116984 +static const_tree search_field_decl(const_tree comp_ref)
116985 +{
116986 + const_tree field = NULL_TREE;
116987 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116988 +
116989 + for (i = 0; i < len; i++) {
116990 + field = TREE_OPERAND(comp_ref, i);
116991 + if (TREE_CODE(field) == FIELD_DECL)
116992 + break;
116993 + }
116994 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116995 + return field;
116996 +}
116997 +
116998 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116999 + * stmt is a return otherwise it is the callee function.
117000 + */
117001 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
117002 +{
117003 + const_tree fndecl;
117004 +
117005 + if (argnum == 0)
117006 + fndecl = current_function_decl;
117007 + else
117008 + fndecl = gimple_call_fndecl(stmt);
117009 +
117010 + if (fndecl == NULL_TREE)
117011 + return NULL_TREE;
117012 +
117013 + return DECL_ORIGIN(fndecl);
117014 +}
117015 +
117016 +/* Get the param of the intentional_overflow attribute.
117017 + * * 0: MARK_NOT_INTENTIONAL
117018 + * * 1..MAX_PARAM: MARK_YES
117019 + * * -1: MARK_TURN_OFF
117020 + */
117021 +static tree get_attribute_param(const_tree decl)
117022 +{
117023 + const_tree attr;
117024 +
117025 + if (decl == NULL_TREE)
117026 + return NULL_TREE;
117027 +
117028 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
117029 + if (!attr || !TREE_VALUE(attr))
117030 + return NULL_TREE;
117031 +
117032 + return TREE_VALUE(attr);
117033 +}
117034 +
117035 +// MARK_TURN_OFF
117036 +static bool is_turn_off_intentional_attr(const_tree decl)
117037 +{
117038 + const_tree param_head;
117039 +
117040 + param_head = get_attribute_param(decl);
117041 + if (param_head == NULL_TREE)
117042 + return false;
117043 +
117044 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
117045 + return true;
117046 + return false;
117047 +}
117048 +
117049 +// MARK_NOT_INTENTIONAL
117050 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
117051 +{
117052 + const_tree param_head;
117053 +
117054 + if (argnum == 0)
117055 + return false;
117056 +
117057 + param_head = get_attribute_param(decl);
117058 + if (param_head == NULL_TREE)
117059 + return false;
117060 +
117061 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
117062 + return true;
117063 + return false;
117064 +}
117065 +
117066 +// MARK_YES
117067 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
117068 +{
117069 + tree param, param_head;
117070 +
117071 + if (argnum == 0)
117072 + return false;
117073 +
117074 + param_head = get_attribute_param(decl);
117075 + for (param = param_head; param; param = TREE_CHAIN(param))
117076 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
117077 + return true;
117078 + return false;
117079 +}
117080 +
117081 +static const char *get_asm_string(const_gimple stmt)
117082 +{
117083 + if (!stmt)
117084 + return NULL;
117085 + if (gimple_code(stmt) != GIMPLE_ASM)
117086 + return NULL;
117087 +
117088 + return gimple_asm_string(stmt);
117089 +}
117090 +
117091 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
117092 +{
117093 + const char *str;
117094 +
117095 + str = get_asm_string(stmt);
117096 + if (!str)
117097 + return false;
117098 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
117099 +}
117100 +
117101 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
117102 +{
117103 + const char *str;
117104 +
117105 + str = get_asm_string(stmt);
117106 + if (!str)
117107 + return false;
117108 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
117109 +}
117110 +
117111 +static bool is_size_overflow_asm(const_gimple stmt)
117112 +{
117113 + const char *str;
117114 +
117115 + str = get_asm_string(stmt);
117116 + if (!str)
117117 + return false;
117118 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
117119 +}
117120 +
117121 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
117122 +{
117123 + location_t loc;
117124 +
117125 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
117126 + return;
117127 +
117128 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
117129 + return;
117130 +
117131 + loc = DECL_SOURCE_LOCATION(decl);
117132 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
117133 +}
117134 +
117135 +/* Get the type of the intentional_overflow attribute of a node
117136 + * * MARK_TURN_OFF
117137 + * * MARK_YES
117138 + * * MARK_NO
117139 + * * MARK_NOT_INTENTIONAL
117140 + */
117141 +static enum mark get_intentional_attr_type(const_tree node)
117142 +{
117143 + const_tree cur_decl;
117144 +
117145 + if (node == NULL_TREE)
117146 + return MARK_NO;
117147 +
117148 + switch (TREE_CODE(node)) {
117149 + case COMPONENT_REF:
117150 + cur_decl = search_field_decl(node);
117151 + if (is_turn_off_intentional_attr(cur_decl))
117152 + return MARK_TURN_OFF;
117153 + if (is_end_intentional_intentional_attr(cur_decl, 1))
117154 + return MARK_YES;
117155 + break;
117156 + case PARM_DECL: {
117157 + unsigned int argnum;
117158 +
117159 + cur_decl = DECL_ORIGIN(current_function_decl);
117160 + argnum = find_arg_number_tree(node, cur_decl);
117161 + if (argnum == CANNOT_FIND_ARG)
117162 + return MARK_NO;
117163 + if (is_yes_intentional_attr(cur_decl, argnum))
117164 + return MARK_YES;
117165 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
117166 + return MARK_NOT_INTENTIONAL;
117167 + break;
117168 + }
117169 + case FUNCTION_DECL:
117170 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
117171 + return MARK_TURN_OFF;
117172 + break;
117173 + default:
117174 + break;
117175 + }
117176 + return MARK_NO;
117177 +}
117178 +
117179 +// Search for the intentional_overflow attribute on the last nodes
117180 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
117181 +{
117182 + unsigned int i;
117183 + tree last_node;
117184 + enum mark mark = MARK_NO;
117185 +
117186 +#if BUILDING_GCC_VERSION <= 4007
117187 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
117188 +#else
117189 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
117190 +#endif
117191 + mark = get_intentional_attr_type(last_node);
117192 + if (mark != MARK_NO)
117193 + break;
117194 + }
117195 + return mark;
117196 +}
117197 +
117198 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
117199 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
117200 + */
117201 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
117202 +{
117203 + if (!cur_node->intentional_mark_from_gimple)
117204 + return false;
117205 +
117206 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
117207 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
117208 + else
117209 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117210 +
117211 + // skip param decls
117212 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
117213 + return true;
117214 + return true;
117215 +}
117216 +
117217 +/* Search intentional_overflow attribute on caller and on callee too.
117218 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
117219 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
117220 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
117221 +*/
117222 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
117223 +{
117224 + const_tree fndecl;
117225 +
117226 + if (is_intentional_attribute_from_gimple(cur_node))
117227 + return;
117228 +
117229 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117230 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
117231 + return;
117232 + }
117233 +
117234 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
117235 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
117236 + return;
117237 + }
117238 +
117239 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
117240 + return;
117241 +
117242 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
117243 + if (is_turn_off_intentional_attr(fndecl)) {
117244 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
117245 + return;
117246 + }
117247 +
117248 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
117249 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
117250 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
117251 + cur_node->intentional_attr_decl = MARK_YES;
117252 +
117253 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
117254 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
117255 +}
117256 +
117257 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
117258 +static bool skip_asm(const_tree arg)
117259 +{
117260 + gimple def_stmt = get_def_stmt(arg);
117261 +
117262 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
117263 + return false;
117264 +
117265 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
117266 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
117267 +}
117268 +
117269 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
117270 +{
117271 + gimple phi = get_def_stmt(result);
117272 + unsigned int i, n = gimple_phi_num_args(phi);
117273 +
117274 + pointer_set_insert(visited, phi);
117275 + for (i = 0; i < n; i++) {
117276 + tree arg = gimple_phi_arg_def(phi, i);
117277 +
117278 + walk_use_def(visited, cur_node, arg);
117279 + }
117280 +}
117281 +
117282 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117283 +{
117284 + gimple def_stmt = get_def_stmt(lhs);
117285 + tree rhs1, rhs2;
117286 +
117287 + rhs1 = gimple_assign_rhs1(def_stmt);
117288 + rhs2 = gimple_assign_rhs2(def_stmt);
117289 +
117290 + walk_use_def(visited, cur_node, rhs1);
117291 + walk_use_def(visited, cur_node, rhs2);
117292 +}
117293 +
117294 +static void insert_last_node(struct interesting_node *cur_node, tree node)
117295 +{
117296 + unsigned int i;
117297 + tree element;
117298 + enum tree_code code;
117299 +
117300 + gcc_assert(node != NULL_TREE);
117301 +
117302 + if (is_gimple_constant(node))
117303 + return;
117304 +
117305 + code = TREE_CODE(node);
117306 + if (code == VAR_DECL) {
117307 + node = DECL_ORIGIN(node);
117308 + code = TREE_CODE(node);
117309 + }
117310 +
117311 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
117312 + return;
117313 +
117314 +#if BUILDING_GCC_VERSION <= 4007
117315 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
117316 +#else
117317 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
117318 +#endif
117319 + if (operand_equal_p(node, element, 0))
117320 + return;
117321 + }
117322 +
117323 +#if BUILDING_GCC_VERSION <= 4007
117324 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
117325 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
117326 +#else
117327 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
117328 + vec_safe_push(cur_node->last_nodes, node);
117329 +#endif
117330 +}
117331 +
117332 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
117333 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
117334 +{
117335 + if (!is_size_overflow_asm(stmt))
117336 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117337 +}
117338 +
117339 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
117340 + * and component refs (for checking the intentional_overflow attribute).
117341 + */
117342 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117343 +{
117344 + const_gimple def_stmt;
117345 +
117346 + if (TREE_CODE(lhs) != SSA_NAME) {
117347 + insert_last_node(cur_node, lhs);
117348 + return;
117349 + }
117350 +
117351 + def_stmt = get_def_stmt(lhs);
117352 + if (!def_stmt)
117353 + return;
117354 +
117355 + if (pointer_set_insert(visited, def_stmt))
117356 + return;
117357 +
117358 + switch (gimple_code(def_stmt)) {
117359 + case GIMPLE_NOP:
117360 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117361 + case GIMPLE_ASM:
117362 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
117363 + case GIMPLE_CALL: {
117364 + tree fndecl = gimple_call_fndecl(def_stmt);
117365 +
117366 + if (fndecl == NULL_TREE)
117367 + return;
117368 + insert_last_node(cur_node, fndecl);
117369 + return;
117370 + }
117371 + case GIMPLE_PHI:
117372 + return walk_use_def_phi(visited, cur_node, lhs);
117373 + case GIMPLE_ASSIGN:
117374 + switch (gimple_num_ops(def_stmt)) {
117375 + case 2:
117376 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
117377 + case 3:
117378 + return walk_use_def_binary(visited, cur_node, lhs);
117379 + }
117380 + default:
117381 + debug_gimple_stmt((gimple)def_stmt);
117382 + error("%s: unknown gimple code", __func__);
117383 + gcc_unreachable();
117384 + }
117385 +}
117386 +
117387 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
117388 +static void set_last_nodes(struct interesting_node *cur_node)
117389 +{
117390 + struct pointer_set_t *visited;
117391 +
117392 + visited = pointer_set_create();
117393 + walk_use_def(visited, cur_node, cur_node->node);
117394 + pointer_set_destroy(visited);
117395 +}
117396 +
117397 +enum precond {
117398 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
117399 +};
117400 +
117401 +/* 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.
117402 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
117403 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
117404 + * 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.
117405 + */
117406 +static enum precond check_preconditions(struct interesting_node *cur_node)
117407 +{
117408 + bool interesting_conditions[3] = {false, false, false};
117409 +
117410 + set_last_nodes(cur_node);
117411 +
117412 + check_intentional_attribute_ipa(cur_node);
117413 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
117414 + return NO_ATTRIBUTE_SEARCH;
117415 +
117416 + search_interesting_conditions(cur_node, interesting_conditions);
117417 +
117418 + // error code
117419 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
117420 + return NO_ATTRIBUTE_SEARCH;
117421 +
117422 + // unnecessary overflow check
117423 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
117424 + return NO_CHECK_INSERT;
117425 +
117426 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
117427 + return NO_CHECK_INSERT;
117428 +
117429 + return NONE;
117430 +}
117431 +
117432 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
117433 + * 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
117434 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
117435 + */
117436 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
117437 +{
117438 + enum precond ret;
117439 + struct pointer_set_t *visited;
117440 + tree new_node, orig_node = cur_node->node;
117441 +
117442 + ret = check_preconditions(cur_node);
117443 + if (ret == NO_ATTRIBUTE_SEARCH)
117444 + return cnodes;
117445 +
117446 + cnodes = search_overflow_attribute(cnodes, cur_node);
117447 +
117448 + if (ret == NO_CHECK_INSERT)
117449 + return cnodes;
117450 +
117451 + visited = pointer_set_create();
117452 + new_node = expand(visited, caller_node, orig_node);
117453 + pointer_set_destroy(visited);
117454 +
117455 + if (new_node == NULL_TREE)
117456 + return cnodes;
117457 +
117458 + change_orig_node(cur_node, new_node);
117459 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
117460 +
117461 + return cnodes;
117462 +}
117463 +
117464 +// Check visited interesting nodes.
117465 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
117466 +{
117467 + struct interesting_node *cur;
117468 +
117469 + for (cur = head; cur; cur = cur->next) {
117470 + if (!operand_equal_p(node, cur->node, 0))
117471 + continue;
117472 + if (num != cur->num)
117473 + continue;
117474 + if (first_stmt == cur->first_stmt)
117475 + return true;
117476 + }
117477 + return false;
117478 +}
117479 +
117480 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
117481 + 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
117482 + 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
117483 + the intentional_overflow attribute check. They are collected by set_last_nodes().
117484 + num: arg count of a call stmt or 0 when it is a ret
117485 + node: the recursion starts from here, it is a call arg or a return value
117486 + 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.
117487 + intentional_attr_decl: intentional_overflow attribute of the callee function
117488 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
117489 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
117490 + */
117491 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
117492 +{
117493 + struct interesting_node *new_node;
117494 + tree fndecl;
117495 + enum gimple_code code;
117496 +
117497 + gcc_assert(node != NULL_TREE);
117498 + code = gimple_code(first_stmt);
117499 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
117500 +
117501 + if (num == CANNOT_FIND_ARG)
117502 + return head;
117503 +
117504 + if (skip_types(node))
117505 + return head;
117506 +
117507 + if (skip_asm(node))
117508 + return head;
117509 +
117510 + if (is_gimple_call(first_stmt))
117511 + fndecl = gimple_call_fndecl(first_stmt);
117512 + else
117513 + fndecl = current_function_decl;
117514 +
117515 + if (fndecl == NULL_TREE)
117516 + return head;
117517 +
117518 + if (is_in_interesting_node(head, first_stmt, node, num))
117519 + return head;
117520 +
117521 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
117522 +
117523 + new_node->next = NULL;
117524 + new_node->first_stmt = first_stmt;
117525 +#if BUILDING_GCC_VERSION <= 4007
117526 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
117527 +#else
117528 + vec_alloc(new_node->last_nodes, VEC_LEN);
117529 +#endif
117530 + new_node->num = num;
117531 + new_node->node = node;
117532 + new_node->fndecl = fndecl;
117533 + new_node->intentional_attr_decl = MARK_NO;
117534 + new_node->intentional_attr_cur_fndecl = MARK_NO;
117535 + new_node->intentional_mark_from_gimple = asm_stmt;
117536 +
117537 + if (!head)
117538 + return new_node;
117539 +
117540 + new_node->next = head;
117541 + return new_node;
117542 +}
117543 +
117544 +/* 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).
117545 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
117546 + */
117547 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117548 +{
117549 + struct next_cgraph_node *cur_node;
117550 + tree ret = gimple_return_retval(stmt);
117551 +
117552 + if (ret == NULL_TREE)
117553 + return head;
117554 +
117555 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117556 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
117557 + continue;
117558 + if (cur_node->num == 0)
117559 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
117560 + }
117561 +
117562 + return head;
117563 +}
117564 +
117565 +/* 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).
117566 + * If the call stmt is in the next cgraph node list then it's an interesting call.
117567 + */
117568 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117569 +{
117570 + unsigned int argnum;
117571 + tree arg;
117572 + const_tree fndecl;
117573 + struct next_cgraph_node *cur_node;
117574 +
117575 + fndecl = gimple_call_fndecl(stmt);
117576 + if (fndecl == NULL_TREE)
117577 + return head;
117578 +
117579 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117580 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
117581 + continue;
117582 + argnum = get_correct_arg_count(cur_node->num, fndecl);
117583 + gcc_assert(argnum != CANNOT_FIND_ARG);
117584 + if (argnum == 0)
117585 + continue;
117586 +
117587 + arg = gimple_call_arg(stmt, argnum - 1);
117588 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
117589 + }
117590 +
117591 + return head;
117592 +}
117593 +
117594 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
117595 +{
117596 + if (!operand_equal_p(orig_node, node, 0))
117597 + return WRONG_NODE;
117598 + if (skip_types(node))
117599 + return WRONG_NODE;
117600 + return ret_count;
117601 +}
117602 +
117603 +// Get the index of the rhs node in an assignment
117604 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
117605 +{
117606 + const_tree rhs1, rhs2;
117607 + unsigned int ret;
117608 +
117609 + gcc_assert(stmt);
117610 + gcc_assert(is_gimple_assign(stmt));
117611 +
117612 + rhs1 = gimple_assign_rhs1(stmt);
117613 + gcc_assert(rhs1 != NULL_TREE);
117614 +
117615 + switch (gimple_num_ops(stmt)) {
117616 + case 2:
117617 + return check_ops(node, rhs1, 1);
117618 + case 3:
117619 + ret = check_ops(node, rhs1, 1);
117620 + if (ret != WRONG_NODE)
117621 + return ret;
117622 +
117623 + rhs2 = gimple_assign_rhs2(stmt);
117624 + gcc_assert(rhs2 != NULL_TREE);
117625 + return check_ops(node, rhs2, 2);
117626 + default:
117627 + gcc_unreachable();
117628 + }
117629 +}
117630 +
117631 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
117632 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
117633 +{
117634 + unsigned int i;
117635 +
117636 + if (gimple_call_fndecl(stmt) == NULL_TREE)
117637 + return CANNOT_FIND_ARG;
117638 +
117639 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
117640 + tree node;
117641 +
117642 + node = gimple_call_arg(stmt, i);
117643 + if (!operand_equal_p(arg, node, 0))
117644 + continue;
117645 + if (!skip_types(node))
117646 + return i + 1;
117647 + }
117648 +
117649 + return CANNOT_FIND_ARG;
117650 +}
117651 +
117652 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
117653 + * any of return, call or assignment stmts (because of inlining).
117654 + */
117655 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
117656 +{
117657 + use_operand_p use_p;
117658 + imm_use_iterator imm_iter;
117659 + unsigned int argnum;
117660 +
117661 + gcc_assert(TREE_CODE(node) == SSA_NAME);
117662 +
117663 + if (pointer_set_insert(visited, node))
117664 + return head;
117665 +
117666 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117667 + gimple stmt = USE_STMT(use_p);
117668 +
117669 + if (stmt == NULL)
117670 + return head;
117671 + if (is_gimple_debug(stmt))
117672 + continue;
117673 +
117674 + switch (gimple_code(stmt)) {
117675 + case GIMPLE_CALL:
117676 + argnum = find_arg_number_gimple(node, stmt);
117677 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117678 + break;
117679 + case GIMPLE_RETURN:
117680 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
117681 + break;
117682 + case GIMPLE_ASSIGN:
117683 + argnum = get_assign_ops_count(stmt, node);
117684 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117685 + break;
117686 + case GIMPLE_PHI: {
117687 + tree result = gimple_phi_result(stmt);
117688 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
117689 + break;
117690 + }
117691 + case GIMPLE_ASM:
117692 + if (gimple_asm_noutputs(stmt) != 0)
117693 + break;
117694 + if (!is_size_overflow_asm(stmt))
117695 + break;
117696 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
117697 + break;
117698 + case GIMPLE_COND:
117699 + case GIMPLE_SWITCH:
117700 + break;
117701 + default:
117702 + debug_gimple_stmt(stmt);
117703 + gcc_unreachable();
117704 + break;
117705 + }
117706 + }
117707 + return head;
117708 +}
117709 +
117710 +static void remove_size_overflow_asm(gimple stmt)
117711 +{
117712 + gimple_stmt_iterator gsi;
117713 + tree input, output;
117714 +
117715 + if (!is_size_overflow_asm(stmt))
117716 + return;
117717 +
117718 + if (gimple_asm_noutputs(stmt) == 0) {
117719 + gsi = gsi_for_stmt(stmt);
117720 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
117721 + gsi_remove(&gsi, true);
117722 + return;
117723 + }
117724 +
117725 + input = gimple_asm_input_op(stmt, 0);
117726 + output = gimple_asm_output_op(stmt, 0);
117727 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
117728 +}
117729 +
117730 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
117731 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
117732 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
117733 + */
117734 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
117735 +{
117736 + const_tree output;
117737 + struct pointer_set_t *visited;
117738 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
117739 +
117740 + if (!is_size_overflow_asm(stmt))
117741 + return head;
117742 +
117743 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
117744 + intentional_asm = stmt;
117745 +
117746 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
117747 +
117748 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
117749 + return head;
117750 +
117751 + if (gimple_asm_noutputs(stmt) == 0) {
117752 + const_tree input;
117753 +
117754 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
117755 + return head;
117756 +
117757 + input = gimple_asm_input_op(stmt, 0);
117758 + remove_size_overflow_asm(stmt);
117759 + if (is_gimple_constant(TREE_VALUE(input)))
117760 + return head;
117761 + visited = pointer_set_create();
117762 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
117763 + pointer_set_destroy(visited);
117764 + return head;
117765 + }
117766 +
117767 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
117768 + remove_size_overflow_asm(stmt);
117769 +
117770 + visited = pointer_set_create();
117771 + output = gimple_asm_output_op(stmt, 0);
117772 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
117773 + pointer_set_destroy(visited);
117774 + return head;
117775 +}
117776 +
117777 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
117778 + * or a call stmt or a return stmt and store them in the interesting_node list
117779 + */
117780 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
117781 +{
117782 + basic_block bb;
117783 + struct interesting_node *head = NULL;
117784 +
117785 + FOR_ALL_BB_FN(bb, cfun) {
117786 + gimple_stmt_iterator gsi;
117787 +
117788 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117789 + enum gimple_code code;
117790 + gimple stmt = gsi_stmt(gsi);
117791 +
117792 + code = gimple_code(stmt);
117793 +
117794 + if (code == GIMPLE_ASM)
117795 + head = handle_stmt_by_size_overflow_asm(stmt, head);
117796 +
117797 + if (!next_node)
117798 + continue;
117799 + if (code == GIMPLE_CALL)
117800 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
117801 + if (code == GIMPLE_RETURN)
117802 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
117803 + }
117804 + }
117805 + return head;
117806 +}
117807 +
117808 +static void set_current_function_decl(tree fndecl)
117809 +{
117810 + gcc_assert(fndecl != NULL_TREE);
117811 +
117812 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117813 + calculate_dominance_info(CDI_DOMINATORS);
117814 + current_function_decl = fndecl;
117815 +}
117816 +
117817 +static void unset_current_function_decl(void)
117818 +{
117819 + free_dominance_info(CDI_DOMINATORS);
117820 + pop_cfun();
117821 + current_function_decl = NULL_TREE;
117822 +}
117823 +
117824 +static void free_interesting_node(struct interesting_node *head)
117825 +{
117826 + struct interesting_node *cur;
117827 +
117828 + while (head) {
117829 + cur = head->next;
117830 +#if BUILDING_GCC_VERSION <= 4007
117831 + VEC_free(tree, gc, head->last_nodes);
117832 +#else
117833 + vec_free(head->last_nodes);
117834 +#endif
117835 + free(head);
117836 + head = cur;
117837 + }
117838 +}
117839 +
117840 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
117841 +{
117842 + struct visited *new_visited;
117843 +
117844 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
117845 + new_visited->fndecl = cur_node->fndecl;
117846 + new_visited->num = cur_node->num;
117847 + new_visited->next = NULL;
117848 +
117849 + if (!head)
117850 + return new_visited;
117851 +
117852 + new_visited->next = head;
117853 + return new_visited;
117854 +}
117855 +
117856 +/* 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
117857 + * it is a visited function.
117858 + */
117859 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
117860 +{
117861 + struct visited *cur;
117862 +
117863 + if (!head)
117864 + return false;
117865 +
117866 + if (get_stmt_flag(cur_node->first_stmt) != VISITED_STMT)
117867 + return false;
117868 +
117869 + for (cur = head; cur; cur = cur->next) {
117870 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
117871 + continue;
117872 + if (cur_node->num == cur->num)
117873 + return true;
117874 + }
117875 + return false;
117876 +}
117877 +
117878 +static void free_next_cgraph_node(struct next_cgraph_node *head)
117879 +{
117880 + struct next_cgraph_node *cur;
117881 +
117882 + while (head) {
117883 + cur = head->next;
117884 + free(head);
117885 + head = cur;
117886 + }
117887 +}
117888 +
117889 +static void remove_all_size_overflow_asm(void)
117890 +{
117891 + basic_block bb;
117892 +
117893 + FOR_ALL_BB_FN(bb, cfun) {
117894 + gimple_stmt_iterator si;
117895 +
117896 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117897 + remove_size_overflow_asm(gsi_stmt(si));
117898 + }
117899 +}
117900 +
117901 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
117902 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
117903 + * the newly collected interesting functions (they are interesting if there is control flow between
117904 + * the interesting stmts and them).
117905 + */
117906 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
117907 +{
117908 + struct interesting_node *head, *cur_node;
117909 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117910 +
117911 + set_current_function_decl(NODE_DECL(node));
117912 + call_count = 0;
117913 +
117914 + head = collect_interesting_stmts(next_node);
117915 +
117916 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117917 + if (is_visited_function(visited, cur_node))
117918 + continue;
117919 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
117920 + set_stmt_flag(cur_node->first_stmt, VISITED_STMT);
117921 + visited = insert_visited_function(visited, cur_node);
117922 + }
117923 +
117924 + free_interesting_node(head);
117925 + remove_all_size_overflow_asm();
117926 + unset_current_function_decl();
117927 +
117928 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117929 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
117930 +
117931 + free_next_cgraph_node(cnodes_head);
117932 + return visited;
117933 +}
117934 +
117935 +static void free_visited(struct visited *head)
117936 +{
117937 + struct visited *cur;
117938 +
117939 + while (head) {
117940 + cur = head->next;
117941 + free(head);
117942 + head = cur;
117943 + }
117944 +}
117945 +
117946 +// erase the local flag
117947 +static void set_plf_false(void)
117948 +{
117949 + basic_block bb;
117950 +
117951 + FOR_ALL_BB_FN(bb, cfun) {
117952 + gimple_stmt_iterator si;
117953 +
117954 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117955 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117956 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117957 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117958 + }
117959 +}
117960 +
117961 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117962 +static unsigned int search_function(void)
117963 +{
117964 + struct cgraph_node *node;
117965 + struct visited *visited = NULL;
117966 +
117967 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117968 + set_current_function_decl(NODE_DECL(node));
117969 + set_plf_false();
117970 + unset_current_function_decl();
117971 + }
117972 +
117973 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117974 + gcc_assert(cgraph_function_flags_ready);
117975 +#if BUILDING_GCC_VERSION <= 4007
117976 + gcc_assert(node->reachable);
117977 +#endif
117978 +
117979 + visited = handle_function(node, NULL, visited);
117980 + }
117981 +
117982 + free_visited(visited);
117983 + return 0;
117984 +}
117985 +
117986 +#if BUILDING_GCC_VERSION >= 4009
117987 +static const struct pass_data ipa_pass_data = {
117988 +#else
117989 +static struct ipa_opt_pass_d ipa_pass = {
117990 + .pass = {
117991 +#endif
117992 + .type = SIMPLE_IPA_PASS,
117993 + .name = "size_overflow",
117994 +#if BUILDING_GCC_VERSION >= 4008
117995 + .optinfo_flags = OPTGROUP_NONE,
117996 +#endif
117997 +#if BUILDING_GCC_VERSION >= 4009
117998 + .has_gate = false,
117999 + .has_execute = true,
118000 +#else
118001 + .gate = NULL,
118002 + .execute = search_function,
118003 + .sub = NULL,
118004 + .next = NULL,
118005 + .static_pass_number = 0,
118006 +#endif
118007 + .tv_id = TV_NONE,
118008 + .properties_required = 0,
118009 + .properties_provided = 0,
118010 + .properties_destroyed = 0,
118011 + .todo_flags_start = 0,
118012 + .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,
118013 +#if BUILDING_GCC_VERSION < 4009
118014 + },
118015 + .generate_summary = NULL,
118016 + .write_summary = NULL,
118017 + .read_summary = NULL,
118018 +#if BUILDING_GCC_VERSION >= 4006
118019 + .write_optimization_summary = NULL,
118020 + .read_optimization_summary = NULL,
118021 +#endif
118022 + .stmt_fixup = NULL,
118023 + .function_transform_todo_flags_start = 0,
118024 + .function_transform = NULL,
118025 + .variable_transform = NULL,
118026 +#endif
118027 +};
118028 +
118029 +#if BUILDING_GCC_VERSION >= 4009
118030 +namespace {
118031 +class ipa_pass : public ipa_opt_pass_d {
118032 +public:
118033 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118034 + unsigned int execute() { return search_function(); }
118035 +};
118036 +}
118037 +
118038 +static opt_pass *make_ipa_pass(void)
118039 +{
118040 + return new ipa_pass();
118041 +}
118042 +#else
118043 +static struct opt_pass *make_ipa_pass(void)
118044 +{
118045 + return &ipa_pass.pass;
118046 +}
118047 +#endif
118048 +
118049 +// data for the size_overflow asm stmt
118050 +struct asm_data {
118051 + gimple def_stmt;
118052 + tree input;
118053 + tree output;
118054 +};
118055 +
118056 +#if BUILDING_GCC_VERSION <= 4007
118057 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
118058 +#else
118059 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
118060 +#endif
118061 +{
118062 + tree list;
118063 +#if BUILDING_GCC_VERSION <= 4007
118064 + VEC(tree, gc) *vec_list = NULL;
118065 +#else
118066 + vec<tree, va_gc> *vec_list = NULL;
118067 +#endif
118068 +
118069 + list = build_tree_list(NULL_TREE, string);
118070 + list = chainon(NULL_TREE, build_tree_list(list, io));
118071 +#if BUILDING_GCC_VERSION <= 4007
118072 + VEC_safe_push(tree, gc, vec_list, list);
118073 +#else
118074 + vec_safe_push(vec_list, list);
118075 +#endif
118076 + return vec_list;
118077 +}
118078 +
118079 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
118080 +{
118081 + gimple asm_stmt;
118082 + gimple_stmt_iterator gsi;
118083 +#if BUILDING_GCC_VERSION <= 4007
118084 + VEC(tree, gc) *input, *output = NULL;
118085 +#else
118086 + vec<tree, va_gc> *input, *output = NULL;
118087 +#endif
118088 +
118089 + input = create_asm_io_list(str_input, asm_data->input);
118090 +
118091 + if (asm_data->output)
118092 + output = create_asm_io_list(str_output, asm_data->output);
118093 +
118094 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
118095 + gsi = gsi_for_stmt(asm_data->def_stmt);
118096 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
118097 +
118098 + if (asm_data->output)
118099 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
118100 +}
118101 +
118102 +static void replace_call_lhs(const struct asm_data *asm_data)
118103 +{
118104 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
118105 + update_stmt(asm_data->def_stmt);
118106 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
118107 +}
118108 +
118109 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
118110 +{
118111 + enum mark cur_fndecl_attr;
118112 + gimple phi = get_def_stmt(result);
118113 + unsigned int i, n = gimple_phi_num_args(phi);
118114 +
118115 + pointer_set_insert(visited, phi);
118116 + for (i = 0; i < n; i++) {
118117 + tree arg = gimple_phi_arg_def(phi, i);
118118 +
118119 + cur_fndecl_attr = search_intentional(visited, arg);
118120 + if (cur_fndecl_attr != MARK_NO)
118121 + return cur_fndecl_attr;
118122 + }
118123 + return MARK_NO;
118124 +}
118125 +
118126 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
118127 +{
118128 + enum mark cur_fndecl_attr;
118129 + const_tree rhs1, rhs2;
118130 + gimple def_stmt = get_def_stmt(lhs);
118131 +
118132 + rhs1 = gimple_assign_rhs1(def_stmt);
118133 + rhs2 = gimple_assign_rhs2(def_stmt);
118134 +
118135 + cur_fndecl_attr = search_intentional(visited, rhs1);
118136 + if (cur_fndecl_attr != MARK_NO)
118137 + return cur_fndecl_attr;
118138 + return search_intentional(visited, rhs2);
118139 +}
118140 +
118141 +// Look up the intentional_overflow attribute on the caller and the callee functions.
118142 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
118143 +{
118144 + const_gimple def_stmt;
118145 +
118146 + if (TREE_CODE(lhs) != SSA_NAME)
118147 + return get_intentional_attr_type(lhs);
118148 +
118149 + def_stmt = get_def_stmt(lhs);
118150 + if (!def_stmt)
118151 + return MARK_NO;
118152 +
118153 + if (pointer_set_contains(visited, def_stmt))
118154 + return MARK_NO;
118155 +
118156 + switch (gimple_code(def_stmt)) {
118157 + case GIMPLE_NOP:
118158 + return search_intentional(visited, SSA_NAME_VAR(lhs));
118159 + case GIMPLE_ASM:
118160 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
118161 + return MARK_TURN_OFF;
118162 + return MARK_NO;
118163 + case GIMPLE_CALL:
118164 + return MARK_NO;
118165 + case GIMPLE_PHI:
118166 + return search_intentional_phi(visited, lhs);
118167 + case GIMPLE_ASSIGN:
118168 + switch (gimple_num_ops(def_stmt)) {
118169 + case 2:
118170 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
118171 + case 3:
118172 + return search_intentional_binary(visited, lhs);
118173 + }
118174 + case GIMPLE_RETURN:
118175 + return MARK_NO;
118176 + default:
118177 + debug_gimple_stmt((gimple)def_stmt);
118178 + error("%s: unknown gimple code", __func__);
118179 + gcc_unreachable();
118180 + }
118181 +}
118182 +
118183 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
118184 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
118185 +{
118186 + const_tree fndecl;
118187 + struct pointer_set_t *visited;
118188 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
118189 +
118190 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
118191 + if (is_end_intentional_intentional_attr(fndecl, argnum))
118192 + decl_attr = MARK_NOT_INTENTIONAL;
118193 + else if (is_yes_intentional_attr(fndecl, argnum))
118194 + decl_attr = MARK_YES;
118195 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
118196 + return MARK_TURN_OFF;
118197 + }
118198 +
118199 + visited = pointer_set_create();
118200 + cur_fndecl_attr = search_intentional(visited, arg);
118201 + pointer_set_destroy(visited);
118202 +
118203 + switch (cur_fndecl_attr) {
118204 + case MARK_NO:
118205 + case MARK_TURN_OFF:
118206 + return cur_fndecl_attr;
118207 + default:
118208 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
118209 + return MARK_YES;
118210 + }
118211 +}
118212 +
118213 +static void check_missing_size_overflow_attribute(tree var)
118214 +{
118215 + tree orig_fndecl;
118216 + unsigned int num;
118217 +
118218 + if (is_a_return_check(var))
118219 + orig_fndecl = DECL_ORIGIN(var);
118220 + else
118221 + orig_fndecl = DECL_ORIGIN(current_function_decl);
118222 +
118223 + num = get_function_num(var, orig_fndecl);
118224 + if (num == CANNOT_FIND_ARG)
118225 + return;
118226 +
118227 + is_missing_function(orig_fndecl, num);
118228 +}
118229 +
118230 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
118231 +{
118232 + gimple phi = get_def_stmt(result);
118233 + unsigned int i, n = gimple_phi_num_args(phi);
118234 +
118235 + pointer_set_insert(visited, phi);
118236 + for (i = 0; i < n; i++) {
118237 + tree arg = gimple_phi_arg_def(phi, i);
118238 +
118239 + search_size_overflow_attribute(visited, arg);
118240 + }
118241 +}
118242 +
118243 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
118244 +{
118245 + const_gimple def_stmt = get_def_stmt(lhs);
118246 + tree rhs1, rhs2;
118247 +
118248 + rhs1 = gimple_assign_rhs1(def_stmt);
118249 + rhs2 = gimple_assign_rhs2(def_stmt);
118250 +
118251 + search_size_overflow_attribute(visited, rhs1);
118252 + search_size_overflow_attribute(visited, rhs2);
118253 +}
118254 +
118255 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
118256 +{
118257 + const_gimple def_stmt;
118258 +
118259 + if (TREE_CODE(lhs) == PARM_DECL) {
118260 + check_missing_size_overflow_attribute(lhs);
118261 + return;
118262 + }
118263 +
118264 + def_stmt = get_def_stmt(lhs);
118265 + if (!def_stmt)
118266 + return;
118267 +
118268 + if (pointer_set_insert(visited, def_stmt))
118269 + return;
118270 +
118271 + switch (gimple_code(def_stmt)) {
118272 + case GIMPLE_NOP:
118273 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
118274 + case GIMPLE_ASM:
118275 + return;
118276 + case GIMPLE_CALL: {
118277 + tree fndecl = gimple_call_fndecl(def_stmt);
118278 +
118279 + if (fndecl == NULL_TREE)
118280 + return;
118281 + check_missing_size_overflow_attribute(fndecl);
118282 + return;
118283 + }
118284 + case GIMPLE_PHI:
118285 + return search_size_overflow_attribute_phi(visited, lhs);
118286 + case GIMPLE_ASSIGN:
118287 + switch (gimple_num_ops(def_stmt)) {
118288 + case 2:
118289 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
118290 + case 3:
118291 + return search_size_overflow_attribute_binary(visited, lhs);
118292 + }
118293 + default:
118294 + debug_gimple_stmt((gimple)def_stmt);
118295 + error("%s: unknown gimple code", __func__);
118296 + gcc_unreachable();
118297 + }
118298 +}
118299 +
118300 +// Search missing entries in the hash table (invoked from the gimple pass)
118301 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
118302 +{
118303 + tree fndecl = NULL_TREE;
118304 + tree lhs;
118305 + struct pointer_set_t *visited;
118306 +
118307 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
118308 + return;
118309 +
118310 + if (num == 0) {
118311 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
118312 + lhs = gimple_return_retval(stmt);
118313 + } else {
118314 + gcc_assert(is_gimple_call(stmt));
118315 + lhs = gimple_call_arg(stmt, num - 1);
118316 + fndecl = gimple_call_fndecl(stmt);
118317 + }
118318 +
118319 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
118320 + return;
118321 +
118322 + visited = pointer_set_create();
118323 + search_size_overflow_attribute(visited, lhs);
118324 + pointer_set_destroy(visited);
118325 +}
118326 +
118327 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118328 +{
118329 + gimple_stmt_iterator gsi;
118330 + gimple assign;
118331 +
118332 + assign = gimple_build_assign(asm_data->input, asm_data->output);
118333 + gsi = gsi_for_stmt(stmt);
118334 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
118335 + asm_data->def_stmt = assign;
118336 +
118337 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
118338 + asm_data->output = make_ssa_name(asm_data->output, stmt);
118339 + if (gimple_code(stmt) == GIMPLE_RETURN)
118340 + gimple_return_set_retval(stmt, asm_data->output);
118341 + else
118342 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
118343 + update_stmt(stmt);
118344 +}
118345 +
118346 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
118347 +{
118348 + const char *fn_name;
118349 + char *asm_comment;
118350 + unsigned int len;
118351 +
118352 + if (argnum == 0)
118353 + fn_name = DECL_NAME_POINTER(current_function_decl);
118354 + else
118355 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
118356 +
118357 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
118358 + gcc_assert(len > 0);
118359 +
118360 + return asm_comment;
118361 +}
118362 +
118363 +static const char *convert_mark_to_str(enum mark mark)
118364 +{
118365 + switch (mark) {
118366 + case MARK_NO:
118367 + return OK_ASM_STR;
118368 + case MARK_YES:
118369 + case MARK_NOT_INTENTIONAL:
118370 + return YES_ASM_STR;
118371 + case MARK_TURN_OFF:
118372 + return TURN_OFF_ASM_STR;
118373 + }
118374 +
118375 + gcc_unreachable();
118376 +}
118377 +
118378 +/* Create the input of the size_overflow asm stmt.
118379 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
118380 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118381 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
118382 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
118383 + */
118384 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118385 +{
118386 + if (!asm_data->def_stmt) {
118387 + asm_data->input = NULL_TREE;
118388 + return;
118389 + }
118390 +
118391 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
118392 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
118393 +
118394 + switch (gimple_code(asm_data->def_stmt)) {
118395 + case GIMPLE_ASSIGN:
118396 + case GIMPLE_CALL:
118397 + replace_call_lhs(asm_data);
118398 + break;
118399 + case GIMPLE_PHI:
118400 + create_output_from_phi(stmt, argnum, asm_data);
118401 + break;
118402 + case GIMPLE_NOP: {
118403 + enum mark mark;
118404 + const char *mark_str;
118405 + char *asm_comment;
118406 +
118407 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
118408 +
118409 + asm_data->input = asm_data->output;
118410 + asm_data->output = NULL;
118411 + asm_data->def_stmt = stmt;
118412 +
118413 + mark_str = convert_mark_to_str(mark);
118414 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118415 +
118416 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
118417 + free(asm_comment);
118418 + asm_data->input = NULL_TREE;
118419 + break;
118420 + }
118421 + case GIMPLE_ASM:
118422 + if (is_size_overflow_asm(asm_data->def_stmt)) {
118423 + asm_data->input = NULL_TREE;
118424 + break;
118425 + }
118426 + default:
118427 + debug_gimple_stmt(asm_data->def_stmt);
118428 + gcc_unreachable();
118429 + }
118430 +}
118431 +
118432 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
118433 + * is of the right kind create the appropriate size_overflow asm stmts:
118434 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
118435 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118436 + */
118437 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
118438 +{
118439 + struct asm_data asm_data;
118440 + const char *mark_str;
118441 + char *asm_comment;
118442 + enum mark mark;
118443 +
118444 + if (is_gimple_constant(output_node))
118445 + return;
118446 +
118447 + asm_data.output = output_node;
118448 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
118449 + if (mark != MARK_TURN_OFF)
118450 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
118451 +
118452 + asm_data.def_stmt = get_def_stmt(asm_data.output);
118453 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
118454 + return;
118455 +
118456 + create_asm_input(stmt, argnum, &asm_data);
118457 + if (asm_data.input == NULL_TREE)
118458 + return;
118459 +
118460 + mark_str = convert_mark_to_str(mark);
118461 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118462 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118463 + free(asm_comment);
118464 +}
118465 +
118466 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
118467 +static bool create_mark_asm(gimple stmt, enum mark mark)
118468 +{
118469 + struct asm_data asm_data;
118470 + const char *asm_str;
118471 +
118472 + switch (mark) {
118473 + case MARK_TURN_OFF:
118474 + asm_str = TURN_OFF_ASM_STR;
118475 + break;
118476 + case MARK_NOT_INTENTIONAL:
118477 + case MARK_YES:
118478 + asm_str = YES_ASM_STR;
118479 + break;
118480 + default:
118481 + gcc_unreachable();
118482 + }
118483 +
118484 + asm_data.def_stmt = stmt;
118485 + asm_data.output = gimple_call_lhs(stmt);
118486 +
118487 + if (asm_data.output == NULL_TREE) {
118488 + asm_data.input = gimple_call_arg(stmt, 0);
118489 + if (is_gimple_constant(asm_data.input))
118490 + return false;
118491 + asm_data.output = NULL;
118492 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
118493 + return true;
118494 + }
118495 +
118496 + create_asm_input(stmt, 0, &asm_data);
118497 + gcc_assert(asm_data.input != NULL_TREE);
118498 +
118499 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118500 + return true;
118501 +}
118502 +
118503 +static bool is_from_cast(const_tree node)
118504 +{
118505 + gimple def_stmt = get_def_stmt(node);
118506 +
118507 + if (!def_stmt)
118508 + return false;
118509 +
118510 + if (gimple_assign_cast_p(def_stmt))
118511 + return true;
118512 +
118513 + return false;
118514 +}
118515 +
118516 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
118517 +static bool skip_ptr_minus(gimple stmt)
118518 +{
118519 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
118520 +
118521 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
118522 + return false;
118523 +
118524 + rhs1 = gimple_assign_rhs1(stmt);
118525 + if (!is_from_cast(rhs1))
118526 + return false;
118527 +
118528 + rhs2 = gimple_assign_rhs2(stmt);
118529 + if (!is_from_cast(rhs2))
118530 + return false;
118531 +
118532 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
118533 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
118534 +
118535 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
118536 + return false;
118537 +
118538 + create_mark_asm(stmt, MARK_YES);
118539 + return true;
118540 +}
118541 +
118542 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
118543 +{
118544 + gimple def_stmt;
118545 +
118546 + def_stmt = get_def_stmt(lhs);
118547 + if (!def_stmt)
118548 + return;
118549 +
118550 + if (pointer_set_insert(visited, def_stmt))
118551 + return;
118552 +
118553 + switch (gimple_code(def_stmt)) {
118554 + case GIMPLE_NOP:
118555 + case GIMPLE_ASM:
118556 + case GIMPLE_CALL:
118557 + break;
118558 + case GIMPLE_PHI: {
118559 + unsigned int i, n = gimple_phi_num_args(def_stmt);
118560 +
118561 + pointer_set_insert(visited, def_stmt);
118562 +
118563 + for (i = 0; i < n; i++) {
118564 + tree arg = gimple_phi_arg_def(def_stmt, i);
118565 +
118566 + walk_use_def_ptr(visited, arg);
118567 + }
118568 + }
118569 + case GIMPLE_ASSIGN:
118570 + switch (gimple_num_ops(def_stmt)) {
118571 + case 2:
118572 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118573 + return;
118574 + case 3:
118575 + if (skip_ptr_minus(def_stmt))
118576 + return;
118577 +
118578 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118579 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
118580 + return;
118581 + default:
118582 + return;
118583 + }
118584 + default:
118585 + debug_gimple_stmt((gimple)def_stmt);
118586 + error("%s: unknown gimple code", __func__);
118587 + gcc_unreachable();
118588 + }
118589 +}
118590 +
118591 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
118592 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
118593 +{
118594 + struct pointer_set_t *visited;
118595 +
118596 + visited = pointer_set_create();
118597 + walk_use_def_ptr(visited, arg);
118598 + pointer_set_destroy(visited);
118599 +}
118600 +
118601 +// Determine the return value and insert the asm stmt to mark the return stmt.
118602 +static void insert_asm_ret(gimple stmt)
118603 +{
118604 + tree ret;
118605 +
118606 + ret = gimple_return_retval(stmt);
118607 + create_size_overflow_asm(stmt, ret, 0);
118608 +}
118609 +
118610 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
118611 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
118612 +{
118613 + tree arg;
118614 + unsigned int argnum;
118615 +
118616 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
118617 + gcc_assert(argnum != 0);
118618 + if (argnum == CANNOT_FIND_ARG)
118619 + return;
118620 +
118621 + arg = gimple_call_arg(stmt, argnum - 1);
118622 + gcc_assert(arg != NULL_TREE);
118623 +
118624 + // skip all ptr - ptr expressions
118625 + insert_mark_not_intentional_asm_at_ptr(arg);
118626 +
118627 + create_size_overflow_asm(stmt, arg, argnum);
118628 +}
118629 +
118630 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
118631 +static void set_argnum_attribute(const_tree attr, bool *argnums)
118632 +{
118633 + unsigned int argnum;
118634 + tree attr_value;
118635 +
118636 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
118637 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
118638 + argnums[argnum] = true;
118639 + }
118640 +}
118641 +
118642 +// If a function arg or the return value is in the hash table then set its index in the array.
118643 +static void set_argnum_hash(tree fndecl, bool *argnums)
118644 +{
118645 + unsigned int num;
118646 + const struct size_overflow_hash *hash;
118647 +
118648 + hash = get_function_hash(DECL_ORIGIN(fndecl));
118649 + if (!hash)
118650 + return;
118651 +
118652 + for (num = 0; num <= MAX_PARAM; num++) {
118653 + if (!(hash->param & (1U << num)))
118654 + continue;
118655 +
118656 + argnums[num] = true;
118657 + }
118658 +}
118659 +
118660 +static bool is_all_the_argnums_empty(bool *argnums)
118661 +{
118662 + unsigned int i;
118663 +
118664 + for (i = 0; i <= MAX_PARAM; i++)
118665 + if (argnums[i])
118666 + return false;
118667 + return true;
118668 +}
118669 +
118670 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
118671 +static void search_interesting_args(tree fndecl, bool *argnums)
118672 +{
118673 + const_tree attr;
118674 +
118675 + set_argnum_hash(fndecl, argnums);
118676 + if (!is_all_the_argnums_empty(argnums))
118677 + return;
118678 +
118679 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
118680 + if (attr && TREE_VALUE(attr))
118681 + set_argnum_attribute(attr, argnums);
118682 +}
118683 +
118684 +/*
118685 + * Look up the intentional_overflow attribute that turns off ipa based duplication
118686 + * on the callee function.
118687 + */
118688 +static bool is_mark_turn_off_attribute(gimple stmt)
118689 +{
118690 + enum mark mark;
118691 + const_tree fndecl = gimple_call_fndecl(stmt);
118692 +
118693 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
118694 + if (mark == MARK_TURN_OFF)
118695 + return true;
118696 + return false;
118697 +}
118698 +
118699 +// 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
118700 +static void handle_interesting_function(gimple stmt)
118701 +{
118702 + unsigned int argnum;
118703 + tree fndecl;
118704 + bool orig_argnums[MAX_PARAM + 1] = {false};
118705 +
118706 + if (gimple_call_num_args(stmt) == 0)
118707 + return;
118708 + fndecl = gimple_call_fndecl(stmt);
118709 + if (fndecl == NULL_TREE)
118710 + return;
118711 + fndecl = DECL_ORIGIN(fndecl);
118712 +
118713 + if (is_mark_turn_off_attribute(stmt)) {
118714 + create_mark_asm(stmt, MARK_TURN_OFF);
118715 + return;
118716 + }
118717 +
118718 + search_interesting_args(fndecl, orig_argnums);
118719 +
118720 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
118721 + if (orig_argnums[argnum])
118722 + insert_asm_arg(stmt, argnum);
118723 +}
118724 +
118725 +// 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
118726 +static void handle_interesting_ret(gimple stmt)
118727 +{
118728 + bool orig_argnums[MAX_PARAM + 1] = {false};
118729 +
118730 + search_interesting_args(current_function_decl, orig_argnums);
118731 +
118732 + if (orig_argnums[0])
118733 + insert_asm_ret(stmt);
118734 +}
118735 +
118736 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
118737 +static unsigned int search_interesting_functions(void)
118738 +{
118739 + basic_block bb;
118740 +
118741 + FOR_ALL_BB_FN(bb, cfun) {
118742 + gimple_stmt_iterator gsi;
118743 +
118744 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118745 + gimple stmt = gsi_stmt(gsi);
118746 +
118747 + if (is_size_overflow_asm(stmt))
118748 + continue;
118749 +
118750 + if (is_gimple_call(stmt))
118751 + handle_interesting_function(stmt);
118752 + else if (gimple_code(stmt) == GIMPLE_RETURN)
118753 + handle_interesting_ret(stmt);
118754 + }
118755 + }
118756 + return 0;
118757 +}
118758 +
118759 +/*
118760 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
118761 + * this pass inserts asm stmts to mark the interesting args
118762 + * that the ipa pass will detect and insert the size overflow checks for.
118763 + */
118764 +#if BUILDING_GCC_VERSION >= 4009
118765 +static const struct pass_data insert_size_overflow_asm_pass_data = {
118766 +#else
118767 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
118768 + .pass = {
118769 +#endif
118770 + .type = GIMPLE_PASS,
118771 + .name = "insert_size_overflow_asm",
118772 +#if BUILDING_GCC_VERSION >= 4008
118773 + .optinfo_flags = OPTGROUP_NONE,
118774 +#endif
118775 +#if BUILDING_GCC_VERSION >= 4009
118776 + .has_gate = false,
118777 + .has_execute = true,
118778 +#else
118779 + .gate = NULL,
118780 + .execute = search_interesting_functions,
118781 + .sub = NULL,
118782 + .next = NULL,
118783 + .static_pass_number = 0,
118784 +#endif
118785 + .tv_id = TV_NONE,
118786 + .properties_required = PROP_cfg,
118787 + .properties_provided = 0,
118788 + .properties_destroyed = 0,
118789 + .todo_flags_start = 0,
118790 + .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
118791 +#if BUILDING_GCC_VERSION < 4009
118792 + }
118793 +#endif
118794 +};
118795 +
118796 +#if BUILDING_GCC_VERSION >= 4009
118797 +namespace {
118798 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
118799 +public:
118800 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
118801 + unsigned int execute() { return search_interesting_functions(); }
118802 +};
118803 +}
118804 +
118805 +static opt_pass *make_insert_size_overflow_asm_pass(void)
118806 +{
118807 + return new insert_size_overflow_asm_pass();
118808 +}
118809 +#else
118810 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
118811 +{
118812 + return &insert_size_overflow_asm_pass.pass;
118813 +}
118814 +#endif
118815 +
118816 +// Create the noreturn report_size_overflow() function decl.
118817 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
118818 +{
118819 + tree const_char_ptr_type_node;
118820 + tree fntype;
118821 +
118822 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
118823 +
118824 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
118825 + fntype = build_function_type_list(void_type_node,
118826 + const_char_ptr_type_node,
118827 + unsigned_type_node,
118828 + const_char_ptr_type_node,
118829 + const_char_ptr_type_node,
118830 + NULL_TREE);
118831 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
118832 +
118833 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
118834 + TREE_PUBLIC(report_size_overflow_decl) = 1;
118835 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
118836 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
118837 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
118838 +}
118839 +
118840 +static unsigned int dump_functions(void)
118841 +{
118842 + struct cgraph_node *node;
118843 +
118844 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118845 + basic_block bb;
118846 +
118847 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118848 + current_function_decl = NODE_DECL(node);
118849 +
118850 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118851 +
118852 + FOR_ALL_BB_FN(bb, cfun) {
118853 + gimple_stmt_iterator si;
118854 +
118855 + fprintf(stderr, "<bb %u>:\n", bb->index);
118856 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118857 + debug_gimple_stmt(gsi_stmt(si));
118858 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118859 + debug_gimple_stmt(gsi_stmt(si));
118860 + fprintf(stderr, "\n");
118861 + }
118862 +
118863 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118864 +
118865 + pop_cfun();
118866 + current_function_decl = NULL_TREE;
118867 + }
118868 +
118869 + fprintf(stderr, "###############################################################################\n");
118870 +
118871 + return 0;
118872 +}
118873 +
118874 +#if BUILDING_GCC_VERSION >= 4009
118875 +static const struct pass_data dump_pass_data = {
118876 +#else
118877 +static struct ipa_opt_pass_d dump_pass = {
118878 + .pass = {
118879 +#endif
118880 + .type = SIMPLE_IPA_PASS,
118881 + .name = "dump",
118882 +#if BUILDING_GCC_VERSION >= 4008
118883 + .optinfo_flags = OPTGROUP_NONE,
118884 +#endif
118885 +#if BUILDING_GCC_VERSION >= 4009
118886 + .has_gate = false,
118887 + .has_execute = true,
118888 +#else
118889 + .gate = NULL,
118890 + .execute = dump_functions,
118891 + .sub = NULL,
118892 + .next = NULL,
118893 + .static_pass_number = 0,
118894 +#endif
118895 + .tv_id = TV_NONE,
118896 + .properties_required = 0,
118897 + .properties_provided = 0,
118898 + .properties_destroyed = 0,
118899 + .todo_flags_start = 0,
118900 + .todo_flags_finish = 0,
118901 +#if BUILDING_GCC_VERSION < 4009
118902 + },
118903 + .generate_summary = NULL,
118904 + .write_summary = NULL,
118905 + .read_summary = NULL,
118906 +#if BUILDING_GCC_VERSION >= 4006
118907 + .write_optimization_summary = NULL,
118908 + .read_optimization_summary = NULL,
118909 +#endif
118910 + .stmt_fixup = NULL,
118911 + .function_transform_todo_flags_start = 0,
118912 + .function_transform = NULL,
118913 + .variable_transform = NULL,
118914 +#endif
118915 +};
118916 +
118917 +#if BUILDING_GCC_VERSION >= 4009
118918 +namespace {
118919 +class dump_pass : public ipa_opt_pass_d {
118920 +public:
118921 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118922 + unsigned int execute() { return dump_functions(); }
118923 +};
118924 +}
118925 +
118926 +static opt_pass *make_dump_pass(void)
118927 +{
118928 + return new dump_pass();
118929 +}
118930 +#else
118931 +static struct opt_pass *make_dump_pass(void)
118932 +{
118933 + return &dump_pass.pass;
118934 +}
118935 +#endif
118936 +
118937 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118938 +{
118939 + int i;
118940 + const char * const plugin_name = plugin_info->base_name;
118941 + const int argc = plugin_info->argc;
118942 + const struct plugin_argument * const argv = plugin_info->argv;
118943 + bool enable = true;
118944 + struct register_pass_info insert_size_overflow_asm_pass_info;
118945 + struct register_pass_info __unused dump_before_pass_info;
118946 + struct register_pass_info __unused dump_after_pass_info;
118947 + struct register_pass_info ipa_pass_info;
118948 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
118949 + {
118950 + .base = &report_size_overflow_decl,
118951 + .nelt = 1,
118952 + .stride = sizeof(report_size_overflow_decl),
118953 + .cb = &gt_ggc_mx_tree_node,
118954 + .pchw = &gt_pch_nx_tree_node
118955 + },
118956 + LAST_GGC_ROOT_TAB
118957 + };
118958 +
118959 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
118960 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
118961 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
118962 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118963 +
118964 + dump_before_pass_info.pass = make_dump_pass();
118965 + dump_before_pass_info.reference_pass_name = "increase_alignment";
118966 + dump_before_pass_info.ref_pass_instance_number = 1;
118967 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118968 +
118969 + ipa_pass_info.pass = make_ipa_pass();
118970 + ipa_pass_info.reference_pass_name = "increase_alignment";
118971 + ipa_pass_info.ref_pass_instance_number = 1;
118972 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118973 +
118974 + dump_after_pass_info.pass = make_dump_pass();
118975 + dump_after_pass_info.reference_pass_name = "increase_alignment";
118976 + dump_after_pass_info.ref_pass_instance_number = 1;
118977 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118978 +
118979 + if (!plugin_default_version_check(version, &gcc_version)) {
118980 + error(G_("incompatible gcc/plugin versions"));
118981 + return 1;
118982 + }
118983 +
118984 + for (i = 0; i < argc; ++i) {
118985 + if (!strcmp(argv[i].key, "no-size-overflow")) {
118986 + enable = false;
118987 + continue;
118988 + }
118989 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118990 + }
118991 +
118992 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
118993 + if (enable) {
118994 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
118995 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
118996 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
118997 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
118998 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
118999 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
119000 + }
119001 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
119002 +
119003 + return 0;
119004 +}
119005 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
119006 new file mode 100644
119007 index 0000000..dd94983
119008 --- /dev/null
119009 +++ b/tools/gcc/stackleak_plugin.c
119010 @@ -0,0 +1,376 @@
119011 +/*
119012 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
119013 + * Licensed under the GPL v2
119014 + *
119015 + * Note: the choice of the license means that the compilation process is
119016 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
119017 + * but for the kernel it doesn't matter since it doesn't link against
119018 + * any of the gcc libraries
119019 + *
119020 + * gcc plugin to help implement various PaX features
119021 + *
119022 + * - track lowest stack pointer
119023 + *
119024 + * TODO:
119025 + * - initialize all local variables
119026 + *
119027 + * BUGS:
119028 + * - none known
119029 + */
119030 +
119031 +#include "gcc-common.h"
119032 +
119033 +int plugin_is_GPL_compatible;
119034 +
119035 +static int track_frame_size = -1;
119036 +static const char track_function[] = "pax_track_stack";
119037 +static const char check_function[] = "pax_check_alloca";
119038 +static tree track_function_decl, check_function_decl;
119039 +static bool init_locals;
119040 +
119041 +static struct plugin_info stackleak_plugin_info = {
119042 + .version = "201402131920",
119043 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
119044 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
119045 +};
119046 +
119047 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
119048 +{
119049 + gimple check_alloca;
119050 + tree alloca_size;
119051 +
119052 + // insert call to void pax_check_alloca(unsigned long size)
119053 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
119054 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
119055 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
119056 +}
119057 +
119058 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
119059 +{
119060 + gimple track_stack;
119061 +
119062 + // insert call to void pax_track_stack(void)
119063 + track_stack = gimple_build_call(track_function_decl, 0);
119064 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
119065 +}
119066 +
119067 +static bool is_alloca(gimple stmt)
119068 +{
119069 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
119070 + return true;
119071 +
119072 +#if BUILDING_GCC_VERSION >= 4007
119073 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
119074 + return true;
119075 +#endif
119076 +
119077 + return false;
119078 +}
119079 +
119080 +static unsigned int execute_stackleak_tree_instrument(void)
119081 +{
119082 + basic_block bb, entry_bb;
119083 + bool prologue_instrumented = false, is_leaf = true;
119084 +
119085 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
119086 +
119087 + // 1. loop through BBs and GIMPLE statements
119088 + FOR_EACH_BB_FN(bb, cfun) {
119089 + gimple_stmt_iterator gsi;
119090 +
119091 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119092 + gimple stmt;
119093 +
119094 + stmt = gsi_stmt(gsi);
119095 +
119096 + if (is_gimple_call(stmt))
119097 + is_leaf = false;
119098 +
119099 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
119100 + if (!is_alloca(stmt))
119101 + continue;
119102 +
119103 + // 2. insert stack overflow check before each __builtin_alloca call
119104 + stackleak_check_alloca(&gsi);
119105 +
119106 + // 3. insert track call after each __builtin_alloca call
119107 + stackleak_add_instrumentation(&gsi);
119108 + if (bb == entry_bb)
119109 + prologue_instrumented = true;
119110 + }
119111 + }
119112 +
119113 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
119114 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
119115 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
119116 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
119117 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
119118 + return 0;
119119 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
119120 + return 0;
119121 +
119122 + // 4. insert track call at the beginning
119123 + if (!prologue_instrumented) {
119124 + gimple_stmt_iterator gsi;
119125 +
119126 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119127 + if (dom_info_available_p(CDI_DOMINATORS))
119128 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119129 + gsi = gsi_start_bb(bb);
119130 + stackleak_add_instrumentation(&gsi);
119131 + }
119132 +
119133 + return 0;
119134 +}
119135 +
119136 +static unsigned int execute_stackleak_final(void)
119137 +{
119138 + rtx insn, next;
119139 +
119140 + if (cfun->calls_alloca)
119141 + return 0;
119142 +
119143 + // keep calls only if function frame is big enough
119144 + if (get_frame_size() >= track_frame_size)
119145 + return 0;
119146 +
119147 + // 1. find pax_track_stack calls
119148 + for (insn = get_insns(); insn; insn = next) {
119149 + // 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))
119150 + rtx body;
119151 +
119152 + next = NEXT_INSN(insn);
119153 + if (!CALL_P(insn))
119154 + continue;
119155 + body = PATTERN(insn);
119156 + if (GET_CODE(body) != CALL)
119157 + continue;
119158 + body = XEXP(body, 0);
119159 + if (GET_CODE(body) != MEM)
119160 + continue;
119161 + body = XEXP(body, 0);
119162 + if (GET_CODE(body) != SYMBOL_REF)
119163 + continue;
119164 +// if (strcmp(XSTR(body, 0), track_function))
119165 + if (SYMBOL_REF_DECL(body) != track_function_decl)
119166 + continue;
119167 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
119168 + // 2. delete call
119169 + delete_insn_and_edges(insn);
119170 +#if BUILDING_GCC_VERSION >= 4007
119171 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
119172 + insn = next;
119173 + next = NEXT_INSN(insn);
119174 + delete_insn_and_edges(insn);
119175 + }
119176 +#endif
119177 + }
119178 +
119179 +// print_simple_rtl(stderr, get_insns());
119180 +// print_rtl(stderr, get_insns());
119181 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
119182 +
119183 + return 0;
119184 +}
119185 +
119186 +static bool gate_stackleak_track_stack(void)
119187 +{
119188 + return track_frame_size >= 0;
119189 +}
119190 +
119191 +static void stackleak_start_unit(void *gcc_data, void *user_data)
119192 +{
119193 + tree fntype;
119194 +
119195 + // void pax_track_stack(void)
119196 + fntype = build_function_type_list(void_type_node, NULL_TREE);
119197 + track_function_decl = build_fn_decl(track_function, fntype);
119198 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
119199 + TREE_PUBLIC(track_function_decl) = 1;
119200 + DECL_EXTERNAL(track_function_decl) = 1;
119201 + DECL_ARTIFICIAL(track_function_decl) = 1;
119202 +
119203 + // void pax_check_alloca(unsigned long)
119204 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
119205 + check_function_decl = build_fn_decl(check_function, fntype);
119206 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
119207 + TREE_PUBLIC(check_function_decl) = 1;
119208 + DECL_EXTERNAL(check_function_decl) = 1;
119209 + DECL_ARTIFICIAL(check_function_decl) = 1;
119210 +}
119211 +
119212 +#if BUILDING_GCC_VERSION >= 4009
119213 +static const struct pass_data stackleak_tree_instrument_pass_data = {
119214 +#else
119215 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
119216 + .pass = {
119217 +#endif
119218 + .type = GIMPLE_PASS,
119219 + .name = "stackleak_tree_instrument",
119220 +#if BUILDING_GCC_VERSION >= 4008
119221 + .optinfo_flags = OPTGROUP_NONE,
119222 +#endif
119223 +#if BUILDING_GCC_VERSION >= 4009
119224 + .has_gate = true,
119225 + .has_execute = true,
119226 +#else
119227 + .gate = gate_stackleak_track_stack,
119228 + .execute = execute_stackleak_tree_instrument,
119229 + .sub = NULL,
119230 + .next = NULL,
119231 + .static_pass_number = 0,
119232 +#endif
119233 + .tv_id = TV_NONE,
119234 + .properties_required = PROP_gimple_leh | PROP_cfg,
119235 + .properties_provided = 0,
119236 + .properties_destroyed = 0,
119237 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
119238 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
119239 +#if BUILDING_GCC_VERSION < 4009
119240 + }
119241 +#endif
119242 +};
119243 +
119244 +#if BUILDING_GCC_VERSION >= 4009
119245 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
119246 +#else
119247 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
119248 + .pass = {
119249 +#endif
119250 + .type = RTL_PASS,
119251 + .name = "stackleak_final",
119252 +#if BUILDING_GCC_VERSION >= 4008
119253 + .optinfo_flags = OPTGROUP_NONE,
119254 +#endif
119255 +#if BUILDING_GCC_VERSION >= 4009
119256 + .has_gate = true,
119257 + .has_execute = true,
119258 +#else
119259 + .gate = gate_stackleak_track_stack,
119260 + .execute = execute_stackleak_final,
119261 + .sub = NULL,
119262 + .next = NULL,
119263 + .static_pass_number = 0,
119264 +#endif
119265 + .tv_id = TV_NONE,
119266 + .properties_required = 0,
119267 + .properties_provided = 0,
119268 + .properties_destroyed = 0,
119269 + .todo_flags_start = 0,
119270 + .todo_flags_finish = TODO_dump_func
119271 +#if BUILDING_GCC_VERSION < 4009
119272 + }
119273 +#endif
119274 +};
119275 +
119276 +#if BUILDING_GCC_VERSION >= 4009
119277 +namespace {
119278 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
119279 +public:
119280 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
119281 + bool gate() { return gate_stackleak_track_stack(); }
119282 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
119283 +};
119284 +
119285 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
119286 +public:
119287 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
119288 + bool gate() { return gate_stackleak_track_stack(); }
119289 + unsigned int execute() { return execute_stackleak_final(); }
119290 +};
119291 +}
119292 +
119293 +static opt_pass *make_stackleak_tree_instrument_pass(void)
119294 +{
119295 + return new stackleak_tree_instrument_pass();
119296 +}
119297 +
119298 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
119299 +{
119300 + return new stackleak_final_rtl_opt_pass();
119301 +}
119302 +#else
119303 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
119304 +{
119305 + return &stackleak_tree_instrument_pass.pass;
119306 +}
119307 +
119308 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
119309 +{
119310 + return &stackleak_final_rtl_opt_pass.pass;
119311 +}
119312 +#endif
119313 +
119314 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119315 +{
119316 + const char * const plugin_name = plugin_info->base_name;
119317 + const int argc = plugin_info->argc;
119318 + const struct plugin_argument * const argv = plugin_info->argv;
119319 + int i;
119320 + struct register_pass_info stackleak_tree_instrument_pass_info;
119321 + struct register_pass_info stackleak_final_pass_info;
119322 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
119323 + {
119324 + .base = &track_function_decl,
119325 + .nelt = 1,
119326 + .stride = sizeof(track_function_decl),
119327 + .cb = &gt_ggc_mx_tree_node,
119328 + .pchw = &gt_pch_nx_tree_node
119329 + },
119330 + {
119331 + .base = &check_function_decl,
119332 + .nelt = 1,
119333 + .stride = sizeof(check_function_decl),
119334 + .cb = &gt_ggc_mx_tree_node,
119335 + .pchw = &gt_pch_nx_tree_node
119336 + },
119337 + LAST_GGC_ROOT_TAB
119338 + };
119339 +
119340 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
119341 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
119342 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
119343 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
119344 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119345 +
119346 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
119347 + stackleak_final_pass_info.reference_pass_name = "final";
119348 + stackleak_final_pass_info.ref_pass_instance_number = 1;
119349 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119350 +
119351 + if (!plugin_default_version_check(version, &gcc_version)) {
119352 + error(G_("incompatible gcc/plugin versions"));
119353 + return 1;
119354 + }
119355 +
119356 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
119357 +
119358 + for (i = 0; i < argc; ++i) {
119359 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
119360 + if (!argv[i].value) {
119361 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119362 + continue;
119363 + }
119364 + track_frame_size = atoi(argv[i].value);
119365 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
119366 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119367 + continue;
119368 + }
119369 + if (!strcmp(argv[i].key, "initialize-locals")) {
119370 + if (argv[i].value) {
119371 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119372 + continue;
119373 + }
119374 + init_locals = true;
119375 + continue;
119376 + }
119377 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119378 + }
119379 +
119380 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
119381 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
119382 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
119383 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
119384 +
119385 + return 0;
119386 +}
119387 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
119388 new file mode 100644
119389 index 0000000..4ee2231
119390 --- /dev/null
119391 +++ b/tools/gcc/structleak_plugin.c
119392 @@ -0,0 +1,274 @@
119393 +/*
119394 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
119395 + * Licensed under the GPL v2
119396 + *
119397 + * Note: the choice of the license means that the compilation process is
119398 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
119399 + * but for the kernel it doesn't matter since it doesn't link against
119400 + * any of the gcc libraries
119401 + *
119402 + * gcc plugin to forcibly initialize certain local variables that could
119403 + * otherwise leak kernel stack to userland if they aren't properly initialized
119404 + * by later code
119405 + *
119406 + * Homepage: http://pax.grsecurity.net/
119407 + *
119408 + * Usage:
119409 + * $ # for 4.5/4.6/C based 4.7
119410 + * $ 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
119411 + * $ # for C++ based 4.7/4.8+
119412 + * $ 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
119413 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
119414 + *
119415 + * TODO: eliminate redundant initializers
119416 + * increase type coverage
119417 + */
119418 +
119419 +#include "gcc-common.h"
119420 +
119421 +// unused C type flag in all versions 4.5-4.9
119422 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
119423 +
119424 +int plugin_is_GPL_compatible;
119425 +
119426 +static struct plugin_info structleak_plugin_info = {
119427 + .version = "201401260140",
119428 + .help = "disable\tdo not activate plugin\n",
119429 +};
119430 +
119431 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119432 +{
119433 + *no_add_attrs = true;
119434 +
119435 + // check for types? for now accept everything linux has to offer
119436 + if (TREE_CODE(*node) != FIELD_DECL)
119437 + return NULL_TREE;
119438 +
119439 + *no_add_attrs = false;
119440 + return NULL_TREE;
119441 +}
119442 +
119443 +static struct attribute_spec user_attr = {
119444 + .name = "user",
119445 + .min_length = 0,
119446 + .max_length = 0,
119447 + .decl_required = false,
119448 + .type_required = false,
119449 + .function_type_required = false,
119450 + .handler = handle_user_attribute,
119451 +#if BUILDING_GCC_VERSION >= 4007
119452 + .affects_type_identity = true
119453 +#endif
119454 +};
119455 +
119456 +static void register_attributes(void *event_data, void *data)
119457 +{
119458 + register_attribute(&user_attr);
119459 +// register_attribute(&force_attr);
119460 +}
119461 +
119462 +static tree get_field_type(tree field)
119463 +{
119464 + return strip_array_types(TREE_TYPE(field));
119465 +}
119466 +
119467 +static bool is_userspace_type(tree type)
119468 +{
119469 + tree field;
119470 +
119471 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
119472 + tree fieldtype = get_field_type(field);
119473 + enum tree_code code = TREE_CODE(fieldtype);
119474 +
119475 + if (code == RECORD_TYPE || code == UNION_TYPE)
119476 + if (is_userspace_type(fieldtype))
119477 + return true;
119478 +
119479 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
119480 + return true;
119481 + }
119482 + return false;
119483 +}
119484 +
119485 +static void finish_type(void *event_data, void *data)
119486 +{
119487 + tree type = (tree)event_data;
119488 +
119489 + if (TYPE_USERSPACE(type))
119490 + return;
119491 +
119492 + if (is_userspace_type(type))
119493 + TYPE_USERSPACE(type) = 1;
119494 +}
119495 +
119496 +static void initialize(tree var)
119497 +{
119498 + basic_block bb;
119499 + gimple_stmt_iterator gsi;
119500 + tree initializer;
119501 + gimple init_stmt;
119502 +
119503 + // this is the original entry bb before the forced split
119504 + // TODO: check further BBs in case more splits occured before us
119505 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
119506 +
119507 + // first check if the variable is already initialized, warn otherwise
119508 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119509 + gimple stmt = gsi_stmt(gsi);
119510 + tree rhs1;
119511 +
119512 + // we're looking for an assignment of a single rhs...
119513 + if (!gimple_assign_single_p(stmt))
119514 + continue;
119515 + rhs1 = gimple_assign_rhs1(stmt);
119516 +#if BUILDING_GCC_VERSION >= 4007
119517 + // ... of a non-clobbering expression...
119518 + if (TREE_CLOBBER_P(rhs1))
119519 + continue;
119520 +#endif
119521 + // ... to our variable...
119522 + if (gimple_get_lhs(stmt) != var)
119523 + continue;
119524 + // if it's an initializer then we're good
119525 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
119526 + return;
119527 + }
119528 +
119529 + // these aren't the 0days you're looking for
119530 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
119531 +
119532 + // build the initializer expression
119533 + initializer = build_constructor(TREE_TYPE(var), NULL);
119534 +
119535 + // build the initializer stmt
119536 + init_stmt = gimple_build_assign(var, initializer);
119537 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
119538 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
119539 + update_stmt(init_stmt);
119540 +}
119541 +
119542 +static unsigned int handle_function(void)
119543 +{
119544 + basic_block bb;
119545 + unsigned int ret = 0;
119546 + tree var;
119547 + unsigned int i;
119548 +
119549 + // split the first bb where we can put the forced initializers
119550 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119551 + if (dom_info_available_p(CDI_DOMINATORS))
119552 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119553 +
119554 + // enumarate all local variables and forcibly initialize our targets
119555 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
119556 + tree type = TREE_TYPE(var);
119557 +
119558 + gcc_assert(DECL_P(var));
119559 + if (!auto_var_in_fn_p(var, current_function_decl))
119560 + continue;
119561 +
119562 + // only care about structure types
119563 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
119564 + continue;
119565 +
119566 + // if the type is of interest, examine the variable
119567 + if (TYPE_USERSPACE(type))
119568 + initialize(var);
119569 + }
119570 +
119571 + return ret;
119572 +}
119573 +
119574 +#if BUILDING_GCC_VERSION >= 4009
119575 +static const struct pass_data structleak_pass_data = {
119576 +#else
119577 +static struct gimple_opt_pass structleak_pass = {
119578 + .pass = {
119579 +#endif
119580 + .type = GIMPLE_PASS,
119581 + .name = "structleak",
119582 +#if BUILDING_GCC_VERSION >= 4008
119583 + .optinfo_flags = OPTGROUP_NONE,
119584 +#endif
119585 +#if BUILDING_GCC_VERSION >= 4009
119586 + .has_gate = false,
119587 + .has_execute = true,
119588 +#else
119589 + .gate = NULL,
119590 + .execute = handle_function,
119591 + .sub = NULL,
119592 + .next = NULL,
119593 + .static_pass_number = 0,
119594 +#endif
119595 + .tv_id = TV_NONE,
119596 + .properties_required = PROP_cfg,
119597 + .properties_provided = 0,
119598 + .properties_destroyed = 0,
119599 + .todo_flags_start = 0,
119600 + .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
119601 +#if BUILDING_GCC_VERSION < 4009
119602 + }
119603 +#endif
119604 +};
119605 +
119606 +#if BUILDING_GCC_VERSION >= 4009
119607 +namespace {
119608 +class structleak_pass : public gimple_opt_pass {
119609 +public:
119610 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
119611 + unsigned int execute() { return handle_function(); }
119612 +};
119613 +}
119614 +
119615 +static opt_pass *make_structleak_pass(void)
119616 +{
119617 + return new structleak_pass();
119618 +}
119619 +#else
119620 +static struct opt_pass *make_structleak_pass(void)
119621 +{
119622 + return &structleak_pass.pass;
119623 +}
119624 +#endif
119625 +
119626 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119627 +{
119628 + int i;
119629 + const char * const plugin_name = plugin_info->base_name;
119630 + const int argc = plugin_info->argc;
119631 + const struct plugin_argument * const argv = plugin_info->argv;
119632 + bool enable = true;
119633 + struct register_pass_info structleak_pass_info;
119634 +
119635 + structleak_pass_info.pass = make_structleak_pass();
119636 + structleak_pass_info.reference_pass_name = "ssa";
119637 + structleak_pass_info.ref_pass_instance_number = 1;
119638 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
119639 +
119640 + if (!plugin_default_version_check(version, &gcc_version)) {
119641 + error(G_("incompatible gcc/plugin versions"));
119642 + return 1;
119643 + }
119644 +
119645 + if (strcmp(lang_hooks.name, "GNU C")) {
119646 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
119647 + enable = false;
119648 + }
119649 +
119650 + for (i = 0; i < argc; ++i) {
119651 + if (!strcmp(argv[i].key, "disable")) {
119652 + enable = false;
119653 + continue;
119654 + }
119655 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119656 + }
119657 +
119658 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
119659 + if (enable) {
119660 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
119661 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
119662 + }
119663 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
119664 +
119665 + return 0;
119666 +}
119667 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
119668 index fbc6665..5e9ce79 100644
119669 --- a/tools/include/linux/compiler.h
119670 +++ b/tools/include/linux/compiler.h
119671 @@ -35,4 +35,12 @@
119672 # define unlikely(x) __builtin_expect(!!(x), 0)
119673 #endif
119674
119675 +#ifndef __size_overflow
119676 +# define __size_overflow(...)
119677 +#endif
119678 +
119679 +#ifndef __intentional_overflow
119680 +# define __intentional_overflow(...)
119681 +#endif
119682 +
119683 #endif /* _TOOLS_LINUX_COMPILER_H */
119684 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
119685 index ed2f51e..cc2d8f6 100644
119686 --- a/tools/lib/api/Makefile
119687 +++ b/tools/lib/api/Makefile
119688 @@ -14,7 +14,7 @@ LIB_OBJS += $(OUTPUT)fs/debugfs.o
119689
119690 LIBFILE = libapikfs.a
119691
119692 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119693 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119694 EXTLIBS = -lelf -lpthread -lrt -lm
119695 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
119696 ALL_LDFLAGS = $(LDFLAGS)
119697 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
119698 index 6789d78..4afd019e 100644
119699 --- a/tools/perf/util/include/asm/alternative-asm.h
119700 +++ b/tools/perf/util/include/asm/alternative-asm.h
119701 @@ -5,4 +5,7 @@
119702
119703 #define altinstruction_entry #
119704
119705 + .macro pax_force_retaddr rip=0, reload=0
119706 + .endm
119707 +
119708 #endif
119709 diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
119710 index ce9ed99..8c805a0 100644
119711 --- a/virt/kvm/ioapic.c
119712 +++ b/virt/kvm/ioapic.c
119713 @@ -306,7 +306,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq, bool line_status)
119714 BUG_ON(ioapic->rtc_status.pending_eoi != 0);
119715 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,
119716 ioapic->rtc_status.dest_map);
119717 - ioapic->rtc_status.pending_eoi = ret;
119718 + ioapic->rtc_status.pending_eoi = (ret < 0 ? 0 : ret);
119719 } else
119720 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
119721
119722 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
119723 index 03a0381..8b31923 100644
119724 --- a/virt/kvm/kvm_main.c
119725 +++ b/virt/kvm/kvm_main.c
119726 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
119727
119728 static cpumask_var_t cpus_hardware_enabled;
119729 static int kvm_usage_count = 0;
119730 -static atomic_t hardware_enable_failed;
119731 +static atomic_unchecked_t hardware_enable_failed;
119732
119733 struct kmem_cache *kvm_vcpu_cache;
119734 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
119735
119736 -static __read_mostly struct preempt_ops kvm_preempt_ops;
119737 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
119738 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
119739 +static struct preempt_ops kvm_preempt_ops = {
119740 + .sched_in = kvm_sched_in,
119741 + .sched_out = kvm_sched_out,
119742 +};
119743
119744 struct dentry *kvm_debugfs_dir;
119745
119746 @@ -758,7 +763,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
119747 /* We can read the guest memory with __xxx_user() later on. */
119748 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
119749 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
119750 - !access_ok(VERIFY_WRITE,
119751 + !access_ok_noprefault(VERIFY_WRITE,
119752 (void __user *)(unsigned long)mem->userspace_addr,
119753 mem->memory_size)))
119754 goto out;
119755 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
119756
119757 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
119758 {
119759 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
119760 + int r;
119761 + unsigned long addr;
119762
119763 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
119764 + addr = gfn_to_hva(kvm, gfn);
119765 + if (kvm_is_error_hva(addr))
119766 + return -EFAULT;
119767 + r = __clear_user((void __user *)addr + offset, len);
119768 + if (r)
119769 + return -EFAULT;
119770 + mark_page_dirty(kvm, gfn);
119771 + return 0;
119772 }
119773 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
119774
119775 @@ -1867,7 +1880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
119776 return 0;
119777 }
119778
119779 -static struct file_operations kvm_vcpu_fops = {
119780 +static file_operations_no_const kvm_vcpu_fops __read_only = {
119781 .release = kvm_vcpu_release,
119782 .unlocked_ioctl = kvm_vcpu_ioctl,
119783 #ifdef CONFIG_COMPAT
119784 @@ -2532,7 +2545,7 @@ out:
119785 }
119786 #endif
119787
119788 -static struct file_operations kvm_vm_fops = {
119789 +static file_operations_no_const kvm_vm_fops __read_only = {
119790 .release = kvm_vm_release,
119791 .unlocked_ioctl = kvm_vm_ioctl,
119792 #ifdef CONFIG_COMPAT
119793 @@ -2632,7 +2645,7 @@ out:
119794 return r;
119795 }
119796
119797 -static struct file_operations kvm_chardev_ops = {
119798 +static file_operations_no_const kvm_chardev_ops __read_only = {
119799 .unlocked_ioctl = kvm_dev_ioctl,
119800 .compat_ioctl = kvm_dev_ioctl,
119801 .llseek = noop_llseek,
119802 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
119803
119804 if (r) {
119805 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
119806 - atomic_inc(&hardware_enable_failed);
119807 + atomic_inc_unchecked(&hardware_enable_failed);
119808 printk(KERN_INFO "kvm: enabling virtualization on "
119809 "CPU%d failed\n", cpu);
119810 }
119811 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
119812
119813 kvm_usage_count++;
119814 if (kvm_usage_count == 1) {
119815 - atomic_set(&hardware_enable_failed, 0);
119816 + atomic_set_unchecked(&hardware_enable_failed, 0);
119817 on_each_cpu(hardware_enable_nolock, NULL, 1);
119818
119819 - if (atomic_read(&hardware_enable_failed)) {
119820 + if (atomic_read_unchecked(&hardware_enable_failed)) {
119821 hardware_disable_all_nolock();
119822 r = -EBUSY;
119823 }
119824 @@ -3121,7 +3134,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
119825 kvm_arch_vcpu_put(vcpu);
119826 }
119827
119828 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119829 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119830 struct module *module)
119831 {
119832 int r;
119833 @@ -3168,7 +3181,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119834 if (!vcpu_align)
119835 vcpu_align = __alignof__(struct kvm_vcpu);
119836 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
119837 - 0, NULL);
119838 + SLAB_USERCOPY, NULL);
119839 if (!kvm_vcpu_cache) {
119840 r = -ENOMEM;
119841 goto out_free_3;
119842 @@ -3178,9 +3191,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119843 if (r)
119844 goto out_free;
119845
119846 + pax_open_kernel();
119847 kvm_chardev_ops.owner = module;
119848 kvm_vm_fops.owner = module;
119849 kvm_vcpu_fops.owner = module;
119850 + pax_close_kernel();
119851
119852 r = misc_register(&kvm_dev);
119853 if (r) {
119854 @@ -3190,9 +3205,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119855
119856 register_syscore_ops(&kvm_syscore_ops);
119857
119858 - kvm_preempt_ops.sched_in = kvm_sched_in;
119859 - kvm_preempt_ops.sched_out = kvm_sched_out;
119860 -
119861 r = kvm_init_debug();
119862 if (r) {
119863 printk(KERN_ERR "kvm: create debugfs files failed\n");